diff --git a/src/main/java/net/knarcraft/dropper/Dropper.java b/src/main/java/net/knarcraft/dropper/Dropper.java index feb6735..5843a92 100644 --- a/src/main/java/net/knarcraft/dropper/Dropper.java +++ b/src/main/java/net/knarcraft/dropper/Dropper.java @@ -2,7 +2,25 @@ package net.knarcraft.dropper; import net.knarcraft.dropper.arena.DropperArenaHandler; import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry; +import net.knarcraft.dropper.command.CreateArenaCommand; +import net.knarcraft.dropper.command.EditArenaCommand; +import net.knarcraft.dropper.command.EditArenaTabCompleter; +import net.knarcraft.dropper.command.JoinArenaCommand; +import net.knarcraft.dropper.command.LeaveArenaCommand; +import net.knarcraft.dropper.command.ListArenaCommand; +import net.knarcraft.dropper.command.RemoveArenaCommand; +import net.knarcraft.dropper.listener.DamageListener; +import net.knarcraft.dropper.listener.MoveListener; +import net.knarcraft.dropper.listener.PlayerLeaveListener; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabCompleter; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.logging.Level; /** * The dropper plugin's main class @@ -49,34 +67,49 @@ public final class Dropper extends JavaPlugin { 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). - // Remember to cancel the event so they don't die. - //TODO: Make a listener for whether someone in an arena is about to hit a block (for cobwebs or similar). Use - // another check in the listener to check if a player is hitting water -> do whatever should be done when winning. - - //TODO: Arena settings: Spawn (where players are teleported to), Velocity (the downwards speed added to players. - // Might need a scheduler to maintain the speed), Stage (a numeric integer. if set, only allow access if the - // previous stage has been cleared), A configurable reward of some sort?, A name (just for easy differentiation), - // possibly a leave location to make sure pressure plates won't create an infinite loop - //TODO: Add a command for joining a specific arena. Only teleport if the stage check succeeds (The server can // use something like https://www.spigotmc.org/resources/commandblocks.62720/ for immersion) //TODO: Store various information about players' performance, and hook into PlaceholderAPI - //TODO: Implement optional time trial/least deaths game-mode somehow //TODO: Possibly implement an optional queue mode, which only allows one player inside one dropper arena at any - // time (to prevent players from pushing each-other) + // time (to prevent players from pushing each-other)? - //TODO: Set player.setAllowFlight to true while in the arena to avoid flight blocking for high velocities + PluginManager pluginManager = getServer().getPluginManager(); + pluginManager.registerEvents(new DamageListener(), this); + pluginManager.registerEvents(new MoveListener(), this); + pluginManager.registerEvents(new PlayerLeaveListener(), this); - - //TODO: Register event listeners - //TODO: Register commands + registerCommand("droppercreate", new CreateArenaCommand(), null); + registerCommand("dropperlist", new ListArenaCommand(), null); + registerCommand("dropperjoin", new JoinArenaCommand(), null); + registerCommand("dropperleave", new LeaveArenaCommand(), null); + registerCommand("dropperedit", new EditArenaCommand(), new EditArenaTabCompleter()); + registerCommand("dropperremove", new RemoveArenaCommand(), null); } @Override public void onDisable() { } + + /** + * Registers a command + * + * @param commandName
The name of the command to register (defined in plugin.yml)
+ * @param commandExecutorThe executor for the command
+ * @param tabCompleterThe tab-completer to use, or null
+ */ + private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor commandExecutor, + @Nullable TabCompleter tabCompleter) { + PluginCommand command = this.getCommand(commandName); + if (command != null) { + command.setExecutor(commandExecutor); + if (tabCompleter != null) { + command.setTabCompleter(tabCompleter); + } + } else { + getLogger().log(Level.SEVERE, "Unable to register the command " + commandName); + } + } + } diff --git a/src/main/java/net/knarcraft/dropper/arena/DropperArenaHandler.java b/src/main/java/net/knarcraft/dropper/arena/DropperArenaHandler.java index 5bfddaf..f9196a9 100644 --- a/src/main/java/net/knarcraft/dropper/arena/DropperArenaHandler.java +++ b/src/main/java/net/knarcraft/dropper/arena/DropperArenaHandler.java @@ -9,10 +9,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.logging.Level; /** @@ -23,28 +21,8 @@ public class DropperArenaHandler { private static final File arenaFile = new File(Dropper.getInstance().getDataFolder(), "arenas.yml"); private ListThe arena session to register
- */ - public void registerArenaSession(@NotNull DropperArenaSession session) { - this.activeSessions.add(session); - } - - /** - * Unregisters the given arena session from known active arena sessions - * - * @param sessionThe session to remove
- * @returnTrue if the session was removed
- */ - public boolean unregisterArenaSession(@NotNull DropperArenaSession session) { - return this.activeSessions.remove(session); - } - /** * Tries to register the given stage as cleared * diff --git a/src/main/java/net/knarcraft/dropper/arena/DropperArenaPlayerRegistry.java b/src/main/java/net/knarcraft/dropper/arena/DropperArenaPlayerRegistry.java index 2426039..acc1caa 100644 --- a/src/main/java/net/knarcraft/dropper/arena/DropperArenaPlayerRegistry.java +++ b/src/main/java/net/knarcraft/dropper/arena/DropperArenaPlayerRegistry.java @@ -29,18 +29,8 @@ public class DropperArenaPlayerRegistry { * * @param playerThe player to remove
*/ - public void removePlayer(@NotNull Player player) { - this.arenaPlayers.remove(player); - } - - /** - * Gets whether the given player is currently playing in an arena - * - * @param playerThe player to check
- * @returnTrue if the player is currently in an arena
- */ - public boolean isInArena(@NotNull Player player) { - return getArenaSession(player) != null; + public boolean removePlayer(@NotNull Player player) { + return this.arenaPlayers.remove(player) != null; } /** diff --git a/src/main/java/net/knarcraft/dropper/arena/DropperArenaSession.java b/src/main/java/net/knarcraft/dropper/arena/DropperArenaSession.java index e298d6c..cdb0d9d 100644 --- a/src/main/java/net/knarcraft/dropper/arena/DropperArenaSession.java +++ b/src/main/java/net/knarcraft/dropper/arena/DropperArenaSession.java @@ -88,7 +88,7 @@ public class DropperArenaSession { */ private void removeSession() { // Remove this session for game sessions to stop listeners from fiddling more with the player - boolean removedSession = Dropper.getInstance().getArenaHandler().unregisterArenaSession(this); + boolean removedSession = Dropper.getInstance().getPlayerRegistry().removePlayer(player); if (!removedSession) { Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to remove dropper arena session for " + player.getName() + ". This will have unintended consequences."); diff --git a/src/main/java/net/knarcraft/dropper/command/CreateArenaCommand.java b/src/main/java/net/knarcraft/dropper/command/CreateArenaCommand.java index cc35982..99db88d 100644 --- a/src/main/java/net/knarcraft/dropper/command/CreateArenaCommand.java +++ b/src/main/java/net/knarcraft/dropper/command/CreateArenaCommand.java @@ -5,12 +5,19 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +/** + * The command for creating a new dropper arena + */ public class CreateArenaCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { - //TODO: Implement command behavior + //TODO: Make sure the console cannot run this + //TODO: Make sure the arena name isn't a duplicate and doesn't contain any unwanted characters + //TODO: Create a new arena + //TODO: Register the new arena in the arena handler + //TODO: Tell the user of success return false; } diff --git a/src/main/java/net/knarcraft/dropper/command/EditArenaCommand.java b/src/main/java/net/knarcraft/dropper/command/EditArenaCommand.java index 50e3de2..164d175 100644 --- a/src/main/java/net/knarcraft/dropper/command/EditArenaCommand.java +++ b/src/main/java/net/knarcraft/dropper/command/EditArenaCommand.java @@ -5,12 +5,17 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +/** + * The command for editing an existing dropper arena + */ public class EditArenaCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { - //TODO: Implement command behavior + //TODO: Make sure the console cannot run this + //TODO: If an arena name and a property is given, display the current value + //TODO: If an arena name, a property and a value is given, check if it's valid, and update the property return false; } diff --git a/src/main/java/net/knarcraft/dropper/command/EditArenaTabCompleter.java b/src/main/java/net/knarcraft/dropper/command/EditArenaTabCompleter.java new file mode 100644 index 0000000..7205e4b --- /dev/null +++ b/src/main/java/net/knarcraft/dropper/command/EditArenaTabCompleter.java @@ -0,0 +1,24 @@ +package net.knarcraft.dropper.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * The tab-completer for the edit arena command + */ +public class EditArenaTabCompleter implements TabCompleter { + + @Override + public @Nullable List