Search in sources :

Example 1 with Builder

use of org.spongepowered.api.text.Text.Builder in project ProjectWorlds by trentech.

the class CommandList method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    List<Text> list = new ArrayList<>();
    for (WorldProperties properties : Sponge.getServer().getAllWorldProperties()) {
        Optional<World> optionalWorld = Sponge.getServer().getWorld(properties.getUniqueId());
        if (optionalWorld.isPresent()) {
            World world = optionalWorld.get();
            Builder builder = Text.builder().color(TextColors.GREEN).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Click to view properies")));
            builder.onClick(TextActions.runCommand("/pjw:world properties " + world.getName())).append(Text.of(TextColors.GREEN, world.getName(), ": ", Lists.newArrayList(world.getLoadedChunks()).size(), " Loaded chunks, ", world.getEntities().size(), " Entities"));
            list.add(builder.build());
        } else {
            Builder builder = Text.builder().color(TextColors.GREEN).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Click to load world")));
            builder.onClick(TextActions.runCommand("/pjw:world load " + properties.getWorldName())).append(Text.of(TextColors.GREEN, properties.getWorldName(), ": ", TextColors.GRAY, " Unloaded"));
            list.add(builder.build());
        }
    }
    if (source instanceof Player) {
        PaginationList.Builder pages = PaginationList.builder();
        pages.title(Text.builder().color(TextColors.DARK_GREEN).append(Text.of(TextColors.GREEN, "Worlds")).build());
        pages.contents(list);
        pages.sendTo(source);
    } else {
        for (Text text : list) {
            source.sendMessage(text);
        }
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PaginationList(org.spongepowered.api.service.pagination.PaginationList) Builder(org.spongepowered.api.text.Text.Builder) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 2 with Builder

use of org.spongepowered.api.text.Text.Builder in project modules-extra by CubeEngine.

the class ChatCommands method chatcolors.

@Command(desc = "Displays the colors")
public void chatcolors(CommandSource context) {
    i18n.send(context, POSITIVE, "The following chat codes are available:");
    Builder builder = Text.builder();
    int i = 0;
    for (TextColor color : Sponge.getRegistry().getAllOf(TextColor.class)) {
        if (color == TextColors.NONE) {
            continue;
        }
        if (i++ % 3 == 0) {
            builder.append(Text.NEW_LINE);
        }
        builder.append(Text.of(" ")).append(Text.of(color, color.getName())).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(color)), ")"));
    }
    builder.append(Text.NEW_LINE);
    builder.append(Text.of(" ")).append(Text.of(BOLD, "bold")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(BOLD)), ")"));
    builder.append(Text.of(" ")).append(Text.of(ITALIC, "italic")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(ITALIC)), ")"));
    builder.append(Text.of(" ")).append(Text.of(UNDERLINE, "underline")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(UNDERLINE)), ")"));
    builder.append(Text.NEW_LINE);
    builder.append(Text.of(" ")).append(Text.of(STRIKETHROUGH, "strikethrough")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(STRIKETHROUGH)), ")"));
    builder.append(Text.of(" ")).append(Text.of(OBFUSCATED, "obfuscated")).append(Text.of(" (", FORMATTING_CODE.serialize(Text.of(OBFUSCATED)), ")"));
    context.sendMessage(builder.build());
}
Also used : Builder(org.spongepowered.api.text.Text.Builder) TextColor(org.spongepowered.api.text.format.TextColor) Command(org.cubeengine.butler.parametric.Command)

Example 3 with Builder

use of org.spongepowered.api.text.Text.Builder in project RedProtect by FabioZumbi12.

the class RPCommands method getRegionforList.

private static void getRegionforList(CommandSource p, String uuid, int Page) {
    Set<Region> regions = RedProtect.get().rm.getRegions(uuid);
    String pname = RPUtil.UUIDtoPlayer(uuid);
    int length = regions.size();
    if (pname == null || length == 0) {
        RPLang.sendMessage(p, "cmdmanager.player.noregions");
    } else {
        p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-------------------------------------------------"));
        RPLang.sendMessage(p, RPLang.get("cmdmanager.region.created.list") + " " + pname);
        p.sendMessage(RPUtil.toText("-----"));
        if (RedProtect.get().cfgs.getBool("region-settings.region-list.simple-listing")) {
            for (World w : Sponge.getServer().getWorlds()) {
                String colorChar = RedProtect.get().cfgs.getString("region-settings.world-colors." + w.getName());
                Set<Region> wregions = RedProtect.get().rm.getRegions(uuid, w);
                if (wregions.size() > 0) {
                    Iterator<Region> it = wregions.iterator();
                    Builder worldregions = Text.builder();
                    if (RedProtect.get().ph.hasRegionPermAdmin(p, "teleport", null)) {
                        boolean first = true;
                        while (it.hasNext()) {
                            Region r = it.next();
                            if (first) {
                                first = false;
                                worldregions.append(Text.builder().append(RPUtil.toText("&8" + r.getName())).onHover(TextActions.showText(RPUtil.toText(RPLang.get("cmdmanager.list.hover").replace("{region}", r.getName())))).onClick(TextActions.runCommand("/rp " + getCmd("teleport") + " " + r.getName() + " " + r.getWorld())).build());
                            } else {
                                worldregions.append(Text.builder().append(RPUtil.toText(RPLang.get("general.color") + ", &8" + r.getName())).onHover(TextActions.showText(RPUtil.toText(RPLang.get("cmdmanager.list.hover").replace("{region}", r.getName())))).onClick(TextActions.runCommand("/rp " + getCmd("teleport") + " " + r.getName() + " " + r.getWorld())).build());
                            }
                        }
                    } else {
                        boolean first = true;
                        while (it.hasNext()) {
                            Region r = it.next();
                            if (first) {
                                first = false;
                                worldregions.append(Text.builder().append(RPUtil.toText("&8" + r.getName())).build());
                            } else {
                                worldregions.append(Text.builder().append(RPUtil.toText(RPLang.get("general.color") + ", &8" + r.getName())).build());
                            }
                        }
                    }
                    p.sendMessage(RPUtil.toText(RPLang.get("general.color") + RPLang.get("region.world").replace(":", "") + " " + colorChar + w.getName() + "[" + wregions.size() + "]&r: "));
                    p.sendMessages(worldregions.build());
                    p.sendMessage(RPUtil.toText("-----"));
                }
            }
        } else {
            Iterator<Region> i = regions.iterator();
            if (Page == 0) {
                Page = 1;
            }
            int max = (10 * Page);
            int min = max - 10;
            int count = 0;
            int last = 0;
            while (i.hasNext()) {
                String info = i.next().info().toPlain();
                if (count >= min && count <= max) {
                    p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-------------------------------------------------"));
                    p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "[" + (count + 1) + "] " + info));
                    last = count;
                }
                count++;
            }
            if (max > count) {
                min = 0;
            }
            p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "------------- " + (min + 1) + "-" + (last + 1) + "/" + count + " --------------"));
            if (count > max) {
                p.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.listpage.more").replace("{player}", pname + " " + (Page + 1))));
            } else {
                if (Page != 1) {
                    p.sendMessage(RPUtil.toText(RPLang.get("cmdmanager.region.listpage.nomore")));
                }
            }
        }
    }
}
Also used : DefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder) RedefineRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.RedefineRegionBuilder) Builder(org.spongepowered.api.text.Text.Builder) World(org.spongepowered.api.world.World)

Example 4 with Builder

use of org.spongepowered.api.text.Text.Builder in project UltimateChat by FabioZumbi12.

the class UCJedisLoader method sendTellMessage.

public void sendTellMessage(CommandSource sender, String tellReceiver, Text msg) {
    Builder text = Text.builder();
    text.append(UCUtil.toText(this.thisId));
    // send spy
    if (!sender.hasPermission("uchat.chat-spy.bypass")) {
        for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
            if (!receiver.getName().equals(tellReceiver) && !receiver.equals(sender) && UChat.get().isSpy.contains(receiver.getName()) && UChat.get().getPerms().hasSpyPerm(receiver, "private")) {
                String spyformat = UChat.get().getConfig().root().general.spy_format;
                spyformat = spyformat.replace("{output}", UCUtil.stripColor(UCMessages.sendMessage(sender, tellReceiver, msg, new UCChannel("tell"), true).toPlain()));
                receiver.sendMessage(UCUtil.toText(spyformat));
            }
        }
    }
    text.append(UCMessages.sendMessage(sender, tellReceiver, msg, new UCChannel("tell"), false));
    tellPlayers.put(tellReceiver, sender.getName());
    if (Arrays.asList(channels).contains("tellsend")) {
        Sponge.getScheduler().createAsyncExecutor(UChat.get()).execute(() -> {
            try {
                connectPool();
                Jedis jedis = pool.getResource();
                // string 0 1 2
                jedis.publish("tellsend", this.thisId + "$" + tellReceiver + "$" + TextSerializers.JSON.serialize(text.build()));
                jedis.quit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Player(org.spongepowered.api.entity.living.player.Player) Builder(org.spongepowered.api.text.Text.Builder) UCChannel(br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 5 with Builder

use of org.spongepowered.api.text.Text.Builder in project UltimateChat by FabioZumbi12.

the class UCCommands method registerUmsgAliases.

private void registerUmsgAliases() {
    // register umsg aliases
    for (String msga : UChat.get().getConfig().getMsgAliases()) {
        unregisterCmd(msga);
        manager.register(UChat.get().instance(), CommandSpec.builder().arguments(GenericArguments.player(Text.of("player")), GenericArguments.remainingJoinedStrings(Text.of("message"))).permission("uchat.cmd.umsg").description(Text.of("Send a message directly to a player.")).executor((src, args) -> {
            {
                Player receiver = args.<Player>getOne("player").get();
                String msg = args.<String>getOne("message").get();
                Builder txtBuilder = Text.builder().append(UCUtil.toText(msg));
                for (String arg : msg.split(" ")) {
                    try {
                        txtBuilder.onClick(TextActions.openUrl(new URL(arg)));
                        txtBuilder.onHover(TextActions.showText(UCUtil.toText(UChat.get().getConfig().root().general.URL_template.replace("{url}", arg))));
                    } catch (MalformedURLException ignored) {
                    }
                }
                receiver.sendMessage(txtBuilder.build());
                Sponge.getServer().getConsole().sendMessage(UCUtil.toText("&8> Private to &6" + receiver.getName() + "&8: &r" + txtBuilder.build().toPlain()));
                return CommandResult.success();
            }
        }).build(), msga);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MalformedURLException(java.net.MalformedURLException) Builder(org.spongepowered.api.text.Text.Builder) URL(java.net.URL)

Aggregations

Builder (org.spongepowered.api.text.Text.Builder)11 Player (org.spongepowered.api.entity.living.player.Player)6 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 World (org.spongepowered.api.world.World)2 DefineRegionBuilder (br.net.fabiozumbi12.RedProtect.Sponge.actions.DefineRegionBuilder)1 RedefineRegionBuilder (br.net.fabiozumbi12.RedProtect.Sponge.actions.RedefineRegionBuilder)1 UCChannel (br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JDABuilder (jdalib.jda.core.JDABuilder)1 ClanPlayer (nl.riebie.mcclans.api.ClanPlayer)1 Command (org.cubeengine.butler.parametric.Command)1 BlockType (org.spongepowered.api.block.BlockType)1 DataContainer (org.spongepowered.api.data.DataContainer)1 DataView (org.spongepowered.api.data.DataView)1 PaginationList (org.spongepowered.api.service.pagination.PaginationList)1 Text (org.spongepowered.api.text.Text)1 TextColor (org.spongepowered.api.text.format.TextColor)1