From 2ca5e447c0bbd389af0f6e0c026e27d80ac59345 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Mon, 11 Jun 2018 23:52:47 +0200 Subject: [PATCH] Add support for dedicated potion effect node in classes. This makes it a little less awkward to add potion effects to a class, giving them their own node instead of having to "share" with the items node. --- .../com/garbagemule/MobArena/ArenaClass.java | 9 ++++++++ .../garbagemule/MobArena/ArenaMasterImpl.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/com/garbagemule/MobArena/ArenaClass.java b/src/main/java/com/garbagemule/MobArena/ArenaClass.java index 068cc95..dad68a4 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaClass.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaClass.java @@ -28,6 +28,7 @@ public class ArenaClass private Thing helmet, chestplate, leggings, boots, offhand; private List armor; private List items; + private List effects; private Map perms; private Map lobbyperms; private boolean unbreakableWeapons, unbreakableArmor; @@ -44,6 +45,7 @@ public class ArenaClass this.items = new ArrayList<>(); this.armor = new ArrayList<>(4); + this.effects = new ArrayList<>(); this.perms = new HashMap<>(); this.lobbyperms = new HashMap<>(); @@ -136,6 +138,10 @@ public class ArenaClass public void setArmor(List armor) { this.armor = armor; } + + public void setEffects(List effects) { + this.effects = effects; + } public boolean hasPermission(Player p) { String perm = "mobarena.classes." + configName; @@ -165,6 +171,9 @@ public class ArenaClass if (leggings != null) leggings.giveTo(p); if (boots != null) boots.giveTo(p); if (offhand != null) offhand.giveTo(p); + + // Potion effects + effects.forEach(thing -> thing.giveTo(p)); } /** diff --git a/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java index 4c0974f..f057267 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaMasterImpl.java @@ -331,6 +331,9 @@ public class ArenaMasterImpl implements ArenaMaster // Load armor loadClassArmor(section, arenaClass); + // Load potion effects + loadClassPotionEffects(section, arenaClass); + // Per-class permissions loadClassPermissions(arenaClass, section); loadClassLobbyPermissions(arenaClass, section); @@ -403,6 +406,24 @@ public class ArenaMasterImpl implements ArenaMaster setter.accept(thing); } + private void loadClassPotionEffects(ConfigurationSection section, ArenaClass arenaClass) { + List effects = section.getStringList("effects"); + if (effects == null || effects.isEmpty()) { + String value = section.getString("effects", ""); + effects = Arrays.asList(value.split(",")); + } + + // Prepend "effect:" for the potion effect thing parser + List things = effects.stream() + .map(String::trim) + .map(s -> "effect:" + s) + .map(plugin.getThingManager()::parse) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + arenaClass.setEffects(things); + } + private void loadClassPermissions(ArenaClass arenaClass, ConfigurationSection section) { List perms = section.getStringList("permissions"); if (perms.isEmpty()) return;