From 1e629734f4970870fa36b4ccf5b7e0804df4b94f Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 30 Jun 2024 18:14:13 -0500 Subject: [PATCH] Remove needlessly confusing Match/Event subclasses that did nothing --- .../java/org/battleplugins/arena/Arena.java | 4 +- .../arena/competition/Competition.java | 2 +- .../arena/competition/CompetitionType.java | 57 +++---------------- .../arena/competition/LiveCompetition.java | 11 +++- .../arena/competition/event/Event.java | 21 ------- .../arena/competition/event/LiveEvent.java | 15 ----- .../competition/map/LiveCompetitionMap.java | 5 +- .../arena/competition/match/LiveMatch.java | 15 ----- .../arena/competition/match/Match.java | 23 -------- 9 files changed, 23 insertions(+), 130 deletions(-) delete mode 100644 plugin/src/main/java/org/battleplugins/arena/competition/event/Event.java delete mode 100644 plugin/src/main/java/org/battleplugins/arena/competition/event/LiveEvent.java delete mode 100644 plugin/src/main/java/org/battleplugins/arena/competition/match/LiveMatch.java delete mode 100644 plugin/src/main/java/org/battleplugins/arena/competition/match/Match.java diff --git a/plugin/src/main/java/org/battleplugins/arena/Arena.java b/plugin/src/main/java/org/battleplugins/arena/Arena.java index 5ef74380..8b34a0ee 100644 --- a/plugin/src/main/java/org/battleplugins/arena/Arena.java +++ b/plugin/src/main/java/org/battleplugins/arena/Arena.java @@ -54,7 +54,7 @@ public class Arena implements ArenaLike, ArenaListener { private List aliases; @ArenaOption(name = "type", description = "The competition type", required = true) - private CompetitionType type; + private CompetitionType type; @ArenaOption(name = "team-options", description = "The options for teams.", required = true) private Teams teams; @@ -209,7 +209,7 @@ public List getAliases() { * * @return the competition type for this arena */ - public final CompetitionType getType() { + public final CompetitionType getType() { return this.type; } diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/Competition.java b/plugin/src/main/java/org/battleplugins/arena/competition/Competition.java index 3669db8c..e289a89d 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/Competition.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/Competition.java @@ -27,7 +27,7 @@ public interface Competition> extends CompetitionLike getType(); + CompetitionType getType(); /** * Gets the map for this competition. diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionType.java b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionType.java index f143a9ab..f4ec49e5 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionType.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionType.java @@ -1,70 +1,29 @@ package org.battleplugins.arena.competition; -import org.battleplugins.arena.Arena; -import org.battleplugins.arena.competition.event.Event; -import org.battleplugins.arena.competition.event.LiveEvent; -import org.battleplugins.arena.competition.map.LiveCompetitionMap; -import org.battleplugins.arena.competition.match.LiveMatch; -import org.battleplugins.arena.competition.match.Match; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.Objects; /** * Represents a competition type. - * - * @param the type of competition */ -public final class CompetitionType> { - private static final Map> COMPETITION_TYPES = new HashMap<>(); +public final class CompetitionType { + private static final Map COMPETITION_TYPES = new HashMap<>(); - public static final CompetitionType EVENT = new CompetitionType<>("Event", Event.class, LiveEvent::new); - public static final CompetitionType MATCH = new CompetitionType<>("Match", Match.class, LiveMatch::new); + public static final CompetitionType EVENT = new CompetitionType("Event"); + public static final CompetitionType MATCH = new CompetitionType("Match"); - private final Class clazz; - private final CompetitionFactory factory; + private final String name; - CompetitionType(String name, Class clazz, CompetitionFactory factory) { - this.clazz = clazz; - this.factory = factory; + CompetitionType(String name) { + this.name = name; COMPETITION_TYPES.put(name, this); } - public Class getCompetitionType() { - return this.clazz; - } - - public T create(Arena arena, LiveCompetitionMap map) { - return this.factory.create(arena, map); - } - @Nullable - public static CompetitionType get(String name) { + public static CompetitionType get(String name) { return COMPETITION_TYPES.get(name); } - - public static > CompetitionType create(String name, Class clazz, CompetitionFactory factory) { - return new CompetitionType<>(name, clazz, factory); - } - - @Override - public boolean equals(Object object) { - if (this == object) return true; - if (object == null || getClass() != object.getClass()) return false; - CompetitionType that = (CompetitionType) object; - return Objects.equals(this.clazz, that.clazz); - } - - @Override - public int hashCode() { - return Objects.hash(this.clazz); - } - - public interface CompetitionFactory> { - - T create(Arena arena, LiveCompetitionMap map); - } } diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/LiveCompetition.java b/plugin/src/main/java/org/battleplugins/arena/competition/LiveCompetition.java index ea2c0514..b77b9365 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/LiveCompetition.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/LiveCompetition.java @@ -36,8 +36,9 @@ * A {@link Competition} that is occurring on the same server * that this plugin is running on. */ -public abstract class LiveCompetition> implements ArenaLike, Competition { +public class LiveCompetition> implements ArenaLike, Competition { private final Arena arena; + private final CompetitionType type; private final LiveCompetitionMap map; private final Map players = new HashMap<>(); @@ -51,8 +52,9 @@ public abstract class LiveCompetition> implements Arena private final OptionsListener optionsListener; private final StatListener statListener; - public LiveCompetition(Arena arena, LiveCompetitionMap map) { + public LiveCompetition(Arena arena, CompetitionType type, LiveCompetitionMap map) { this.arena = arena; + this.type = type; this.map = map; this.phaseManager = new PhaseManager<>(arena, (T) this); @@ -143,6 +145,11 @@ public final Arena getArena() { return this.arena; } + @Override + public CompetitionType getType() { + return this.type; + } + @Override public final LiveCompetitionMap getMap() { return this.map; diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/event/Event.java b/plugin/src/main/java/org/battleplugins/arena/competition/event/Event.java deleted file mode 100644 index 84e2d067..00000000 --- a/plugin/src/main/java/org/battleplugins/arena/competition/event/Event.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.battleplugins.arena.competition.event; - -import org.battleplugins.arena.competition.Competition; -import org.battleplugins.arena.competition.CompetitionType; - -/** - * Represents an event competition. - *

- * An event is a mode that is started based on a certain interval, - * or when triggered by a server action. These games cannot be joined - * normally unless the event is active. - *

- * The bulk of event management logic is handled in the {@link EventScheduler}. - */ -public interface Event extends Competition { - - @Override - default CompetitionType getType() { - return CompetitionType.EVENT; - } -} diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/event/LiveEvent.java b/plugin/src/main/java/org/battleplugins/arena/competition/event/LiveEvent.java deleted file mode 100644 index 8f3abfc0..00000000 --- a/plugin/src/main/java/org/battleplugins/arena/competition/event/LiveEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.battleplugins.arena.competition.event; - -import org.battleplugins.arena.Arena; -import org.battleplugins.arena.competition.LiveCompetition; -import org.battleplugins.arena.competition.map.LiveCompetitionMap; - -/** - * Represents an event which is live on this server. - */ -public class LiveEvent extends LiveCompetition implements Event { - - public LiveEvent(Arena arena, LiveCompetitionMap map) { - super(arena, map); - } -} diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/map/LiveCompetitionMap.java b/plugin/src/main/java/org/battleplugins/arena/competition/map/LiveCompetitionMap.java index 4d6455f5..2a89af8c 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/map/LiveCompetitionMap.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/map/LiveCompetitionMap.java @@ -4,6 +4,8 @@ import org.battleplugins.arena.Arena; import org.battleplugins.arena.ArenaLike; import org.battleplugins.arena.competition.Competition; +import org.battleplugins.arena.competition.CompetitionType; +import org.battleplugins.arena.competition.LiveCompetition; import org.battleplugins.arena.competition.map.options.Bounds; import org.battleplugins.arena.competition.map.options.Spawns; import org.battleplugins.arena.config.ArenaOption; @@ -173,7 +175,6 @@ public final void setSpawns(Spawns spawns) { this.spawns = spawns; } - /** * Creates a new competition for this map. * @@ -181,7 +182,7 @@ public final void setSpawns(Spawns spawns) { * @return the created competition */ public Competition createCompetition(Arena arena) { - return arena.getType().create(arena, this); + return new LiveCompetition<>(arena, arena.getType(), this); } /** diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/match/LiveMatch.java b/plugin/src/main/java/org/battleplugins/arena/competition/match/LiveMatch.java deleted file mode 100644 index 8ba09f6f..00000000 --- a/plugin/src/main/java/org/battleplugins/arena/competition/match/LiveMatch.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.battleplugins.arena.competition.match; - -import org.battleplugins.arena.Arena; -import org.battleplugins.arena.competition.LiveCompetition; -import org.battleplugins.arena.competition.map.LiveCompetitionMap; - -/** - * Represents a match which is live on this server. - */ -public class LiveMatch extends LiveCompetition implements Match { - - public LiveMatch(Arena arena, LiveCompetitionMap map) { - super(arena, map); - } -} diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/match/Match.java b/plugin/src/main/java/org/battleplugins/arena/competition/match/Match.java deleted file mode 100644 index 2bbb6628..00000000 --- a/plugin/src/main/java/org/battleplugins/arena/competition/match/Match.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.battleplugins.arena.competition.match; - -import org.battleplugins.arena.competition.Competition; -import org.battleplugins.arena.competition.CompetitionType; -import org.battleplugins.arena.competition.event.EventScheduler; - -/** - * Represents a match competition. - *

- * A match is a mode that is started when a certain condition is met (i.e. number of players), - * or is always active. These games can be joined at any time, as long as there are available - * maps. - *

- * The bulk of match management logic is handled by the plugin and manual intervention in terms - * of starting the match is not required. - */ -public interface Match extends Competition { - - @Override - default CompetitionType getType() { - return CompetitionType.MATCH; - } -}