2021-08-23 17:57:50 +00:00
|
|
|
package net.tylermurphy.hideAndSeek;
|
2021-08-13 20:49:36 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2021-08-23 17:57:50 +00:00
|
|
|
import net.tylermurphy.hideAndSeek.commands.About;
|
|
|
|
import net.tylermurphy.hideAndSeek.commands.Help;
|
|
|
|
import net.tylermurphy.hideAndSeek.commands.SetBorder;
|
|
|
|
import net.tylermurphy.hideAndSeek.commands.SetSpawnLocation;
|
|
|
|
import net.tylermurphy.hideAndSeek.commands.Start;
|
|
|
|
import net.tylermurphy.hideAndSeek.commands.Stop;
|
|
|
|
import net.tylermurphy.hideAndSeek.util.ICommand;
|
2021-08-13 20:49:36 +00:00
|
|
|
|
|
|
|
import static net.tylermurphy.hideAndSeek.Store.*;
|
|
|
|
|
2021-08-23 17:57:50 +00:00
|
|
|
public class CommandHandler {
|
2021-08-13 20:49:36 +00:00
|
|
|
|
|
|
|
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>();
|
|
|
|
|
|
|
|
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 Start());
|
|
|
|
registerCommand(new Stop());
|
|
|
|
registerCommand(new SetSpawnLocation());
|
|
|
|
registerCommand(new SetBorder());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
|
|
if(sender instanceof Player == false) {
|
|
|
|
sender.sendMessage(errorPrefix + "This command can only be run as a player.");
|
|
|
|
} else if(args.length < 1) {
|
|
|
|
COMMAND_REGISTER.get("about").execute(sender, new String[0]);
|
|
|
|
} else if(!COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
|
|
|
|
COMMAND_REGISTER.get("about").execute(sender, Arrays.copyOfRange(args, 1, args.length));
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2021-08-23 17:57:50 +00:00
|
|
|
return CommandHandler.handleCommand(sender, command, label, args);
|
2021-08-13 20:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|