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:
@@ -28,6 +28,7 @@ public class ArenaClass
|
|||||||
private Thing helmet, chestplate, leggings, boots, offhand;
|
private Thing helmet, chestplate, leggings, boots, offhand;
|
||||||
private List<Thing> armor;
|
private List<Thing> armor;
|
||||||
private List<Thing> items;
|
private List<Thing> items;
|
||||||
|
private List<Thing> effects;
|
||||||
private Map<String,Boolean> perms;
|
private Map<String,Boolean> perms;
|
||||||
private Map<String,Boolean> lobbyperms;
|
private Map<String,Boolean> lobbyperms;
|
||||||
private boolean unbreakableWeapons, unbreakableArmor;
|
private boolean unbreakableWeapons, unbreakableArmor;
|
||||||
@@ -44,6 +45,7 @@ public class ArenaClass
|
|||||||
|
|
||||||
this.items = new ArrayList<>();
|
this.items = new ArrayList<>();
|
||||||
this.armor = new ArrayList<>(4);
|
this.armor = new ArrayList<>(4);
|
||||||
|
this.effects = new ArrayList<>();
|
||||||
this.perms = new HashMap<>();
|
this.perms = new HashMap<>();
|
||||||
this.lobbyperms = new HashMap<>();
|
this.lobbyperms = new HashMap<>();
|
||||||
|
|
||||||
@@ -136,6 +138,10 @@ public class ArenaClass
|
|||||||
public void setArmor(List<Thing> armor) {
|
public void setArmor(List<Thing> armor) {
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEffects(List<Thing> effects) {
|
||||||
|
this.effects = effects;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPermission(Player p) {
|
public boolean hasPermission(Player p) {
|
||||||
String perm = "mobarena.classes." + configName;
|
String perm = "mobarena.classes." + configName;
|
||||||
@@ -165,6 +171,9 @@ public class ArenaClass
|
|||||||
if (leggings != null) leggings.giveTo(p);
|
if (leggings != null) leggings.giveTo(p);
|
||||||
if (boots != null) boots.giveTo(p);
|
if (boots != null) boots.giveTo(p);
|
||||||
if (offhand != null) offhand.giveTo(p);
|
if (offhand != null) offhand.giveTo(p);
|
||||||
|
|
||||||
|
// Potion effects
|
||||||
|
effects.forEach(thing -> thing.giveTo(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -331,6 +331,9 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
// Load armor
|
// Load armor
|
||||||
loadClassArmor(section, arenaClass);
|
loadClassArmor(section, arenaClass);
|
||||||
|
|
||||||
|
// Load potion effects
|
||||||
|
loadClassPotionEffects(section, arenaClass);
|
||||||
|
|
||||||
// Per-class permissions
|
// Per-class permissions
|
||||||
loadClassPermissions(arenaClass, section);
|
loadClassPermissions(arenaClass, section);
|
||||||
loadClassLobbyPermissions(arenaClass, section);
|
loadClassLobbyPermissions(arenaClass, section);
|
||||||
@@ -403,6 +406,24 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
setter.accept(thing);
|
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) {
|
private void loadClassPermissions(ArenaClass arenaClass, ConfigurationSection section) {
|
||||||
List<String> perms = section.getStringList("permissions");
|
List<String> perms = section.getStringList("permissions");
|
||||||
if (perms.isEmpty()) return;
|
if (perms.isEmpty()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user