Added updating regions at plugin startup

Removed the '/as updaterents' and '/as updatebuys' commands, '/as
reload' also updates regions now.
This commit is contained in:
Thijs Wiefferink 2015-02-10 22:57:09 +01:00
parent b0f3bdc560
commit 4e5061ba54
12 changed files with 78 additions and 132 deletions

View File

@ -41,6 +41,9 @@ checkForUpdates: true
useColorsInConsole: false
## Post error messages in the console when a command run from the config fails (from the 'runCommands' section for example)
postCommandErrors: true
## Update all region flags and signs after starting the plugin (uses the 'regionsPerTick' setting from the 'update' section)
## This ensures that changes to the config are directly visible after restarting the server
updateRegionsOnStartup: 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!

View File

@ -31,9 +31,7 @@ help-unrent: "&6/as unrent &7-&r Unrent a region."
help-unrentOwn: "&6/as unrent &7-&r Unrent your own region."
help-sell: "&6/as sell &7-&r Sell a region."
help-sellOwn: "&6/as sell &7-&r Sell your own region."
help-updaterents: "&6/as updaterents &7-&r Update all rent signs and regions."
help-updatebuys: "&6/as updatebuys &7-&r Update all buy signs and regions."
help-reload: "&6/as reload &7-&r Reload the config and languages."
help-reload: "&6/as reload &7-&r Reload all files and update the regions."
help-setrestore: "&6/as setrestore &7-&r Set restoring on/off and choose profile."
help-setprice: "&6/as setprice &7-&r Change the price of a region."
help-setduration: "&6/as setduration &7-&r Change the duration of a rent region."
@ -104,23 +102,18 @@ unrent-other: "The region has been unrented for player %0%."
unrent-expired: "Your rent of %0% has expired."
sell-help: "/as sell [regionname], the region you stand in will be used if not specified."
sell-notRegistered: "The region can't be selled because it is not registered for buying."
sell-notBought: "The region can't be selled because it is not someone's property."
sell-notRegistered: "The region can't be sold because it is not registered for buying."
sell-notBought: "The region can't be sold because it is not someone's property."
sell-sold: "The region has been sold for player %0%."
sell-soldYours: "Your region has been sold."
sell-noPermission: "You don't have permission to sell a region."
sell-noPermissionOther: "You don't have permission to sell another region."
rents-updated: "All signs and regions for renting have been updated."
rents-noPermission: "You don't have permission to update all rent signs and regions."
rents-notUpdated: "Not all signs have been updated, maybe reload fixes it."
buys-updated: "All signs and regions for selling have been updated."
buys-noPermission: "You don't have permission to update all buy signs and regions."
buys-notUpdated: "Not all signs have been updated, maybe reload fixes it."
reload-reloaded: "The config has been reloaded successfully."
reload-noPermission: "You don't have permission to reload the config."
reload-reloaded: "All files have been reloaded successfully."
reload-updateStart: "&7Updating %0% regions at %1% per second."
reload-updateComplete: "&7Updating regions complete."
reload-noPermission: "You don't have permission to reload the config files."
reload-updateCommandChanged: "'/as updaterents' and '/as updatebuys' have been removed, '/as reload' will also update the regions now so use that command instead."
info-help: "/as info <all|rented|forrent|sold|forsale|player|region|nogroup>."
info-noPermission: "You don't have permission to get information about regions."

View File

@ -23,8 +23,6 @@ permissions:
areashop.buy: true
areashop.unrent: true
areashop.info: true
areashop.updaterents: true
areashop.updatebuys: true
areashop.reload: true
areashop.setrestore: true
areashop.setprice: true
@ -88,14 +86,8 @@ permissions:
areashop.info:
description: Allows you check the status of regions and players
default: true
areashop.updaterents:
description: Allows you to update all rent signs and regions
default: op
areashop.updatebuys:
description: Allows you to update all buy signs and regions
default: op
areashop.reload:
description: Allows you to reload the config
description: Allows you to reload the config and update all region flags and signs
default: op
areashop.setrestore:
description: Allows you to change the restore settings

View File

@ -360,6 +360,17 @@ public final class AreaShop extends JavaPlugin {
}
}.runTaskTimer(this, expireWarning, expireWarning);
}
// Update all regions on startup
if(getConfig().getBoolean("updateRegionsOnStartup")) {
new BukkitRunnable() {
@Override
public void run() {
finalPlugin.getFileManager().updateAllRegions();
AreaShop.debug("Updating all regions at startup...");
}
}.runTaskLater(this, 20L);
}
}
/**
@ -506,15 +517,26 @@ public final class AreaShop extends JavaPlugin {
}
/**
* Reload all files of the plugin
* Reload all files of the plugin and update all regions
* confirmationReceiver The CommandSender that should receive confirmation messages, null for nobody
*/
public void reload() {
public void reload(CommandSender confirmationReceiver) {
fileManager.saveRequiredFilesAtOnce();
chatprefix = this.getConfig().getString("chatPrefix");
debug = this.getConfig().getBoolean("debug");
fileManager.loadFiles();
languageManager = new LanguageManager(this);
languageManager.startup();
fileManager.checkRents();
if(confirmationReceiver != null) {
this.message(confirmationReceiver, "reload-reloaded");
}
fileManager.updateAllRegions(confirmationReceiver);
}
/**
* Reload all files of the plugin and update all regions
*/
public void reload() {
reload(null);
}
/**

View File

@ -76,14 +76,14 @@ public class GroupaddCommand extends CommandAreaShop {
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));
}
if(namesFailed.size() != 0) {
plugin.message(player, "groupadd-weFailed", group.getName(), Utils.createCommaSeparatedList(namesFailed));
}
// Update all regions, this does it in a task, updating them without lag
plugin.getFileManager().updateRegions(toUpdate, player);
group.saveRequired();
} else {
GeneralRegion region = plugin.getFileManager().getRegion(args[2]);

View File

@ -76,14 +76,14 @@ public class GroupdelCommand extends CommandAreaShop {
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));
}
if(namesFailed.size() != 0) {
plugin.message(player, "groupdel-weFailed", group.getName(), Utils.createCommaSeparatedList(namesFailed));
}
// Update all regions, this does it in a task, updating them without lag
plugin.getFileManager().updateRegions(toUpdate, player);
group.saveRequired();
} else {
GeneralRegion region = plugin.getFileManager().getRegion(args[2]);

View File

@ -30,8 +30,8 @@ public class ReloadCommand extends CommandAreaShop {
@Override
public void execute(CommandSender sender, Command command, String[] args) {
if(sender.hasPermission("areashop.reload")) {
plugin.reload();
plugin.message(sender, "reload-reloaded");
// Reload the configuration files and update all region flags/signs
plugin.reload(sender);
} else {
plugin.message(sender, "reload-noPermission");
}

View File

@ -1,44 +0,0 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class UpdatebuysCommand extends CommandAreaShop {
public UpdatebuysCommand(AreaShop plugin) {
super(plugin);
}
@Override
public String getCommandStart() {
return "areashop updatebuys";
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.updatebuys")) {
return plugin.getLanguageManager().getLang("help-updatebuys");
}
return null;
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
if(!sender.hasPermission("areashop.updatebuys")) {
plugin.message(sender, "buys-noPermission");
return;
}
plugin.getFileManager().updateBuySignsAndFlags(sender);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
return result;
}
}

View File

@ -1,44 +0,0 @@
package nl.evolutioncoding.areashop.commands;
import java.util.ArrayList;
import java.util.List;
import nl.evolutioncoding.areashop.AreaShop;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class UpdaterentsCommand extends CommandAreaShop {
public UpdaterentsCommand(AreaShop plugin) {
super(plugin);
}
@Override
public String getCommandStart() {
return "areashop updaterents";
}
@Override
public String getHelp(CommandSender target) {
if(target.hasPermission("areashop.updaterents")) {
return plugin.getLanguageManager().getLang("help-updaterents");
}
return null;
}
@Override
public void execute(CommandSender sender, Command command, String[] args) {
if(!sender.hasPermission("areashop.updaterents")) {
plugin.message(sender, "rents-noPermission");
return;
}
plugin.getFileManager().updateRentSignsAndFlags(sender);
}
@Override
public List<String> getTabCompleteList(int toComplete, String[] start, CommandSender sender) {
ArrayList<String> result = new ArrayList<String>();
return result;
}
}

View File

@ -36,8 +36,6 @@ import nl.evolutioncoding.areashop.commands.SetteleportCommand;
import nl.evolutioncoding.areashop.commands.StopresellCommand;
import nl.evolutioncoding.areashop.commands.TeleportCommand;
import nl.evolutioncoding.areashop.commands.UnrentCommand;
import nl.evolutioncoding.areashop.commands.UpdatebuysCommand;
import nl.evolutioncoding.areashop.commands.UpdaterentsCommand;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -71,8 +69,6 @@ public class CommandManager implements CommandExecutor, TabCompleter {
commands.add(new FindCommand(plugin));
commands.add(new ResellCommand(plugin));
commands.add(new StopresellCommand(plugin));
commands.add(new UpdaterentsCommand(plugin));
commands.add(new UpdatebuysCommand(plugin));
commands.add(new SetrestoreCommand(plugin));
commands.add(new SetpriceCommand(plugin));
commands.add(new SetownerCommand(plugin));
@ -140,7 +136,12 @@ public class CommandManager implements CommandExecutor, TabCompleter {
if(!executed && args.length == 0) {
this.showHelp(sender);
} else if(!executed && args.length > 0) {
plugin.message(sender, "cmd-notValid");
// Indicate that the '/as updaterents' and '/as updatebuys' commands are removed
if("updaterents".equalsIgnoreCase(args[0]) || "updatebuys".equalsIgnoreCase(args[0])) {
plugin.message(sender, "reload-updateCommandChanged");
} else {
plugin.message(sender, "cmd-notValid");
}
}
return true;
}

View File

@ -485,12 +485,16 @@ public class FileManager {
* Update regions in a task to minimize lag
* @param regions Regions to update
*/
public void updateRegions(final List<GeneralRegion> regions) {
public void updateRegions(final List<GeneralRegion> regions, final CommandSender confirmationReceiver) {
final int regionsPerTick = plugin.getConfig().getInt("update.regionsPerTick");
if(confirmationReceiver != null) {
plugin.message(confirmationReceiver, "reload-updateStart", regions.size(), regionsPerTick*20);
}
new BukkitRunnable() {
private int current = 0;
@Override
public void run() {
for(int i=0; i<plugin.getConfig().getInt("update.regionsPerTick"); i++) {
for(int i=0; i<regionsPerTick; i++) {
if(current < regions.size()) {
regions.get(current).updateSigns();
regions.get(current).updateRegionFlags();
@ -498,11 +502,27 @@ public class FileManager {
}
}
if(current >= regions.size()) {
if(confirmationReceiver != null) {
plugin.message(confirmationReceiver, "reload-updateComplete");
}
this.cancel();
}
}
}.runTaskTimer(plugin, 1, 1);
}
public void updateRegions(List<GeneralRegion> regions) {
updateRegions(regions, null);
}
/**
* Update all regions, happens in a task to minimize lag
*/
public void updateAllRegions() {
updateRegions(getRegions(), null);
}
public void updateAllRegions(CommandSender confirmationReceiver) {
updateRegions(getRegions(), confirmationReceiver);
}
/**
* Save the group file to disk

View File

@ -30,11 +30,14 @@ public class LanguageManager {
*/
public LanguageManager(AreaShop plugin) {
this.plugin = plugin;
/* Save default language files if not present */
startup();
}
/**
* Save the default language files and open the current and backup language file
*/
public void startup() {
this.saveDefaults();
/* Open current language file */
this.loadLanguage();
}