From 23fd210fd3c8e5e20713c60588a797ff146c6844 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 2 Jan 2019 12:15:41 +0200 Subject: [PATCH] Implement CoolDown for calling level method. --- .../commands/island/IslandLevelCommand.java | 32 ++++++++++++++++--- .../world/bentobox/level/config/Settings.java | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java b/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java index 84cfb3a..b2390a3 100644 --- a/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java +++ b/src/main/java/world/bentobox/level/commands/island/IslandLevelCommand.java @@ -34,17 +34,39 @@ public class IslandLevelCommand extends CompositeCommand { user.sendMessage("general.errors.unknown-player"); return true; } else if (user.getUniqueId().equals(playerUUID) ) { - // Self level request - levelPlugin.calculateIslandLevel(getWorld(), user, user.getUniqueId()); + return this.calculateLevel(user); } else { user.sendMessage("island.level.island-level-is", "[level]", String.valueOf(levelPlugin.getIslandLevel(getWorld(), playerUUID))); return true; } } else { - // Self level request - levelPlugin.calculateIslandLevel(getWorld(), user, user.getUniqueId()); + return this.calculateLevel(user); } - return false; } + + /** + * This method calls island level calculation if it is allowed by cooldown. + * @param user User which island level must be calculated. + * @return True if le + */ + private boolean calculateLevel(User user) + { + int coolDown = this.levelPlugin.getSettings().getLevelWait(); + + if (coolDown > 0 && this.checkCooldown(user, null)) + { + return false; + } + + // Self level request + this.levelPlugin.calculateIslandLevel(getWorld(), user, user.getUniqueId()); + + if (coolDown > 0) + { + this.setCooldown(user.getUniqueId(), null, coolDown); + } + + return true; + } } diff --git a/src/main/java/world/bentobox/level/config/Settings.java b/src/main/java/world/bentobox/level/config/Settings.java index c308317..d0d7952 100644 --- a/src/main/java/world/bentobox/level/config/Settings.java +++ b/src/main/java/world/bentobox/level/config/Settings.java @@ -167,7 +167,7 @@ public class Settings { /** * @return the levelWait */ - private int getLevelWait() { + public final int getLevelWait() { return levelWait; } /**