kenshinshideandseek/src/main/java/net/tylermurphy/hideAndSeek/game/CommandHandler.java

90 lines
3 KiB
Java
Raw Normal View History

/*
* 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, either version 3 of the License.
*
* 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/>.
*
*/
2021-12-26 22:58:18 +00:00
package net.tylermurphy.hideAndSeek.game;
2021-08-13 20:49:36 +00:00
2021-10-23 00:03:15 +00:00
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
2021-08-13 20:49:36 +00:00
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2021-09-01 01:55:27 +00:00
import net.tylermurphy.hideAndSeek.command.*;
2021-08-13 20:49:36 +00:00
public class CommandHandler {
2021-08-13 20:49:36 +00:00
2021-12-26 22:58:18 +00:00
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
2021-08-13 20:49:36 +00:00
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());
2021-10-18 02:52:57 +00:00
registerCommand(new Setup());
2021-08-13 20:49:36 +00:00
registerCommand(new Start());
registerCommand(new Stop());
registerCommand(new SetSpawnLocation());
2021-10-11 21:06:21 +00:00
registerCommand(new SetLobbyLocation());
2021-10-18 02:52:57 +00:00
registerCommand(new SetExitLocation());
2021-08-13 20:49:36 +00:00
registerCommand(new SetBorder());
registerCommand(new Reload());
2021-08-27 21:20:07 +00:00
registerCommand(new SaveMap());
2021-10-27 23:57:44 +00:00
registerCommand(new SetBounds());
2021-10-11 21:06:21 +00:00
registerCommand(new Join());
registerCommand(new Leave());
2021-12-26 04:46:22 +00:00
registerCommand(new Top());
registerCommand(new Wins());
2021-08-13 20:49:36 +00:00
}
2021-12-26 22:58:18 +00:00
public static boolean handleCommand(CommandSender sender, String[] args) {
2021-12-25 14:23:19 +00:00
if(!(sender instanceof Player)) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY"));
} else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) {
if(permissionsRequired && !sender.hasPermission("hideandseek.about")) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + LOCAL.get(""));
} else {
COMMAND_REGISTER.get("about").execute(sender, null);
}
2021-08-13 20:49:36 +00:00
} else {
2021-12-25 14:23:19 +00:00
if(!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
2021-08-28 00:32:50 +00:00
} else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
} else {
try {
COMMAND_REGISTER.get(args[0].toLowerCase()).execute(sender,Arrays.copyOfRange(args, 1, args.length));
} catch (Exception e) {
sender.sendMessage(errorPrefix + "An error has occured.");
e.printStackTrace();
}
2021-08-13 20:49:36 +00:00
}
}
return true;
}
2021-12-26 04:46:22 +00:00
2021-08-13 20:49:36 +00:00
}