org.spongepowered.api.command.CommandResult Java Examples
The following examples show how to use
org.spongepowered.api.command.CommandResult.
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: UnregisterCommand.java From FlexibleLogin with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) { if (args.hasAny("a")) { Task.builder().execute(plugin.getDatabase()::clearTable).async().submit(plugin); src.sendMessage(settings.getText().getTableCleared()); return CommandResult.success(); } User user = args.<User>getOne("user").get(); Task.builder() //Async as it could run a SQL query .async() .execute(new UnregisterTask(plugin, src, user.getUniqueId())) .submit(plugin); return CommandResult.success(); }
Example #2
Source File: BlacklistBase.java From EssentialCmds with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { String itemId = ctx.<String> getOne("item id").get(); if (Utils.getBlacklistItems().contains(itemId)) { Utils.removeBlacklistItem(itemId); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, itemId + " has been un-blacklisted.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "This item is not blacklisted.")); } return CommandResult.success(); }
Example #3
Source File: PurgeLimitCommand.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to check purge limit.")) .permission("redprotect.command.purge-limit") .executor((src, args) -> { if (!(src instanceof Player) || !RedProtect.get().config.configRoot().purge.enabled) { HandleHelpPage(src, 1); } else { Player player = (Player) src; int limit = RedProtect.get().ph.getPurgeLimit(player); long amount = RedProtect.get().rm.getCanPurgePlayer(player.getUniqueId().toString(), player.getWorld().getName()); RedProtect.get().lang.sendMessage(player, "playerlistener.region.purge-limit", new Replacer[]{ new Replacer("{limit}", String.valueOf(limit)), new Replacer("{total}", String.valueOf(amount)) }); } return CommandResult.success(); }).build(); }
Example #4
Source File: CommandTrustList.java From GriefPrevention with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation()); showTrustList(src, claim, player, TrustType.NONE); return CommandResult.success(); }
Example #5
Source File: ExpExecutor.java From EssentialCmds with MIT License | 6 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if(src instanceof Player) { Player player = (Player) src; ExperienceHolderData expHolderData = player.getOrCreate(ExperienceHolderData.class).get(); player.sendMessage(Text.of(TextColors.GOLD, "Your current experience: ", TextColors.GRAY, expHolderData.totalExperience().get())); player.sendMessage(Text.of(TextColors.GOLD, "Experience to next level: ", TextColors.GRAY, expHolderData.getExperienceBetweenLevels().get() - expHolderData.experienceSinceLevel().get())); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command!")); } return CommandResult.success(); }
Example #6
Source File: AccountsCommand.java From FlexibleLogin with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<InetAddress> optIP = args.getOne("ip"); optIP.ifPresent(inetAddress -> Task.builder() //we are executing a SQL Query which is blocking .async() .execute(() -> { Set<Account> accounts = plugin.getDatabase().getAccountsByIp(inetAddress); sendAccountNames(src, inetAddress.getHostAddress(), accounts); }) .submit(plugin)); Optional<User> optUser = args.getOne("user"); optUser.ifPresent(user -> Task.builder() //we are executing a SQL Query which is blocking .async() .execute(() -> queryAccountsByName(src, user.getName())) .submit(plugin)); return CommandResult.success(); }
Example #7
Source File: SpongeCommands.java From BlueMap with MIT License | 6 votes |
@Override public CommandResult process(CommandSource source, String arguments) throws CommandException { String command = label; if (!arguments.isEmpty()) { command += " " + arguments; } try { return CommandResult.successCount(dispatcher.execute(command, source)); } catch (CommandSyntaxException ex) { source.sendMessage(Text.of(TextColors.RED, ex.getRawMessage().getString())); String context = ex.getContext(); if (context != null) source.sendMessage(Text.of(TextColors.GRAY, context)); return CommandResult.empty(); } }
Example #8
Source File: CommandTrust.java From GriefPrevention with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { User user = ctx.<User>getOne("user").orElse(null); String group = null; if (user == null) { group = ctx.<String>getOne("group").orElse(null); if (group.equalsIgnoreCase("public") || group.equalsIgnoreCase("all")) { user = GriefPreventionPlugin.PUBLIC_USER; group = null; } } try { if (user != null) { CommandHelper.handleUserTrustCommand(GriefPreventionPlugin.checkPlayer(src), TrustType.BUILDER, user); } else { CommandHelper.handleGroupTrustCommand(GriefPreventionPlugin.checkPlayer(src), TrustType.BUILDER, group); } } catch (CommandException e) { src.sendMessage(e.getText()); } return CommandResult.success(); }
Example #9
Source File: DelTpCommand.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to delete a teleport location.")) .permission("redprotect.command.deltp") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; Region r = RedProtect.get().rm.getTopRegion(player.getLocation(), this.getClass().getName()); if (r != null) { if (RedProtect.get().ph.hasRegionPermLeader(player, "deltp", r)) { r.setTPPoint(null); RedProtect.get().lang.sendMessage(player, "cmdmanager.region.settp.removed"); } else { RedProtect.get().lang.sendMessage(player, "playerlistener.region.cantuse"); } } else { RedProtect.get().lang.sendMessage(player, "cmdmanager.region.todo.that"); } } return CommandResult.success(); }).build(); }
Example #10
Source File: LeaveCommand.java From EagleFactions with MIT License | 6 votes |
private CommandResult leaveFaction(final Player player, final Faction faction, boolean isLeader) { final boolean isCancelled = EventRunner.runFactionLeaveEvent(player, faction); if (isCancelled) return CommandResult.success(); if (isLeader) { super.getPlugin().getFactionLogic().setLeader(new UUID(0, 0), faction.getName()); } else { super.getPlugin().getFactionLogic().leaveFaction(player.getUniqueId(), faction.getName()); } player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_LEFT_FACTION, TextColors.GREEN, Collections.singletonMap(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, faction.getName()))))); EagleFactionsPlugin.AUTO_CLAIM_LIST.remove(player.getUniqueId()); EagleFactionsPlugin.CHAT_LIST.remove(player.getUniqueId()); return CommandResult.success(); }
Example #11
Source File: DebugCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource source, CommandContext context) throws CommandException { 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; if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(player.getUniqueId())) { EagleFactionsPlugin.DEBUG_MODE_PLAYERS.remove(player.getUniqueId()); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.DEBUG_MODE_HAS_BEEN_TURNED_OFF)); } else { EagleFactionsPlugin.DEBUG_MODE_PLAYERS.add(player.getUniqueId()); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.DEBUG_MODE_HAS_BEEN_TURNED_ON)); } return CommandResult.success(); }
Example #12
Source File: PasswordRegisterCommand.java From FlexibleLogin with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { if (!(src instanceof Player)) { throw new CommandException(settings.getText().getPlayersOnly()); } Collection<String> passwords = args.getAll("password"); List<String> indexPasswords = Lists.newArrayList(passwords); String password = indexPasswords.get(0); if (!password.equals(indexPasswords.get(1))) { //Check if the first two passwords are equal to prevent typos throw new CommandException(settings.getText().getUnequalPasswords()); } if (password.length() < settings.getGeneral().getMinPasswordLength()) { throw new CommandException(settings.getText().getTooShortPassword()); } Task.builder() //we are executing a SQL Query which is blocking .async() .execute(new RegisterTask(plugin, protectionManager, (Player) src, password)) .name("Register Query") .submit(plugin); return CommandResult.success(); }
Example #13
Source File: VersionCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { try { source.sendMessage(Text.of( TextActions.showText(Text.of(TextColors.BLUE, "Click to view Github")), TextActions.openUrl(new URL("https://github.com/Aquerr/EagleFactions")), PluginInfo.PLUGIN_PREFIX, TextColors.AQUA, PluginInfo.NAME, TextColors.WHITE, " - ", TextColors.GOLD, Messages.VERSION + " ", PluginInfo.VERSION, TextColors.WHITE, " made by ", TextColors.GOLD, PluginInfo.AUTHOR)); } catch(final MalformedURLException e) { e.printStackTrace(); } return CommandResult.success(); }
Example #14
Source File: CommandClaimBasic.java From GriefPrevention with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); playerData.shovelMode = ShovelMode.Basic; playerData.claimSubdividing = null; GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimModeBasic.toText()); return CommandResult.success(); }
Example #15
Source File: ForceLoginCommand.java From FlexibleLogin with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Player player = args.<Player>getOne("account").get(); if (plugin.getDatabase().isLoggedIn(player)) { throw new CommandException(settings.getText().getForceLoginAlreadyLoggedIn()); } Task.builder() //we are executing a SQL Query which is blocking .async() .execute(new ForceLoginTask(plugin, attemptManager, protectionManager, player, src)) .name("Force Login Query") .submit(plugin); return CommandResult.success(); }
Example #16
Source File: SetSpawnExecutor.java From EssentialCmds with MIT License | 6 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; Utils.setSpawn(player.getTransform(), player.getWorld().getName()); player.getWorld().getProperties().setSpawnPosition(player.getLocation().getBlockPosition()); src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Spawn set.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /setspawn!")); } return CommandResult.success(); }
Example #17
Source File: CommandRestoreNatureFill.java From GriefPrevention with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); playerData.shovelMode = ShovelMode.RestoreNatureFill; // set radius based on arguments playerData.fillRadius = ctx.<Integer>getOne("radius").get(); if (playerData.fillRadius < 0) { playerData.fillRadius = 2; } final Text message = GriefPreventionPlugin.instance.messageData.restoreNatureFillModeActive .apply(ImmutableMap.of( "radius", playerData.fillRadius)).build(); GriefPreventionPlugin.sendMessage(player, message); return CommandResult.success(); }
Example #18
Source File: CommandContainerTrust.java From GriefPrevention with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) { User user = ctx.<User>getOne("user").orElse(null); String group = null; if (user == null) { group = ctx.<String>getOne("group").orElse(null); if (group.equalsIgnoreCase("public") || group.equalsIgnoreCase("all")) { user = GriefPreventionPlugin.PUBLIC_USER; group = null; } } try { if (user != null) { CommandHelper.handleUserTrustCommand(GriefPreventionPlugin.checkPlayer(src), TrustType.CONTAINER, user); } else { CommandHelper.handleGroupTrustCommand(GriefPreventionPlugin.checkPlayer(src), TrustType.CONTAINER, group); } } catch (CommandException e) { src.sendMessage(e.getText()); } return CommandResult.success(); }
Example #19
Source File: OwnedByCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext args) throws CommandException { final FactionPlayer factionPlayer = args.requireOne(Text.of("player")); 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)); final Faction playerFaction = optionalPlayerFaction.get(); // Access can be run only by leader and officers if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS)); // Get claim at player's location return showOwnedBy(player, factionPlayer, playerFaction); }
Example #20
Source File: PermsCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { 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 = 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)); final Faction faction = optionalPlayerFaction.get(); if(!faction.getLeader().equals(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_TO_DO_THIS)); showPerms(player, faction); return CommandResult.success(); }
Example #21
Source File: TagColorCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { if (!getPlugin().getConfiguration().getChatConfig().canColorTags()) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.TAG_COLORING_IS_TURNED_OFF_ON_THIS_SERVER)); if (!(source instanceof Player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND)); final TextColor color = context.requireOne("color"); final Player player = (Player)source; final Optional<Faction> optionalPlayerFaction = 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)); Faction playerFaction = optionalPlayerFaction.get(); if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player)) throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS)); super.getPlugin().getFactionLogic().changeTagColor(playerFaction, color); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.TAG_COLOR_HAS_BEEN_CHANGED)); return CommandResult.success(); }
Example #22
Source File: RemoveLeaderCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to remove leaders to regions.")) .arguments(GenericArguments.string(Text.of("player")), GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.removeleader")), GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.removeleader"))) .permission("redprotect.command.removeleader") .executor((src, args) -> { if (args.hasAny("region") && args.hasAny("world")) { String region = args.<String>getOne("region").get(); WorldProperties worldProperties = args.<WorldProperties>getOne("world").get(); if (!RedProtect.get().getServer().getWorld(worldProperties.getWorldName()).isPresent()) { src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.invalidworld"))); return CommandResult.success(); } Region r = RedProtect.get().rm.getRegion(region, worldProperties.getWorldName()); if (r == null) { src.sendMessage(RedProtect.get().getUtil().toText(RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + region)); return CommandResult.success(); } handleRemoveLeader(src, args.<String>getOne("player").get(), r); return CommandResult.success(); } else if (src instanceof Player) { Player player = (Player) src; handleRemoveLeader(player, args.<String>getOne("player").get(), null); return CommandResult.success(); } RedProtect.get().lang.sendCommandHelp(src, "removeleader", true); return CommandResult.success(); }).build(); }
Example #23
Source File: CommandAdjustBonusClaimBlocks.java From GriefPrevention with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) { WorldProperties worldProperties = args.<WorldProperties> getOne("world").orElse(Sponge.getServer().getDefaultWorld().get()); if (worldProperties == null) { if (src instanceof Player) { worldProperties = ((Player) src).getWorld().getProperties(); } else { worldProperties = Sponge.getServer().getDefaultWorld().get(); } } if (worldProperties == null || !GriefPreventionPlugin.instance.claimsEnabledForWorld(worldProperties)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.claimDisabledWorld.toText()); return CommandResult.success(); } // parse the adjustment amount int adjustment = args.<Integer>getOne("amount").get(); User user = args.<User>getOne("user").get(); // give blocks to player GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(worldProperties, user.getUniqueId()); playerData.setBonusClaimBlocks(playerData.getBonusClaimBlocks() + adjustment); playerData.getStorageData().save(); final Text message = GriefPreventionPlugin.instance.messageData.adjustBlocksSuccess .apply(ImmutableMap.of( "player", Text.of(user.getName()), "adjustment", Text.of(adjustment), "total", Text.of(playerData.getBonusClaimBlocks()))).build(); GriefPreventionPlugin .sendMessage(src, message); GriefPreventionPlugin.addLogEntry( src.getName() + " adjusted " + user.getName() + "'s bonus claim blocks by " + adjustment + ".", CustomLogEntryTypes.AdminActivity); return CommandResult.success(); }
Example #24
Source File: LoreBase.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { int number = ctx.<Integer> getOne("number").get(); if (src instanceof Player) { Player player = (Player) src; if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { ItemStack stack = player.getItemInHand(HandTypes.MAIN_HAND).get(); LoreData loreData = stack.getOrCreate(LoreData.class).get(); List<Text> newLore = loreData.lore().get(); newLore.remove(number - 1); DataTransactionResult dataTransactionResult = stack.offer(Keys.ITEM_LORE, newLore); if (dataTransactionResult.isSuccessful()) { player.setItemInHand(HandTypes.MAIN_HAND, stack); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Removed lore from item.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Could not remove lore from item.")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding an item!")); } } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be a player to name items.")); } return CommandResult.success(); }
Example #25
Source File: NationChatExecutor.java From Nations with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId()); if (nation == null) { player.setMessageChannel(MessageChannel.TO_ALL); src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION)); return CommandResult.success(); } NationMessageChannel channel = nation.getMessageChannel(); if (!ctx.<String>getOne("msg").isPresent()) { if (player.getMessageChannel().equals(channel)) { player.setMessageChannel(MessageChannel.TO_ALL); src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHAT_OFF)); } else { player.setMessageChannel(channel); src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHATON_ON)); } } else { Text header = TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(player.getUniqueId()))); Text msg = Text.of(header, TextColors.RESET, player.getName(), TextColors.WHITE, ": ", TextColors.YELLOW, ctx.<String>getOne("msg").get()); channel.send(player, msg); DataHandler.getSpyChannel().send(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, msg)); } } else { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER)); } return CommandResult.success(); }
Example #26
Source File: SubCommand.java From SubServers-2 with Apache License 2.0 | 5 votes |
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (canRun(sender)) { 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 #27
Source File: PEXActions.java From ChatUI with MIT License | 5 votes |
@Override public SubjectReference addSubjectToCollection(Player player, SubjectCollection collection, String subjIdentifier) { CommandResult res = command(player, new StringBuilder("pex ") .append(collection.getIdentifier()).append(' ') .append(subjIdentifier).append(" info").toString()); if (res.getSuccessCount().isPresent() && res.getSuccessCount().get() > 0) { return collection.newSubjectReference(subjIdentifier); } return null; }
Example #28
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 #29
Source File: ExpExecutor.java From EssentialCmds with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { int expLevel = ctx.<Integer> getOne("exp").get(); Player player = ctx.<Player> getOne("target").get(); player.offer(Keys.TOTAL_EXPERIENCE, expLevel); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set " + player.getName() + "'s experience level to " + expLevel + ".")); return CommandResult.success(); }
Example #30
Source File: DefineCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to claim regions as server.")) .arguments( GenericArguments.optional(GenericArguments.string(Text.of("regionName"))) ) .permission("redprotect.command.define") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; PlayerRegion serverName = new PlayerRegion(RedProtect.get().config.configRoot().region_settings.default_leader, RedProtect.get().config.configRoot().region_settings.default_leader); String name = RedProtect.get().getUtil().nameGen(RedProtect.get().config.configRoot().region_settings.default_leader, player.getWorld().getName()); if (args.hasAny("regionName")) { name = args.<String>getOne("regionName").get(); } RegionBuilder rb2 = new DefineRegionBuilder(player, RedProtect.get().firstLocationSelections.get(player), RedProtect.get().secondLocationSelections.get(player), name, serverName, new HashSet<>(), true); if (rb2.ready()) { Region r2 = rb2.build(); RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.created") + " " + r2.getName() + "."); RedProtect.get().rm.add(r2, player.getWorld().getName()); RedProtect.get().firstLocationSelections.remove(player); RedProtect.get().secondLocationSelections.remove(player); RedProtect.get().logger.addLog("(World " + r2.getWorld() + ") Player " + player.getName() + " DEFINED region " + r2.getName()); } } return CommandResult.success(); }).build(); }