Search in sources :

Example 51 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project Hyperium by HyperiumClient.

the class LevelheadChatRenderer method chat.

@InvokeEvent
public void chat(ServerChatEvent event) {
    if (!levelhead.getDisplayManager().getMasterConfig().isEnabled())
        return;
    LevelheadDisplay chat = Levelhead.getInstance().getDisplayManager().getChat();
    if (chat == null || !levelhead.getLevelheadPurchaseStates().isChat() || !chat.getConfig().isEnabled())
        return;
    List<IChatComponent> siblings = event.getChat().getSiblings();
    if (siblings.size() == 0)
        return;
    IChatComponent chatComponent = siblings.get(0);
    if (chatComponent instanceof ChatComponentText) {
        ChatStyle style = chatComponent.getChatStyle();
        ClickEvent clickEvent = style.getChatClickEvent();
        if (clickEvent != null && clickEvent.getAction() == ClickEvent.Action.RUN_COMMAND) {
            String value = clickEvent.getValue();
            HoverEvent hoverEvent = style.getChatHoverEvent();
            if (hoverEvent != null && hoverEvent.getAction() == HoverEvent.Action.SHOW_TEXT) {
                String[] split = value.split(" ");
                if (split.length == 2) {
                    String uuid = split[1];
                    UUID key = UUID.fromString(uuid);
                    String tag = chat.getTrueValueCache().get(key);
                    if (tag != null) {
                        event.setChat(modifyChat(event.getChat(), tag, chat.getConfig()));
                    } else if (!(chat.getCache().get(key) instanceof NullLevelheadTag)) {
                        levelhead.fetch(key, chat, false);
                    }
                }
            }
        }
    }
}
Also used : HoverEvent(net.minecraft.event.HoverEvent) ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent) UUID(java.util.UUID) ChatComponentText(net.minecraft.util.ChatComponentText) LevelheadDisplay(cc.hyperium.mods.levelhead.display.LevelheadDisplay) InvokeEvent(cc.hyperium.event.InvokeEvent)

Example 52 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project Hyperium by HyperiumClient.

the class ToggleChatEvents method onChatReceive.

// We use the high priority to grab things first
@InvokeEvent(priority = Priority.HIGH)
public void onChatReceive(ServerChatEvent event) {
    // Strip the message of any colors for improved detectability
    String unformattedText = ChatColor.stripColor(event.getChat().getUnformattedText());
    // The formatted message for a few of the custom toggles
    String formattedText = event.getChat().getFormattedText();
    try {
        // Loop through all the toggles
        for (ToggleBase type : mod.getToggleHandler().getToggles().values()) {
            // The chat its looking for shouldn't be toggled, move to next one!
            if (type.isEnabled())
                continue;
            // the whole toggle system crashing down in flames.
            try {
                // The text we want to input into the shouldToggle method.
                String input = type.useFormattedMessage() ? formattedText : unformattedText;
                // don't send the message to the player & stop looping
                if (type.shouldToggle(input)) {
                    if (type instanceof TypeMessageSeparator) {
                        // Attempt to keep the formatting
                        ChatStyle style = event.getChat().getChatStyle();
                        String edited = ((TypeMessageSeparator) type).editMessage(formattedText);
                        // Don't bother sending the message if its empty
                        if (!input.equals(edited) && edited.isEmpty()) {
                            event.setCancelled(true);
                        } else {
                            event.setChat(new ChatComponentText(edited).setChatStyle(style));
                        }
                    } else {
                        event.setCancelled(true);
                    }
                    break;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) TypeMessageSeparator(cc.hyperium.mods.togglechat.toggles.defaults.TypeMessageSeparator) ChatComponentText(net.minecraft.util.ChatComponentText) ToggleBase(cc.hyperium.mods.togglechat.toggles.ToggleBase) InvokeEvent(cc.hyperium.event.InvokeEvent)

Example 53 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project Hyperium by HyperiumClient.

the class MyPosition method sendMyPosCommand.

private void sendMyPosCommand() {
    Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentText(ChatColor.RED.toString() + ChatColor.BOLD + "------| Auto MyPosition |------"));
    Minecraft.getMinecraft().thePlayer.sendChatMessage("/myposition");
}
Also used : ChatComponentText(net.minecraft.util.ChatComponentText)

Example 54 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project SimplyJetpacks by Tonius.

the class PackBase method toggleState.

protected void toggleState(boolean on, ItemStack stack, String type, String tag, EntityPlayer player, boolean showInChat) {
    stack.stackTagCompound.setBoolean(tag, !on);
    if (player != null && showInChat) {
        String color = on ? StringHelper.LIGHT_RED : StringHelper.BRIGHT_GREEN;
        type = type != null && !type.equals("") ? "chat." + this.name + "." + type + ".on" : "chat." + this.name + ".on";
        String msg = SJStringHelper.localize(type) + " " + color + SJStringHelper.localize("chat." + (on ? "disabled" : "enabled"));
        player.addChatMessage(new ChatComponentText(msg));
    }
}
Also used : ChatComponentText(net.minecraft.util.ChatComponentText)

Example 55 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project Charset by CharsetMC.

the class ItemDramaInABottle method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    if (!worldIn.isRemote) {
        if (itemStackIn.hasTagCompound() && itemStackIn.getTagCompound().hasKey("drama")) {
            playerIn.addChatComponentMessage(new ChatComponentText(itemStackIn.getTagCompound().getString("drama")));
        } else {
            itemStackIn.setTagCompound(new NBTTagCompound());
            itemStackIn.getTagCompound().setString("drama", DramaGenerator.INSTANCE.createDrama());
            playerIn.addChatComponentMessage(new ChatComponentText(itemStackIn.getTagCompound().getString("drama")));
        }
    }
    return itemStackIn;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ChatComponentText (net.minecraft.util.ChatComponentText)383 IChatComponent (net.minecraft.util.IChatComponent)55 EntityPlayer (net.minecraft.entity.player.EntityPlayer)43 ChatStyle (net.minecraft.util.ChatStyle)39 ItemStack (net.minecraft.item.ItemStack)36 ClickEvent (net.minecraft.event.ClickEvent)31 World (net.minecraft.world.World)28 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)26 TileEntity (net.minecraft.tileentity.TileEntity)25 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)25 HoverEvent (net.minecraft.event.HoverEvent)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 ArrayList (java.util.ArrayList)17 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)16 Block (net.minecraft.block.Block)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)14 Entity (net.minecraft.entity.Entity)14 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)13 File (java.io.File)12