diff --git a/config.yml b/config.yml index 98662e7d..196a4687 100644 --- a/config.yml +++ b/config.yml @@ -37,7 +37,7 @@ postCommandErrors: true ## Enables / disables debug messages in the console, could be useful to figure out where errors come from debug: false ## Version of the config, do not change! -version: 2.1.0 +version: 2.1.1 # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/plugin.yml b/plugin.yml index 3efca4bb..da668d27 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: AreaShop main: nl.evolutioncoding.areashop.AreaShop -version: 2.1.0 +version: 2.1.1 depend: [Vault, WorldGuard, WorldEdit] softdepend: [Multiverse-Core] author: NLThijs48 diff --git a/src/nl/evolutioncoding/areashop/FileManager.java b/src/nl/evolutioncoding/areashop/FileManager.java index 5bf647e0..387f6542 100644 --- a/src/nl/evolutioncoding/areashop/FileManager.java +++ b/src/nl/evolutioncoding/areashop/FileManager.java @@ -479,6 +479,29 @@ public void run() { }.runTaskTimer(plugin, 1, 1); } + /** + * Update regions in a task to minimize lag + * @param regions Regions to update + */ + public void updateRegions(final List regions) { + new BukkitRunnable() { + private int current = 0; + @Override + public void run() { + for(int i=0; i= regions.size()) { + this.cancel(); + } + } + }.runTaskTimer(plugin, 1, 1); + } + /** * Save the group file to disk */ diff --git a/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java b/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java index a45fd4eb..d8292495 100644 --- a/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java +++ b/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java @@ -67,13 +67,17 @@ public void execute(CommandSender sender, Command command, String[] args) { } ArrayList namesSuccess = new ArrayList(); ArrayList namesFailed = new ArrayList(); + ArrayList toUpdate = new ArrayList(); for(GeneralRegion region : regions) { if(group.addMember(region)) { namesSuccess.add(region.getName()); + toUpdate.add(region); } else { namesFailed.add(region.getName()); } } + // Update all regions, this does it in a task, updating them without lag + plugin.getFileManager().updateRegions(toUpdate); if(namesSuccess.size() != 0) { plugin.message(player, "groupadd-weSuccess", group.getName(), Utils.createCommaSeparatedList(namesSuccess)); } @@ -88,6 +92,8 @@ public void execute(CommandSender sender, Command command, String[] args) { return; } if(group.addMember(region)) { + region.updateRegionFlags(); + region.updateSigns(); plugin.message(sender, "groupadd-success", region.getName(), group.getName(), group.getMembers().size()); } else { plugin.message(sender, "groupadd-failed", region.getName(), group.getName()); diff --git a/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java b/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java index a4ef455f..43860276 100644 --- a/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java +++ b/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java @@ -67,13 +67,17 @@ public void execute(CommandSender sender, Command command, String[] args) { } ArrayList namesSuccess = new ArrayList(); ArrayList namesFailed = new ArrayList(); + ArrayList toUpdate = new ArrayList(); for(GeneralRegion region : regions) { - if(group.removeMember(region)) { + if(group.addMember(region)) { namesSuccess.add(region.getName()); + toUpdate.add(region); } else { namesFailed.add(region.getName()); } } + // Update all regions, this does it in a task, updating them without lag + plugin.getFileManager().updateRegions(toUpdate); if(namesSuccess.size() != 0) { plugin.message(player, "groupdel-weSuccess", group.getName(), Utils.createCommaSeparatedList(namesSuccess)); } @@ -88,6 +92,8 @@ public void execute(CommandSender sender, Command command, String[] args) { return; } if(group.removeMember(region)) { + region.updateRegionFlags(); + region.updateSigns(); plugin.message(sender, "groupdel-success", region.getName(), group.getName(), group.getMembers().size()); } else { plugin.message(sender, "groupdel-failed", region.getName(), group.getName());