Search in sources :

Example 1 with BetterChat

use of org.bleachhack.module.mods.BetterChat in project BleachHack by BleachDrinker420.

the class CmdBetterChat method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    if (args.length < 2) {
        throw new CmdSyntaxException();
    }
    BetterChat chat = ModuleManager.getModule(BetterChat.class);
    if (args[0].equalsIgnoreCase("filter")) {
        if (args[1].equalsIgnoreCase("list")) {
            MutableText text = new LiteralText("Filter Entries:");
            int i = 1;
            for (Pattern pat : chat.filterPatterns) {
                text = text.append(new LiteralText("\n\u00a76" + i + " > \u00a7f" + pat.pattern()).styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to remove this filter."))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, getPrefix() + "betterchat filter remove " + pat.pattern()))));
                i++;
            }
            BleachLogger.info(text);
        } else if (args[1].equalsIgnoreCase("add")) {
            String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
            chat.filterPatterns.add(Pattern.compile(arg));
            JsonArray jsonFilter = new JsonArray();
            chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
            BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
            BleachLogger.info("Added \"" + arg + "\" to the filter patterns.");
        } else if (args[1].equalsIgnoreCase("remove")) {
            String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
            if (chat.filterPatterns.removeIf(p -> p.toString().equals(arg))) {
                JsonArray jsonFilter = new JsonArray();
                chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
                BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
                BleachLogger.info("Removed \"" + arg + "\" from the filter patterns.");
            } else {
                BleachLogger.info("Could not find \"" + arg + "\" in the pattern list.");
            }
        } else {
            throw new CmdSyntaxException();
        }
    } else if (args[0].equalsIgnoreCase("prefix")) {
        if (args[1].equalsIgnoreCase("current")) {
            BleachLogger.info("Current prefix: \"" + chat.prefix + "\"");
        } else if (args[1].equalsIgnoreCase("reset")) {
            chat.prefix = "";
            BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
            BleachLogger.info("Reset the customchat prefix!");
        } else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
            chat.prefix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
            BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
            BleachLogger.info("Set prefix to: \"" + chat.prefix + "\"");
        } else {
            throw new CmdSyntaxException();
        }
    } else if (args[0].equalsIgnoreCase("suffix")) {
        if (args[1].equalsIgnoreCase("current")) {
            BleachLogger.info("Current suffix: \"" + chat.suffix + "\"");
        } else if (args[1].equalsIgnoreCase("reset")) {
            chat.suffix = " \u25ba \u0432\u029f\u0454\u03b1c\u043d\u043d\u03b1c\u043a";
            BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
            BleachLogger.info("Reset the customchat suffix!");
        } else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
            chat.suffix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
            BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
            BleachLogger.info("Set suffix to: \"" + chat.suffix + "\"");
        } else {
            throw new CmdSyntaxException();
        }
    } else {
        throw new CmdSyntaxException();
    }
}
Also used : MutableText(net.minecraft.text.MutableText) JsonArray(com.google.gson.JsonArray) CommandCategory(org.bleachhack.command.CommandCategory) LiteralText(net.minecraft.text.LiteralText) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) Command(org.bleachhack.command.Command) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) HoverEvent(net.minecraft.text.HoverEvent) ModuleManager(org.bleachhack.module.ModuleManager) BetterChat(org.bleachhack.module.mods.BetterChat) JsonArray(com.google.gson.JsonArray) ClickEvent(net.minecraft.text.ClickEvent) BleachLogger(org.bleachhack.util.BleachLogger) MutableText(net.minecraft.text.MutableText) Pattern(java.util.regex.Pattern) JsonPrimitive(com.google.gson.JsonPrimitive) Pattern(java.util.regex.Pattern) HoverEvent(net.minecraft.text.HoverEvent) BetterChat(org.bleachhack.module.mods.BetterChat) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) JsonPrimitive(com.google.gson.JsonPrimitive) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Pattern (java.util.regex.Pattern)1 ClickEvent (net.minecraft.text.ClickEvent)1 HoverEvent (net.minecraft.text.HoverEvent)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 Command (org.bleachhack.command.Command)1 CommandCategory (org.bleachhack.command.CommandCategory)1 CmdSyntaxException (org.bleachhack.command.exception.CmdSyntaxException)1 ModuleManager (org.bleachhack.module.ModuleManager)1 BetterChat (org.bleachhack.module.mods.BetterChat)1 BleachLogger (org.bleachhack.util.BleachLogger)1 BleachFileHelper (org.bleachhack.util.io.BleachFileHelper)1