Java Code Examples for org.spongepowered.api.command.args.CommandContext#getOne()
The following examples show how to use
org.spongepowered.api.command.args.CommandContext#getOne() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StopExecutor.java From EssentialCmds with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<String> stopMessage = ctx.<String> getOne("reason"); if (stopMessage.isPresent()) { Sponge.getServer().shutdown(TextSerializers.FORMATTING_CODE.deserialize(stopMessage.get())); } else { Sponge.getServer().shutdown(); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Stopped server.")); return CommandResult.success(); }
Example 2
Source File: MuteExecutor.java From EssentialCmds with MIT License | 6 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { Game game = EssentialCmds.getEssentialCmds().getGame(); Player p = ctx.<Player> getOne("player").get(); // Uses the TimespanParser. Optional<Long> time = ctx.<Long> getOne("time"); if (time.isPresent()) { Task.Builder taskBuilder = game.getScheduler().createTaskBuilder(); taskBuilder.execute(() -> { if (EssentialCmds.muteList.contains(p.getUniqueId())) EssentialCmds.muteList.remove(p.getUniqueId()); }).delay(time.get(), TimeUnit.SECONDS).name("EssentialCmds - Remove previous mutes").submit(EssentialCmds.getEssentialCmds()); } EssentialCmds.muteList.add(p.getUniqueId()); Utils.addMute(p.getUniqueId()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player muted.")); }
Example 3
Source File: SubCommand.java From SubServers-2 with Apache License 2.0 | 6 votes |
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (canRun(sender)) { Optional<String> subcommand = args.getOne(Text.of("subcommand")); if (subcommand.isPresent()) { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Subcommand").replace("$str$", subcommand.get()))); return CommandResult.builder().successCount(0).build(); } else { if (sender.hasPermission("subservers.interface") && sender instanceof Player && plugin.gui != null) { plugin.gui.getRenderer((Player) sender).newUI(); } else { sender.sendMessages(printHelp()); } return CommandResult.builder().successCount(1).build(); } } else { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))); return CommandResult.builder().successCount(0).build(); } }
Example 4
Source File: CmdUserRemove.java From Web-API with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<String> optUsername = args.getOne("username"); if (!optUsername.isPresent()) { return CommandResult.empty(); } String username = optUsername.get(); Optional<UserPermissionStruct> optUser = WebAPI.getUserService().removeUser(username); if (!optUser.isPresent()) { src.sendMessage(Text.builder("Couldn't find user to remove " + username) .color(TextColors.RED).build()); return CommandResult.empty(); } src.sendMessage(Text.builder("Removed user ") .append(Text.builder(username).color(TextColors.GOLD).build()) .build()); return CommandResult.success(); }
Example 5
Source File: CmdBlockUpdatesPause.java From Web-API with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<BlockOperation> op = args.getOne("uuid"); if (!op.isPresent()) { src.sendMessage(Text.builder("Invalid block operation uuid!") .color(TextColors.DARK_RED) .build()); return CommandResult.empty(); } if (op.get().getStatus() == BlockOperationStatus.RUNNING) { op.get().pause(); } else { op.get().start(); } return CommandResult.success(); }
Example 6
Source File: CmdBlockUpdatesStop.java From Web-API with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<BlockOperation> op = args.getOne("uuid"); if (!op.isPresent()) { src.sendMessage(Text.builder("Invalid block operation uuid!") .color(TextColors.DARK_RED) .build()); return CommandResult.empty(); } op.get().stop(null); src.sendMessage(Text.builder("Successfully cancelled block operation") .color(TextColors.DARK_GREEN) .build()); return CommandResult.success(); }
Example 7
Source File: DescriptionCommand.java From EagleFactions with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource source, CommandContext context) throws CommandException { final Optional<String> optionalDescription = context.<String>getOne("description"); if (!optionalDescription.isPresent()) { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.WRONG_COMMAND_ARGUMENTS)); source.sendMessage(Text.of(TextColors.RED, Messages.USAGE + " /f desc <description>")); return CommandResult.success(); } if (!(source instanceof Player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND)); final Player player = (Player) source; final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId()); if (!optionalPlayerFaction.isPresent()) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND)); //Check if player is leader if (!optionalPlayerFaction.get().getLeader().equals(player.getUniqueId()) && !optionalPlayerFaction.get().getOfficers().contains(player.getUniqueId())) { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS)); return CommandResult.success(); } final String description = optionalDescription.get(); //Check description length if(description.length() > 255) { player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.DESCRIPTION_IS_TOO_LONG + " (" + Messages.MAX + " " + 255 + " " + Messages.CHARS + ")")); return CommandResult.success(); } super.getPlugin().getFactionLogic().setDescription(optionalPlayerFaction.get(), description); player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GREEN, Messages.FACTION_DESCRIPTION_HAS_BEEN_UPDATED))); return CommandResult.success(); }
Example 8
Source File: KickExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); Server server = game.getServer(); Player player = ctx.<Player> getOne("player").get(); Optional<String> reason = ctx.<String> getOne("reason"); if (server.getPlayer(player.getUniqueId()).isPresent()) { Text finalKickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName()); if (reason.isPresent()) { Text reas = TextSerializers.formattingCode('&').deserialize(reason.get()); Text kickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName() + " for ", TextColors.RED); finalKickMessage = Text.builder().append(kickMessage).append(reas).build(); player.kick(reas); } else { player.kick(); } MessageChannel.TO_ALL.send(finalKickMessage); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player kicked.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player doesn't appear to be online!")); } return CommandResult.success(); }
Example 9
Source File: WorldsBase.java From EssentialCmds with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { GameMode gamemode = ctx.<GameMode> getOne("gamemode").get(); Optional<String> worldName = ctx.<String> getOne("world"); World world = null; if (worldName.isPresent()) { world = Sponge.getServer().getWorld(worldName.get()).orElse(null); } else { if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player or specify the world name to set its gamemode!")); } } if (world != null) { world.getProperties().setGameMode(gamemode); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set gamemode of world.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!")); } return CommandResult.success(); }
Example 10
Source File: KillExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<Player> p = ctx.<Player> getOne("player"); if (p.isPresent() && src.hasPermission("essentialcmds.kill.others")) { p.get().offer(Keys.HEALTH, 0d); Utils.setLastTeleportOrDeathLocation(p.get().getUniqueId(), p.get().getLocation()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Killed player " + p.get().getName())); p.get().sendMessage(Text.of(TextColors.RED, "You have been killed by " + src.getName())); } else if (!p.isPresent()) { if (src instanceof Player) { Player player = (Player) src; player.offer(Keys.HEALTH, 0d); Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Killed yourself.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot kill yourself, you are not a player!")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to kill other players!")); } return CommandResult.success(); }
Example 11
Source File: CmdUserChangePassword.java From Web-API with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<String> optUsername = args.getOne("username"); if (!optUsername.isPresent()) { return CommandResult.empty(); } String username = optUsername.get(); Optional<String> optPassword = args.getOne("password"); if (!optPassword.isPresent()) { return CommandResult.empty(); } String password = optPassword.get(); UserService srv = WebAPI.getUserService(); Optional<UserPermissionStruct> optUser = srv.getUser(username); if (!optUser.isPresent()) { src.sendMessage(Text.builder("Could not find user '" + username + "'").color(TextColors.RED).build()); return CommandResult.empty(); } UserPermissionStruct user = optUser.get(); user.setPassword(srv.hashPassword(password)); src.sendMessage(Text.builder("Changed password for ") .append(Text.builder(username).color(TextColors.GOLD).build()) .build()); srv.save(); return CommandResult.success(); }
Example 12
Source File: CreateWorldCommand.java From UltimateCore with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { String name = (String) args.getOne("name").get(); Optional<DimensionType> dimension = args.getOne("dimension"); Optional<GeneratorType> generator = args.getOne("generator"); Collection<WorldGeneratorModifier> wgm = args.getAll("wgm"); Optional<Long> seed = args.getOne("seed"); Optional<GameMode> gm = args.getOne("gamemode"); Optional<Difficulty> diff = args.getOne("difficulty"); boolean nostructures = args.hasAny("n"); boolean load = args.<Boolean>getOne("l").orElse(true); boolean keepspawnloaded = args.<Boolean>getOne("k").orElse(true); boolean allowcommands = args.<Boolean>getOne("c").orElse(true); boolean bonuschest = args.<Boolean>getOne("b").orElse(true); Path path = Sponge.getGame().getSavesDirectory(); if (Files.exists(path.resolve(name.toLowerCase())) || Files.exists(path.resolve(name)) || Sponge.getServer().getAllWorldProperties().stream().anyMatch(x -> x.getWorldName().equalsIgnoreCase(name))) { throw new ErrorMessageException(Messages.getFormatted(sender, "world.exists", "%name%", name)); } Messages.send(sender, "world.command.world.create.starting", "%name%", name); WorldArchetype.Builder archetype = WorldArchetype.builder().enabled(true); dimension.ifPresent(archetype::dimension); generator.ifPresent(archetype::generator); archetype.generatorModifiers(wgm.toArray(new WorldGeneratorModifier[wgm.size()])); seed.ifPresent(archetype::seed); gm.ifPresent(archetype::gameMode); diff.ifPresent(archetype::difficulty); archetype.usesMapFeatures(!nostructures); archetype.loadsOnStartup(load); archetype.keepsSpawnLoaded(keepspawnloaded); archetype.commandsAllowed(allowcommands); archetype.generateBonusChest(bonuschest); WorldProperties props; try { props = Sponge.getServer().createWorldProperties(name.toLowerCase(), archetype.build(name.toLowerCase(), name)); } catch (IOException e) { throw new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.fileerror", "%error%", e.getMessage())); } Sponge.getServer().saveWorldProperties(props); World world = Sponge.getServer().loadWorld(props).orElseThrow(() -> new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.loaderror"))); Messages.send(sender, "world.command.world.create.success", "%name%", world.getName()); return CommandResult.success(); }
Example 13
Source File: WorldsBase.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<String> worldName = ctx.<String> getOne("world"); World world; if (worldName.isPresent()) { if (Sponge.getServer().getWorld(worldName.get()).isPresent()) { world = Sponge.getServer().getWorld(worldName.get()).get(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!")); return CommandResult.empty(); } } else { if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!")); return CommandResult.empty(); } } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); ArrayList<Text> gameruleText = Lists.newArrayList(); for (Entry<String, String> gamerule : world.getGameRules().entrySet()) { Text item = Text.builder(gamerule.getKey()) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Value ", TextColors.GOLD, gamerule.getValue()))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); gameruleText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(gameruleText).title(Text.of(TextColors.GREEN, "Showing Gamerules")).padding(Text.of("-")); paginationBuilder.sendTo(src); return CommandResult.success(); }
Example 14
Source File: TeleportPosExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<Player> p = ctx.<Player> getOne("player"); World world = null; if (ctx.hasAny("world")) { Optional<WorldProperties> optionalWorldProperties = ctx.<WorldProperties> getOne("world"); WorldProperties worldProperties = optionalWorldProperties.orElse(null); if (worldProperties != null) { // check if world is loaded Optional<World> optionalWorld = Sponge.getServer().getWorld(worldProperties.getUniqueId()); world = optionalWorld.orElse(null); if (world == null) { // attempt to load world world = Sponge.getServer().loadWorld(worldProperties).orElse(null); if (world == null) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not load world " + worldProperties.getWorldName() + ".")); return CommandResult.success(); } } } } else { if (p.isPresent()) { world = p.get().getWorld(); } else if (src instanceof Player) { world = ((Player) src).getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No valid world could be found!")); return CommandResult.success(); } } int x = ctx.<Integer> getOne("x").get(); int y = ctx.<Integer> getOne("y").get(); int z = ctx.<Integer> getOne("z").get(); if (p.isPresent()) { if (src.hasPermission("teleport.pos.others")) { Utils.setLastTeleportOrDeathLocation(p.get().getUniqueId(), p.get().getLocation()); p.get().setLocation(new Location<>(world, x, y, z)); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported player " + p.get().getName() + " to " + x + "," + y + "," + z + ".")); p.get().sendMessage(Text.of(TextColors.GOLD, "You have been teleported by " + src.getName())); } } else { if (src instanceof Player) { Player player = (Player) src; Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation()); player.setLocation(new Location<>(world, x, y, z)); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to coords.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!")); } } return CommandResult.success(); }
Example 15
Source File: WorldsBase.java From EssentialCmds with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { String name = ctx.<String> getOne("name").get(); Optional<String> dimensionInput = ctx.<String> getOne("dimension"); Optional<String> generatorInput = ctx.<String> getOne("generator"); Optional<String> difficultyInput = ctx.<String> getOne("difficulty"); Optional<GameMode> gamemode = ctx.<GameMode> getOne("gamemode"); Difficulty difficulty = Difficulties.NORMAL; DimensionType dimension = DimensionTypes.OVERWORLD; GeneratorType generator = GeneratorTypes.OVERWORLD; if (dimensionInput.isPresent() && Sponge.getRegistry().getType(DimensionType.class, dimensionInput.get()).isPresent()) { dimension = Sponge.getRegistry().getType(DimensionType.class, dimensionInput.get()).get(); } else if (dimensionInput.isPresent()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Dimension type specified not found.")); } if (generatorInput.isPresent() && Sponge.getRegistry().getType(GeneratorType.class, generatorInput.get()).isPresent()) { generator = Sponge.getRegistry().getType(GeneratorType.class, generatorInput.get()).get(); } else if (generatorInput.isPresent()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Generator type specified not found.")); } if (difficultyInput.isPresent() && Sponge.getRegistry().getType(Difficulty.class, difficultyInput.get()).isPresent()) { difficulty = Sponge.getRegistry().getType(Difficulty.class, difficultyInput.get()).get(); } else if (difficultyInput.isPresent()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Difficulty specified not found.")); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Beginning loading of world.")); WorldArchetype worldSettings = WorldArchetype.builder() .enabled(true) .loadsOnStartup(true) .keepsSpawnLoaded(true) .dimension(dimension) .generator(generator) .gameMode(gamemode.orElse(GameModes.SURVIVAL)) .build(name.toLowerCase(), name); try { WorldProperties worldProperties = Sponge.getGame().getServer().createWorldProperties(name, worldSettings); Optional<World> world = Sponge.getGame().getServer().loadWorld(worldProperties); if (world.isPresent()) { world.get().getProperties().setDifficulty(difficulty); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "World ", TextColors.GRAY, name, TextColors.GOLD, " has been loaded.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world could not be created.")); } } catch (IOException e) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world properties could not be created.")); } return CommandResult.success(); }
Example 16
Source File: TimeExecutor.java From EssentialCmds with MIT License | 4 votes |
public static void setTime(CommandSource src, CommandContext ctx) { Optional<String> timeString = ctx.<String> getOne("time"); Optional<Integer> timeTicks = ctx.<Integer> getOne("ticks"); World world = null; if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else if (src instanceof CommandBlock) { CommandBlock commandBlock = (CommandBlock) src; world = commandBlock.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a in-game player to do /time!")); return; } if (timeTicks.isPresent()) { world.getProperties().setWorldTime(timeTicks.get()); src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeTicks.get())); } else if (timeString.isPresent()) { if (timeString.get().toLowerCase().equals("dawn") || timeString.get().toLowerCase().equals("morning")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(0); } else if (timeString.get().toLowerCase().equals("day")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(1000); } else if (timeString.get().toLowerCase().equals("afternoon") || timeString.get().toLowerCase().equals("noon")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(6000); } else if (timeString.get().toLowerCase().equals("dusk")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(12000); } else if (timeString.get().toLowerCase().equals("night")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(14000); } else if (timeString.get().toLowerCase().equals("midnight")) { src.sendMessage(Text.of(TextColors.GOLD, "Set time to ", TextColors.GRAY, timeString.get().toLowerCase())); world.getProperties().setWorldTime(18000); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not understand input.")); } } }
Example 17
Source File: SubCommand.java From SubServers-2 with Apache License 2.0 | 4 votes |
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (canRun(sender)) { Optional<String[]> s = args.getOne(Text.of("Subservers")); Optional<String> version = args.getOne(Text.of("Version")); if (s.isPresent()) { selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.update"), select -> { if (select.subservers.length > 0) { PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0); AsyncConsolidator merge = new AsyncConsolidator(() -> { if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString()))); }); for (SubServer server : select.subservers) { merge.reserve(); ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, server.getName(), (version.isPresent() && version.get().length() > 0)?new Version(version.get()):null, data -> { switch (data.getInt(0x0001)) { case 3: case 4: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Disappeared").replace("$str$", server.getName()))); break; case 5: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Host-Unavailable").replace("$str$", server.getName()))); break; case 6: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Host-Disabled").replace("$str$", server.getName()))); break; case 7: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Server-Unavailable").replace("$str$", server.getName()))); break; case 8: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Running").replace("$str$", server.getName()))); break; case 9: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName()))); break; case 10: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName()))); break; case 11: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName()))); break; case 12: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Version-Required").replace("$str$", server.getName()))); break; case 0: success.value++; break; } merge.release(); })); } } }); return CommandResult.builder().successCount(1).build(); } else { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub update <Subservers> [Version]"))); return CommandResult.builder().successCount(0).build(); } } else { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))); return CommandResult.builder().successCount(0).build(); } }
Example 18
Source File: PowertoolExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Optional<String> optionalCommand = ctx.<String> getOne("command"); Player player = (Player) src; // TODO: Allow players not holding an item to remove their powertool if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { if (optionalCommand.isPresent()) { String command = optionalCommand.get(); // If there is a powertool for the player, remove it. EssentialCmds.powertools.stream() .filter(p -> p.getPlayer().equals(player) && p.getItemID().equals(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName())) .findFirst().ifPresent(x -> EssentialCmds.powertools.remove(x)); Powertool powertool = new Powertool(player, player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName(), command); EssentialCmds.powertools.add(powertool); player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Successfully bound command ", TextColors.BLUE, command, TextColors.YELLOW, " to ", TextColors.RED, player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName(), TextColors.YELLOW, "!")); } else { Optional<Powertool> powertoolToRemove = EssentialCmds.powertools.stream() .filter(p -> p.getPlayer().equals(player) && p.getItemID().equals(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName())) .findFirst(); if (powertoolToRemove.isPresent()) { EssentialCmds.powertools.remove(powertoolToRemove.get()); player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Removed command from this powertool!")); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "There is no command assigned to this!")); } } } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding something to use /powertool!")); } } else if (src instanceof ConsoleSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /powertool!")); } else if (src instanceof CommandBlockSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /powertool!")); } return CommandResult.success(); }
Example 19
Source File: SubCommand.java From SubServers-2 with Apache License 2.0 | 4 votes |
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (canRun(sender)) { Optional<String[]> s = args.getOne(Text.of("Subservers")); if (s.isPresent()) { selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.start"), select -> { if (select.subservers.length > 0) { PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0); PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0); AsyncConsolidator merge = new AsyncConsolidator(() -> { if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Start.Running").replace("$int$", running.value.toString()))); if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Start").replace("$int$", success.value.toString()))); }); for (SubServer server : select.subservers) { merge.reserve(); server.start((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> { switch (response) { case 3: case 4: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Disappeared").replace("$str$", server.getName()))); break; case 5: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Host-Unavailable").replace("$str$", server.getName()))); break; case 6: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Host-Disabled").replace("$str$", server.getName()))); break; case 7: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Unavailable").replace("$str$", server.getName()))); break; case 8: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Disabled").replace("$str$", server.getName()))); break; case 9: running.value++; break; case 10: sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", server.getName()))); break; case 0: success.value++; break; } merge.release(); }); } } }); return CommandResult.builder().successCount(1).build(); } else { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub start <Subservers>"))); return CommandResult.builder().successCount(0).build(); } } else { sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))); return CommandResult.builder().successCount(0).build(); } }
Example 20
Source File: WeatherExecutor.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { String weatherString = ctx.<String> getOne("weather").get(); Optional<Integer> duration = ctx.<Integer> getOne("duration"); if (src instanceof Player) { Player player = (Player) src; Weather weather; if (weatherString.toLowerCase().equals("clear") || weatherString.toLowerCase().equals("sun")) { weather = Weathers.CLEAR; player.sendMessage(Text.of(TextColors.GOLD, "Changing weather to ", TextColors.GRAY, "sunny.")); } else if (weatherString.toLowerCase().equals("rain")) { weather = Weathers.RAIN; player.sendMessage(Text.of(TextColors.GOLD, "Changing weather to ", TextColors.GRAY, "rain.")); } else if (weatherString.toLowerCase().equals("storm") || weatherString.toLowerCase().equals("thunderstorm")) { weather = Weathers.THUNDER_STORM; player.sendMessage(Text.of(TextColors.GOLD, "Changing weather to ", TextColors.GRAY, "storm.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Input invalid: " + weatherString)); return CommandResult.success(); } if (duration.isPresent()) { player.getWorld().setWeather(weather, duration.get()); } else { player.getWorld().setWeather(weather); } return CommandResult.success(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a in-game player to do /weather!")); return CommandResult.success(); } }