Search in sources :

Example 6 with AbstractCommand

use of com.builtbroken.mc.prefab.commands.AbstractCommand in project Engine by VoltzEngine-Project.

the class CommandRegion method handleEntityPlayerCommand.

@Override
public boolean handleEntityPlayerCommand(EntityPlayer player, String[] args) {
    if (args.length > 0) {
        String name = args[0];
        Region region = RegionManager.getControllerForWorld(player.worldObj).getRegion(name);
        if (region != null) {
            if (args.length > 1) {
                for (AbstractCommand command : subCommands) {
                    if (command instanceof SubCommandRegion && command.getCommandName().equalsIgnoreCase(args[1])) {
                        if (((SubCommandRegion) command).handle(player, region, removeFront(args, 2))) {
                            return true;
                        }
                    }
                }
            }
            player.addChatMessage(new ChatComponentText("Unknown region sub command"));
        } else {
            player.addChatMessage(new ChatComponentText("Unknown region"));
        }
    } else {
        player.addChatMessage(new ChatComponentText("Missing region name"));
    }
    return true;
}
Also used : SubCommandRegion(com.builtbroken.mc.core.commands.ext.SubCommandRegion) AbstractCommand(com.builtbroken.mc.prefab.commands.AbstractCommand) Region(com.builtbroken.mc.lib.modflags.Region) SubCommandRegion(com.builtbroken.mc.core.commands.ext.SubCommandRegion) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 7 with AbstractCommand

use of com.builtbroken.mc.prefab.commands.AbstractCommand in project Engine by VoltzEngine-Project.

the class CommandGroup method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    String name = args[0];
    AccessGroup group = GroupProfileHandler.GLOBAL.getAccessProfile().getGroup(name);
    if (group != null) {
        if (args.length > 1) {
            for (AbstractCommand command : subCommands) {
                if (command instanceof GroupSubCommand && command.getCommandName().equalsIgnoreCase(args[1])) {
                    if (((GroupSubCommand) command).handle(sender, group, "", removeFront(args, 2))) {
                        return true;
                    }
                }
            }
        }
        sender.addChatMessage(new ChatComponentText("Unknown group sub command"));
    } else {
        sender.addChatMessage(new ChatComponentText("Unknown group"));
    }
    return true;
}
Also used : AccessGroup(com.builtbroken.mc.lib.access.AccessGroup) AbstractCommand(com.builtbroken.mc.prefab.commands.AbstractCommand) ChatComponentText(net.minecraft.util.ChatComponentText) GroupSubCommand(com.builtbroken.mc.core.commands.ext.GroupSubCommand)

Example 8 with AbstractCommand

use of com.builtbroken.mc.prefab.commands.AbstractCommand in project Engine by VoltzEngine-Project.

the class CommandUser method getHelpOutput.

@Override
public void getHelpOutput(ICommandSender sender, List<String> items) {
    List<String> commands;
    for (AbstractCommand command : subCommands) {
        commands = new ArrayList();
        command.getHelpOutput(sender, commands);
        for (String s : commands) {
            items.add("[name] " + command.getCommandName() + " " + s);
        }
    }
}
Also used : AbstractCommand(com.builtbroken.mc.prefab.commands.AbstractCommand) ArrayList(java.util.ArrayList)

Example 9 with AbstractCommand

use of com.builtbroken.mc.prefab.commands.AbstractCommand in project Engine by VoltzEngine-Project.

the class CommandUser method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    if (isHelpCommand(args)) {
        handleHelp(sender, args);
    } else {
        String name = args[0];
        AccessUser user = GroupProfileHandler.GLOBAL.getAccessProfile().getUserAccess(name);
        if (user != null && user.getGroup() != null) {
            if (args.length > 1) {
                for (AbstractCommand command : subCommands) {
                    if (command instanceof UserSubCommand && command.getCommandName().equalsIgnoreCase(args[1])) {
                        if (((UserSubCommand) command).handle(sender, user, removeFront(args, 2))) {
                            return true;
                        }
                    }
                }
            }
            sender.addChatMessage(new ChatComponentText("Unknown user sub command"));
        } else {
            sender.addChatMessage(new ChatComponentText("User not found in permissions profile"));
        }
    }
    return true;
}
Also used : UserSubCommand(com.builtbroken.mc.core.commands.ext.UserSubCommand) AbstractCommand(com.builtbroken.mc.prefab.commands.AbstractCommand) ChatComponentText(net.minecraft.util.ChatComponentText) AccessUser(com.builtbroken.mc.lib.access.AccessUser)

Example 10 with AbstractCommand

use of com.builtbroken.mc.prefab.commands.AbstractCommand in project Engine by VoltzEngine-Project.

the class TestAbstractCommand method testCombineArgs.

@Test
public void testCombineArgs() {
    AbstractCommand command = new AbstractCommand("command");
    String[] args = new String[] { "Hi", "we", "love", "testing", ":p" };
    String combined = command.combine(args);
    assertTrue(combined.equals("Hi we love testing :p"));
    combined = command.combine(args, 0, 2);
    assertTrue(combined.equals("Hi we"));
    combined = command.combine(args, 2, 4);
    assertTrue(combined.equals("love testing"));
}
Also used : AbstractCommand(com.builtbroken.mc.prefab.commands.AbstractCommand) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Aggregations

AbstractCommand (com.builtbroken.mc.prefab.commands.AbstractCommand)10 ArrayList (java.util.ArrayList)4 ChatComponentText (net.minecraft.util.ChatComponentText)4 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)2 Test (org.junit.Test)2 GroupSubCommand (com.builtbroken.mc.core.commands.ext.GroupSubCommand)1 SubCommandRegion (com.builtbroken.mc.core.commands.ext.SubCommandRegion)1 UserSubCommand (com.builtbroken.mc.core.commands.ext.UserSubCommand)1 AccessGroup (com.builtbroken.mc.lib.access.AccessGroup)1 AccessUser (com.builtbroken.mc.lib.access.AccessUser)1 Region (com.builtbroken.mc.lib.modflags.Region)1