Fix a bug where regions would not update after added to a group

Also applicable for removing regions from a group.
This commit is contained in:
Thijs Wiefferink 2014-12-10 16:08:52 +01:00
parent b679c49405
commit 715bbfd9e3
5 changed files with 38 additions and 3 deletions

View File

@ -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
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐

View File

@ -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

View File

@ -479,6 +479,29 @@ public class FileManager {
}.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
*/

View File

@ -67,13 +67,17 @@ public class GroupaddCommand extends CommandAreaShop {
}
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));
}
@ -88,6 +92,8 @@ public class GroupaddCommand extends CommandAreaShop {
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());

View File

@ -67,13 +67,17 @@ public class GroupdelCommand extends CommandAreaShop {
}
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));
}
@ -88,6 +92,8 @@ public class GroupdelCommand extends CommandAreaShop {
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());