From c395e315f108d3459c6689acab3bcf84c8af52e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kol=C3=A1=C5=99?= Date: Thu, 3 Aug 2017 19:54:29 +0200 Subject: [PATCH] Add custom potion duration, Add cancel potion effects on warmup cancel option --- plugin/pom.xml | 4 ++-- .../Managers/BoosConfigManager.java | 16 +++++--------- .../Managers/BoosWarmUpManager.java | 21 ++++++++++++------- .../Runnables/BoosWarmUpTimer.java | 4 ++++ plugin/src/main/resources/config.yml | 6 ++++-- plugin/src/main/resources/plugin.yml | 2 +- pom.xml | 2 +- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index e3927d2..f8667b6 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -63,8 +63,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 1.7 + 1.7 diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java index 148ac17..fc08ed7 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java @@ -315,19 +315,13 @@ public class BoosConfigManager { return conf.getString("options.messages.paid_for_command", "Price of &command& was %s and you now have %s"); } - static Map getPotionEffects(String regexCommand, Player player) { + static List getPotionEffects(String regexCommand, Player player) { String group = getCommandGroup(player); - Map result = new HashMap<>(); - List temp = conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion"); - temp.forEach(entry -> { - String[] item; - item = entry.split(","); - if (item.length == 2) { - result.put(item[0], Integer.valueOf(item[1])); - } - }); + return conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion"); + } - return result; + public static boolean getCancelPotionsOnWarmupCancel() { + return conf.getBoolean("options.options.cancel_potions_on_warmup_cancel", false); } public static double getPrice(String regexCommand, Player player) { diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosWarmUpManager.java b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosWarmUpManager.java index 8df5e0d..6788a5f 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosWarmUpManager.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosWarmUpManager.java @@ -6,6 +6,7 @@ import java.util.Timer; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import cz.boosik.boosCooldown.BoosCoolDown; @@ -17,18 +18,24 @@ public class BoosWarmUpManager { private static final ConcurrentHashMap playercommands = new ConcurrentHashMap<>(); private static void applyPotionEffect(Player player, String regexCommand, int warmUpSeconds) { - BoosConfigManager.getPotionEffects(regexCommand, player).forEach((potion, potionStrength) -> { - PotionEffectType effect = PotionEffectType.getByName(potion); - player.addPotionEffect( - effect.createEffect(warmUpSeconds * 20, potionStrength - 1), - true); - }); + for (String potionUnparsed : BoosConfigManager.getPotionEffects(regexCommand, player)) { + String[] potionParsed = potionUnparsed.split(","); + PotionEffectType type = PotionEffectType.getByName(potionParsed[0]); + final int duration = potionParsed.length == 3 ? Integer.valueOf(potionParsed[2]) * 20 : warmUpSeconds * 20; + player.addPotionEffect(new PotionEffect(type, duration, Integer.valueOf(potionParsed[1]) - 1), true); + } } public static void cancelWarmUps(Player player) { Iterator iter = ((Map) playercommands).keySet().iterator(); while (iter.hasNext()) { - if (iter.next().startsWith(player.getUniqueId() + "@")) { + final String key = iter.next(); + if (key.startsWith(player.getUniqueId() + "@")) { + if (BoosConfigManager.getCancelPotionsOnWarmupCancel()) { + for (String potionUnparsed : BoosConfigManager.getPotionEffects(playercommands.get(key).getRegexCommand(), player)) { + player.removePotionEffect(PotionEffectType.getByName(potionUnparsed.split(",")[0])); + } + } killTimer(player); iter.remove(); } diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/Runnables/BoosWarmUpTimer.java b/plugin/src/main/java/cz/boosik/boosCooldown/Runnables/BoosWarmUpTimer.java index 8ddf4bf..95ec750 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/Runnables/BoosWarmUpTimer.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/Runnables/BoosWarmUpTimer.java @@ -53,4 +53,8 @@ public class BoosWarmUpTimer extends TimerTask { } } } + + public String getRegexCommand() { + return regexCommand; + } } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index c002cda..890e860 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -28,6 +28,8 @@ options: cancel_warmup_on_sprint: false #should warmups be canceled when player changes gamemode? cancel_warmup_on_gamemode_change: false + #should potion effects be cancelled when warmups are cancelled? + cancel_potions_on_warmup_cancel: false #should container access be disable during warmups? block_interact_during_warmup: false #should cooldowns be cleared on server restart? @@ -146,10 +148,10 @@ commands: #price of 10 money price: 10.0 limit: 5 - #potion effect and its strength that will affect player for the warmup time (5 seconds here) has to be one from this list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html + #potion effect and its strength and its duration (duration is optional and defaults to warmup duration) that will affect player for the warmup time (5 seconds here) has to be one from this list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html potion: - WEAKNESS,3 - - SLOW,5 + - SLOW,5,10 /test: #message that is sent to player when he uses this command message: You just used /test! diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index 4ec9f2d..e498977 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: boosCooldowns main: cz.boosik.boosCooldown.BoosCoolDown -version: 3.14.0 +version: 3.14.1 authors: [LordBoos (boosik)] softdepend: [Vault, PlayerPoints] description: > diff --git a/pom.xml b/pom.xml index e07bd71..1db754c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ pom http://maven.apache.org - 3.14.0 + 3.14.1 UTF-8 UTF-8 1.12