Skip to content

Commit

Permalink
Fix a bug where regions would not update after added to a group
Browse files Browse the repository at this point in the history
Also applicable for removing regions from a group.
  • Loading branch information
NLthijs48 committed Dec 10, 2014
1 parent b679c49 commit 715bbfd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/nl/evolutioncoding/areashop/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeneralRegion> regions) {
new BukkitRunnable() {
private int current = 0;
@Override
public void run() {
for(int i=0; i<plugin.getConfig().getInt("update.regionsPerTick"); i++) {
if(current < regions.size()) {
regions.get(current).updateSigns();
regions.get(current).updateRegionFlags();
current++;
}
}
if(current >= regions.size()) {
this.cancel();
}
}
}.runTaskTimer(plugin, 1, 1);
}

/**
* Save the group file to disk
*/
Expand Down
6 changes: 6 additions & 0 deletions src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ public void execute(CommandSender sender, Command command, String[] args) {
}
ArrayList<String> namesSuccess = new ArrayList<String>();
ArrayList<String> namesFailed = new ArrayList<String>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<GeneralRegion>();
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));
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ public void execute(CommandSender sender, Command command, String[] args) {
}
ArrayList<String> namesSuccess = new ArrayList<String>();
ArrayList<String> namesFailed = new ArrayList<String>();
ArrayList<GeneralRegion> toUpdate = new ArrayList<GeneralRegion>();
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));
}
Expand All @@ -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());
Expand Down

0 comments on commit 715bbfd

Please sign in to comment.