Search in sources :

Example 11 with ClickEvent

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

the class OperationRegistry method queueOperation.

public static void queueOperation(Operation operation, ICommandSender commandSender) throws PlayerNotFoundException {
    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, ServerTranslations.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, ServerTranslations.get("commands.rccancel.run")));
                commandSender.sendMessage(ServerTranslations.format("commands.rc.queuedOp", confirmComponent, cancelComponent));
            }
        }
    }
    if (instant)
        operation.perform((WorldServer) commandSender.getEntityWorld());
}
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 12 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent 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)

Example 13 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.

the class ListColoniesCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int page = getIthArgument(args, 0, 1);
    final int abandonedSince = getIthArgument(args, 1, 0);
    final List<Colony> colonies;
    if (abandonedSince > 0) {
        colonies = ColonyManager.getColoniesAbandonedSince(abandonedSince);
    } else {
        colonies = ColonyManager.getColonies();
    }
    final int colonyCount = colonies.size();
    // check to see if we have to add one page to show the half page
    final int halfPage = (colonyCount % COLONIES_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((colonyCount) / COLONIES_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = COLONIES_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(COLONIES_ON_PAGE * page, colonyCount);
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (colonyCount / COLONIES_ON_PAGE) + halfPage);
    final List<Colony> coloniesPage;
    if (pageStartIndex < 0 || pageStartIndex >= colonyCount) {
        coloniesPage = new ArrayList<>();
    } else {
        coloniesPage = colonies.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(PAGE_TOP_LEFT + page + PAGE_TOP_MIDDLE + pageCount + PAGE_TOP_RIGHT);
    sender.sendMessage(headerLine);
    for (final Colony colony : coloniesPage) {
        sender.sendMessage(new TextComponentString(String.format(ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))));
        final BlockPos center = colony.getCenter();
        final ITextComponent teleport = new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, center.getX(), center.getY(), center.getZ())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + colony.getID())));
        sender.sendMessage(teleport);
    }
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + prevPage)));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + nextPage)));
    final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
    final ITextComponent endLine = new TextComponentString(PAGE_LINE);
    sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 14 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.

the class ListCitizensCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int colonyId = getIthArgument(args, 0, getColonyId(sender));
    if (sender instanceof EntityPlayer) {
        if (colonyId == -1) {
            IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
            if (colony != null) {
                colonyId = colony.getID();
            }
        }
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, LISTCITIZENS, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
            return;
        }
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    final List<CitizenData> citizens = new ArrayList<>(colony.getCitizens().values());
    final int citizenCount = citizens.size();
    // check to see if we have to add one page to show the half page
    int page = getIthArgument(args, 1, 1);
    final int halfPage = (citizenCount % CITIZENS_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((citizenCount) / CITIZENS_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = CITIZENS_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(CITIZENS_ON_PAGE * page, citizenCount);
    final List<CitizenData> citizensPage;
    if (pageStartIndex < 0 || pageStartIndex >= citizenCount) {
        citizensPage = new ArrayList<>();
    } else {
        citizensPage = citizens.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(String.format(PAGE_TOP, page, pageCount));
    sender.sendMessage(headerLine);
    for (final CitizenData citizen : citizensPage) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizen.getId(), citizen.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO, citizen.getColony().getID(), citizen.getId())))));
        if (citizen.getCitizenEntity() != null) {
            final BlockPos position = citizen.getCitizenEntity().getPosition();
            sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
        }
    }
    drawPageSwitcher(sender, page, citizenCount, halfPage, colonyId);
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) IColony(com.minecolonies.coremod.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Example 15 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project Pearcel-Mod by MiningMark48.

the class EventOnJoin method onJoin.

@SubscribeEvent
public void onJoin(TickEvent.PlayerTickEvent e) {
    if (!PearcelMod.haveWarnedVersionOutOfDate && e.player.world.isRemote) {
        if (!PearcelMod.versionChecker.isLatestVersion()) {
            ClickEvent versionCheckClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://minecraft.curseforge.com/projects/pearcel-mod");
            e.player.sendMessage(new TextComponentString(TextFormatting.YELLOW + Translate.toLocal("chat.versionChecker.outOfDate") + TextFormatting.AQUA + " v" + PearcelMod.versionChecker.getLatestVersion()).setStyle(new Style().setClickEvent(versionCheckClickEvent)));
            PearcelMod.haveWarnedVersionOutOfDate = true;
        }
    }
    if (!JoinMessageWikiSent && e.player.world.isRemote) {
        //TODO: Make config setting for message
        ClickEvent versionCheckClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, "http://miningmark48.xyz/pearcelmod");
        e.player.sendMessage(new TextComponentString(TextFormatting.GREEN + Translate.toLocal("chat.joinMessage.wiki")).setStyle(new Style().setClickEvent(versionCheckClickEvent)));
        JoinMessageWikiSent = true;
    }
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ClickEvent (net.minecraft.util.text.event.ClickEvent)22 HoverEvent (net.minecraft.util.text.event.HoverEvent)16 TextComponentString (net.minecraft.util.text.TextComponentString)9 ITextComponent (net.minecraft.util.text.ITextComponent)8 Nonnull (javax.annotation.Nonnull)7 Style (net.minecraft.util.text.Style)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Colony (com.minecolonies.coremod.colony.Colony)2 BlockPos (net.minecraft.util.math.BlockPos)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 IColony (com.minecolonies.coremod.colony.IColony)1 RCEntityInfo (ivorius.reccomplex.capability.RCEntityInfo)1 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)1 WorldRandomData (ivorius.reccomplex.world.gen.feature.WorldRandomData)1 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)1 Metadata (ivorius.reccomplex.world.gen.feature.structure.generic.Metadata)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1