Skip to content

Commit

Permalink
Remove needlessly confusing Match/Event subclasses that did nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jun 30, 2024
1 parent cdab9c8 commit 1e62973
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 130 deletions.
4 changes: 2 additions & 2 deletions plugin/src/main/java/org/battleplugins/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Arena implements ArenaLike, ArenaListener {
private List<String> 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;
Expand Down Expand Up @@ -209,7 +209,7 @@ public List<String> getAliases() {
*
* @return the competition type for this arena
*/
public final CompetitionType<?> getType() {
public final CompetitionType getType() {
return this.type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface Competition<T extends Competition<T>> extends CompetitionLike<T
*
* @return the type of competition
*/
CompetitionType<T> getType();
CompetitionType getType();

/**
* Gets the map for this competition.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T> the type of competition
*/
public final class CompetitionType<T extends Competition<T>> {
private static final Map<String, CompetitionType<?>> COMPETITION_TYPES = new HashMap<>();
public final class CompetitionType {
private static final Map<String, CompetitionType> COMPETITION_TYPES = new HashMap<>();

public static final CompetitionType<Event> EVENT = new CompetitionType<>("Event", Event.class, LiveEvent::new);
public static final CompetitionType<Match> 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<T> clazz;
private final CompetitionFactory<T> factory;
private final String name;

CompetitionType(String name, Class<T> clazz, CompetitionFactory<T> factory) {
this.clazz = clazz;
this.factory = factory;
CompetitionType(String name) {
this.name = name;

COMPETITION_TYPES.put(name, this);
}

public Class<T> 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 <T extends Competition<T>> CompetitionType<T> create(String name, Class<T> clazz, CompetitionFactory<T> 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 extends Competition<T>> {

T create(Arena arena, LiveCompetitionMap map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
* A {@link Competition} that is occurring on the same server
* that this plugin is running on.
*/
public abstract class LiveCompetition<T extends Competition<T>> implements ArenaLike, Competition<T> {
public class LiveCompetition<T extends Competition<T>> implements ArenaLike, Competition<T> {
private final Arena arena;
private final CompetitionType type;
private final LiveCompetitionMap map;

private final Map<Player, ArenaPlayer> players = new HashMap<>();
Expand All @@ -51,8 +52,9 @@ public abstract class LiveCompetition<T extends Competition<T>> implements Arena
private final OptionsListener<T> optionsListener;
private final StatListener<T> 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);
Expand Down Expand Up @@ -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;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,15 +175,14 @@ public final void setSpawns(Spawns spawns) {
this.spawns = spawns;
}


/**
* Creates a new competition for this map.
*
* @param arena the arena to create the competition for
* @return the created competition
*/
public Competition<?> createCompetition(Arena arena) {
return arena.getType().create(arena, this);
return new LiveCompetition<>(arena, arena.getType(), this);
}

/**
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 1e62973

Please sign in to comment.