mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-04 16:33:14 +01:00
Prepares for command implementation
Removes some finished TODOs Registers all listeners Registers all commands Adds more descriptive TODO comments to each command Removes unintended double storage of dropper arena sessions in DropperArenaHandler
This commit is contained in:
parent
ee8f232b0b
commit
906543f017
@ -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 <p>The name of the command to register (defined in plugin.yml)</p>
|
||||
* @param commandExecutor <p>The executor for the command</p>
|
||||
* @param tabCompleter <p>The tab-completer to use, or null</p>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 List<DropperArena> arenas = new ArrayList<>();
|
||||
private final Set<DropperArenaSession> activeSessions = new HashSet<>();
|
||||
private final Map<Player, Integer> stagesCleared = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Registers the given arena session to known active arena sessions
|
||||
*
|
||||
* @param session <p>The arena session to register</p>
|
||||
*/
|
||||
public void registerArenaSession(@NotNull DropperArenaSession session) {
|
||||
this.activeSessions.add(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the given arena session from known active arena sessions
|
||||
*
|
||||
* @param session <p>The session to remove</p>
|
||||
* @return <p>True if the session was removed</p>
|
||||
*/
|
||||
public boolean unregisterArenaSession(@NotNull DropperArenaSession session) {
|
||||
return this.activeSessions.remove(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to register the given stage as cleared
|
||||
*
|
||||
|
@ -29,18 +29,8 @@ public class DropperArenaPlayerRegistry {
|
||||
*
|
||||
* @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 getArenaSession(player) != null;
|
||||
public boolean removePlayer(@NotNull Player player) {
|
||||
return this.arenaPlayers.remove(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] args) {
|
||||
//TODO: Tab-complete existing arena names
|
||||
//TODO: If an arena name is given, tab-complete change-able properties
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -18,8 +18,10 @@ public class JoinArenaCommand implements CommandExecutor {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
return false;
|
||||
}
|
||||
//TODO: Implement command behavior
|
||||
//TODO: Remember to check if the player is already in an arena first!
|
||||
//TODO: Create a new arena session
|
||||
//TODO: Register the session in the arena player registry
|
||||
//TODO: Teleport the player to the arena's start location
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,17 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The command used to leave the current dropper arena
|
||||
*/
|
||||
public class LeaveArenaCommand 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 the player isn't currently in an arena, just display an error message
|
||||
//TODO: Trigger the player's session's triggerQuit() method
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A command for listing existing dropper arenas
|
||||
*/
|
||||
public class ListArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
//TODO: List all existing arenas, and possibly information about a specified arena
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -5,13 +5,18 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The method used for removing an existing arena
|
||||
*/
|
||||
public class RemoveArenaCommand 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 to kick players if the arena is currently in use
|
||||
//TODO: Make sure to kick any playing players if the arena is currently in use, by triggering their sessions'
|
||||
// triggerQuit() method
|
||||
//TODO: Remove the arena from DropperArenaHandler
|
||||
//TODO: Notify the user of success
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user