Search in sources :

Example 31 with ClickEvent

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

the class CheckForAutoDeletesCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final boolean confirmDelete) throws CommandException {
    if (sender instanceof EntityPlayer && !isPlayerOpped(sender)) {
        sender.sendMessage(new TextComponentString("Must be OP to use command"));
        return;
    } else if (sender instanceof TileEntity) {
        return;
    }
    final List<Colony> colonies = ColonyManager.getColonies();
    final List<Colony> coloniesToDelete = new ArrayList<>();
    for (int index = 0; colonies.size() - 1 >= index; index++) {
        final Colony colony = colonies.get(index);
        if (colony.canBeAutoDeleted() && Configurations.gameplay.autoDeleteColoniesInHours != 0 && colony.getLastContactInHours() >= Configurations.gameplay.autoDeleteColoniesInHours) {
            coloniesToDelete.add(colony);
        }
    }
    if (confirmDelete) {
        sender.sendMessage(new TextComponentString("Successful"));
        for (final Colony col : coloniesToDelete) {
            server.addScheduledTask(() -> ColonyManager.deleteColony(col.getID(), Configurations.gameplay.autoDestroyColonyBlocks));
        }
    } else {
        final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, COMMAND_CHECK_FOR_AUTODELETES)));
        sender.sendMessage(new TextComponentString("There are: " + coloniesToDelete.size() + " of a total of " + colonies.size() + " to delete."));
        sender.sendMessage(new TextComponentString("Click [DELETE] to confirm"));
        sender.sendMessage(deleteButton);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 32 with ClickEvent

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

the class DeleteColonyCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final Colony colony, final boolean canDestroy, final boolean confirmDelete) throws CommandException {
    if (!confirmDelete) {
        final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(DELETE_COLONY_CONFIRM_DELETE_COMMAND_SUGGESTED, colony.getID(), canDestroy ? "true" : "false"))));
        sender.sendMessage(new TextComponentString("Click [DELETE] to confirm the deletion of colony: " + colony.getID()));
        sender.sendMessage(deleteButton);
        return;
    }
    final Entity senderEntity = sender.getCommandSenderEntity();
    if (senderEntity instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, DELETECOLONY, colony.getID())) {
            senderEntity.sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    final boolean shouldDestroy = canDestroy;
    // TODO: pass in sender and notify when the delete task finishes.
    server.addScheduledTask(() -> ColonyManager.deleteColony(colony.getID(), shouldDestroy));
    senderEntity.sendMessage(new TextComponentString(DELETE_COLONY_TASK_SCHEDULED));
}
Also used : Entity(net.minecraft.entity.Entity) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 33 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project ChatTweaks by blay09.

the class GuiChatExt method handleComponentClick.

@Override
public boolean handleComponentClick(ITextComponent component) {
    if (component != null) {
        if (MinecraftForge.EVENT_BUS.post(new ChatComponentClickEvent(component))) {
            return true;
        }
        ClickEvent clickEvent = component.getStyle().getClickEvent();
        if (clickEvent != null) {
            if (clickEvent.getAction() == ClickEvent.Action.OPEN_URL) {
                String url = clickEvent.getValue();
                String directURL = null;
                for (Function<String, String> function : ChatTweaks.getImageURLTransformers()) {
                    directURL = function.apply(url);
                    if (directURL != null) {
                        break;
                    }
                }
                if (directURL != null) {
                    try {
                        Minecraft.getMinecraft().displayGuiScreen(new GuiImagePreview(Minecraft.getMinecraft().currentScreen, new URL(url), new URL(directURL)));
                        return true;
                    } catch (MalformedURLException e) {
                        ChatTweaks.logger.error("Could not open image preview: ", e);
                    }
                }
            }
        }
    }
    return super.handleComponentClick(component);
}
Also used : MalformedURLException(java.net.MalformedURLException) ChatComponentClickEvent(net.blay09.mods.chattweaks.event.ChatComponentClickEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ChatComponentClickEvent(net.blay09.mods.chattweaks.event.ChatComponentClickEvent) URL(java.net.URL)

Example 34 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project Bookshelf by Darkhax-Minecraft.

the class CommandHand method hand.

private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
    final OutputType type = context.getArgument("type", OutputType.class);
    final ServerPlayerEntity player = context.getSource().getPlayerOrException();
    final String outputText = type.converter.apply(player.getMainHandItem());
    final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
        return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
    }));
    context.getSource().sendSuccess(component, false);
    return 0;
}
Also used : JsonObject(com.google.gson.JsonObject) VanillaIngredientSerializer(net.minecraftforge.common.crafting.VanillaIngredientSerializer) Serializers(net.darkhax.bookshelf.serialization.Serializers) ClickEvent(net.minecraft.util.text.event.ClickEvent) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) StringTextComponent(net.minecraft.util.text.StringTextComponent) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) CommandContext(com.mojang.brigadier.context.CommandContext) TextFormatting(net.minecraft.util.text.TextFormatting) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) TextComponentUtils(net.minecraft.util.text.TextComponentUtils) HoverEvent(net.minecraft.util.text.event.HoverEvent) StringJoiner(java.util.StringJoiner) ResourceLocation(net.minecraft.util.ResourceLocation) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Commands(net.minecraft.command.Commands) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 35 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)41 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)10 Nonnull (javax.annotation.Nonnull)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 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 Matcher (java.util.regex.Matcher)2 CommandException (net.minecraft.command.CommandException)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 JsonElement (com.google.gson.JsonElement)1