diff --git a/src/main/java/me/despical/kotl/ConfigPreferences.java b/src/main/java/me/despical/kotl/ConfigPreferences.java index 105eec7..fd99f10 100644 --- a/src/main/java/me/despical/kotl/ConfigPreferences.java +++ b/src/main/java/me/despical/kotl/ConfigPreferences.java @@ -86,6 +86,7 @@ public enum Option { REMOVE_COOLDOWN_ON_LEAVE("King-Settings.Remove-Cooldown-On.Leave", false), COOLDOWN_WHEN_ALONE("King-Settings.Cooldown-When-Alone", false), SHOW_COOLDOWN_ON_REJOIN("King-Settings.Show-Cooldown-If-Rejoin"), + RESET_COOLDOWNS_ON_NEW_KING("King-Settings.Reset-Cooldowns-On-New-King"), APPLY_KING_DELAY_BAR("King-Settings.Apply-Cooldown-Bar"), UPDATE_GAME_MODE((config) -> !config.getStringList("Inventory-Manager.Do-Not-Restore").contains("game-mode")), UPDATE_HUNGER((config) -> !config.getStringList("Inventory-Manager.Do-Not-Restore").contains("hunger")), diff --git a/src/main/java/me/despical/kotl/api/StatsStorage.java b/src/main/java/me/despical/kotl/api/StatsStorage.java index 2020f96..72e5afd 100644 --- a/src/main/java/me/despical/kotl/api/StatsStorage.java +++ b/src/main/java/me/despical/kotl/api/StatsStorage.java @@ -79,7 +79,10 @@ public static int getUserStats(Player player, StatisticType statisticType) { } public enum StatisticType { - TOURS_PLAYED("toursplayed"), SCORE("score"); + + TOURS_PLAYED("toursplayed"), + SCORE("score"), + LOCAL_RESET_COOLDOWN("local_reset_cooldown", false); final String name; final boolean persistent; diff --git a/src/main/java/me/despical/kotl/events/ArenaEvents.java b/src/main/java/me/despical/kotl/events/ArenaEvents.java index b92df85..7615dca 100644 --- a/src/main/java/me/despical/kotl/events/ArenaEvents.java +++ b/src/main/java/me/despical/kotl/events/ArenaEvents.java @@ -38,6 +38,8 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitRunnable; +import java.util.HashSet; + /** * @author Despical *

@@ -88,6 +90,13 @@ public void onInteractWithPlate(PlayerInteractEvent event) { arena.setKing(player.getName()); + if (plugin.getOption(ConfigPreferences.Option.RESET_COOLDOWNS_ON_NEW_KING)) { + var players = new HashSet<>(arena.getPlayers()); + players.remove(player); + + players.stream().map(plugin.getUserManager()::getUser).forEach(pUser -> pUser.setStat(StatsStorage.StatisticType.LOCAL_RESET_COOLDOWN, 1)); + } + chatManager.broadcastAction(arena, player, ActionType.NEW_KING); user.addStat(StatsStorage.StatisticType.SCORE, 1); diff --git a/src/main/java/me/despical/kotl/util/Utils.java b/src/main/java/me/despical/kotl/util/Utils.java index b3b6af0..2d65b37 100644 --- a/src/main/java/me/despical/kotl/util/Utils.java +++ b/src/main/java/me/despical/kotl/util/Utils.java @@ -2,6 +2,7 @@ import me.despical.kotl.ConfigPreferences; import me.despical.kotl.Main; +import me.despical.kotl.api.StatsStorage; import me.despical.kotl.user.User; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -31,6 +32,14 @@ public static void applyActionBarCooldown(User user, int seconds) { @Override public void run() { + if (user.getStat(StatsStorage.StatisticType.LOCAL_RESET_COOLDOWN) == 1) { + cancel(); + + user.setCooldown("king", 0); + user.setStat(StatsStorage.StatisticType.LOCAL_RESET_COOLDOWN, 0); + return; + } + final var arena = user.getArena(); user.setCooldown("king", seconds - Math.ceil(ticks / 20D)); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f0611b8..6eab5b6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -54,6 +54,9 @@ King-Settings: # Should we show the cooldown bar if player has cooldown and rejoins the arena again? Show-Cooldown-If-Rejoin: true + # Should we reset players' cooldown, other than new king, when someone becomes king? + Reset-Cooldowns-On-New-King: true + Remove-Cooldown-On: # Should we remove player's becoming king cooldown when they join an arena, if they have? Join: false