/** * Gets the command dispatcher used for registering and dispatching * registered commands. * * @return The command dispatcher */ default CommandManager getCommandManager() { return Sponge.getCommandManager(); }
@Override public void registerCommands(Dispatcher dispatcher) { for (CommandMapping command : dispatcher.getCommands()) { CommandAdapter adapter = new CommandAdapter(command) { @Override public CommandResult process(CommandSource source, String arguments) throws org.spongepowered.api.command.CommandException { CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments); WorldEdit.getInstance().getEventBus().post(weEvent); return weEvent.isCancelled() ? CommandResult.success() : CommandResult.empty(); } @Override public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException { CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getPrimaryAlias() + " " + arguments); WorldEdit.getInstance().getEventBus().post(weEvent); return weEvent.getSuggestions(); } }; Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, command.getAllAliases()); } }
@Override public CommandResult process(CommandSource source, String commandLine) throws CommandException { final String[] argSplit = commandLine.split(" ", 2); Optional<CommandMapping> cmdOptional = get(argSplit[0], source); if (!cmdOptional.isPresent()) { throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]); // TODO: Fix properly to use a SpongeTranslation?? } final String arguments = argSplit.length > 1 ? argSplit[1] : ""; CommandMapping mapping = cmdOptional.get(); Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping); pluginOwner.ifPresent(pluginContainer -> Sponge.getCauseStackManager().pushCause(pluginContainer)); final CommandCallable spec = mapping.getCallable(); Sponge.getCauseStackManager().pushCause(spec); try { return spec.process(source, arguments); } catch (CommandNotFoundException e) { throw new CommandException(t("No such child command: %s", e.getCommand())); } finally { if (pluginOwner.isPresent()) { Sponge.getCauseStackManager().popCause(); } Sponge.getCauseStackManager().popCause(); } }
@Override public void onDisable() { super.onDisable(); signs.clear(); if (signCommandManager != null) { Sponge.getCommandManager().removeMapping(signCommandManager); } }
@Override public void onDisable() { super.onDisable(); if (areaCommandMapping != null) { Sponge.getCommandManager().removeMapping(areaCommandMapping); } }
@Override public void onDisable() { super.onDisable(); disabledPlayers.save(config); if (treelopperCommandMapping != null) { Sponge.getCommandManager().removeMapping(treelopperCommandMapping); } }
public void updateCommands() { assert Sponge.getServer().isMainThread(); commands.clear(); Collection<CommandMapping> newCommands = Sponge.getCommandManager().getAll().values(); for (CommandMapping cmd : newCommands) { if (commands.containsKey(cmd.getPrimaryAlias())) continue; commands.put(cmd.getPrimaryAlias(), new CachedCommand(cmd)); } }
@Override public void onDisable() { super.onDisable(); try { config.getNode("variables").setValue(new TypeToken<Map<String, Map<String, String>>>() {}, variableStore); } catch (ObjectMappingException e) { e.printStackTrace(); } if (variableCommandMapping != null) { Sponge.getCommandManager().removeMapping(variableCommandMapping); } }
public static void dispatchCommand(MessageReceivedEvent e) { String args[] = e.getMessage().getContentDisplay().replace(MagiBridge.getConfig().CHANNELS.CONSOLE_COMMAND + " ", "").split(" "); if (!canUseCommand(e.getMember(), args[0])) { DiscordHandler.sendMessageToChannel(e.getChannel().getId(), MagiBridge.getConfig().MESSAGES.CONSOLE_NO_PERMISSION); return; } String cmd = e.getMessage().getContentDisplay().replace(MagiBridge.getConfig().CHANNELS.CONSOLE_COMMAND + " ", ""); Sponge.getCommandManager().process(new BridgeCommandSource(e.getChannel().getId(), Sponge.getServer().getConsole()), cmd); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder().arguments(GenericArguments.playerOrSource(Text.of("sniper"))).executor(new VoxelDefaultCommand()) .permission(VoxelSniperConfiguration.PERMISSION_SNIPER).description(Text.of("Resets your VoxelSniper brush settings")) .build(), "d"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder().arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.integer(Text.of("center"))) .executor(new VoxelCenterCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper Center point selection")).build(), "vc"); }
public static void setup(Object plugin) { Sponge.getCommandManager() .register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.remainingJoinedStrings(Text.of("args"))) .executor(new VoxelBrushToolCommand()) .permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper brush tool settings")).build(), "btool"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder().arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.integer(Text.of("height"))) .executor(new VoxelHeightCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper Height selection")).build(), "vh"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.optional(GenericArguments.integer(Text.of("count")))) .executor(new VoxelUndoCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper undo")).build(), "u"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("args")))) .executor(new VoxelSniperCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper material list selection")).build(), "vs"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.optional(GenericArguments.string(Text.of("material")))) .executor(new VoxelVoxelCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper material selection")).build(), "v"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("args")))) .executor(new VoxelListCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper material list selection")).build(), "vl"); }
public static void setup(Object plugin) { Sponge.getCommandManager() .register(plugin, CommandSpec.builder() .arguments( GenericArguments.optional(GenericArguments.string(Text.of("brush"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("brush_args")))) .executor(new VoxelBrushCommand()) .permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper brush settings")).build(), "b", "brush"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.string(Text.of("key")), GenericArguments.literal(Text.of("equals"), "="), GenericArguments.string(Text.of("value"))) .executor(new VoxelInkReplaceCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper Replace Ink selection")).build(), "vir"); }
public static void setup(Object plugin) { Sponge.getCommandManager().register(plugin, CommandSpec.builder() .arguments(GenericArguments.playerOrSource(Text.of("sniper")), GenericArguments.string(Text.of("key")), GenericArguments.literal(Text.of("equals"), "="), GenericArguments.string(Text.of("value"))) .executor(new VoxelInkCommand()).permission(VoxelSniperConfiguration.PERMISSION_SNIPER) .description(Text.of("VoxelSniper Ink selection")).build(), "vi"); }