From f8bdfba5abbaded9a3c482b7c8cc4cea751e3b72 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 13 Jul 2024 15:22:54 -0500 Subject: [PATCH] Add permission option to equip classes --- .../arena/module/classes/ArenaClass.java | 2 +- .../battleplugins/arena/module/classes/Classes.java | 8 ++++++-- .../classes/{ArenaClasses.java => ClassesConfig.java} | 11 +++++++++-- .../arena/module/classes/ClassesExecutor.java | 7 +++++++ module/classes/src/main/resources/classes.yml | 6 ++++++ 5 files changed, 29 insertions(+), 5 deletions(-) rename module/classes/src/main/java/org/battleplugins/arena/module/classes/{ArenaClasses.java => ClassesConfig.java} (60%) diff --git a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClass.java b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClass.java index 11072699..3b780527 100644 --- a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClass.java +++ b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClass.java @@ -18,7 +18,7 @@ public class ArenaClass implements PostProcessable { @Scoped - private ArenaClasses classes; + private ClassesConfig classes; @ArenaOption(name = "name", description = "The name of the class.", required = true) private String name; diff --git a/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java b/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java index a88cd96d..8fde74df 100644 --- a/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java +++ b/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java @@ -31,7 +31,7 @@ public class Classes implements ArenaModuleInitializer { public static final ArenaOptionType CLASS_EQUIPPING_OPTION = ArenaOptionType.create("class-equipping", BooleanArenaOption::new); public static final ArenaOptionType CLASS_EQUIP_ONLY_SELECTS_OPTION = ArenaOptionType.create("class-equip-only-selects", BooleanArenaOption::new); - private ArenaClasses classes; + private ClassesConfig classes; @EventHandler public void onPostInitialize(BattleArenaPostInitializeEvent event) { @@ -54,7 +54,7 @@ public void onPostInitialize(BattleArenaPostInitializeEvent event) { Configuration classesConfig = YamlConfiguration.loadConfiguration(classesPath.toFile()); try { - this.classes = ArenaConfigParser.newInstance(classesPath, ArenaClasses.class, classesConfig, event.getBattleArena()); + this.classes = ArenaConfigParser.newInstance(classesPath, ClassesConfig.class, classesConfig, event.getBattleArena()); } catch (ParseException e) { ParseException.handle(e); @@ -76,6 +76,10 @@ public ArenaClass getClass(String name) { return this.classes.getClasses().get(name); } + public boolean isRequirePermission() { + return this.classes.isRequirePermission(); + } + public Map getClasses() { return this.classes.getClasses(); } diff --git a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClasses.java b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesConfig.java similarity index 60% rename from module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClasses.java rename to module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesConfig.java index 378b2f18..fdba089e 100644 --- a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ArenaClasses.java +++ b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesConfig.java @@ -8,14 +8,21 @@ import java.util.Map; @DocumentationSource("https://docs.battleplugins.org/books/user-guide/page/classes") -public class ArenaClasses { +public class ClassesConfig { @Scoped BattleArena plugin; + @ArenaOption(name = "require-permission", description = "Whether players need specific permission nodes in order to equip classes.", required = true) + private boolean requirePermission; + @ArenaOption(name = "classes", description = "The classes that will be added to the arena.") private Map classes; + public boolean isRequirePermission() { + return this.requirePermission; + } + public Map getClasses() { - return this.classes; + return this.classes == null ? Map.of() : Map.copyOf(this.classes); } } diff --git a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesExecutor.java b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesExecutor.java index d2417d4a..75469f40 100644 --- a/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesExecutor.java +++ b/module/classes/src/main/java/org/battleplugins/arena/module/classes/ClassesExecutor.java @@ -36,6 +36,13 @@ public void equip(Player player, @Argument(name = "class") ArenaClass arenaClass return; } + if (this.module.isRequirePermission()) { + if (!player.hasPermission("battlearena.classes.equip." + arenaClass.getName().toLowerCase())) { + Messages.NO_PERMISSION.send(player); + return; + } + } + // Ensure that the current competition phase allows class equipping boolean canEquip = arenaPlayer.getCompetition().option(Classes.CLASS_EQUIPPING_OPTION) .map(BooleanArenaOption::isEnabled) diff --git a/module/classes/src/main/resources/classes.yml b/module/classes/src/main/resources/classes.yml index 6e982491..883b81e8 100644 --- a/module/classes/src/main/resources/classes.yml +++ b/module/classes/src/main/resources/classes.yml @@ -7,6 +7,12 @@ # ----------------- config-version: 1.0 # The config version, do not change! +# Whether players need specific permission nodes in order to +# equip classes. If set to true, players will need the permission +# battlearena.classes.equip. to equip the class. +require-permission: true + +# Configuration for classes classes: warrior: name: Warrior