diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-11-24 21:58:26 -0500 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-11-24 21:58:26 -0500 |
commit | c466240003b130b43c17da9e585b80380154e4c4 (patch) | |
tree | ba6a03498dac85027d853e535aea0c71542d1f2f /src/main/java/me/Danker/features/Alerts.java | |
parent | b733d88cb79942d4a260293d1bb1f2d27fcc61e2 (diff) | |
download | SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.tar.gz SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.tar.bz2 SkyblockMod-c466240003b130b43c17da9e585b80380154e4c4.zip |
Add custom alerts based on chat
Also move some other stuff around
Diffstat (limited to 'src/main/java/me/Danker/features/Alerts.java')
-rw-r--r-- | src/main/java/me/Danker/features/Alerts.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/main/java/me/Danker/features/Alerts.java b/src/main/java/me/Danker/features/Alerts.java new file mode 100644 index 0000000..2a00fef --- /dev/null +++ b/src/main/java/me/Danker/features/Alerts.java @@ -0,0 +1,81 @@ +package me.Danker.features; + +import com.google.gson.GsonBuilder; +import me.Danker.commands.ToggleCommand; +import me.Danker.utils.Utils; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StringUtils; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Alerts { + + public static List<Alert> alerts = new ArrayList<>(); + public static String configFile; + + @SubscribeEvent + public void onChat(ClientChatReceivedEvent event) { + if (!ToggleCommand.alerts || !Utils.inSkyblock || event.type == 2) return; + + String message = StringUtils.stripControlCodes(event.message.getUnformattedText()); + + for (Alert alert : alerts) { + if (!alert.toggled) continue; + + boolean trigger; + switch (alert.mode) { + case "Starts With": + trigger = message.startsWith(alert.message); + break; + case "Contains": + trigger = message.contains(alert.message); + break; + case "Ends With": + trigger = message.endsWith(alert.message); + break; + default: + continue; + } + + if (trigger) { + Utils.createTitle(EnumChatFormatting.RED + alert.alert.replace("&", "ยง"), 2); + return; + } + } + } + + public static void saveToFile() { + try (FileWriter writer = new FileWriter(configFile)) { + new GsonBuilder().create().toJson(alerts, writer); + writer.flush(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public static class Alert { + + public String mode; + public String message; + public String alert; + public boolean toggled; + + public Alert(String mode, String message, String alert, boolean toggled) { + this.mode = mode; + this.message = message; + this.alert = alert; + this.toggled = toggled; + } + + public void toggle() { + toggled = !toggled; + } + + } + +} |