diff --git a/Settings.yml b/Settings.yml index 533ac26c..42245306 100644 --- a/Settings.yml +++ b/Settings.yml @@ -16,6 +16,14 @@ interval check: 5 # This is the interval between checks of Autorank (in minutes). # Lowering this number will increase accuracy but will also increase server lag. +use more accurate timings: false +#if it is "true", the plugin will compute the time between every update to add the time elapsed + +enable multiplier command: false +#this will enable the multiplier command. It is useful if there is an event or a special day/hour. +#Usage in game: if you want players to get x2 time, use "/ar multiplier 2". +#If the server is restarted the multiplier is lost. + leaderboard layout: '&6&r | &b&p - &7&d %day%, &h %hour% and &m %minute%.' leaderboard length: 5 # changes the appearance of the /ar leaderboard command diff --git a/src/me/armar/plugins/autorank/commands/MultiplierCommand.java b/src/me/armar/plugins/autorank/commands/MultiplierCommand.java new file mode 100644 index 00000000..d5ac037b --- /dev/null +++ b/src/me/armar/plugins/autorank/commands/MultiplierCommand.java @@ -0,0 +1,69 @@ +package me.armar.plugins.autorank.commands; + +import me.armar.plugins.autorank.Autorank; +import me.armar.plugins.autorank.commands.manager.AutorankCommand; +import me.armar.plugins.autorank.language.Lang; +import me.armar.plugins.autorank.permissions.AutorankPermission; +import me.armar.plugins.autorank.util.AutorankTools; +import me.armar.plugins.autorank.playtimes.PlayTimeManager; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +/** + * The command delegator for the '/ar set' command. + */ +public class MultiplierCommand extends AutorankCommand { + + private final Autorank plugin; + + public MultiplierCommand(final Autorank instance) { + plugin = instance; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + + + if (args.length < 2) { + sender.sendMessage(Lang.INVALID_FORMAT.getConfigValue(this.getUsage())); + return true; + } + + int value = AutorankTools.readTimeInput(args, 1); + + if (value >= 1) { + + if (!this.hasPermission(AutorankPermission.SET_LOCAL_TIME, sender)) { + return true; + } + + if(plugin.getSettingsConfig().multiplierCommandIsEnabled()){ + PlayTimeManager.MULTIPLIER=value; + sender.sendMessage(ChatColor.AQUA + "MULTIPLIER = " + PlayTimeManager.MULTIPLIER); + }else{ + sender.sendMessage(ChatColor.AQUA + "Multipler command is disabled in settings config."); + } + + } else { + AutorankTools.sendColoredMessage(sender, Lang.INVALID_FORMAT.getConfigValue(this.getUsage())); + } + + return true; + } + + @Override + public String getDescription() { + return "Set multiplier's time to [value]."; + } + + @Override + public String getPermission() { + return AutorankPermission.SET_LOCAL_TIME; + } + + @Override + public String getUsage() { + return "/ar multiplier [value]"; + } +} diff --git a/src/me/armar/plugins/autorank/commands/manager/CommandsManager.java b/src/me/armar/plugins/autorank/commands/manager/CommandsManager.java index 073ddfaa..71a51f45 100644 --- a/src/me/armar/plugins/autorank/commands/manager/CommandsManager.java +++ b/src/me/armar/plugins/autorank/commands/manager/CommandsManager.java @@ -73,6 +73,7 @@ public CommandsManager(final Autorank plugin) { registeredCommands.put(Arrays.asList("info"), new InfoCommand(plugin)); registeredCommands.put(Arrays.asList("editor"), new EditorCommand(plugin)); registeredCommands.put(Arrays.asList("migrate"), new MigrateCommand(plugin)); + registeredCommands.put(Arrays.asList("multiplier"), new MultiplierCommand(plugin)); } /** diff --git a/src/me/armar/plugins/autorank/config/SettingsConfig.java b/src/me/armar/plugins/autorank/config/SettingsConfig.java index 79b6fbff..d349a53c 100644 --- a/src/me/armar/plugins/autorank/config/SettingsConfig.java +++ b/src/me/armar/plugins/autorank/config/SettingsConfig.java @@ -89,6 +89,14 @@ public int getIntervalTime() { return this.getConfig().getInt("interval check", 5); } + public boolean useMoreAccurateTimings() { + return this.getConfig().getBoolean("use more accurate timings", false); + } + + public boolean multiplierCommandIsEnabled() { + return this.getConfig().getBoolean("enable multiplier command", false); + } + /** * Get the layout of the leaderboards. * diff --git a/src/me/armar/plugins/autorank/playtimes/PlayTimeManager.java b/src/me/armar/plugins/autorank/playtimes/PlayTimeManager.java index 76bd7741..73fcb548 100644 --- a/src/me/armar/plugins/autorank/playtimes/PlayTimeManager.java +++ b/src/me/armar/plugins/autorank/playtimes/PlayTimeManager.java @@ -28,6 +28,8 @@ public class PlayTimeManager { // How often do we check whether a player is still online? (in minutes) public static int INTERVAL_MINUTES = 5; + //Mutiplier, can be changed in game by command if "enable multiplier command" is true + public static int MULTIPLIER = 1; private final Autorank plugin; diff --git a/src/me/armar/plugins/autorank/playtimes/UpdateTimePlayedTask.java b/src/me/armar/plugins/autorank/playtimes/UpdateTimePlayedTask.java index edc0727f..0ed0b163 100644 --- a/src/me/armar/plugins/autorank/playtimes/UpdateTimePlayedTask.java +++ b/src/me/armar/plugins/autorank/playtimes/UpdateTimePlayedTask.java @@ -26,6 +26,8 @@ public UpdateTimePlayedTask(Autorank instance, UUID uuid) { public void run() { Player player = plugin.getServer().getPlayer(uuid); + long lastPlayTimeUpdate=plugin.getTaskManager().getLastPlayTimeUpdate(uuid); + int timeToAdd; // Cancel task as player is not online anymore. if (player == null || !player.isOnline()) { @@ -55,9 +57,18 @@ public void run() { return; } + + if(plugin.getSettingsConfig().useMoreAccurateTimings()){ + //This compute the time elapsed between the last update and the current update. + timeToAdd=(int)Math.round((System.currentTimeMillis()-lastPlayTimeUpdate)/60000f*PlayTimeManager.MULTIPLIER); + }else{ + //Multiply by 1 doesn't affect the performance + timeToAdd=PlayTimeManager.INTERVAL_MINUTES*PlayTimeManager.MULTIPLIER; + } + // Add time to a player's current time for all storage providers. for (final TimeType type : TimeType.values()) { - plugin.getPlayTimeStorageManager().addPlayerTime(type, uuid, PlayTimeManager.INTERVAL_MINUTES); + plugin.getPlayTimeStorageManager().addPlayerTime(type, uuid, timeToAdd); } // Auto assign path (if possible) diff --git a/src/me/armar/plugins/autorank/tasks/TaskManager.java b/src/me/armar/plugins/autorank/tasks/TaskManager.java index 3809fc44..beaba4d3 100644 --- a/src/me/armar/plugins/autorank/tasks/TaskManager.java +++ b/src/me/armar/plugins/autorank/tasks/TaskManager.java @@ -35,6 +35,7 @@ public void startUpdatePlayTimeTask(UUID uuid) { new UpdateTimePlayedTask(plugin, uuid) , PlayTimeManager.INTERVAL_MINUTES * AutorankTools.TICKS_PER_MINUTE, PlayTimeManager .INTERVAL_MINUTES * AutorankTools.TICKS_PER_MINUTE); + // Store taskID so we can refer to it later. updatePlayTimeTaskIds.put(uuid, task.getTaskId());