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.
This commit is contained in:
Andreas Troelsen 2018-06-11 23:52:47 +02:00
parent a2e235e77a
commit 2ca5e447c0
2 changed files with 30 additions and 0 deletions

View File

@ -28,6 +28,7 @@ public class ArenaClass
private Thing helmet, chestplate, leggings, boots, offhand;
private List<Thing> armor;
private List<Thing> items;
private List<Thing> effects;
private Map<String,Boolean> perms;
private Map<String,Boolean> 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<Thing> armor) {
this.armor = armor;
}
public void setEffects(List<Thing> 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));
}
/**

View File

@ -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<String> 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<Thing> 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<String> perms = section.getStringList("permissions");
if (perms.isEmpty()) return;