net.minecraft.util.ChatStyle Java Examples

The following examples show how to use net.minecraft.util.ChatStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkHandler.java    From Hyperium with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Override
public void handleChat(String s) {
    if (s.toLowerCase().contains("reconnecting hyperium connection")) return;
    Hyperium.LOGGER.debug("Chat: {}", s);
    s = s.replace("&", C.COLOR_CODE_SYMBOL);
    IChatComponent chatComponent = new ChatComponentText("");

    Arrays.stream(s.split(" ")).forEach(s1 -> {
        ChatComponentText iChatComponents = new ChatComponentText(s1 + " ");
        if (s1.contains(".") && !s1.startsWith(".") && !s1.endsWith(".")) {
            ChatStyle chatStyle = new ChatStyle();
            chatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, s1.startsWith("http") ? s1 : "http://" + s1));
            iChatComponents.setChatStyle(chatStyle);
        }
        chatComponent.appendSibling(iChatComponents);
    });

    GeneralChatHandler.instance().sendMessage(chatComponent);
}
 
Example #2
Source File: MixinGuiEditSign.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@Inject(method = "actionPerformed", at = @At("HEAD"))
private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
    switch(button.id) {
        case 0:
            if(!signCommand1.getText().isEmpty())
                tileSign.signText[0].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand1.getText())));

            if(!signCommand2.getText().isEmpty())
                tileSign.signText[1].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand2.getText())));

            if(!signCommand3.getText().isEmpty())
                tileSign.signText[2].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand3.getText())));

            if(!signCommand4.getText().isEmpty())
                tileSign.signText[3].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand4.getText())));
            break;
        case 1:
            enabled = !enabled;
            toggleButton.displayString = enabled ? "Disable Formatting codes" : "Enable Formatting codes";
            break;
    }
}
 
Example #3
Source File: MixinGuiEditSign.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@Inject(method = "actionPerformed", at = @At("HEAD"))
private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
    switch(button.id) {
        case 0:
            if(!signCommand1.getText().isEmpty())
                tileSign.signText[0].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand1.getText())));

            if(!signCommand2.getText().isEmpty())
                tileSign.signText[1].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand2.getText())));

            if(!signCommand3.getText().isEmpty())
                tileSign.signText[2].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand3.getText())));

            if(!signCommand4.getText().isEmpty())
                tileSign.signText[3].setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, signCommand4.getText())));
            break;
        case 1:
            enabled = !enabled;
            toggleButton.displayString = enabled ? "Disable Formatting codes" : "Enable Formatting codes";
            break;
    }
}
 
Example #4
Source File: HyperiumChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getFormattingCode(ChatStyle parentStyle) {
    if (cachedState != null) return cachedState;
    if (parent.isEmpty()) {
        return parentStyle != null ? parentStyle.getFormattingCode() : "";
    } else {
        StringBuilder stringbuilder = new StringBuilder();

        if (parent.getColor() != null) stringbuilder.append(parent.getColor());
        if (parent.getBold()) stringbuilder.append(EnumChatFormatting.BOLD);
        if (parent.getItalic()) stringbuilder.append(EnumChatFormatting.ITALIC);
        if (parent.getUnderlined()) stringbuilder.append(EnumChatFormatting.UNDERLINE);
        if (parent.getObfuscated()) stringbuilder.append(EnumChatFormatting.OBFUSCATED);
        if (parent.getStrikethrough()) stringbuilder.append(EnumChatFormatting.STRIKETHROUGH);

        String s = stringbuilder.toString();
        cachedState = s;
        return s;
    }
}
 
Example #5
Source File: MixinGuiScreen.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
    if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
        return;

    final ChatStyle chatStyle = component.getChatStyle();

    final ClickEvent clickEvent = chatStyle.getChatClickEvent();
    final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();

    drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
 
Example #6
Source File: MixinGuiScreen.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
    if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
        return;

    final ChatStyle chatStyle = component.getChatStyle();

    final ClickEvent clickEvent = chatStyle.getChatClickEvent();
    final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();

    drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
 
Example #7
Source File: ParamJam.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public static void jamOpenCommand(String playername, String[] args, WCommandSender listener, boolean jam) {
    RedstoneEtherServer ether = RedstoneEther.server();

    if (args.length == 0) {
        listener.chatT("wrcbe_core.param.invalidno");
        return;
    }

    if ((args.length == 1 && ServerUtils.getPlayer(playername) == null)) {
        listener.chatT("wrcbe_core.param.jam.noplayer");
        return;
    }

    String range = args[args.length - 1];
    String jamPlayer = args.length == 1 ? playername : args[0];

    int startfreq;
    int endfreq;

    if (range.equals("all")) {
        startfreq = 1;
        endfreq = RedstoneEther.numfreqs;
    } else if (range.equals("default")) {
        startfreq = ether.getLastSharedFrequency() + 1;
        endfreq = RedstoneEther.numfreqs;
    } else {
        int[] freqrange = RedstoneEther.parseFrequencyRange(range);
        startfreq = freqrange[0];
        endfreq = freqrange[1];
    }

    if (startfreq < 1 || endfreq > RedstoneEther.numfreqs || endfreq < startfreq) {
        listener.chatT("wrcbe_core.param.invalidfreqrange");
        return;
    }

    ether.setFrequencyRangeCommand(jamPlayer, startfreq, endfreq, jam);

    int publicend = ether.getLastPublicFrequency();
    EntityPlayer player = ServerUtils.getPlayer(jamPlayer);
    String paramName = jam ? "jam" : "open";
    ChatStyle playerStyle = new ChatStyle().setColor(EnumChatFormatting.YELLOW);
    if (startfreq == endfreq) {
        if (startfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed", playername, jamPlayer, startfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed", startfreq).setChatStyle(playerStyle));
    } else {
        if (startfreq <= publicend && endfreq <= publicend) {
            listener.chatT("wrcbe_core.param.jam.errpublic");
            return;
        }
        if (startfreq <= publicend)
            startfreq = publicend + 1;

        listener.chatOpsT("wrcbe_core.param."+paramName+".opjammed2", playername, jamPlayer, startfreq + "-" + endfreq);
        if (player != null)
            player.addChatComponentMessage(new ChatComponentTranslation("wrcbe_core.param."+paramName+".jammed2", startfreq + "-" + endfreq).setChatStyle(playerStyle));
    }
}
 
Example #8
Source File: Rank.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@Override
public IChatComponent toChatMessage() {
    return LocalManager.get("mytown.format.rank", name).setChatStyle(new ChatStyle().setColor(type.color));
}
 
Example #9
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setParentStyle", at = @At("HEAD"))
private void setChatHoverEvent(ChatStyle boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #10
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setInsertion", at = @At("HEAD"))
private void setChatHoverEvent(String boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #11
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setChatHoverEvent", at = @At("HEAD"))
private void setChatHoverEvent(HoverEvent boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #12
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setChatClickEvent", at = @At("HEAD"))
private void setChatClickEvent(ClickEvent boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #13
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setObfuscated", at = @At("HEAD"))
private void setObfuscated(Boolean boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #14
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setUnderlined", at = @At("HEAD"))
private void setUnderlined(Boolean boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #15
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setStrikethrough", at = @At("HEAD"))
private void setStrikethrough(Boolean boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #16
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setItalic", at = @At("HEAD"))
private void setItalic(Boolean boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #17
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setBold", at = @At("HEAD"))
private void setBold(Boolean boldIn, CallbackInfoReturnable<ChatStyle> callbackInfoReturnable) {
    hyperiumChatStyle.resetCache();
}
 
Example #18
Source File: MixinChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author Sk1er
 */
@Inject(method = "setColor", at = @At("HEAD"))
private void setColor(EnumChatFormatting color, CallbackInfoReturnable<ChatStyle> info) {
    hyperiumChatStyle.resetCache();
}
 
Example #19
Source File: MixinChatComponentStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Inject(method = "setChatStyle", at = @At("HEAD"), cancellable = true)
private void setChatStyle(ChatStyle style, CallbackInfoReturnable<IChatComponent> ci) {
    hyperiumChatComponentStyle.invalidateCache();
}
 
Example #20
Source File: MixinChatComponentStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Shadow
public abstract ChatStyle getChatStyle();
 
Example #21
Source File: ToggleChatEvents.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@InvokeEvent(priority = Priority.HIGH) // We use the high priority to grab things first
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;

            // We don't want an issue with one toggle bringing
            // 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;

                // If the toggle should toggle the specified message and
                // the toggle is not enabled (this message is turned off)
                // 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();
    }
}
 
Example #22
Source File: HyperiumChatStyle.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public HyperiumChatStyle(ChatStyle parent) {
    this.parent = parent;
}
 
Example #23
Source File: WrapperChatStyle.java    From ClientBase with MIT License 4 votes vote down vote up
public ChatStyle unwrap() {
    return this.real;
}
 
Example #24
Source File: WrapperChatStyle.java    From ClientBase with MIT License 4 votes vote down vote up
public WrapperChatStyle(ChatStyle var1) {
    this.real = var1;
}