Skip to content

Commit

Permalink
Added updating regions at plugin startup
Browse files Browse the repository at this point in the history
Removed the '/as updaterents' and '/as updatebuys' commands, '/as
reload' also updates regions now.
  • Loading branch information
NLthijs48 committed Feb 10, 2015
1 parent b0f3bdc commit 4e5061b
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 132 deletions.
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
23 changes: 8 additions & 15 deletions lang/EN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
10 changes: 1 addition & 9 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions src/nl/evolutioncoding/areashop/AreaShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/nl/evolutioncoding/areashop/commands/GroupaddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/nl/evolutioncoding/areashop/commands/GroupdelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/nl/evolutioncoding/areashop/commands/ReloadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
44 changes: 0 additions & 44 deletions src/nl/evolutioncoding/areashop/commands/UpdatebuysCommand.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/nl/evolutioncoding/areashop/commands/UpdaterentsCommand.java

This file was deleted.

11 changes: 6 additions & 5 deletions src/nl/evolutioncoding/areashop/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 22 additions & 2 deletions src/nl/evolutioncoding/areashop/managers/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,24 +485,44 @@ public void run() {
* 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();
current++;
}
}
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
Expand Down
11 changes: 7 additions & 4 deletions src/nl/evolutioncoding/areashop/managers/LanguageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 4e5061b

Please sign in to comment.