Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.rw_craft.elitemctntwars;
- import java.util.ArrayList;
- import java.util.Arrays;
- import me.rw_craft.elitemctntwars.cmds.Create;
- import me.rw_craft.elitemctntwars.cmds.Delete;
- import me.rw_craft.elitemctntwars.cmds.ForceStart;
- import me.rw_craft.elitemctntwars.cmds.ForceStop;
- import me.rw_craft.elitemctntwars.cmds.Join;
- import me.rw_craft.elitemctntwars.cmds.Leave;
- import me.rw_craft.elitemctntwars.cmds.SetLocation;
- import me.rw_craft.elitemctntwars.cmds.SubCommand;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- public class CommandManager implements CommandExecutor {
- private ArrayList<SubCommand> commands = new ArrayList<SubCommand>();
- public void Setup() {
- commands.add(new Create());
- commands.add(new Delete());
- commands.add(new ForceStart());
- commands.add(new ForceStop());
- commands.add(new Join());
- commands.add(new Leave());
- commands.add(new SetLocation());
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (!(sender instanceof Player)) {
- MessageManager.getInstance().severe(sender, "Only Players Can Use Commands (You're A Snowman? <3)");
- return true;
- }
- Player p = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("tntwars")) {
- if (args.length == 0) {
- for (SubCommand c : commands) {
- MessageManager.getInstance().info(p, "/tntwars" + c.name() + "(" + aliases(c) + ")" + "-" + c.info());
- }
- return true;
- }
- SubCommand target = get(args[0]);
- if (target == null) {
- MessageManager.getInstance().severe(p, "/tntwars" + args[0] + "Is Not A Valid Sub-Command");
- return true;
- }
- ArrayList<String> a = new ArrayList<String>();
- a.addAll(Arrays.asList(args));
- a.remove(0);
- args = a.toArray(new String[a.size()]);
- try {
- target.onCommand(p, args);
- }
- catch (Exception e) {
- MessageManager.getInstance().severe(p, "An Error Has Occured, Please Report It To A Server Administrator: "+e.getCause());
- e.printStackTrace();
- }
- }
- return true;
- }
- private String aliases(SubCommand cmd) {
- String fin = "";
- for (String a : cmd.aliases()) {
- fin += a = " | ";
- }
- return fin.substring(0, fin.lastIndexOf("|"));
- }
- private SubCommand get(String name) {
- for (SubCommand cmd : commands) {
- if (cmd.name().equalsIgnoreCase(name)) return cmd;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement