Search in sources :

Example 1 with ClickEvent

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

the class RCTextStyle method visitFile.

@Nonnull
public static ITextComponent visitFile(String id) {
    ITextComponent submit = ServerTranslations.get("reccomplex.save.submit");
    submit.getStyle().setColor(TextFormatting.AQUA);
    submit.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.get("reccomplex.save.submit.hover")));
    submit.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Repository.submitURL(id)));
    return submit;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Nonnull(javax.annotation.Nonnull)

Example 2 with ClickEvent

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

the class GuiHider method hideGUI.

public static boolean hideGUI() {
    if (!canHide())
        return false;
    Minecraft mc = Minecraft.getMinecraft();
    hiddenGUI = mc.currentScreen;
    if (hiddenGUI == null)
        return false;
    mc.displayGuiScreen(null);
    ITextComponent reopen = new TextComponentString("/" + RCCommands.reopen.getName());
    reopen.getStyle().setColor(TextFormatting.GREEN);
    reopen.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.reopen.getName()));
    reopen.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.get("commands.rcreopen.run")));
    mc.player.sendMessage(ServerTranslations.format("commands.rc.didhide", reopen));
    return true;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Minecraft(net.minecraft.client.Minecraft) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project SpongeCommon by SpongePowered.

the class SpongeClickAction method getHandle.

public static ClickEvent getHandle(ClickAction<?> action) {
    final String text;
    if (action instanceof ClickAction.ExecuteCallback) {
        UUID callbackId = SpongeCallbackHolder.getInstance().getOrCreateIdForCallback(((ClickAction.ExecuteCallback) action).getResult());
        text = SpongeCallbackHolder.CALLBACK_COMMAND_QUALIFIED + " " + callbackId;
    } else {
        text = action.getResult().toString();
    }
    ClickEvent event = new ClickEvent(getType(action), text);
    ((IMixinClickEvent) event).setHandle(action);
    return event;
}
Also used : ClickAction(org.spongepowered.api.text.action.ClickAction) IMixinClickEvent(org.spongepowered.common.interfaces.text.IMixinClickEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) IMixinClickEvent(org.spongepowered.common.interfaces.text.IMixinClickEvent) UUID(java.util.UUID)

Example 4 with ClickEvent

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

the class ListColoniesCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @Nullable final Integer pageProvided, @Nullable final Integer abandonedSinceTimeInHoursProvided) throws CommandException {
    int page;
    if (null != pageProvided) {
        page = pageProvided.intValue();
    } else {
        page = 1;
    }
    int abandonedSinceTimeInHours;
    if (null != abandonedSinceTimeInHoursProvided) {
        abandonedSinceTimeInHours = abandonedSinceTimeInHoursProvided.intValue();
    } else {
        abandonedSinceTimeInHours = 0;
    }
    final List<Colony> colonies;
    if (abandonedSinceTimeInHours > 0) {
        colonies = ColonyManager.getColoniesAbandonedSince(abandonedSinceTimeInHours);
    } 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()));
        if (isPlayerOpped(sender)) {
            teleport.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 5 with ClickEvent

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

the class ListCitizensCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final Colony colony, final Integer pageProvided) throws CommandException {
    int page;
    if (null != pageProvided) {
        page = pageProvided.intValue();
    } else {
        page = 1;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if ((null != colony) && !canPlayerUseCommand(player, LISTCITIZENS, colony.getID())) {
            player.sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
            return;
        }
    }
    final List<CitizenData> citizens = colony.getCitizenManager().getCitizens();
    final int citizenCount = citizens.size();
    // check to see if we have to add one page to show the half page
    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())))));
        citizen.getCitizenEntity().ifPresent(entityCitizen -> {
            final BlockPos position = entityCitizen.getPosition();
            sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
        });
    }
    drawPageSwitcher(sender, page, citizenCount, halfPage, (null != colony ? colony.getID() : -1));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Style(net.minecraft.util.text.Style) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ClickEvent (net.minecraft.util.text.event.ClickEvent)37 HoverEvent (net.minecraft.util.text.event.HoverEvent)21 TextComponentString (net.minecraft.util.text.TextComponentString)19 ITextComponent (net.minecraft.util.text.ITextComponent)16 Style (net.minecraft.util.text.Style)9 Nonnull (javax.annotation.Nonnull)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 BlockPos (net.minecraft.util.math.BlockPos)4 JsonObject (com.google.gson.JsonObject)3 Colony (com.minecolonies.coremod.colony.Colony)3 Minecraft (net.minecraft.client.Minecraft)3 JsonArray (com.google.gson.JsonArray)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 JsonElement (com.google.gson.JsonElement)1