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();
}
}
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;
}
}
}
}
Aggregations