Java Code Examples for net.minecraft.command.CommandHandler

The following are top voted examples for showing how to use net.minecraft.command.CommandHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: EnderCore   File: EnderCore.java   View source code 6 votes vote down vote up
@EventHandler
public void init(FMLInitializationEvent event) {
  EnderPacketHandler.init();

  for (IConfigHandler c : configs) {
    c.initHook();
  }

  Handlers.register(event);
  CompatRegistry.INSTANCE.handle(event);
  ClientCommandHandler.instance.registerCommand(CommandReloadConfigs.CLIENT);
  if (event.getSide().isServer()) {
    ((CommandHandler) MinecraftServer.getServer().getCommandManager()).registerCommand(CommandReloadConfigs.SERVER);
  }

  IMCRegistry.INSTANCE.init();
}
 
Example 2
Project: ItemBlacklist   File: ItemBlacklist.java   View source code 6 votes vote down vote up
private void updateConfig()
{
    message = configuration.getString("message", CATEGORY_GENERAL, "Now is not the time to use that. ~Prof. Oak", "The message you get when using an item that is banned.");
    log = configuration.getBoolean("log", CATEGORY_GENERAL, false, "Log every instance of any banned item used. (SPAM WARNING!)");
    unpack4all = configuration.getBoolean("unpack4all", CATEGORY_GENERAL, true, "Let everyone unpack items by using the 'unpack' command. So items can be used in crafting.");

    if (configuration.hasChanged()) configuration.save();

    if (pastStart)
    {
        CommandHandler ch = (CommandHandler) FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager();
        if (unpack4all) ch.registerCommand(CommandUnpack.I);
        else
        {
            ch.getCommands().remove(CommandUnpack.I.getName());
            for (String s : CommandUnpack.I.getAliases()) ch.getCommands().remove(s);
        }
    }
}
 
Example 3
Project: ServerTools-PERMISSION   File: CommandRemovePerm.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] strings) {

    if (strings.length == 1) {
        CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
        List<String> ret = new ArrayList<>(ch.getCommands().size());
        for (ICommand command : (Collection<ICommand>) ch.getCommands().values()) {
            ret.add("cmd." + command.getCommandName());
        }
        return getListOfStringsFromIterableMatchingLastWord(strings, ret);
    } else if (strings.length == 2) {
        Collection<String> groupKeys = PermissionManager.getGroupNames();
        return getListOfStringsMatchingLastWord(strings, groupKeys.toArray(new String[groupKeys.size()]));
    } else {
        return null;
    }

}
 
Example 4
Project: ServerTools-PERMISSION   File: CommandAddPerm.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] strings) {

    if (strings.length == 1) {
        CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
        List<String> ret = new ArrayList<>(ch.getCommands().size());
        for (ICommand command : (Collection<ICommand>) ch.getCommands().values()) {
            ret.add("cmd." + command.getCommandName());
        }
        return getListOfStringsFromIterableMatchingLastWord(strings, ret);
    } else if (strings.length == 2) {
        Collection<String> groupKeys = PermissionManager.getGroupNames();
        return getListOfStringsMatchingLastWord(strings, groupKeys.toArray(new String[groupKeys.size()]));
    } else {
        return null;
    }

}
 
Example 5
Project: LoreExpansion_old   File: CommandDelayHandler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void tick(TickEvent.ServerTickEvent event) {
    if (event.phase == TickEvent.Phase.START)
        return;

    Iterator<DelayedCommand> delayedIterator = delayedCommands.iterator();
    while (delayedIterator.hasNext()) {
        DelayedCommand delayedCommand = delayedIterator.next();

        delayedCommand.timer--;
        if (delayedCommand.timer <= 0) {
            CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
            LoreCommandSender commandSender = new LoreCommandSender(delayedCommand.getPlayer());

            for (String command : delayedCommand.commands) {
                ch.executeCommand(commandSender, command);
            }

            delayedIterator.remove();
        }
    }
}
 
Example 6
Project: FirstAid   File: FirstAid.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void beforeServerStart(FMLServerAboutToStartEvent event) {
    ICommandManager manager = event.getServer().getCommandManager();
    if (manager instanceof CommandHandler) {
        ((CommandHandler) manager).registerCommand(new DebugDamageCommand());
    }
}
 
Example 7
Project: TaleCraft   File: TaleCraft.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event){
	MinecraftServer server = event.getServer();

	ICommandManager cmdmng = server.getCommandManager();
	if (cmdmng instanceof ServerCommandManager && cmdmng instanceof CommandHandler) {
		CommandHandler cmdhnd = (CommandHandler) cmdmng;
		TaleCraftCommands.register(cmdhnd);
	}

	// By calling this method, we create the ServerMirror for the given server.
	ServerHandler.getServerMirror(server);
}
 
Example 8
Project: MeddleAPI   File: MeddleAPI.java   View source code 5 votes vote down vote up
public static void registerCommandHandler(ICommand cmd)
{
	if (MeddleUtil.isClientJar()) delayedICommands.add(cmd);
	else {
		((CommandHandler) getServer().getCommandManager()).registerCommand(cmd);
	}
}
 
Example 9
Project: MeddleAPI   File: MeddleAPI.java   View source code 5 votes vote down vote up
public static void onServerRunHook(MinecraftServer server)
{	
	if (MeddleUtil.isClientJar()) {			
		CommandHandler cmdHandler = (CommandHandler) server.getCommandManager();
		for (ICommand cmd : delayedICommands)
		{
			cmdHandler.registerCommand(cmd);
		}
	}
}
 
Example 10
Project: LambdaLib   File: LambdaLib.java   View source code 5 votes vote down vote up
@EventHandler()
public void serverStarting(FMLServerStartingEvent event) {
    CommandHandler cm = (CommandHandler) event.getServer().getCommandManager();
    if (DEBUG) {
        cm.registerCommand(new CmdMineStatistics());
    }
    RegistrationManager.INSTANCE.registerAll(this, "StartServer");
}
 
Example 11
Project: morecommands   File: ServerPlayerSettings.java   View source code 5 votes vote down vote up
@Override
protected void registerAliases() {
	CommandHandler commandHandler = (CommandHandler) FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager();
	String command;
	
	for (String alias : this.aliases.keySet()) {
		command = this.aliases.get(alias).split(" ")[0];
		
		if (!command.equalsIgnoreCase(alias) && !commandHandler.getCommands().containsKey(alias)) {
			DummyCommand cmd = new DummyCommand(alias, false);
			commandHandler.getCommands().put(alias, cmd);
		}
	}
}
 
Example 12
Project: NeptuneMod   File: MixinCommandHandler.java   View source code 5 votes vote down vote up
/**
 * @author jamierocks - 15th May 2015
 * @reason Add Canary tab-completion results
 */
@Overwrite
public List<String> getTabCompletionOptions(ICommandSender sender, String input, BlockPos pos) {
    final String[] commandSplit = input.split(" ", -1);
    final String commandName = commandSplit[0];

    if (commandSplit.length == 1) {
        final List<String> matches = Lists.newArrayList();

        // Neptune - Add Canary command matches
        matches.addAll(Canary.commands().matchCommandNames((MessageReceiver) sender, commandName, false));
        // Neptune - end

        for (final Map.Entry<String, ICommand> alias : this.commandMap.entrySet()) {
            if (CommandBase.doesStringStartWith(commandName, alias.getKey()) && alias.getValue().canCommandSenderUseCommand(sender)) {
                matches.add(alias.getKey());
            }
        }

        return matches;
    } else {
        if (commandSplit.length > 1) {
            // Neptune - Tab complete through Canary if possible
            final List<String> options = Canary.commands().tabComplete((MessageReceiver) sender, commandName, CommandHandler.dropFirstString(commandSplit));
            if (options != null) {
                return options;
            }
            // Neptune - end

            final ICommand command = this.commandMap.get(commandName);
            if (command != null && command.canCommandSenderUseCommand(sender)) {
                return command.addTabCompletionOptions(sender, CommandHandler.dropFirstString(commandSplit), pos);
            }
        }

        return null;
    }
}
 
Example 13
Project: D3Commands   File: D3Commands.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
    CommandHandler ch = (CommandHandler) event.getServer().getCommandManager();
    for (CommandEntry e : commandsMap.values())
    {
        if (e.isEnabled()) ch.registerCommand(e.getInstance());
    }
    pastStart = true;
}
 
Example 14
Project: libsandstone   File: Sandstone.java   View source code 5 votes vote down vote up
@EventHandler
public void serverStarted(FMLServerStartedEvent event) {
    CommandHandler handler = (CommandHandler) MinecraftServer.getServer().getCommandManager();

    if ((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) {
        handler.registerCommand(new CommandDebug());
    }
}
 
Example 15
Project: ServerTools-CORE   File: CommandManager.java   View source code 5 votes vote down vote up
private void overrideHelp(final CommandHandler commandHandler) {
    if (Loader.isModLoaded("HelpFixer")) {
        log.trace("HelpFixer detected. Not overriding /help");
    } else {
        log.trace("Overriding /help");
        commandHandler.registerCommand(new CommandHelp() {

            @Override
            protected List<ICommand> getSortedPossibleCommands(final ICommandSender sender) {
                final List<ICommand> list = MinecraftServer.getServer().getCommandManager().getPossibleCommands(sender);
                final Iterator<ICommand> iterator = list.iterator();
                while (iterator.hasNext()) {
                    ICommand command = iterator.next();
                    if (command.getCommandName() == null) {
                        log.warn("Identified command with a null name: {}", command.getClass());
                        iterator.remove();
                    } else if (command.getCommandUsage(sender) == null) {
                        log.warn("Identified command with null usage: {}", command.getClass());
                        iterator.remove();
                    }
                }

                Collections.sort(list, (o1, o2) -> o1.getCommandName().compareTo(o2.getCommandName()));
                return list;
            }
        });
    }
}
 
Example 16
Project: ServerTools-CORE   File: CommandManager.java   View source code 5 votes vote down vote up
/**
 * <em>Internal Use Only!</em>
 *
 * @param server The server
 */
public void doRegister(final MinecraftServer server) {
    log.trace("Registering commands with Minecraft...");
    CommandHandler commandHandler = (CommandHandler) server.getCommandManager();
    commands.forEach(commandHandler::registerCommand);

    if (ServerToolsCore.instance().getConfig().getGeneral().isHelpOverrideEnabled()) {
        overrideHelp(commandHandler);
    }
}
 
Example 17
Project: ForestryLegacy   File: ForestryCore.java   View source code 5 votes vote down vote up
public void serverStarting(MinecraftServer server) {
	CommandHandler commandManager = (CommandHandler) server.getCommandManager();
	for (IPlugin plugin : PluginManager.plugins)
		if (plugin.isAvailable()) {
			ICommand[] commands = plugin.getConsoleCommands();
			if (commands == null) {
				continue;
			}
			for (ICommand command : commands) {
				commandManager.registerCommand(command);
			}
		}
}
 
Example 18
Project: Hats   File: ProxyCommon.java   View source code 5 votes vote down vote up
public void initCommands(MinecraftServer server)
{
    ICommandManager manager = server.getCommandManager();
    if(manager instanceof CommandHandler)
    {
        CommandHandler handler = (CommandHandler)manager;
        handler.registerCommand(new CommandHats());
    }
}
 
Example 19
Project: Sojourn   File: Sojourn.java   View source code 5 votes vote down vote up
@EventHandler
public void serverStarting(FMLServerStartingEvent event)
{       
    CommandHandler commandManager = (CommandHandler)event.getServer().getCommandManager();
    commandManager.registerCommand(new CommandCreateGroup());
    commandManager.registerCommand(new CommandJoinGroup());
}
 
Example 20
Project: Morph   File: CommonProxy.java   View source code 5 votes vote down vote up
public void initCommands(MinecraftServer server)
{
    ICommandManager manager = server.getCommandManager();
    if(manager instanceof CommandHandler)
    {
        CommandHandler handler = (CommandHandler)manager;
        handler.registerCommand(new CommandMorph());
    }
}
 
Example 21
Project: Gravestone-mod-Graves   File: Commands.java   View source code 5 votes vote down vote up
public static void registration(FMLServerStartingEvent event) {
    CommandHandler commandManager = (CommandHandler) event.getServer().getCommandManager();
    commandManager.registerCommand(new Command());
    commandManager.registerCommand(new CommandLowerCase());
    commandManager.registerCommand(new CommandGravestone());
    commandManager.registerCommand(new CommandGravestoneLowerCase());
}
 
Example 22
Project: EnchancedAdventuronics   File: EnhancedAdventuronics.java   View source code 5 votes vote down vote up
@EventHandler
public void onServerStart(FMLServerAboutToStartEvent event){
	CommandHandler manager = (CommandHandler) event.getServer().getCommandManager();
	manager.registerCommand(new VelocityCommand());
	manager.registerCommand(new CTabCommand());
	manager.registerCommand(new NotifyCommand());
	manager.registerCommand(new WipeEntitiesCommand());

}
 
Example 23
Project: CustomWorldGen   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 24
Project: 4Space-5   File: ServerUtils.java   View source code 4 votes vote down vote up
public static void registerCommand(ICommand command) {
    ((CommandHandler) mc().getCommandManager()).registerCommand(command);
}
 
Example 25
Project: TRHS_Club_Mod_2016   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().func_71187_D();
    ch.func_71560_a(command);
}
 
Example 26
Project: TaleCraft   File: TaleCraftCommands.java   View source code 4 votes vote down vote up
public static void register(CommandHandler registry) {
	for(ICommand cmd : commands) {
		registry.registerCommand(cmd);
	}
}
 
Example 27
Project: LambdaLib   File: CommandRegistration.java   View source code 4 votes vote down vote up
@Override
protected void register( Class<? extends ICommand> theClass, RegCommand anno) throws Exception {
    CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
    ch.registerCommand(theClass.newInstance());
}
 
Example 28
Project: CauldronGit   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 29
Project: CreativeBlocks   File: Commands.java   View source code 4 votes vote down vote up
public static void init(MinecraftServer server)
{
    CommandHandler commandHandler = (CommandHandler) server.getCommandManager();

    commandHandler.registerCommand(new CommandCreativeBlocks());
}
 
Example 30
Project: D3Commands   File: D3Commands.java   View source code 4 votes vote down vote up
private void updateConfig()
{
    final String items = "itemcommands";

    configuration.setCategoryLanguageKey(items, "d3.cmd.config.items");
    configuration.addCustomCategoryComment(items, "Make new categories like the example to add new commands that give a specific item.");
    configuration.setCategoryRequiresWorldRestart(items, true);

    {
        final String example = items + ".key";
        configuration.addCustomCategoryComment(example,
                "Example, don't delete, just disable if you don't want it. Values in here are defaults, except for enabled.\n" +
                "CHANGES: modid became modids! All mods have to be present for the command to work. Useful for compatibility items.");
        configuration.getString("name", example, "key", "The name of the command. aka the part after the slash. Cannot have spaces. Case sensitive! Required!");
        configuration.getStringList("aliases", example, new String[] {"spectre", "spectrekey"}, "A list of alternative names. Case sensitive!");
        configuration.getBoolean("allowUsername", example, true, "Allow a username to be specified, to give the item to someone else.");
        configuration.getStringList("modids", example, new String[] {"RandomThings"}, "The modid that needs to be loaded for this command to work. Case sensitive!");
        configuration.getString("item", example, "RandomThings:spectreKey", "Like you would use in '/give' Required!");
        configuration.getInt("meta", example, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, "Metadata or Damage value of the item.");
        configuration.getInt("stacksize", example, 1, 0, 64, "The stacksize. 0 is a nice troll btw :p");
        configuration.getString("message", example, "Here you go!", "The message that appears after a successful command.");
        configuration.getString("displayname", example, "", "Set a custom display name if you want it.");
        configuration.getBoolean("enabled", example, false, "Easy enable / disable here. Enabled by default!");
    }

    ConfigCategory root = configuration.getCategory(items);
    for (ConfigCategory cat : root.getChildren())
    {
        if (!commandsMap.containsKey(cat.getQualifiedName()))
        {
            ItemCommandEntry entry = new ItemCommandEntry(cat);
            commandsMap.put(entry.getUniqueName(), entry);
        }
    }

    configuration.setCategoryLanguageKey(MODID, "d3.cmd.config.cmd");
    configuration.addCustomCategoryComment(MODID, "Set any value to false to disable the command.");
    configuration.setCategoryRequiresWorldRestart(MODID, true);

    if (pastStart)
    {
        CommandHandler ch = (CommandHandler) FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager();
        for (CommandEntry e : commandsMap.values())
        {
            boolean was = e.isEnabled();
            e.doConfig(configuration);
            boolean is = e.isEnabled();
            if (pastStart && was != is) // If we are past start, and the status has changed
            {
                if (!is) // Remove
                {
                    ch.getCommands().remove(e.getInstance().getCommandName());
                    for (String s : e.getInstance().getCommandAliases()) ch.getCommands().remove(s);
                }
                else // Add
                {
                    ch.registerCommand(e.getInstance());
                }
            }
        }
    }

    if (configuration.hasChanged()) configuration.save();
}
 
Example 31
Project: Dimensional-Pockets   File: CommandAbstract.java   View source code 4 votes vote down vote up
public CommandAbstract register() {
    CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
    ch.registerCommand(this);
    return this;
}
 
Example 32
Project: Cauldron   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 33
Project: Cauldron   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 34
Project: Cauldron   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 35
Project: Blockbender   File: mod_Avatar.java   View source code 4 votes vote down vote up
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
	CommandHandler commandManager = (CommandHandler) event.getServer().getCommandManager();
	commandManager.registerCommand(new CommandBending());
	commandManager.registerCommand(new CommandRegion());
}
 
Example 36
Project: LoreExpansion_old   File: PlayerTickHandler.java   View source code 4 votes vote down vote up
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.START && event.side == Side.SERVER) {
        if (!event.player.capabilities.isCreativeMode) {
            for (int i = 0; i < event.player.inventory.getSizeInventory(); i++) {
                ItemStack stack = event.player.inventory.getStackInSlot(i);

                if (stack != null && stack.getItem() == LoreExpansion.lorePage) {
                    LoreKey key = ItemLorePage.getLore(stack);
                    if (key != null) {
                        Lore lore = LoreLoader.getLore(key);

                        if (lore == null) {
                            return;
                        }

                        LoreProperties collectedLore = PlayerHandler.getCollectedLore(event.player);
                        if (!collectedLore.hasLore(key)) {
                            collectedLore.addLore(key);

                            PacketSyncLore.updateLore((EntityPlayerMP) event.player);


                            // Pickup notification packet
                            PacketNotification.notify(event.player, PacketNotification.TYPE_CLIENT_PICKUP, key);

                            // Autoplay handling
                            LoreProperties properties = PlayerHandler.getCollectedLore(event.player);
                            if (lore.autoplay && properties.canAutoplay(key)) {
                                properties.setAutoplayed(key, true);
                                PacketNotification.notify(event.player, PacketNotification.TYPE_CLIENT_AUTOPLAY, key);
                            }

                            if (lore.commands.commands != null) {
                                for (Commands.CommandEntry command : lore.commands.commands) {
                                    if (command.delay > 0) {
                                        CommandDelayHandler.queueCommand(event.player, command);
                                    } else {
                                        CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
                                        LoreCommandSender commandSender = new LoreCommandSender(event.player);
                                        for (String c : command.commands) {
                                            ch.executeCommand(commandSender, c);
                                        }
                                    }
                                }
                            }
                        }

                        event.player.inventory.setInventorySlotContents(i, null);
                        event.player.inventory.markDirty();

                        return;
                    }

                    // Only set this to false if no lore has been updated this tick
                    notifiedThisTick = false;
                }
            }
        }
    }
}
 
Example 37
Project: Hackery   File: HackeryCommonProxy.java   View source code 4 votes vote down vote up
public void registerServerCommands() {
    ((CommandHandler) MinecraftServer.getServer().getCommandManager()).registerCommand(new nsodCommand());
}
 
Example 38
Project: RuneCraftery   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().func_71187_D();
    ch.func_71560_a(command);
}
 
Example 39
Project: RuneCraftery   File: FMLServerStartingEvent.java   View source code 4 votes vote down vote up
public void registerServerCommand(ICommand command)
{
    CommandHandler ch = (CommandHandler) getServer().getCommandManager();
    ch.registerCommand(command);
}
 
Example 40
Project: Realms-of-Chaos   File: RealmsOfChaos.java   View source code 4 votes vote down vote up
@EventHandler
   public void serverStarting(FMLServerStartingEvent event){
	if (MinecraftServer.getServer().getCommandManager() instanceof ServerCommandManager) {
		((CommandHandler) MinecraftServer.getServer().getCommandManager()).registerCommand(new CommandFloor());
	}
}