From 7b9f5b730b18ed459c600165ca27a8ce92632ae0 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 30 Jun 2024 13:01:49 -0500 Subject: [PATCH] More docs and CompetitionListener API --- .../java/org/battleplugins/arena/Arena.java | 126 ++++++++++++++++-- .../org/battleplugins/arena/BattleArena.java | 2 +- .../arena/editor/ArenaEditorWizards.java | 4 +- .../arena/event/CompetitionListener.java | 25 ++++ 4 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 plugin/src/main/java/org/battleplugins/arena/event/CompetitionListener.java diff --git a/plugin/src/main/java/org/battleplugins/arena/Arena.java b/plugin/src/main/java/org/battleplugins/arena/Arena.java index e5bd80f1..4a2c5309 100644 --- a/plugin/src/main/java/org/battleplugins/arena/Arena.java +++ b/plugin/src/main/java/org/battleplugins/arena/Arena.java @@ -106,20 +106,44 @@ public Arena() { // API methods + /** + * Creates a new command executor for this arena. + * + * @return a new command executor for this arena + */ public ArenaCommandExecutor createCommandExecutor() { return new ArenaCommandExecutor(this); } + /** + * Returns the {@link LiveCompetitionMap} type for this arena. + * + * @return the {@link LiveCompetitionMap} type for this arena + */ public Class getCompetitionMapType() { return LiveCompetitionMap.class; } + /** + * Returns whether the given module is enabled for this arena. + * + * @param module the module to check + * @return whether the given module is enabled for this arena + */ public boolean isModuleEnabled(String module) { return this.modules != null && this.modules.contains(module); } // Internal methods (cannot be overridden by extending plugins) + /** + * Creates a new phase for the given competition. + * + * @param type the phase type + * @param competition the competition + * @return the new phase + * @param the type of competition + */ @SuppressWarnings({"rawtypes", "unchecked"}) public final > CompetitionPhase createPhase(CompetitionPhaseType type, C competition) { CompetitionPhaseType.Provider provider = this.phases.get(type); @@ -130,63 +154,151 @@ public final > CompetitionPhase createPhase(Competit return ((CompetitionPhaseType.Provider) provider).create(competition); } + /** + * Gets the {@link CompetitionPhaseType phases} for this arena. + * + * @return the phases for this arena + */ public final Set> getPhases() { return Set.copyOf(this.phases.keySet()); } - public final Path getMapsPath() { + /** + * Gets the path to the map for this arena. + * + * @return the path to the map for this arena + */ + public final Path getMapPath() { return this.plugin.getMapsPath().resolve(this.name.toLowerCase(Locale.ROOT)); } + /** + * Gets the plugin associated with this arena. + * + * @return the plugin associated with this arena + */ public final BattleArena getPlugin() { return this.plugin; } + /** + * Gets the name of this arena. + * + * @return the name of this arena + */ public final String getName() { return this.name; } + /** + * Gets the command aliases for this arena. + * + * @return the aliases for this arena + */ public List getAliases() { return this.aliases == null ? List.of() : List.copyOf(this.aliases); } + /** + * Gets the {@link CompetitionType} for this arena. + * + * @return the competition type for this arena + */ public final CompetitionType getType() { return this.type; } + /** + * Gets the {@link Teams} for this arena. + * + * @return the teams for this arena + */ public final Teams getTeams() { return this.teams; } + /** + * Gets the {@link Lives} for this arena. + * + * @return the lives for this arena + */ + public final Optional lives() { + return Optional.ofNullable(this.lives); + } + + /** + * Gets the {@link Lives} for this arena. + * + * @return the lives for this arena, or null if lives are not enabled + */ @Nullable public final Lives getLives() { return this.lives; } - public final Optional lives() { - return Optional.ofNullable(this.lives); - } - + /** + * Returns whether lives are enabled for this arena. + * + * @return whether lives are enabled for this arena + */ public final boolean isLivesEnabled() { return this.lives != null && this.lives.isEnabled(); } + /** + * Gets the initial {@link CompetitionPhaseType phase} for this arena. + * + * @return the initial phase for this arena + */ public final CompetitionPhaseType getInitialPhase() { return this.initialPhase; } + /** + * Gets the {@link EventAction actions} for this arena. + * + * @return the event actions for this arena + */ public final Map, List> getEventActions() { return this.eventActions; } + /** + * Gets the {@link VictoryConditionType victory conditions} for this arena. + * + * @return the victory conditions for this arena + */ public final Map, VictoryConditionType.Provider> getVictoryConditions() { return this.victoryConditions; } + /** + * Gets the {@link ArenaEventManager} for this arena. + * + * @return the event manager for this arena + */ public final ArenaEventManager getEventManager() { return this.eventManager; } + /** + * Gets the {@link org.battleplugins.arena.options.ArenaOption} of the specified type. + * + * @param type the type of option + * @param the type of option + * @return the option of the specified type + */ + public Optional option(ArenaOptionType type) { + return Optional.ofNullable(this.getOption(type)); + } + + /** + * Gets the {@link org.battleplugins.arena.options.ArenaOption} of the specified type. + * + * @param type the type of option + * @param the type of option + * @return the option of the specified type, or null if the option does not exist + */ @Nullable public final E getOption(ArenaOptionType type) { if (this.options == null) { @@ -196,10 +308,6 @@ public final E getOption return (E) this.options.get(type); } - public Optional option(ArenaOptionType type) { - return Optional.ofNullable(this.getOption(type)); - } - @Override public final Arena getArena() { return this; diff --git a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java index 4af116c0..f5b5f93f 100644 --- a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java +++ b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java @@ -435,7 +435,7 @@ public void removeArenaMap(Arena arena, LiveCompetitionMap map) { } // Now remove the map from the file system - Path mapPath = arena.getMapsPath().resolve(map.getName().toLowerCase(Locale.ROOT) + ".yml"); + Path mapPath = arena.getMapPath().resolve(map.getName().toLowerCase(Locale.ROOT) + ".yml"); try { Files.deleteIfExists(mapPath); } catch (IOException e) { diff --git a/plugin/src/main/java/org/battleplugins/arena/editor/ArenaEditorWizards.java b/plugin/src/main/java/org/battleplugins/arena/editor/ArenaEditorWizards.java index 4c636ab7..fd8f588a 100644 --- a/plugin/src/main/java/org/battleplugins/arena/editor/ArenaEditorWizards.java +++ b/plugin/src/main/java/org/battleplugins/arena/editor/ArenaEditorWizards.java @@ -84,7 +84,7 @@ public final class ArenaEditorWizards { ctx.saveTo(map); - Path mapPath = ctx.getArena().getMapsPath().resolve(map.getName().toLowerCase(Locale.ROOT) + ".yml"); + Path mapPath = ctx.getArena().getMapPath().resolve(map.getName().toLowerCase(Locale.ROOT) + ".yml"); try { FileConfiguration configuration = YamlConfiguration.loadConfiguration(Files.newBufferedReader(mapPath)); @@ -137,7 +137,7 @@ public final class ArenaEditorWizards { BattleArena.getInstance().addCompetition(ctx.getArena(), competition); } - Path mapsPath = ctx.getArena().getMapsPath(); + Path mapsPath = ctx.getArena().getMapPath(); if (Files.notExists(mapsPath)) { try { Files.createDirectories(mapsPath); diff --git a/plugin/src/main/java/org/battleplugins/arena/event/CompetitionListener.java b/plugin/src/main/java/org/battleplugins/arena/event/CompetitionListener.java new file mode 100644 index 00000000..f0a41566 --- /dev/null +++ b/plugin/src/main/java/org/battleplugins/arena/event/CompetitionListener.java @@ -0,0 +1,25 @@ +package org.battleplugins.arena.event; + +import org.battleplugins.arena.competition.Competition; +import org.battleplugins.arena.competition.CompetitionLike; + +/** + * A listener for competitions. + *

+ * This functionality extends upon {@link ArenaListener} and + * further isolates any event actions to the given {@link T competition}. + * + * @param the type of competition + */ +public class CompetitionListener> implements ArenaListener, CompetitionLike { + private final T competition; + + public CompetitionListener(T competition) { + this.competition = competition; + } + + @Override + public T getCompetition() { + return competition; + } +}