summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/util')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java111
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java59
2 files changed, 0 insertions, 170 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java
deleted file mode 100644
index 3b0f1b4..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/util/CommandHandler.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package net.tylermurphy.hideAndSeek.util;
-
-import net.tylermurphy.hideAndSeek.command.*;
-import net.tylermurphy.hideAndSeek.command.location.SetExitLocation;
-import net.tylermurphy.hideAndSeek.command.location.SetLobbyLocation;
-import net.tylermurphy.hideAndSeek.command.location.SetSeekerLobbyLocation;
-import net.tylermurphy.hideAndSeek.command.location.SetSpawnLocation;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
-import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.LOCAL;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
-
-public class CommandHandler {
-
- public static final Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
-
- private static void registerCommand(ICommand command) {
- if (!COMMAND_REGISTER.containsKey(command.getLabel())) {
- COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command);
- }
- }
-
- public static void registerCommands() {
- registerCommand(new About());
- registerCommand(new Help());
- registerCommand(new Setup());
- registerCommand(new Start());
- registerCommand(new Stop());
- registerCommand(new SetSpawnLocation());
- registerCommand(new SetLobbyLocation());
- registerCommand(new SetSeekerLobbyLocation());
- registerCommand(new SetExitLocation());
- registerCommand(new SetBorder());
- registerCommand(new Reload());
- registerCommand(new SaveMap());
- registerCommand(new SetBounds());
- registerCommand(new Join());
- registerCommand(new Leave());
- registerCommand(new Top());
- registerCommand(new Wins());
- registerCommand(new Debug());
- registerCommand(new AddMap());
- registerCommand(new RemoveMap());
- registerCommand(new ListMaps());
- registerCommand(new SetMap());
- }
-
- public static boolean handleCommand(CommandSender sender, String[] args) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY"));
- return true;
- }
- Player player = (Player) sender;
- if (args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) {
- if (permissionsRequired && !sender.hasPermission("hideandseek.about")) {
- sender.sendMessage(errorPrefix + LOCAL.get(""));
- } else {
- COMMAND_REGISTER.get("about").execute(player, null);
- }
- } else {
- if (!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) {
- sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
- } else if (permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) {
- sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
- } else {
-
- try {
- ICommand command = COMMAND_REGISTER.get(args[0].toLowerCase());
- int parameters = (int) Arrays.stream(command.getUsage().split(" ")).filter(p -> p.startsWith("<") && !p.startsWith("<*")).count();
- if(args.length - 1 < parameters) {
- sender.sendMessage(errorPrefix + message("ARGUMENT_COUNT"));
- return true;
- }
- command.execute(player,Arrays.copyOfRange(args, 1, args.length));
- } catch (Exception e) {
- sender.sendMessage(errorPrefix + "An error has occurred.");
- e.printStackTrace();
- }
- }
- }
- return true;
- }
-
-}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java b/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java
deleted file mode 100644
index 28154d1..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/util/TabCompleter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package net.tylermurphy.hideAndSeek.util;
-
-import net.tylermurphy.hideAndSeek.command.ICommand;
-import org.bukkit.command.CommandSender;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.stream.Collectors;
-
-public class TabCompleter {
-
- public static List<String> handleTabComplete(CommandSender sender, String[] args) {
- if (args.length == 1) {
- return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet())
- .stream()
- .filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
- .collect(Collectors.toList());
- } else if (args.length > 1) {
- if (!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
- return new ArrayList<>();
- } else {
- ICommand command = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase());
- String[] usage = command.getUsage().split(" ");
- List<String> complete;
- if (args.length - 2 < usage.length) {
- String parameter = usage[args.length-2];
- String name = parameter.replace("<", "").replace(">", "");
- complete = command.autoComplete(name);
- } else {
- complete = command.autoComplete(null);
- }
- if(complete == null) return new ArrayList<>();
- else return complete;
- }
- }
- return null;
- }
-
-}