org.spongepowered.api.command.args.CommandContext Java Examples
The following examples show how to use
org.spongepowered.api.command.args.CommandContext.
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: CommandClaimSubdivide.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.Subdivide; playerData.claimSubdividing = null; GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimModeSubdivision.toText()); return CommandResult.success(); }
Example #2
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 #3
Source File: UnjailCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, JailPermissions.UC_JAIL_UNJAIL_BASE); //Find player Player t = args.<Player>getOne("player").get(); UltimateUser ut = UltimateCore.get().getUserService().getUser(t); if (!ut.get(JailKeys.JAIL).isPresent()) { Messages.send(sender, "jail.command.unjail.notjailed", "%player%", t); return CommandResult.success(); } ut.offer(JailKeys.JAIL, null); Messages.send(sender, "jail.command.unjail.success", "%player%", t); Messages.send(t, "jail.target.unjailed"); return CommandResult.success(); }
Example #4
Source File: MapCommand.java From EagleFactions with MIT License | 6 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { if (source instanceof Player) { final Player player = (Player) source; if (this.protectionConfig.getClaimableWorldNames().contains(player.getWorld().getName())) { generateMap(player); } else { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_VIEW_MAP_IN_THIS_WORLD)); } } else { source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND)); } return CommandResult.success(); }
Example #5
Source File: KickCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, KickPermissions.UC_KICK_KICK_BASE); Player target = args.<Player>getOne("player").get(); Text reason = args.hasAny("reason") ? Text.of(args.<String>getOne("reason").get()) : Messages.getFormatted("kick.command.kick.defaultreason"); if (sender.equals(target)) { throw new ErrorMessageException(Messages.getFormatted(sender, "kick.command.kick.self")); } if ((KickPermissions.UC_KICK_EXEMPTPOWER.getIntFor(target) > KickPermissions.UC_KICK_POWER.getIntFor(sender)) && sender instanceof Player) { throw new ErrorMessageException(Messages.getFormatted(sender, "kick.command.kick.exempt", "%player%", target)); } Sponge.getServer().getBroadcastChannel().send(Messages.getFormatted("kick.command.kick.broadcast", "%kicker%", sender, "%kicked%", target, "%reason%", reason)); target.kick(Messages.getFormatted("kick.command.kick.message", "%kicker%", sender, "%kicked%", target, "%reason%", reason)); return CommandResult.success(); }
Example #6
Source File: SetTimeCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, TimePermissions.UC_TIME_TIME_TICKS); World world; if (!args.hasAny("world")) { checkIfPlayer(sender); world = ((Player) sender).getWorld(); } else { world = args.<World>getOne("world").get(); } Integer ticks = args.<Integer>getOne("time").get(); world.getProperties().setWorldTime(ticks); Messages.send(sender, "time.command.time.set.ticks", "%ticks%", ticks); return CommandResult.success(); }
Example #7
Source File: PayVirtualCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(Player src, CommandContext args) { if (args.getOne("target").isPresent() && args.getOne("amount").isPresent()) { String target = args.<String>getOne("target").get(); BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get()); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(src.getUniqueId()); // Check for negative payments if (amount.doubleValue() <= 0) { src.sendMessage(messageStorage.getMessage("command.pay.invalid")); } else { if (aOpt.isPresent() && uOpt.isPresent()) { Account receiver = aOpt.get(); UniqueAccount payer = uOpt.get(); if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance()))) .getResult().equals(ResultType.SUCCESS)) { src.sendMessage(messageStorage.getMessage("command.pay.success", "target", receiver.getDisplayName().toPlain())); } else { src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", receiver.getDisplayName().toPlain())); } } } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #8
Source File: DeafCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, DeafPermissions.UC_DEAF_DEAF_BASE); Player t = args.<Player>getOne("player").get(); Long time = args.hasAny("time") ? args.<Long>getOne("time").get() : -1L; Text reason = args.hasAny("reason") ? Text.of(args.<String>getOne("reason").get()) : Messages.getFormatted("deaf.command.deaf.defaultreason"); if ((DeafPermissions.UC_DEAF_EXEMPTPOWER.getIntFor(t) > DeafPermissions.UC_DEAF_POWER.getIntFor(sender)) && sender instanceof Player) { throw new ErrorMessageException(Messages.getFormatted(sender, "deaf.command.deaf.exempt", "%player%", t)); } Long endtime = time == -1L ? -1L : System.currentTimeMillis() + time; Long starttime = System.currentTimeMillis(); UUID deafr = sender instanceof Player ? ((Player) sender).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000"); UUID deafd = t.getUniqueId(); Deaf deaf = new Deaf(deafd, deafr, endtime, starttime, reason); UltimateUser ut = UltimateCore.get().getUserService().getUser(t); ut.offer(DeafKeys.DEAF, deaf); Messages.send(sender, "deaf.command.deaf.success", "%player%", VariableUtil.getNameEntity(t), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason); Messages.send(t, "deaf.deafed", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason); return CommandResult.success(); }
Example #9
Source File: WeakOptionalWrapper.java From UltimateCore with MIT License | 6 votes |
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { if (!args.hasNext()) { return; } Object startState = args.getState(); try { this.element.parse(source, args, context); } catch (ArgumentParseException ex) { if (args.hasNext()) { // If there are more args, suppress. Otherwise, throw the error args.setState(startState); } else { throw ex; } } }
Example #10
Source File: NickExecutor.java From EssentialCmds with MIT License | 6 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Player player = ctx.<Player>getOne("player").get(); String nick = ctx.<String>getOne("nick").get(); if (src instanceof Player && ((Player) src).getUniqueId() != player.getUniqueId() && src.hasPermission("essentialcmds.nick.others")) { Utils.setNick(nick, player.getUniqueId()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Nick successfully set!")); } else if (src instanceof Player && ((Player) src).getUniqueId() != player.getUniqueId()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to make changes to other player's nicknames.!")); } else { Utils.setNick(nick, player.getUniqueId()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Nick successfully set!")); } return CommandResult.success(); }
Example #11
Source File: FoodCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_BASE); if (!args.hasAny("player")) { checkIfPlayer(sender); Player p = (Player) sender; p.offer(Keys.FOOD_LEVEL, p.get(FoodData.class).get().foodLevel().getMaxValue()); p.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue()); Messages.send(p, "food.command.food.success.self"); return CommandResult.success(); } else { checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_OTHERS); Player t = args.<Player>getOne("player").get(); t.offer(Keys.FOOD_LEVEL, t.get(FoodData.class).get().foodLevel().getMaxValue()); t.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue()); Messages.send(sender, "food.command.food.success.others.self", "%player%", t); Messages.send(t, "food.command.food.success.others.others", "%player%", sender); return CommandResult.success(); } }
Example #12
Source File: PayCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(Player src, CommandContext args) { if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) { BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get()); if (amount.doubleValue() <= 0) { src.sendMessage(messageStorage.getMessage("command.pay.invalid")); } else { User target = args.<User>getOne("player").get(); if (!EconomyLite.getConfigManager().getValue(Boolean.class, false, "confirm-offline-payments") || target.isOnline()) { // Complete the payment pay(target, amount, src); } else { src.sendMessage(messageStorage.getMessage("command.pay.confirm", "player", target.getName())); // Check if they want to still pay src.sendMessage(TextUtils.yesOrNo(c -> { pay(target, amount, src); }, c -> { src.sendMessage(messageStorage.getMessage("command.pay.confirmno", "player", target.getName())); })); } } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #13
Source File: WebHookParam.java From Web-API with MIT License | 6 votes |
public Optional<Object> getValue(CommandContext args) { Optional<String> arg = args.getOne(name); if (!arg.isPresent()) return Optional.empty(); Object obj = arg.get(); switch (type) { case STRING: case BOOL: case INTEGER: case DOUBLE: case LOCATION: case VECTOR3D: return Optional.of(obj); case PLAYER: CachedPlayer p = WebAPI.getCacheService().getPlayer((Player)obj); return Optional.of(p); case WORLD: CachedWorld w = WebAPI.getCacheService().getWorld((World)obj); return Optional.of(w); } return Optional.empty(); }
Example #14
Source File: ItemhidetagsCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, ItemPermissions.UC_ITEM_ITEMHIDETAGS_BASE); Player p = (Player) sender; if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) { throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand")); } ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND); Key<Value<Boolean>> key = args.<Key<Value<Boolean>>>getOne("tag").get(); boolean value = args.<Boolean>getOne("enabled").get(); stack.offer(key, value); p.setItemInHand(HandTypes.MAIN_HAND, stack); Messages.send(sender, "item.command.itemhidetags.success", "%tag%", key.getName(), "%status%", Messages.getFormatted(value ? "item.command.itemhidetags.hidden" : "item.command.itemhidetags.shown")); return CommandResult.success(); }
Example #15
Source File: VirtualBalanceCommand.java From EconomyLite with MIT License | 6 votes |
@Override public void run(CommandSource src, CommandContext args) { Currency currency = currencyService.getCurrentCurrency(); if (args.getOne("account").isPresent()) { if (src.hasPermission("economylite.admin.virtualbalance")) { String target = args.<String>getOne("account").get(); Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target); if (aOpt.isPresent()) { BigDecimal bal = aOpt.get().getBalance(currency); Text label = currency.getPluralDisplayName(); if (bal.equals(BigDecimal.ONE)) { label = currency.getDisplayName(); } src.sendMessage(messageStorage.getMessage("command.balanceother", "player", aOpt.get().getDisplayName().toPlain(), "balance", String.format(Locale.ENGLISH, "%,.2f", bal), "label", label.toPlain())); } else { src.sendMessage(messageStorage.getMessage("command.error")); } } else { src.sendMessage(messageStorage.getMessage("command.noperm")); } } else { src.sendMessage(messageStorage.getMessage("command.error")); } }
Example #16
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 #17
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 #18
Source File: FactionPlayerArgument.java From EagleFactions with MIT License | 6 votes |
@Override public List<String> complete(final CommandSource src, final CommandArgs args, final CommandContext context) { final Map<UUID, FactionPlayer> factionPlayerMap = FactionsCache.getPlayersMap(); final List<FactionPlayer> list = new ArrayList<>(factionPlayerMap.values()); if (args.hasNext()) { String charSequence = args.nextIfPresent().get(); final List<String> resultList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { final FactionPlayer factionPlayer = list.get(i); final String factionPlayerName = factionPlayer.getName(); if (factionPlayerName.toLowerCase().startsWith(charSequence.toLowerCase())) { resultList.add(factionPlayerName); } } return resultList; } return list.stream().map(FactionPlayer::getName).collect(Collectors.toList()); }
Example #19
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 #20
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 #21
Source File: NationMarkExecutor.java From Nations with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { DataHandler.toggleMarkJob((Player) src); } else { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER)); } return CommandResult.success(); }
Example #22
Source File: TPADenyExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (src instanceof Player) { Player player = (Player) src; Player sender = null; PendingInvitation cancel = null; for (PendingInvitation invitation : EssentialCmds.pendingInvites) { if (invitation.recipient == player) { sender = invitation.sender; cancel = invitation; break; } } if (cancel != null && sender != null) { sender.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Your TPA Request was Denied by " + player.getName() + "!")); EssentialCmds.pendingInvites.remove(cancel); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, "TPA Request Denied.")); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Pending TPA request not found!")); } } else if (src instanceof ConsoleSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!")); } else if (src instanceof CommandBlockSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!")); } return CommandResult.success(); }
Example #23
Source File: CommandClaimFarewell.java From GriefPrevention with MIT License | 5 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()); if (claim != null) { if (claim.allowEdit(player) != null) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionEditClaim.toText()); return CommandResult.success(); } Text farewell = TextSerializers.FORMATTING_CODE.deserialize(ctx.<String>getOne("message").get()); if (farewell.isEmpty()) { claim.getInternalClaimData().setFarewell(null); } else { claim.getInternalClaimData().setFarewell(farewell); } claim.getInternalClaimData().setRequiresSave(true); final Text message = GriefPreventionPlugin.instance.messageData.claimFarewell .apply(ImmutableMap.of( "farewell", farewell)).build(); GriefPreventionPlugin.sendMessage(src, message); } else { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.claimNotFound.toText()); } return CommandResult.success(); }
Example #24
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, player.get(Keys.TOTAL_EXPERIENCE).get() - expLevel); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Took " + expLevel + " experience from " + player.getName() + ".")); return CommandResult.success(); }
Example #25
Source File: CountryCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, GeoipPermissions.UC_GEOIP_COUNTRY_BASE); if (!GeoipHandler.isLoaded()) { throw new ErrorMessageException(Messages.getFormatted(sender, "geoip.command.country.notenabled")); } Player t = args.<Player>getOne("player").get(); Country country = GeoipHandler.getCountry(t.getConnection().getAddress().getAddress()).orElse(null); if (country == null) { throw new ErrorMessageException(Messages.getFormatted(sender, "geoip.command.country.failed", "%player%", t)); } Messages.send(sender, "geoip.command.country.success", "%player%", t, "%country%", country.getName()); return CommandResult.success(); }
Example #26
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 #27
Source File: WeatherCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, WeatherPermissions.UC_WEATHER_WEATHER_BASE); Weather weather = args.<Weather>getOne("weather").get(); World world = args.hasAny("world") ? args.<World>getOne("world").get() : null; if (world == null) { checkIfPlayer(sender); world = ((Player) sender).getWorld(); } world.setWeather(weather); Messages.send(sender, "weather.command.weather.success", "%weather%", weather.getName().toLowerCase(), "%world%", world.getName()); return CommandResult.success(); }
Example #28
Source File: HelpSubCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { List<Text> texts = new ArrayList<>(); //Add entries to texts texts.add(Messages.getFormatted(src, "core.help.module", "%module%", this.cmd.getModule().getIdentifier())); texts.add(Text.of()); texts.add(Messages.getFormatted(src, "core.help.description", "%description%", this.cmd.getLongDescription(src))); texts.add(Text.of()); texts.add(Messages.getFormatted(src, "core.help.usage", "%usages%", getUsages(src))); //Send page PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted(src, "core.help.header", "%command%", this.cmd.getFullIdentifier()).toBuilder().color(TextColors.DARK_GREEN).build()).build(); paginationList.sendTo(src); return CommandResult.success(); }
Example #29
Source File: TwoFactorRegisterCommand.java From FlexibleLogin with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { if (!(src instanceof Player)) { throw new CommandException(settings.getText().getPlayersOnly()); } Task.builder() //we are executing a SQL Query which is blocking .async() .execute(new RegisterTask(plugin, protectionManager, (Player) src)) .name("Register Query") .submit(plugin); return CommandResult.success(); }
Example #30
Source File: NationDelspawnExecutor.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) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION)); return CommandResult.success(); } if (!ctx.<String>getOne("name").isPresent()) { src.sendMessage(Text.builder() .append(Text.of(TextColors.AQUA, LanguageHandler.INFO_CLICK_DELSPAWN.split("\\{SPAWNLIST\\}")[0])) .append(Utils.formatNationSpawns(nation, TextColors.YELLOW, "delhome")) .append(Text.of(TextColors.AQUA, LanguageHandler.INFO_CLICK_DELSPAWN.split("\\{SPAWNLIST\\}")[1])).build()); return CommandResult.success(); } String spawnName = ctx.<String>getOne("name").get(); if (!nation.isStaff(player.getUniqueId())) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF)); return CommandResult.success(); } if (nation.getSpawn(spawnName) == null) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADSPAWNNAME)); return CommandResult.success(); } nation.removeSpawn(spawnName); DataHandler.saveNation(nation.getUUID()); src.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.SUCCESS_DELNATION)); } else { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER)); } return CommandResult.success(); }