From ae8e3679982671ec10054b41c1582fe5b085553b Mon Sep 17 00:00:00 2001 From: Bella Date: Thu, 12 Mar 2020 16:36:58 -0400 Subject: [PATCH] cleanup customchat code --- .../kami/module/modules/chat/CustomChat.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/chat/CustomChat.java b/src/main/java/me/zeroeightsix/kami/module/modules/chat/CustomChat.java index d14ce128..9c03afd4 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/chat/CustomChat.java +++ b/src/main/java/me/zeroeightsix/kami/module/modules/chat/CustomChat.java @@ -13,29 +13,24 @@ import static me.zeroeightsix.kami.KamiMod.*; /** * Created by 086 on 8/04/2018. - * Updated by S-B99 on 18/02/20 + * Updated by S-B99 on 12/03/20 */ @Module.Info(name = "CustomChat", category = Module.Category.CHAT, description = "Adds a watermark to the end of your message to let others know you're using KAMI Blue", showOnArray = Module.ShowOnArray.OFF) public class CustomChat extends Module { - public Setting startupGlobal = register(Settings.b("Enable Automatically", true)); - public Setting textMode = register(Settings.e("Message", TextMode.ONTOP)); + public Setting textMode = register(Settings.e("Message", TextMode.ON_TOP)); private Setting decoMode = register(Settings.e("Separator", DecoMode.NONE)); private Setting commands = register(Settings.b("Commands", false)); public Setting customText = register(Settings.stringBuilder("Custom Text").withValue("unchanged").withConsumer((old, value) -> {}).build()); - public enum TextMode { - NAME, ONTOP, WEBSITE, JAPANESE, CUSTOM - } - - private enum DecoMode { - SEPARATOR, CLASSIC, NONE - } + private enum DecoMode { SEPARATOR, CLASSIC, NONE } + public enum TextMode { NAME, ON_TOP, WEBSITE, JAPANESE, CUSTOM } + public static String[] cmdCheck = new String[]{"/", ",", ".", "-", ";", "?", "*", "^", "&", Command.getCommandPrefix()}; private String getText(TextMode t) { switch (t) { case NAME: return KAMI_BLUE; - case ONTOP: return KAMI_ONTOP; + case ON_TOP: return KAMI_ONTOP; case WEBSITE: return KAMI_WEBSITE; case JAPANESE: return KAMI_JAPANESE_ONTOP; case CUSTOM: return customText.getValue(); @@ -56,23 +51,20 @@ public class CustomChat extends Module { public Listener listener = new Listener<>(event -> { if (event.getPacket() instanceof CPacketChatMessage) { String s = ((CPacketChatMessage) event.getPacket()).getMessage(); - if (!commands.getValue()) { - if (s.startsWith("/")) return; - else if (s.startsWith(",")) return; - else if (s.startsWith(".")) return; - else if (s.startsWith("-")) return; - else if (s.startsWith(";")) return; - else if (s.startsWith("?")) return; - else if (s.startsWith("*")) return; - else if (s.startsWith("^")) return; - else if (s.startsWith("&")) return; - } + if (!commands.getValue() && isCommand(s)) return; s += getFull(decoMode.getValue()); if (s.length() >= 256) s = s.substring(0, 256); ((CPacketChatMessage) event.getPacket()).message = s; } }); + public boolean isCommand(String s) { + for (String value : cmdCheck) { + if (s.startsWith(value)) return true; + } + return false; + } + private static long startTime = 0; @Override public void onUpdate() {