org.spongepowered.api.text.Text Java Examples
The following examples show how to use
org.spongepowered.api.text.Text.
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: UCCommands.java From UltimateChat with GNU General Public License v3.0 | 6 votes |
private void sendPreTell(CommandSource sender, CommandSource receiver, Text msg) { CommandSource src = sender; if (sender instanceof ConsoleSource) { src = receiver; } UChat.get().getLogger().timings(UCLogger.timingType.START, "UCListener#sendPreTell()|Fire AsyncPlayerChatEvent"); MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat( UChat.get().getVHelper().getCause(src), src.getMessageChannel(), Optional.of(src.getMessageChannel()), new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ") .onShiftClick(TextActions.insertText(src.getName())) .onClick(TextActions.suggestCommand("/msg " + src.getName())) .build(), msg), msg, false); Sponge.getEventManager().post(event); }
Example #2
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 #3
Source File: ItemhidetagsCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandElement[] getArguments() { HashMap<String, Key<Value<Boolean>>> choices = new HashMap<>(); choices.put("attribute", Keys.HIDE_ATTRIBUTES); choices.put("attributes", Keys.HIDE_ATTRIBUTES); choices.put("candestroy", Keys.HIDE_CAN_DESTROY); choices.put("canbreak", Keys.HIDE_CAN_DESTROY); choices.put("canplace", Keys.HIDE_CAN_PLACE); choices.put("canplaceon", Keys.HIDE_CAN_PLACE); choices.put("ench", Keys.HIDE_ENCHANTMENTS); choices.put("enchantment", Keys.HIDE_ENCHANTMENTS); choices.put("enchantments", Keys.HIDE_ENCHANTMENTS); choices.put("misc", Keys.HIDE_MISCELLANEOUS); choices.put("miscellaneous", Keys.HIDE_MISCELLANEOUS); choices.put("unbreakable", Keys.HIDE_UNBREAKABLE); return new CommandElement[]{ Arguments.builder(new ChoicesArgument(Text.of("tag"), choices)).onlyOne().usage("attributes/candestroy/canplaceon/enchantments/miscellaneous/unbreakable").build(), Arguments.builder(new BooleanArgument(Text.of("enabled"))).usageKey("Enable/Disable").onlyOne().build() }; }
Example #4
Source File: BuildPermListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onPlayerPlacesBlock(ChangeBlockEvent.Place event, @First Player player) { if (player.hasPermission("nations.admin.bypass.perm.build")) { return; } event .getTransactions() .stream() .forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> { if (ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean() && !ConfigHandler.isWhitelisted("build", trans.getFinal().getState().getType().getId()) && !DataHandler.getPerm("build", player.getUniqueId(), loc)) { trans.setValid(false); try { player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } catch (Exception e) {} } })); }
Example #5
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 #6
Source File: RuleExecutor.java From EssentialCmds with MIT License | 6 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { ArrayList<String> rules = Utils.getRules(); List<Text> ruleText = Lists.newArrayList(); if (rules.isEmpty()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The rules for this server are not defined.")); return; } for (String rule : rules) { ruleText.add(Text.of(TextColors.GRAY, (rules.indexOf(rule) + 1) + ". ", TextColors.GOLD, rule)); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder().contents(ruleText).title(Text.of(TextColors.GOLD, "Rules")).padding(Text.of("-")); paginationBuilder.sendTo(src); }
Example #7
Source File: NationadminExtraspawnplayerExecutor.java From Nations with MIT License | 6 votes |
public static void create(CommandSpec.Builder cmd) { cmd.child(CommandSpec.builder() .description(Text.of("")) .permission("nations.command.nationadmin.extraspawnplayer") .arguments( GenericArguments.optional(GenericArguments.choices(Text.of("give|take|set"), ImmutableMap.<String, String> builder() .put("give", "give") .put("take", "take") .put("set", "set") .build())), GenericArguments.optional(new PlayerNameElement(Text.of("player"))), GenericArguments.optional(GenericArguments.integer(Text.of("amount")))) .executor(new NationadminExtraspawnplayerExecutor()) .build(), "extraspawnplayer"); }
Example #8
Source File: AdminCommand.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; if(super.getPlugin().getPlayerManager().hasAdminMode(player)) { super.getPlugin().getPlayerManager().deactivateAdminMode(player); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, Messages.ADMIN_MODE_HAS_BEEN_TURNED_OFF)); } else { super.getPlugin().getPlayerManager().activateAdminMode(player); player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, Messages.ADMIN_MODE_HAS_BEEN_TURNED_ON)); } return CommandResult.success(); }
Example #9
Source File: WelcomeCommand.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to set a welcome message for a region.")) .arguments(GenericArguments.remainingJoinedStrings(Text.of("message"))) .permission("redprotect.command.welcome") .executor((src, args) -> { if (!(src instanceof Player)) { HandleHelpPage(src, 1); } else { Player player = (Player) src; String arg = args.<String>getOne("message").get(); if (arg.equals("off")) { handleWelcome(player, ""); } else { handleWelcome(player, arg); } } return CommandResult.success(); }).build(); }
Example #10
Source File: GriefPreventionPlugin.java From GriefPrevention with MIT License | 6 votes |
public static void sendMessage(CommandSource source, Text message, long delayInTicks) { if (source instanceof Player && SpongeImplHooks.isFakePlayer((net.minecraft.entity.Entity) source)) { return; } if (source instanceof Player) { SendPlayerMessageTask task = new SendPlayerMessageTask((Player) source, message); if (delayInTicks > 0) { Sponge.getGame().getScheduler().createTaskBuilder().delayTicks(delayInTicks).execute(task).submit(GriefPreventionPlugin.instance); } else { task.run(); } } else { source.sendMessage(message); } }
Example #11
Source File: NationworldInfoExecutor.java From Nations with MIT License | 5 votes |
public static void create(CommandSpec.Builder cmd) { cmd.child(CommandSpec.builder() .description(Text.of("")) .permission("nations.command.nationworld.info") .arguments(GenericArguments.optional(new WorldNameElement(Text.of("world")))) .executor(new NationworldInfoExecutor()) .build(), "info"); }
Example #12
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 #13
Source File: PermissionsTab.java From ChatUI with MIT License | 5 votes |
@Override public void onTextInput(PlayerChatView view, Text input) { if (this.getRoot() == this.subjViewer) { this.subjViewer.onTextEntered(view, input); } else if (this.getRoot() == this.subjListPane) { this.subjListPane.onTextEntered(view, input); } else if (this.getRoot() == this.entryDisplayer) { this.entryDisplayer.onTextEntered(view, input); } }
Example #14
Source File: NationCreateExecutor.java From Nations with MIT License | 5 votes |
public static void create(CommandSpec.Builder cmd) { cmd.child(CommandSpec.builder() .description(Text.of("")) .permission("nations.command.nation.create") .arguments(GenericArguments.optional(GenericArguments.string(Text.of("name")))) .executor(new NationCreateExecutor()) .build(), "create", "new"); }
Example #15
Source File: HealExecutor.java From EssentialCmds with MIT License | 5 votes |
@Nonnull @Override public CommandSpec getSpec() { return CommandSpec.builder().description(Text.of("Heal Command")).permission("essentialcmds.heal.use") .arguments(GenericArguments.optional(GenericArguments.onlyOne(GenericArguments.player(Text.of("player"))))) .executor(this).build(); }
Example #16
Source File: NationadminForceleaveExecutor.java From Nations with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { if (!ctx.<String>getOne("player").isPresent()) { src.sendMessage(Text.of(TextColors.YELLOW, "/na forceleave <player>")); return CommandResult.success(); } String playerName = ctx.<String>getOne("player").get(); UUID uuid = DataHandler.getPlayerUUID(playerName); if (uuid == null) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADPLAYERNAME)); return CommandResult.success(); } Nation nation = DataHandler.getNationOfPlayer(uuid); if (nation == null) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PLAYERNOTINNATION)); return CommandResult.success(); } if (nation.isPresident(uuid)) { src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PLAYERISPRES)); return CommandResult.success(); } nation.removeCitizen(uuid); DataHandler.saveNation(nation.getUUID()); Sponge.getServer().getPlayer(uuid).ifPresent(p -> p.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.SUCCESS_LEAVENATION))); src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_GENERAL)); return CommandResult.success(); }
Example #17
Source File: Utils.java From Nations with MIT License | 5 votes |
public static Text nationClickable(TextColor color, String name) { if (name == null) { return Text.of(color, LanguageHandler.FORMAT_UNKNOWN); } return Text.builder(name.replace("_", " ")).color(color).onClick(TextActions.runCommand("/n info " + name)).build(); }
Example #18
Source File: Permission.java From UltimateCore with MIT License | 5 votes |
public static Permission create(String identifier, String moduleid, PermissionLevel level, @Nullable String commandid, Text description) { if (UltimateCore.get().getPermissionService().get(identifier).isPresent()) { return UltimateCore.get().getPermissionService().get(identifier).get(); } Optional<Module> module = UltimateCore.get().getModuleService().getModule(moduleid); if (!module.isPresent()) { Messages.log("Failed to register permission " + identifier + ": Invalid module " + moduleid); //TODO ErrorLogger? return null; } Permission perm = new Permission(identifier, module.get(), level, commandid, description); UltimateCore.get().getPermissionService().register(perm); return perm; }
Example #19
Source File: PrismCommands.java From Prism with MIT License | 5 votes |
/** * Build a complete command hierarchy * @return */ public static CommandSpec getCommand() { // Build child commands ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder(); builder.put(ImmutableList.of("i", "wand"), InspectCommand.getCommand()); builder.put(ImmutableList.of("l", "lookup"), LookupCommand.getCommand()); builder.put(ImmutableList.of("near"), NearCommand.getCommand()); // Sort order newest first for rollback, and oldest first for restore. builder.put(ImmutableList.of("rb", "rollback"), ApplierCommand.getCommand(Sort.NEWEST_FIRST)); builder.put(ImmutableList.of("rs", "restore"), ApplierCommand.getCommand(Sort.OLDEST_FIRST)); builder.put(ImmutableList.of("undo"), UndoCommand.getCommand()); builder.put(ImmutableList.of("ext"), ExtinguishCommand.getCommand()); builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand()); return CommandSpec.builder() .executor((source, args) -> { // Check permission here, so the node doesn't apply to all child commands if (source.hasPermission("prism.info")) { source.sendMessage(Text.of( Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi", TextColors.GRAY, ".\n"), TextColors.DARK_AQUA, "Tracking so good the NSA stole our name.\n", TextColors.GRAY, "Help: ", TextColors.WHITE, "/pr ?\n", TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #prism\n", TextColors.GRAY, "Site: ", Format.url(Reference.WEBSITE), "\n", TextColors.GRAY, "Source: ", Format.url(Reference.SOURCE) )); return CommandResult.success(); } else { throw new CommandException(Format.error("You do not have permission to use this command.")); } }) .children(builder.build()).build(); }
Example #20
Source File: SPlayerBoard.java From Netherboard with Apache License 2.0 | 5 votes |
@Override public Map<Integer, Text> getLines() { if(this.deleted) throw new IllegalStateException("The PlayerBoard is deleted!"); return new HashMap<>(lines); }
Example #21
Source File: RemoveAdminCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public CommandSpec register() { return CommandSpec.builder() .description(Text.of("Command to remove admins to regions.")) .arguments(GenericArguments.string(Text.of("player")), GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.string(Text.of("region")), "redprotect.command.admin.removeadmin")), GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.world(Text.of("world")), "redprotect.command.admin.removeadmin"))) .permission("redprotect.command.removeadmin") .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(); } handleRemoveAdmin(src, args.<String>getOne("player").get(), r); return CommandResult.success(); } else if (src instanceof Player) { Player player = (Player) src; handleRemoveAdmin(player, args.<String>getOne("player").get(), null); return CommandResult.success(); } RedProtect.get().lang.sendCommandHelp(src, "removeadmin", true); return CommandResult.success(); }).build(); }
Example #22
Source File: KickAllExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { String reason = ctx.<String> getOne("reason").get(); Text reas = TextSerializers.formattingCode('&').deserialize(reason); for(Player player : Sponge.getServer().getOnlinePlayers()) { if(!src.equals(player)) player.kick(reas); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Kicked all players.")); return CommandResult.success(); }
Example #23
Source File: InteractiveMessageOption.java From Web-API with MIT License | 5 votes |
/** * Gets the value of the message option that is displayed to the user. * @return The value of the message option. */ @ApiModelProperty(dataType = "string", value = "The value of the option (this is displayed to the player)", required = true) @JsonIgnore public Text getValue() { if (value == null) { return null; } return TextSerializers.FORMATTING_CODE.deserialize(value); }
Example #24
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
private static boolean validateCommandMapping(CommandSource src, String command, String pluginId) { CommandMapping commandMapping = Sponge.getCommandManager().get(command).orElse(null); if (commandMapping == null) { src.sendMessage(Text.of( TextColors.RED, "Could not locate the command '", TextColors.GREEN, command, TextColors.RED, "' for mod id '", TextColors.AQUA, pluginId, TextColors.RED, "'.")); return false; } return true; }
Example #25
Source File: DefaultTableRenderer.java From ChatUI with MIT License | 5 votes |
@Override public Text createBorder(TableModel model, int rowIndex, int[] colMaxWidths, PlayerContext ctx) { char left = '├'; char right = '┤'; char join = '┼'; if (rowIndex == -1) { left = '┌'; right = '┐'; join = '┬'; } else if (rowIndex == model.getRowCount() - 1) { left = '└'; right = '┘'; join = '┴'; } Text.Builder lineBuilder = Text.builder(); for (int i = 0; i < colMaxWidths.length; i++) { char edge = i == 0 ? left : join; int edgeWidth = ctx.utils().getWidth(edge, false); int width = colMaxWidths[i] + edgeWidth; if (i < colMaxWidths.length - 1) { ctx.utils().startAndRepeat(lineBuilder, edge, '─', width); } else { width += edgeWidth; ctx.utils().startRepeatTerminate(lineBuilder, edge, '─', right, width); } } return lineBuilder.build(); }
Example #26
Source File: NationadminClaimExecutor.java From Nations with MIT License | 5 votes |
public static void create(CommandSpec.Builder cmd) { cmd.child(CommandSpec.builder() .description(Text.of("")) .permission("nations.command.nationadmin.claim") .arguments(GenericArguments.optional(GenericArguments.string(Text.of("nation")))) .executor(new NationadminClaimExecutor()) .build(), "claim"); }
Example #27
Source File: StorageManagerImpl.java From EagleFactions with MIT License | 5 votes |
public StorageManagerImpl(final EagleFactions plugin, final StorageConfig storageConfig, final Path configDir) { this.configDir = configDir; switch(storageConfig.getStorageType().toLowerCase()) { case "hocon": factionsStorage = new HOCONFactionStorage(configDir); playerStorage = new HOCONPlayerStorage(configDir); plugin.printInfo("HOCON storage has been initialized!"); break; case "h2": factionsStorage = new H2FactionStorage(plugin); playerStorage = new H2PlayerStorage(plugin); plugin.printInfo("H2 storage has been initialized!"); break; case "mysql": factionsStorage = new MySQLFactionStorage(plugin); playerStorage = new MySQLPlayerStorage(plugin); plugin.printInfo("MySQL storage has been initialized!"); break; case "mariadb": factionsStorage = new MariaDbFactionStorage(plugin); playerStorage = new MariaDbPlayerStorage(plugin); plugin.printInfo("MariaDB storage has been initialized!"); break; default: //HOCON plugin.printInfo("Couldn't find provided storage type."); factionsStorage = new HOCONFactionStorage(configDir); playerStorage = new HOCONPlayerStorage(configDir); plugin.printInfo("Initialized default HOCON storage."); break; } this.backupStorage = new BackupStorage(factionsStorage, playerStorage, configDir); Sponge.getServer().getConsole().sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.AQUA, "Filling cache with data...")); prepareFactionsCache(); preparePlayerCache(); //Consider using cache that removes objects which have not been used for a long time. }
Example #28
Source File: LoreBase.java From EssentialCmds with MIT License | 5 votes |
@Nonnull @Override public CommandSpec getSpec() { return CommandSpec .builder() .description(Text.of("Add Lore Command")) .permission("essentialcmds.lore.add") .arguments(GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of("lore")))) .executor(this) .build(); }
Example #29
Source File: NickKeys.java From UltimateCore with MIT License | 5 votes |
@Override public Text load(UltimateUser user) { PlayerDataFile config = new PlayerDataFile(user.getIdentifier()); CommentedConfigurationNode node = config.get(); Text name = Messages.toText(node.getNode("nick").getString()); if (name == null) return null; if (!name.toPlain().matches("[A-Za-z0-9]+")) { //Please don't crash the server return null; } return name; }
Example #30
Source File: TestVoteCmd.java From NuVotifier with GNU General Public License v3.0 | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { Vote v; try { Collection<String> a = args.getAll("args"); v = ArgsToVote.parse(a.toArray(new String[0])); } catch (IllegalArgumentException e) { sender.sendMessage(Text.builder("Error while parsing arguments to create test vote: " + e.getMessage()).color(TextColors.DARK_RED).build()); sender.sendMessage(Text.builder("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]").color(TextColors.GRAY).build()); return CommandResult.empty(); } plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test"); return CommandResult.success(); }