Search in sources :

Example 1 with MCCommand

use of com.laytonsmith.abstraction.MCCommand in project CommandHelper by EngineHub.

the class CommandHelperPlugin method onCommand.

/**
 * Called when a command registered by this plugin is received.
 *
 * @param sender
 * @param cmd
 * @param commandLabel
 * @param args
 * @return
 */
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    String cmdName = cmd.getName().toLowerCase();
    if ((sender.isOp() || (sender instanceof Player && (sender.hasPermission("commandhelper.reloadaliases") || sender.hasPermission("ch.reloadaliases")))) && (cmdName.equals("reloadaliases") || cmdName.equals("reloadalias") || cmdName.equals("recompile"))) {
        MCPlayer player = null;
        if (sender instanceof Player) {
            player = new BukkitMCPlayer((Player) sender);
        }
        ac.reload(player, args, false);
        return true;
    } else if (cmdName.equalsIgnoreCase("commandhelper")) {
        return args.length >= 1 && args[0].equalsIgnoreCase("null");
    } else if (cmdName.equals("runalias")) {
        // Hardcoded alias rebroadcast
        if (args.length == 0) {
            return false;
        }
        String command = StringUtils.Join(args, " ");
        if (sender instanceof Player) {
            PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent((Player) sender, command);
            playerListener.onPlayerCommandPreprocess(pcpe);
        } else if (sender instanceof ConsoleCommandSender || sender instanceof BlockCommandSender || sender instanceof CommandMinecart) {
            // event handler that would get them if they would not have started with "/runalias".
            if (command.startsWith("/")) {
                command = command.substring(1);
            }
            ServerCommandEvent sce = new ServerCommandEvent(sender, command);
            serverListener.onServerCommand(sce);
        }
        return true;
    } else if (cmdName.equalsIgnoreCase("interpreter-on")) {
        if (sender instanceof ConsoleCommandSender) {
            int interpreterTimeout = Prefs.InterpreterTimeout();
            if (interpreterTimeout != 0) {
                interpreterUnlockedUntil = (interpreterTimeout * 60 * 1000) + System.currentTimeMillis();
                sender.sendMessage("Interpreter mode unlocked for " + interpreterTimeout + " minute" + (interpreterTimeout == 1 ? "" : "s"));
            }
        } else {
            sender.sendMessage("This command can only be run from console.");
        }
        return true;
    } else if (sender instanceof Player && cmdName.equalsIgnoreCase("interpreter")) {
        if (!sender.hasPermission("commandhelper.interpreter")) {
            sender.sendMessage(MCChatColor.RED + "You do not have permission to run that command");
        } else if (!Prefs.EnableInterpreter()) {
            sender.sendMessage(MCChatColor.RED + "The interpreter is currently disabled." + " Check your preferences file.");
        } else if (Prefs.InterpreterTimeout() != 0 && interpreterUnlockedUntil < System.currentTimeMillis()) {
            sender.sendMessage(MCChatColor.RED + "Interpreter mode is currently locked. Run \"interpreter-on\"" + " console to unlock it. If you want to turn this off entirely, set the interpreter-timeout" + " option to 0 in " + CommandHelperFileLocations.getDefault().getPreferencesFile().getName());
        } else {
            interpreterListener.startInterpret(sender.getName());
            sender.sendMessage(MCChatColor.YELLOW + "You are now in interpreter mode. Type a dash (-) on a" + " line by itself to exit, and >>> to enter multiline mode.");
        }
        return true;
    } else {
        MCCommandSender mcsender = BukkitConvertor.BukkitGetCorrectSender(sender);
        MCCommand mccmd = new BukkitMCCommand(cmd);
        return mccmd.handleCustomCommand(mcsender, commandLabel, args);
    }
}
Also used : PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Player(org.bukkit.entity.Player) BukkitMCPlayer(com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer) MCPlayer(com.laytonsmith.abstraction.MCPlayer) BukkitMCCommand(com.laytonsmith.abstraction.bukkit.BukkitMCCommand) MCCommand(com.laytonsmith.abstraction.MCCommand) BukkitMCPlayer(com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer) MCPlayer(com.laytonsmith.abstraction.MCPlayer) ServerCommandEvent(org.bukkit.event.server.ServerCommandEvent) BukkitMCPlayer(com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) MCCommandSender(com.laytonsmith.abstraction.MCCommandSender) BukkitMCCommand(com.laytonsmith.abstraction.bukkit.BukkitMCCommand) BlockCommandSender(org.bukkit.command.BlockCommandSender) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart)

Example 2 with MCCommand

use of com.laytonsmith.abstraction.MCCommand in project CommandHelper by EngineHub.

the class CommandHelperPlugin method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    MCCommandSender mcsender = BukkitConvertor.BukkitGetCorrectSender(sender);
    MCCommand cmd = new BukkitMCCommand(command);
    return cmd.handleTabComplete(mcsender, alias, args);
}
Also used : BukkitMCCommand(com.laytonsmith.abstraction.bukkit.BukkitMCCommand) MCCommand(com.laytonsmith.abstraction.MCCommand) MCCommandSender(com.laytonsmith.abstraction.MCCommandSender) BukkitMCCommand(com.laytonsmith.abstraction.bukkit.BukkitMCCommand)

Aggregations

MCCommand (com.laytonsmith.abstraction.MCCommand)2 MCCommandSender (com.laytonsmith.abstraction.MCCommandSender)2 BukkitMCCommand (com.laytonsmith.abstraction.bukkit.BukkitMCCommand)2 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 BukkitMCPlayer (com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer)1 BlockCommandSender (org.bukkit.command.BlockCommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1 CommandMinecart (org.bukkit.entity.minecart.CommandMinecart)1 PlayerCommandPreprocessEvent (org.bukkit.event.player.PlayerCommandPreprocessEvent)1 ServerCommandEvent (org.bukkit.event.server.ServerCommandEvent)1