diff --git a/config.yml b/config.yml index 2d1657f5..7babe0ae 100644 --- a/config.yml +++ b/config.yml @@ -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! diff --git a/lang/EN.yml b/lang/EN.yml index 351ae557..19cb14cf 100644 --- a/lang/EN.yml +++ b/lang/EN.yml @@ -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 ." info-noPermission: "You don't have permission to get information about regions." diff --git a/plugin.yml b/plugin.yml index 8078f146..186a6bf7 100644 --- a/plugin.yml +++ b/plugin.yml @@ -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 diff --git a/src/nl/evolutioncoding/areashop/AreaShop.java b/src/nl/evolutioncoding/areashop/AreaShop.java index c52d471b..4f46aa79 100644 --- a/src/nl/evolutioncoding/areashop/AreaShop.java +++ b/src/nl/evolutioncoding/areashop/AreaShop.java @@ -360,6 +360,17 @@ public void run() { } }.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 static void debug(String message) { } /** - * 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); } /** diff --git a/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java b/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java index bf23feab..6da8f247 100644 --- a/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java +++ b/src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java @@ -76,14 +76,14 @@ public void execute(CommandSender sender, Command command, String[] args) { 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]); diff --git a/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java b/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java index ec957cd3..5564873f 100644 --- a/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java +++ b/src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java @@ -76,14 +76,14 @@ public void execute(CommandSender sender, Command command, String[] args) { 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]); diff --git a/src/nl/evolutioncoding/areashop/commands/ReloadCommand.java b/src/nl/evolutioncoding/areashop/commands/ReloadCommand.java index b28ceb57..bdac7fab 100644 --- a/src/nl/evolutioncoding/areashop/commands/ReloadCommand.java +++ b/src/nl/evolutioncoding/areashop/commands/ReloadCommand.java @@ -30,8 +30,8 @@ public String getHelp(CommandSender target) { @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"); } diff --git a/src/nl/evolutioncoding/areashop/commands/UpdatebuysCommand.java b/src/nl/evolutioncoding/areashop/commands/UpdatebuysCommand.java deleted file mode 100644 index 3f54c479..00000000 --- a/src/nl/evolutioncoding/areashop/commands/UpdatebuysCommand.java +++ /dev/null @@ -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 getTabCompleteList(int toComplete, String[] start, CommandSender sender) { - ArrayList result = new ArrayList(); - return result; - } -} diff --git a/src/nl/evolutioncoding/areashop/commands/UpdaterentsCommand.java b/src/nl/evolutioncoding/areashop/commands/UpdaterentsCommand.java deleted file mode 100644 index 87b39872..00000000 --- a/src/nl/evolutioncoding/areashop/commands/UpdaterentsCommand.java +++ /dev/null @@ -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 getTabCompleteList(int toComplete, String[] start, CommandSender sender) { - ArrayList result = new ArrayList(); - return result; - } -} diff --git a/src/nl/evolutioncoding/areashop/managers/CommandManager.java b/src/nl/evolutioncoding/areashop/managers/CommandManager.java index 639cce86..d4d0a0fc 100644 --- a/src/nl/evolutioncoding/areashop/managers/CommandManager.java +++ b/src/nl/evolutioncoding/areashop/managers/CommandManager.java @@ -36,8 +36,6 @@ 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 CommandManager(AreaShop plugin) { 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 boolean onCommand(CommandSender sender, Command command, String alias, St 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; } diff --git a/src/nl/evolutioncoding/areashop/managers/FileManager.java b/src/nl/evolutioncoding/areashop/managers/FileManager.java index b88775af..47355675 100644 --- a/src/nl/evolutioncoding/areashop/managers/FileManager.java +++ b/src/nl/evolutioncoding/areashop/managers/FileManager.java @@ -485,12 +485,16 @@ public void run() { * Update regions in a task to minimize lag * @param regions Regions to update */ - public void updateRegions(final List regions) { + public void updateRegions(final List 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= regions.size()) { + if(confirmationReceiver != null) { + plugin.message(confirmationReceiver, "reload-updateComplete"); + } this.cancel(); } } }.runTaskTimer(plugin, 1, 1); } + public void updateRegions(List 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 diff --git a/src/nl/evolutioncoding/areashop/managers/LanguageManager.java b/src/nl/evolutioncoding/areashop/managers/LanguageManager.java index 05b48dbd..5bb1ebe3 100644 --- a/src/nl/evolutioncoding/areashop/managers/LanguageManager.java +++ b/src/nl/evolutioncoding/areashop/managers/LanguageManager.java @@ -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(); }