/** * Callback for when the command is executed */ @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if(args.length < 1) { sender.addChatMessage(new TextComponentString(CommandBase.joinNiceStringFromCollection(commandMap.keySet()))); } else { ICommand cmd = getCommandMap().get(args[0]); if(cmd == null) { throw new CommandException("commands.tree_base.invalid_cmd", args[0]); } else if(!cmd.checkPermission(server, sender)) { throw new CommandException("commands.generic.permission"); } else { cmd.execute(server, sender, shiftArgs(args)); } } }
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length == 0) { throw new CommandException("nosubcommandspecified"); } final Optional<CommandBase> first = childCommands .stream() .sorted(Comparator.comparing(ICommand::getCommandName)) .filter(command -> command.getCommandName().equals(args[0])) .findFirst(); if (!first.isPresent()) { throw new CommandException("nosuchsubcommand"); } final CommandBase commandBase = first.get(); final String[] parameters = Arrays.copyOfRange(args, 1, args.length); commandBase.execute(server, sender, parameters); }
@Override public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) { if (args.length <= 1) { return childCommands .stream() .map(ICommand::getCommandName) .sorted() .filter(command -> command.startsWith(args[0])) .collect(Collectors.toList()); } final Optional<CommandBase> first = childCommands .stream() .sorted(Comparator.comparing(ICommand::getCommandName)) .filter(command -> command.getCommandName() == args[0]) .findFirst(); if (!first.isPresent()) { return Lists.newArrayList(); } final String[] parameters = Arrays.copyOfRange(args, 1, args.length - 2); return first.get().getTabCompletionOptions(server, sender, parameters, pos); }
public CommandHandler(TickDynamicMod mod) { this.mod = mod; aliases = new ArrayList<String>(); aliases.add("tickdynamic"); aliases.add("td"); subCommandHandlers = new HashMap<String, ICommand>(); subCommandHandlers.put("reload", new CommandReload(mod)); subCommandHandlers.put("reloadgroups", new CommandReloadGroups(mod)); subCommandHandlers.put("listworlds", new CommandListWorlds(mod)); subCommandHandlers.put("world", new CommandWorld(mod)); subCommandHandlers.put("enabled", new CommandEnabled(mod)); StringBuilder builderSubCommands = new StringBuilder(); SubCommands[] subs = SubCommands.values(); for(SubCommands command : subs) { builderSubCommands.append(command).append(", "); } builderSubCommands.delete(builderSubCommands.length()-2, builderSubCommands.length()); listSubCommands = builderSubCommands.toString(); }
@Override public List addTabCompletionOptions(ICommandSender sender, String[] args) { if(args.length == 1) { List listOut = new LinkedList(); String lastArg = args[args.length-1]; SubCommands[] subCommands = SubCommands.values(); for(SubCommands command : subCommands) { if(command.toString().contains(lastArg)) listOut.add(command.toString()); } return listOut; } else { //Send it over to subCommand handler ICommand subHandler = subCommandHandlers.get(args[0]); if(subHandler == null) return null; return subHandler.addTabCompletionOptions(sender, args); } }
public void unregisterInForge(ICommand command) { Map<String, ICommand> commandMap = this.manager.getCommands(); Set<ICommand> commandSet = this.manager.commandSet; commandSet.remove(command); ICommand otherCommand = commandMap.get(command.getCommandName()); if(otherCommand == command) commandMap.remove(command.getCommandName()); else for(Map.Entry<String, ICommand> entry: commandMap.entrySet()) { if(entry.getValue() == command) { commandMap.remove(entry.getKey()); break; } } }
@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; } }
/** * Checks to see if a command is in the whole list. * @param testedCommand The command to check to see if it exists. * @return Whether or not the command exists. */ public boolean isCommandInList(ICommand testedCommand) { ICommand[] commands = getAllCommands(); if (commands != null) { for (ICommand command : commands) { if (command == testedCommand) { return true; } } } //Should be put in an else block, but that causes an error for some stupid reason. return false; }
public ICommand func_71560_a(ICommand p_71560_1_) { List var2 = p_71560_1_.func_71514_a(); this.field_71562_a.put(p_71560_1_.func_71517_b(), p_71560_1_); this.field_71561_b.add(p_71560_1_); if(var2 != null) { Iterator var3 = var2.iterator(); while(var3.hasNext()) { String var4 = (String)var3.next(); ICommand var5 = (ICommand)this.field_71562_a.get(var4); if(var5 == null || !var5.func_71517_b().equals(var4)) { this.field_71562_a.put(var4, p_71560_1_); } } } return p_71560_1_; }
public List func_71558_b(ICommandSender p_71558_1_, String p_71558_2_) { String[] var3 = p_71558_2_.split(" ", -1); String var4 = var3[0]; if(var3.length == 1) { ArrayList var8 = new ArrayList(); Iterator var6 = this.field_71562_a.entrySet().iterator(); while(var6.hasNext()) { Entry var7 = (Entry)var6.next(); if(CommandBase.func_71523_a(var4, (String)var7.getKey()) && ((ICommand)var7.getValue()).func_71519_b(p_71558_1_)) { var8.add(var7.getKey()); } } return var8; } else { if(var3.length > 1) { ICommand var5 = (ICommand)this.field_71562_a.get(var4); if(var5 != null) { return var5.func_71516_a(p_71558_1_, func_71559_a(var3)); } } return null; } }
@Override public Collection<Node> getPermissionNodes() { HashSet<Node> nodes = new HashSet<>(); MinecraftServer server = MinecraftServer.getServer(); if (server != null) { for (Object o : server.getCommandManager().getCommands().values()) { ICommand command = (ICommand) o; commands.add(command.getCommandName()); nodes.add(new Node(NAME, command.getCommandName())); } } else { nodes.add(new Node(NAME)); } return nodes; }
@Override public void addCommands(Consumer<ICommand> registerCommand) { registerCommand.accept(new PositionCommand("pos1", this::setPositionOne)); registerCommand.accept(new PositionCommand("pos2", this::setPositionTwo)); registerCommand.accept(new LookPositionCommand("hpos1", this::setPositionOne)); registerCommand.accept(new LookPositionCommand("hpos2", this::setPositionTwo)); registerCommand.accept(new ShiftCommand("shift")); registerCommand.accept(new ExpandCommand("expand")); registerCommand.accept(new ContractCommand("contract")); registerCommand.accept(new SelectionWandCommand()); }
@Override public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) { if(args.length == 1) { List<String> keys = new ArrayList<String>(); for(ICommand c : getCommandMap().values()) { if(c.checkPermission(server, sender)) { keys.add(c.getCommandName()); } } Collections.sort(keys, null); return getListOfStringsMatchingLastWord(args, keys); } ICommand cmd = getCommandMap().get(args[0]); if(cmd != null) { return cmd.getTabCompletionOptions(server, sender, shiftArgs(args), pos); } return super.getTabCompletionOptions(server, sender, args, pos); }
/** * Return whether the specified command parameter index is a username parameter. */ @Override public boolean isUsernameIndex(String[] args, int index) { if(index > 0 && args.length > 1) { ICommand cmd = getCommandMap().get(args[0]); if(cmd != null) { return cmd.isUsernameIndex(shiftArgs(args), index - 1); } } return false; }
public static void commandArguments(Expect e, Function<Parameters, Parameter<String>> start) { e.nextRaw((server1, sender, params, pos1) -> { Parameter<String> commandParameter = start.apply(params); Optional<ICommand> other = commandParameter.tryGet().map(server1.getCommandManager().getCommands()::get); return other.map(c -> c.getTabCompletions(server1, sender, commandParameter.move(1).to(NaP::varargs).get(), pos1)).orElse(Collections.emptyList()); }).descriptionU("args..."); }
@Override public void registerClientCommands() { if (XUHelper.deObf || XUHelper.isTema(Minecraft.getMinecraft().getSession().func_148256_e())) { ClientCommandHandler.instance.registerCommand((ICommand)new CommandDumpNEIInfo()); ClientCommandHandler.instance.registerCommand((ICommand)new CommandDumpNEIInfo2()); ClientCommandHandler.instance.registerCommand((ICommand)new CommandDumpTextureSheet()); } ClientCommandHandler.instance.registerCommand((ICommand)CommandTPSTimer.INSTANCE); }
@Override public void registerEventHandler() { MinecraftForge.EVENT_BUS.register((Object)new EventHandlerClient()); FMLCommonHandler.instance().bus().register((Object)new EventHandlerClient()); ((IReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener((IResourceManagerReloadListener)new LiquidColorRegistry()); ((IReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener((IResourceManagerReloadListener)new ParticleHelperClient()); ExtraUtils.handlesClientMethods = true; if (Loader.isModLoaded("ForgeMultipart")) { RenderBlockConnectedTextures.fakeRender = new FakeRenderBlocksMultiPart(); } ClientCommandHandler.instance.registerCommand((ICommand)new CommandHologram()); ClientCommandHandler.instance.registerCommand((ICommand)new CommandUUID()); KeyHandler.INSTANCE.register(); super.registerEventHandler(); }
public void displayHelp(MinecraftServer server, ICommandSender sender) { sender.sendMessage(new TextComponentString(TextFormatting.DARK_GREEN + "Available commands for EnderStorage:")); sender.sendMessage(new TextComponentString(TextFormatting.GOLD + "For more info use \"/" + getName() + " help [command]\"")); for (Entry<String, ICommand> entry : parent.getCommandMap().entrySet()) { String prefix = ""; if (!entry.getValue().checkPermission(server, sender)) { prefix = RED.toString(); } sender.sendMessage(new TextComponentString(prefix + "/EnderStorage " + YELLOW + entry.getValue().getName() + BLUE + " " + getCommandBrief(entry.getValue(), sender))); } for (IHelpPage page : helpPages) { sender.sendMessage(new TextComponentString("/EnderStorage" + YELLOW + " help " + page.name() + BLUE + " " + page.getBrief())); } }
private static String getCommandBrief(ICommand command, ICommandSender sender) { if (command instanceof ICCCommand) { return ((ICCCommand) command).getBrief(); } else { return command.getUsage(sender); } }
public static void injectNewFillCmd(MinecraftServer s) { Map<String, ICommand> cmdMap = s.getCommandManager().getCommands(); if (cmdMap.containsKey("fill")) { if (!(cmdMap.get("fill") instanceof CommandFillTM)) { cmdMap.put("fill", new CommandFillTM()); } } if (cmdMap.containsKey("clone")) { if (!(cmdMap.get("clone") instanceof CommandCloneTM)) { cmdMap.put("clone", new CommandCloneTM()); } } }
@Override protected List getSortedPossibleCommands(ICommandSender player) { List b = super.getSortedPossibleCommands(player); ArrayList<SafetyWrap> ret = new ArrayList<SafetyWrap>(b.size()); for (Object c : b) { ret.add(new SafetyWrap((ICommand) c)); } return ret; }
@Override protected Map getCommands() { Map<String, ICommand> b = super.getCommands(); HashMap<String, SafetyWrap> ret = new HashMap<String, SafetyWrap>(b.size()); for (Map.Entry<String, ICommand> c : b.entrySet()) { ret.put(c.getKey(), new SafetyWrap(c.getValue())); } return ret; }
@Override public int compareTo(ICommand obj) { try { return base.getClass().getName().compareTo(obj.getClass().getName()); } catch (Throwable t) { final int a = System.identityHashCode(base); final int b = System.identityHashCode(obj); if (a == b) return 0; if (a > b) return +1; return -1; } }
public static void registerCommandHandler(ICommand cmd) { if (MeddleUtil.isClientJar()) delayedICommands.add(cmd); else { ((CommandHandler) getServer().getCommandManager()).registerCommand(cmd); } }
public static void onServerRunHook(MinecraftServer server) { if (MeddleUtil.isClientJar()) { CommandHandler cmdHandler = (CommandHandler) server.getCommandManager(); for (ICommand cmd : delayedICommands) { cmdHandler.registerCommand(cmd); } } }
private int getUsernameIndex(ICommand command, String[] args) throws CommandException { if (command == null) return -1; else { for (int i = 0; i < args.length; ++i) if (command.isUsernameIndex(args, i) && EntitySelector.matchesMultiplePlayers(args[i])) return i; return -1; } }
@Override public String execute(CommandSender sender, String[] params) throws CommandException { if (params.length > 1) { if (params[0].equalsIgnoreCase("enable")) { ICommand enable = this.disabledCommands.get(params[1]); if (enable == null && PatchManager.instance().getGlobalAppliedPatches().wasPatchSuccessfullyApplied(PatchList.SERVER_MODDED)) Minecraft.getMinecraft().player.sendChatMessage("/command enable " + params[1]); else if (enable != null) { ClientCommandHandler.instance.registerCommand(enable); this.disabledCommands.remove(params[1]); sender.sendLangfileMessage("command.command.enabled"); } else throw new CommandException("command.command.serverNotModded", sender); } else if (params[0].equalsIgnoreCase("disable")) { if (params[1].equals(this.getCommandName())) throw new CommandException("command.command.wantedToDisable", sender); ICommand disable = (ICommand) ClientCommandHandler.instance.getCommands().get(params[1]); if (disable == null && PatchManager.instance().getGlobalAppliedPatches().wasPatchSuccessfullyApplied(PatchList.SERVER_MODDED)) Minecraft.getMinecraft().player.sendChatMessage("/command disable " + params[1]); else if (disable != null) { this.disabledCommands.put(disable.getName(), disable); ClientCommandHandler.instance.getCommands().remove(params[1]); sender.sendLangfileMessage("command.command.disabled"); } else throw new CommandException("command.command.serverNotModded", sender); } else throw new CommandException("command.generic.invalidUsage", sender, this.getCommandName()); } else throw new CommandException("command.generic.invalidUsage", sender, this.getCommandName()); return null; }
private void disableClientCommands() { if (this.clientCommands.size() != 0) return; this.clientCommands.clear(); for (Map.Entry<String, ICommand> entry : (Set<Map.Entry<String, ICommand>>) ClientCommandHandler.instance.getCommands().entrySet()) if (entry.getValue() instanceof ClientCommand<?> && ((ClientCommand<?>) entry.getValue()).getDelegate() != this) this.clientCommands.put(entry.getKey(), (ClientCommand<?>) entry.getValue()); for (String command : this.clientCommands.keySet()) ClientCommandHandler.instance.getCommands().remove(command); enabled = ClientCommand.clientCommandsEnabled = false; }
@Override public String execute(CommandSender sender, String[] params) throws CommandException { if (params.length > 1) { if (params[0].equalsIgnoreCase("enable")) { ICommand enable = this.disabledCommands.get(params[1]); if (enable != null) { ((ServerCommandManager) sender.getServer().getCommandManager()).registerCommand(enable); this.disabledCommands.remove(params[1]); sender.sendLangfileMessage("command.command.enabled"); } else throw new CommandException("command.command.alreadyEnabled", sender); } else if (params[0].equalsIgnoreCase("disable")) { if (params[1].equals(this.getCommandName())) throw new CommandException("command.command.wantedToDisable", sender); ICommand disable = (ICommand) ((ServerCommandManager) sender.getServer().getCommandManager()).getCommands().get(params[1]); if (disable != null) { this.disabledCommands.put(disable.getName(), disable); ((ServerCommandManager) sender.getServer().getCommandManager()).getCommands().remove(params[1]); sender.sendLangfileMessage("command.command.disabled"); } else throw new CommandException("command.command.alreadyDisabled", sender); } else throw new CommandException("command.generic.invalidUsage", sender, this.getCommandName()); } else throw new CommandException("command.generic.invalidUsage", sender, this.getCommandName()); return null; }
@EventHandler public void serverStarting (FMLServerStartingEvent event) { for (final ICommand command : BookshelfRegistry.getCommands()) { event.registerServerCommand(command); } }
@Override public void processCommand(ICommandSender sender, String[] args) { if(args.length == 0) { sender.addChatMessage(new ChatComponentText("Usage: " + getCommandUsage(sender))); return; } if(args[0].equals("tps")) { sender.addChatMessage(new ChatComponentText("Average TPS: " + getTPSFormatted(mod) + " TPS")); return; } else if(args[0].equals("identify")) { sender.addChatMessage(new ChatComponentText("Command not yet implemented! This will allow you to check what group a Tile or Entity belongs to by right clicking it.(And other info, like TPS)")); return; } else if(args[0].equals("help")) { sender.addChatMessage(new ChatComponentText("You can find the documentation over at http://mods.stjerncraft.com/tickdynamic")); return; } //Send it over to subCommand handler ICommand subHandler = subCommandHandlers.get(args[0]); if(subHandler == null) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "No handler for the command " + EnumChatFormatting.ITALIC + args[0])); return; } subHandler.processCommand(sender, args); }
@Override public int compareTo( Object o ) { if( o instanceof ICommand ) { return ((ICommand)o).getCommandName().compareTo( getCommandName() ); } return 0; }
public NeptuneCommand(final ICommand command) { super(new DynamicCommandAnnotation( (String[]) command.getCommandAliases().toArray(new String[command.getCommandAliases().size()]), new String[0], "", "", "", "", new String[0], 0, 0, "", 2), Neptune.minecraftCommandOwner, null, new TabCompleteDispatch() { @Override public List<String> complete(MessageReceiver msgrec, String[] args) throws TabCompleteException { return command.addTabCompletionOptions((ICommandSender) msgrec, args, BlockPos.ORIGIN); } }); this.command = command; }
@Override public ICommand registerCommand(ICommand command) { NeptuneCommand cmd = new NeptuneCommand(command); if (Canary.instance() != null) { try { Canary.commands().registerCommand(cmd, Neptune.minecraftCommandOwner, false); } catch (CommandDependencyException e) { Canary.log.error("Eh, something has broken :(", e); } } else { earlyRegisterCommands.add(cmd); } return super.registerCommand(command); }
@SuppressWarnings("NullableProblems") @Override public int compareTo(Object obj) { if (obj instanceof ICommand) { return this.compareTo((ICommand) obj); } else { return 0; } }
@EventHandler public void onServerStart(FMLServerStartingEvent event) { ReduxEventDispatcher.getInstance(); // Init Event Dispatcher here because it is no longer used in ReduxCommandBlockTileEntity for (ICommand command : ReduxCommands.getCommands()) { event.registerServerCommand(command); } }
/** * @author jamierocks - 1st September 2016 * @reason Log command feedback */ @Overwrite public void notifyOperators(ICommandSender sender, ICommand command, int flags, String msgFormat, Object... msgParams) { final MinecraftServer server = MinecraftServer.getServer(); final IChatComponent feedback = new ChatComponentTranslation("chat.type.admin", sender.getName(), new ChatComponentTranslation(msgFormat, msgParams)); feedback.getChatStyle().setColor(EnumChatFormatting.GRAY); feedback.getChatStyle().setItalic(true); if (sender.sendCommandFeedback()) { for (final EntityPlayer player : server.getConfigurationManager().getPlayerList()) { if (player != sender && server.getConfigurationManager().canSendCommands(player.getGameProfile()) && command .canCommandSenderUseCommand(sender)) { final boolean broadcastConsoleToOps = sender instanceof MinecraftServer && MinecraftServer.getServer().shouldBroadcastConsoleToOps(); final boolean broadcastRconToOps = sender instanceof RConConsoleSource && MinecraftServer.getServer().shouldBroadcastRconToOps(); if (broadcastConsoleToOps || broadcastRconToOps || !(sender instanceof RConConsoleSource) && !(sender instanceof MinecraftServer)) { player.addChatMessage(feedback); } } } } // Neptune - Always log command feedback //if (sender != server && server.worldServers[0].getGameRules().getBoolean("logAdminCommands")) { server.addChatMessage(feedback); //} // Neptune - end final boolean shouldSendCommandFeedback = sender instanceof CommandBlockLogic ? ((CommandBlockLogic) sender).shouldTrackOutput() : server.worldServers[0].getGameRules().getBoolean("sendCommandFeedback"); if ((flags & 1) != 1 && shouldSendCommandFeedback || sender instanceof MinecraftServer) { sender.addChatMessage(new ChatComponentTranslation(msgFormat, msgParams)); } }
/** * @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; } }
public BasicCommandEntry(Class<? extends ICommand> clazz, String name, boolean enabled, String comment, String... modIds) { super(clazz.getSimpleName(), modIds); this.clazz = clazz; this.name = name; this.defaultEnabled = enabled; this.enabled = enabled; this.comment = comment; }