diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index 112e6ba..17ad4fa 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -57,6 +57,8 @@ import com.tommytony.war.utility.PlayerState; import com.tommytony.war.utility.SizeCounter; import com.tommytony.war.utility.WarLogFormatter; import com.tommytony.war.volume.Volume; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; /** * Main class of War @@ -225,6 +227,7 @@ public class War extends JavaPlugin { teamDefaultConfig.put(TeamConfig.KILLSTREAK, false); teamDefaultConfig.put(TeamConfig.BLOCKWHITELIST, "all"); teamDefaultConfig.put(TeamConfig.PLACEBLOCK, true); + teamDefaultConfig.put(TeamConfig.APPLYPOTION, ""); this.getDefaultInventories().clearLoadouts(); HashMap defaultLoadout = new HashMap(); @@ -1318,4 +1321,23 @@ public class War extends JavaPlugin { public Locale getLoadedLocale() { return messages.getLocale(); } + + /** + * Convert serialized effect to actual effect. + * @param serializedEffect String stored in configuration. + * Format: TYPE:DURATION:AMPLIFY + * @return Potion effect or null otherwise + */ + public PotionEffect getPotionEffect(String serializedEffect) { + String[] arr = serializedEffect.split(":"); + if (arr.length != 3) return null; + try { + PotionEffectType type = PotionEffectType.getByName(arr[0]); + int duration = Integer.parseInt(arr[1]); + int amplification = Integer.parseInt(arr[2]); + return new PotionEffect(type, duration, amplification); + } catch (RuntimeException ex) { + return null; + } + } } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 92337b2..5287c6b 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -36,6 +36,7 @@ import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.permissions.Permissible; +import org.bukkit.potion.PotionEffect; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; @@ -451,6 +452,13 @@ public class Warzone { // clear potion effects PotionEffectHelper.clearPotionEffects(player); + + if (!team.getTeamConfig().getString(TeamConfig.APPLYPOTION).isEmpty()) { + PotionEffect effect = War.war.getPotionEffect(team.getTeamConfig().getString(TeamConfig.APPLYPOTION)); + if (effect != null) { + player.addPotionEffect(effect); + } + } boolean isFirstRespawn = false; if (!this.getLoadoutSelections().keySet().contains(player.getName())) { diff --git a/war/src/main/java/com/tommytony/war/config/TeamConfig.java b/war/src/main/java/com/tommytony/war/config/TeamConfig.java index 222c0d5..807e2de 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamConfig.java +++ b/war/src/main/java/com/tommytony/war/config/TeamConfig.java @@ -17,7 +17,8 @@ public enum TeamConfig { XPKILLMETER (Boolean.class), KILLSTREAK (Boolean.class), BLOCKWHITELIST (String.class), - PLACEBLOCK (Boolean.class); + PLACEBLOCK (Boolean.class), + APPLYPOTION(String.class); private final Class configType;