Search in sources :

Example 41 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.

the class CommandListStructures method showList.

public static void showList(ICommandSender commandSender, int page, List<String> structureNames) {
    int startIndex = page * RESULTS_PER_PAGE;
    int endIndex = Math.min((page + 1) * RESULTS_PER_PAGE, structureNames.size());
    if (endIndex - startIndex > 0) {
        List<ITextComponent> components = new ArrayList<>(endIndex - startIndex + 2);
        components.add(new TextComponentString("[<--]"));
        if (page > 0)
            linkToPage(components.get(0), page - 1, RecurrentComplex.translations.format("commands.rclist.previous"));
        for (int i = 0; i < endIndex - startIndex; i++) components.add(RCTextStyle.structure(structureNames.get(startIndex + i)));
        components.add(new TextComponentString("[-->]"));
        if (page < (structureNames.size() - 1) / RESULTS_PER_PAGE)
            linkToPage(components.get(components.size() - 1), page + 1, RecurrentComplex.translations.format("commands.rclist.next"));
        commandSender.sendMessage(ServerTranslations.join(components));
    } else
        commandSender.sendMessage(RecurrentComplex.translations.get("commands.rclist.none"));
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 42 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.

the class CommandLookupStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String id = parameters.get(0).require();
    GenericStructure structure = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
    Metadata metadata = structure.metadata;
    boolean hasWeblink = !metadata.weblink.trim().isEmpty();
    ITextComponent weblink = hasWeblink ? new TextComponentString(RCStrings.abbreviateFormatted(metadata.weblink, 30)) : RecurrentComplex.translations.format("commands.rclookup.reply.nolink");
    if (hasWeblink) {
        weblink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, metadata.weblink));
        weblink.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(metadata.weblink)));
    }
    ITextComponent level = new TextComponentString(StructureRegistry.INSTANCE.status(id).getLevel().toString());
    level.getStyle().setColor(TextFormatting.YELLOW);
    commandSender.sendMessage(RecurrentComplex.translations.format(StructureRegistry.INSTANCE.hasActive(id) ? "commands.rclookup.reply.generates" : "commands.rclookup.reply.silent", id, RCTextStyle.users(metadata.authors), level, weblink));
    if (!metadata.comment.trim().isEmpty())
        commandSender.sendMessage(RecurrentComplex.translations.format("commands.rclookup.reply.comment", metadata.comment));
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) TextFormatting(net.minecraft.util.text.TextFormatting) ClickEvent(net.minecraft.util.text.event.ClickEvent) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) RCStrings(ivorius.reccomplex.utils.RCStrings) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) HoverEvent(net.minecraft.util.text.event.HoverEvent) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 43 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.

the class RCForgeEventHandler method onPlayerJoin.

@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
    if (RCConfig.postWorldStatus && event.player.canUseCommand(3, "op")) {
        WorldRandomData randomData = WorldRandomData.get(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld());
        if (randomData.postWorldStatus(event.player.getName())) {
            event.player.getServer().commandManager.executeCommand(event.player, RCCommands.sanity.getName() + " --silent --short");
            ITextComponent count = new TextComponentString("" + StructureRegistry.INSTANCE.activeIDs().size());
            count.getStyle().setColor(TextFormatting.AQUA);
            ITextComponent list = new TextComponentString("[List]");
            list.getStyle().setColor(TextFormatting.AQUA);
            list.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Show List")));
            list.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/%s", RCCommands.structures.list())));
            ITextComponent add = new TextComponentString("[Add]");
            add.getStyle().setColor(TextFormatting.GREEN);
            add.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Browse Repository")));
            add.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Repository.browseURL()));
            ITextComponent remove = new TextComponentString("[Remove]");
            remove.getStyle().setColor(TextFormatting.RED);
            remove.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Disabling Structures")));
            remove.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Wiki.DISABLING_STRUCTURES));
            ITextComponent help = new TextComponentString("[Help]");
            help.getStyle().setColor(TextFormatting.AQUA);
            help.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Open Wiki")));
            help.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Wiki.HOME));
            ITextComponent statusMessage = RecurrentComplex.translations.format("reccomplex.server.status", count, list, add, remove, help);
            event.player.sendMessage(statusMessage);
        }
    }
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) WorldRandomData(ivorius.reccomplex.world.gen.feature.WorldRandomData) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 44 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.

the class OperationRegistry method queueOperation.

public static boolean queueOperation(Operation operation, ICommandSender commandSender) throws CommandException {
    if (operation.checkDead(commandSender))
        return false;
    boolean instant = true;
    if (commandSender instanceof EntityPlayer) {
        EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender);
        RCEntityInfo info = RCEntityInfo.get(player, null);
        if (info != null) {
            if (info.getPreviewType() != Operation.PreviewType.NONE) {
                info.queueOperation(operation, player);
                instant = false;
                ITextComponent confirmComponent = new TextComponentString("/" + RCCommands.confirm.getName());
                confirmComponent.getStyle().setColor(TextFormatting.GREEN);
                confirmComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.confirm.getName()));
                confirmComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RecurrentComplex.translations.get("commands.rcconfirm.run")));
                ITextComponent cancelComponent = new TextComponentString("/" + RCCommands.cancel.getName());
                cancelComponent.getStyle().setColor(TextFormatting.RED);
                cancelComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.cancel.getName()));
                cancelComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RecurrentComplex.translations.get("commands.rccancel.run")));
                commandSender.sendMessage(RecurrentComplex.translations.format("commands.rc.queuedOp", confirmComponent, cancelComponent));
            }
        }
    }
    if (instant)
        operation.perform((WorldServer) commandSender.getEntityWorld());
    return true;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 45 with ITextComponent

use of net.minecraft.util.text.ITextComponent in project MinecraftForge by MinecraftForge.

the class ForgeHooks method newChatWithLinks.

public static ITextComponent newChatWithLinks(String string, boolean allowMissingHeader) {
    // Includes ipv4 and domain pattern
    // Matches an ip (xx.xxx.xx.xxx) or a domain (something.com) with or
    // without a protocol or path.
    ITextComponent ichat = null;
    Matcher matcher = URL_PATTERN.matcher(string);
    int lastEnd = 0;
    // Find all urls
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        // Append the previous left overs.
        String part = string.substring(lastEnd, start);
        if (part.length() > 0) {
            if (ichat == null)
                ichat = new TextComponentString(part);
            else
                ichat.appendText(part);
        }
        lastEnd = end;
        String url = string.substring(start, end);
        ITextComponent link = new TextComponentString(url);
        try {
            // Add schema so client doesn't crash.
            if ((new URI(url)).getScheme() == null) {
                if (!allowMissingHeader) {
                    if (ichat == null)
                        ichat = new TextComponentString(url);
                    else
                        ichat.appendText(url);
                    continue;
                }
                url = "http://" + url;
            }
        } catch (URISyntaxException e) {
            // Bad syntax bail out!
            if (ichat == null)
                ichat = new TextComponentString(url);
            else
                ichat.appendText(url);
            continue;
        }
        // Set the click event and append the link.
        ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
        link.getStyle().setClickEvent(click);
        link.getStyle().setUnderlined(true);
        link.getStyle().setColor(TextFormatting.BLUE);
        if (ichat == null)
            ichat = link;
        else
            ichat.appendSibling(link);
    }
    // Append the rest of the message.
    String end = string.substring(lastEnd);
    if (ichat == null)
        ichat = new TextComponentString(end);
    else if (end.length() > 0)
        ichat.appendText(string.substring(lastEnd));
    return ichat;
}
Also used : Matcher(java.util.regex.Matcher) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ITextComponent (net.minecraft.util.text.ITextComponent)96 TextComponentString (net.minecraft.util.text.TextComponentString)54 EntityPlayer (net.minecraft.entity.player.EntityPlayer)26 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)25 ClickEvent (net.minecraft.util.text.event.ClickEvent)16 ItemStack (net.minecraft.item.ItemStack)11 Style (net.minecraft.util.text.Style)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 HoverEvent (net.minecraft.util.text.event.HoverEvent)7 World (net.minecraft.world.World)7 ArrayList (java.util.ArrayList)6 BlockPos (net.minecraft.util.math.BlockPos)6 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)5 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 Minecraft (net.minecraft.client.Minecraft)4 Text (org.spongepowered.api.text.Text)4 MagicBook (cavern.magic.MagicBook)3 SpecialMagic (cavern.magic.SpecialMagic)3 Matcher (java.util.regex.Matcher)3