Mostly implements the join and create commands

This commit is contained in:
Kristian Knarvik 2023-03-24 11:43:33 +01:00
parent 52de9e5161
commit b840a3f500
4 changed files with 75 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import net.knarcraft.dropper.command.CreateArenaCommand;
import net.knarcraft.dropper.command.EditArenaCommand; import net.knarcraft.dropper.command.EditArenaCommand;
import net.knarcraft.dropper.command.EditArenaTabCompleter; import net.knarcraft.dropper.command.EditArenaTabCompleter;
import net.knarcraft.dropper.command.JoinArenaCommand; import net.knarcraft.dropper.command.JoinArenaCommand;
import net.knarcraft.dropper.command.JoinArenaTabCompleter;
import net.knarcraft.dropper.command.LeaveArenaCommand; import net.knarcraft.dropper.command.LeaveArenaCommand;
import net.knarcraft.dropper.command.ListArenaCommand; import net.knarcraft.dropper.command.ListArenaCommand;
import net.knarcraft.dropper.command.RemoveArenaCommand; import net.knarcraft.dropper.command.RemoveArenaCommand;
@ -84,7 +85,7 @@ public final class Dropper extends JavaPlugin {
registerCommand("droppercreate", new CreateArenaCommand(), null); registerCommand("droppercreate", new CreateArenaCommand(), null);
registerCommand("dropperlist", new ListArenaCommand(), null); registerCommand("dropperlist", new ListArenaCommand(), null);
registerCommand("dropperjoin", new JoinArenaCommand(), null); registerCommand("dropperjoin", new JoinArenaCommand(), new JoinArenaTabCompleter());
registerCommand("dropperleave", new LeaveArenaCommand(), null); registerCommand("dropperleave", new LeaveArenaCommand(), null);
registerCommand("dropperedit", new EditArenaCommand(), new EditArenaTabCompleter()); registerCommand("dropperedit", new EditArenaCommand(), new EditArenaTabCompleter());
registerCommand("dropperremove", new RemoveArenaCommand(), null); registerCommand("dropperremove", new RemoveArenaCommand(), null);

View File

@ -1,8 +1,12 @@
package net.knarcraft.dropper.command; 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.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@ -12,13 +16,33 @@ public class CreateArenaCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] strings) { @NotNull String[] arguments) {
//TODO: Make sure the console cannot run this if (!(commandSender instanceof Player player)) {
//TODO: Make sure the arena name isn't a duplicate and doesn't contain any unwanted characters commandSender.sendMessage("This command must be used by a player");
//TODO: Create a new arena return false;
//TODO: Register the new arena in the arena handler }
//TODO: Tell the user of success
return false; // Abort if no name was specified
if (arguments.length < 1) {
return false;
}
String arenaName = arguments[0];
String sanitized = ArenaStorageHelper.sanitizeArenaName(arenaName);
for (DropperArena arena : Dropper.getInstance().getArenaHandler().getArenas()) {
if (sanitized.equals(ArenaStorageHelper.sanitizeArenaName(arena.getArenaName()))) {
commandSender.sendMessage("There already exists a dropper arena with that name!");
return false;
}
}
//TODO: Make sure the arena name doesn't contain any unwanted characters
DropperArena arena = new DropperArena(arenaName, player.getLocation());
Dropper.getInstance().getArenaHandler().addArena(arena);
commandSender.sendMessage("The arena was successfully created!");
return true;
} }
} }

View File

@ -5,6 +5,7 @@ import net.knarcraft.dropper.arena.DropperArena;
import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry; import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.DropperArenaSession; import net.knarcraft.dropper.arena.DropperArenaSession;
import net.knarcraft.dropper.property.ArenaGameMode; import net.knarcraft.dropper.property.ArenaGameMode;
import net.knarcraft.dropper.util.ArenaStorageHelper;
import net.knarcraft.dropper.util.PlayerTeleporter; import net.knarcraft.dropper.util.PlayerTeleporter;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -37,10 +38,10 @@ public class JoinArenaCommand implements CommandExecutor {
} }
// Make sure the arena exists // Make sure the arena exists
String arenaName = arguments[0].trim(); String arenaName = ArenaStorageHelper.sanitizeArenaName(arguments[0]);
DropperArena specifiedArena = null; DropperArena specifiedArena = null;
for (DropperArena arena : Dropper.getInstance().getArenaHandler().getArenas()) { for (DropperArena arena : Dropper.getInstance().getArenaHandler().getArenas()) {
if (arena.getArenaName().equalsIgnoreCase(arenaName)) { if (ArenaStorageHelper.sanitizeArenaName(arena.getArenaName()).equals(arenaName)) {
specifiedArena = arena; specifiedArena = arena;
break; break;
} }

View File

@ -0,0 +1,39 @@
package net.knarcraft.dropper.command;
import net.knarcraft.dropper.Dropper;
import net.knarcraft.dropper.arena.DropperArena;
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 join command
*/
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) {
List<String> gameModes = new ArrayList<>();
gameModes.add("default");
gameModes.add("deaths");
gameModes.add("time");
return gameModes;
} else {
return new ArrayList<>();
}
}
}