Search in sources :

Example 1 with ToggleBase

use of cc.hyperium.mods.togglechat.toggles.ToggleBase 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 2 with ToggleBase

use of cc.hyperium.mods.togglechat.toggles.ToggleBase in project Hyperium by HyperiumClient.

the class ToggleChatMainGui method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    switch(button.id) {
        case 1:
            mc.displayGuiScreen(new ToggleChatMainGui(main, pageNumber - 1));
            return;
        case 2:
            mc.displayGuiScreen(new ToggleChatMainGui(main, pageNumber + 1));
            return;
    }
    // Make sure the id is 0 to prevent other buttons being pressed
    if (button.id == 0) {
        for (ToggleBase base : main.getToggleHandler().getToggles().values()) {
            if (data.containsKey(button) && base.equals(data.get(button))) {
                base.toggle();
                button.displayString = (String.format(base.getDisplayName(), base.getStatus(base.isEnabled())));
                changed = true;
                break;
            }
        }
    }
}
Also used : ToggleBase(cc.hyperium.mods.togglechat.toggles.ToggleBase)

Aggregations

ToggleBase (cc.hyperium.mods.togglechat.toggles.ToggleBase)2 InvokeEvent (cc.hyperium.event.InvokeEvent)1 TypeMessageSeparator (cc.hyperium.mods.togglechat.toggles.defaults.TypeMessageSeparator)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 ChatStyle (net.minecraft.util.ChatStyle)1