mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-05 00:43:15 +01:00
Implements the remove command
This commit is contained in:
parent
14572de102
commit
6385b4c5e8
@ -10,6 +10,7 @@ import net.knarcraft.dropper.command.JoinArenaTabCompleter;
|
||||
import net.knarcraft.dropper.command.LeaveArenaCommand;
|
||||
import net.knarcraft.dropper.command.ListArenaCommand;
|
||||
import net.knarcraft.dropper.command.RemoveArenaCommand;
|
||||
import net.knarcraft.dropper.command.RemoveArenaTabCompleter;
|
||||
import net.knarcraft.dropper.listener.DamageListener;
|
||||
import net.knarcraft.dropper.listener.MoveListener;
|
||||
import net.knarcraft.dropper.listener.PlayerLeaveListener;
|
||||
@ -88,7 +89,7 @@ public final class Dropper extends JavaPlugin {
|
||||
registerCommand("dropperjoin", new JoinArenaCommand(), new JoinArenaTabCompleter());
|
||||
registerCommand("dropperleave", new LeaveArenaCommand(), null);
|
||||
registerCommand("dropperedit", new EditArenaCommand(), new EditArenaTabCompleter());
|
||||
registerCommand("dropperremove", new RemoveArenaCommand(), null);
|
||||
registerCommand("dropperremove", new RemoveArenaCommand(), new RemoveArenaTabCompleter());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +65,7 @@ public class DropperArenaHandler {
|
||||
* @param arena <p>The arena to remove</p>
|
||||
*/
|
||||
public void removeArena(@NotNull DropperArena arena) {
|
||||
Dropper.getInstance().getPlayerRegistry().removeForArena(arena);
|
||||
this.arenas.remove(arena);
|
||||
this.saveArenas();
|
||||
}
|
||||
|
@ -43,4 +43,19 @@ public class DropperArenaPlayerRegistry {
|
||||
return this.arenaPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
*/
|
||||
public void removeForArena(DropperArena arena) {
|
||||
for (Map.Entry<UUID, DropperArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit();
|
||||
this.arenaPlayers.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -18,14 +17,10 @@ public class JoinArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (DropperArena dropperArena : Dropper.getInstance().getArenaHandler().getArenas()) {
|
||||
arenaNames.add(dropperArena.getArenaName());
|
||||
}
|
||||
return arenaNames;
|
||||
} else if (args.length == 2) {
|
||||
@NotNull String label, @NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
} else if (arguments.length == 2) {
|
||||
List<String> gameModes = new ArrayList<>();
|
||||
gameModes.add("default");
|
||||
gameModes.add("deaths");
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.util.ArenaStorageHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,12 +15,26 @@ public class RemoveArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
//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;
|
||||
@NotNull String[] arguments) {
|
||||
// Get the specified arena
|
||||
String arenaName = arguments[0];
|
||||
String sanitized = ArenaStorageHelper.sanitizeArenaName(arenaName);
|
||||
DropperArena targetArena = null;
|
||||
for (DropperArena arena : Dropper.getInstance().getArenaHandler().getArenas()) {
|
||||
if (sanitized.equals(ArenaStorageHelper.sanitizeArenaName(arena.getArenaName()))) {
|
||||
targetArena = arena;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified arena");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
Dropper.getInstance().getArenaHandler().removeArena(targetArena);
|
||||
commandSender.sendMessage("The specified arena has been successfully removed");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The tab-completer for the remove arena command
|
||||
*/
|
||||
public class RemoveArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.knarcraft.dropper.util;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A helper-class for common tab-completions
|
||||
*/
|
||||
public final class TabCompleteHelper {
|
||||
|
||||
private TabCompleteHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of all current arenas
|
||||
*
|
||||
* @return <p>All arena names</p>
|
||||
*/
|
||||
public static @NotNull List<String> getArenas() {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (DropperArena dropperArena : Dropper.getInstance().getArenaHandler().getArenas()) {
|
||||
arenaNames.add(dropperArena.getArenaName());
|
||||
}
|
||||
return arenaNames;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user