mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-05 00:43:15 +01:00
Expands DropperArenaHandler
Adds storage of currently playing players to DropperArenaHandler Adds methods for getting, adding and removing arenas to DropperArenaHandler Adds more annotations in some places
This commit is contained in:
parent
bcde657fdd
commit
730ef3fa13
@ -1,11 +1,13 @@
|
||||
package net.knarcraft.dropper;
|
||||
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Dropper extends JavaPlugin {
|
||||
|
||||
private static Dropper instance;
|
||||
private DropperArenaHandler arenaHandler;
|
||||
|
||||
/**
|
||||
* Gets an instance of this plugin
|
||||
@ -20,6 +22,8 @@ public final class Dropper extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
this.arenaHandler = new DropperArenaHandler();
|
||||
this.arenaHandler.loadArenas();
|
||||
|
||||
//TODO: Keep track of whether players are in a dropper arena, and which arena they are in
|
||||
//TODO: Make an event listener that kicks players from an arena if they take damage (EntityDamageEvent).
|
||||
@ -47,6 +51,6 @@ public final class Dropper extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,23 +4,26 @@ import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A representation of one dropper arena
|
||||
*/
|
||||
public class DropperArena {
|
||||
|
||||
/**
|
||||
* A name used when listing and storing this arena.
|
||||
*/
|
||||
private final String arenaName;
|
||||
private final @NotNull String arenaName;
|
||||
|
||||
/**
|
||||
* The location players are teleported to when joining this arena.
|
||||
*/
|
||||
private final Location spawnLocation;
|
||||
private final @NotNull Location spawnLocation;
|
||||
|
||||
/**
|
||||
* The location players will be sent to when they win or lose the arena. If not set, their entry location should be
|
||||
* used instead.
|
||||
*/
|
||||
private final Location exitLocation;
|
||||
private final @Nullable Location exitLocation;
|
||||
|
||||
/**
|
||||
* The velocity in the y-direction to apply to all players in this arena.
|
||||
@ -30,7 +33,7 @@ public class DropperArena {
|
||||
/**
|
||||
* The stage number of this arena. If not null, the previous stage number must be cleared before access.
|
||||
*/
|
||||
private final Integer stage;
|
||||
private final @Nullable Integer stage;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena
|
||||
|
@ -2,26 +2,100 @@ package net.knarcraft.dropper.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.util.ArenaStorageHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A handler that keeps track of all dropper arenas
|
||||
*/
|
||||
public class DropperArenaHandler {
|
||||
|
||||
List<DropperArena> arenas = new ArrayList<>();
|
||||
|
||||
private static final File arenaFile = new File(Dropper.getInstance().getDataFolder(), "arenas.yml");
|
||||
|
||||
//TODO: Use this class to keep track of all created arenas. Saving and loading arenas is this class's responsibility
|
||||
//TODO: Keep track of which players are in which arenas (should possibly be its own class, depending on complexity)
|
||||
private List<DropperArena> arenas = new ArrayList<>();
|
||||
private final Map<Player, DropperArena> arenaPlayers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Registers that the given player has started playing in the given dropper arena
|
||||
*
|
||||
* @param player <p>The player that started playing</p>
|
||||
* @param arena <p>The arena the player is playing in</p>
|
||||
*/
|
||||
public void registerPlayer(@NotNull Player player, @NotNull DropperArena arena) {
|
||||
this.arenaPlayers.put(player, arena);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this player from players currently playing
|
||||
*
|
||||
* @param player <p>The player to remove</p>
|
||||
*/
|
||||
public void removePlayer(@NotNull Player player) {
|
||||
this.arenaPlayers.remove(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player is currently playing in an arena
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player is currently in an arena</p>
|
||||
*/
|
||||
public boolean isInArena(@NotNull Player player) {
|
||||
return getArena(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the arena the given player is currently playing in
|
||||
*
|
||||
* @param player <p>The player to get arena for</p>
|
||||
* @return <p>The player's active arena, or null if not currently playing</p>
|
||||
*/
|
||||
public @Nullable DropperArena getArena(@NotNull Player player) {
|
||||
return this.arenaPlayers.getOrDefault(player, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new arena
|
||||
*
|
||||
* @param arena <p>The arena to add</p>
|
||||
*/
|
||||
public void addArena(@NotNull DropperArena arena) {
|
||||
this.arenas.add(arena);
|
||||
this.saveArenas();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all known arenas
|
||||
*
|
||||
* @return <p>All known arenas</p>
|
||||
*/
|
||||
public @NotNull List<DropperArena> getArenas() {
|
||||
return new ArrayList<>(this.arenas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove</p>
|
||||
*/
|
||||
public void removeArena(@NotNull DropperArena arena) {
|
||||
this.arenas.remove(arena);
|
||||
this.saveArenas();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current arenas to disk
|
||||
*/
|
||||
private void saveArenas() {
|
||||
public void saveArenas() {
|
||||
try {
|
||||
ArenaStorageHelper.saveArenas(this.arenas, arenaFile);
|
||||
} catch (IOException e) {
|
||||
@ -33,7 +107,7 @@ public class DropperArenaHandler {
|
||||
/**
|
||||
* Loads all arenas from disk
|
||||
*/
|
||||
private void loadArenas() {
|
||||
public void loadArenas() {
|
||||
this.arenas = ArenaStorageHelper.loadArenas(arenaFile);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.knarcraft.dropper.property;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A representation of each key used for storing arena data
|
||||
*/
|
||||
@ -12,14 +14,14 @@ public enum ArenaStorageKey {
|
||||
STAGE("arenaStage"),
|
||||
;
|
||||
|
||||
private final String key;
|
||||
private final @NotNull String key;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena storage key
|
||||
*
|
||||
* @param key <p>The string path of the configuration key this value represents.</p>
|
||||
*/
|
||||
ArenaStorageKey(String key) {
|
||||
ArenaStorageKey(@NotNull String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@ -28,7 +30,7 @@ public enum ArenaStorageKey {
|
||||
*
|
||||
* @return <p>The string key representation.</p>
|
||||
*/
|
||||
public String getKey() {
|
||||
public @NotNull String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public final class ArenaStorageHelper {
|
||||
* @param configurationSection <p>The configuration section containing arena data</p>
|
||||
* @return <p>The loaded arena, or null if invalid</p>
|
||||
*/
|
||||
private static @Nullable DropperArena loadArena(ConfigurationSection configurationSection) {
|
||||
private static @Nullable DropperArena loadArena(@NotNull ConfigurationSection configurationSection) {
|
||||
String arenaName = configurationSection.getString(ArenaStorageKey.NAME.getKey());
|
||||
Location spawnLocation = (Location) configurationSection.get(ArenaStorageKey.SPAWN_LOCATION.getKey());
|
||||
Location exitLocation = (Location) configurationSection.get(ArenaStorageKey.EXIT_LOCATION.getKey());
|
||||
@ -104,7 +104,7 @@ public final class ArenaStorageHelper {
|
||||
* @param arenaName <p>The arena name to sanitize</p>
|
||||
* @return <p>The sanitized arena name</p>
|
||||
*/
|
||||
private static String sanitizeArenaName(String arenaName) {
|
||||
public static @NotNull String sanitizeArenaName(@NotNull String arenaName) {
|
||||
return arenaName.toLowerCase().trim().replaceAll(" ", "_");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user