|
| 1 | +package com.rappytv.tbw; |
| 2 | + |
| 3 | +import com.rappytv.tbw.events.ChatEvent; |
| 4 | +import com.rappytv.tbw.events.OnTickEvent; |
| 5 | +import com.rappytv.tbw.modules.DurabilityModule; |
| 6 | +import net.labymod.api.LabyModAddon; |
| 7 | +import net.labymod.settings.elements.*; |
| 8 | +import net.labymod.utils.Material; |
| 9 | +import net.minecraft.util.ResourceLocation; |
| 10 | + |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +public class ToolBreakWarning extends LabyModAddon { |
| 14 | + |
| 15 | + public static String prefix = "\u00A79\u00A7lTBW \u00A78\u00bb \u00A7r"; |
| 16 | + public static boolean enabled = true; |
| 17 | + public static boolean format = true; |
| 18 | + public static boolean debug = false; |
| 19 | + public static String warnMsg = "\u00A7cDo you really want to continue using this tool? Its durability is {durability}%!"; |
| 20 | + public static String lastHitMsg = "\u00A7cYou should stop using this tool now, this is your last hit!"; |
| 21 | + public static boolean lastHitWarn = true; |
| 22 | + public static int warnPercentageSword = 5; |
| 23 | + public static int warnPercentagePickaxe = 5; |
| 24 | + public static int warnPercentageAxe = 5; |
| 25 | + public static int warnPercentageShovel = 5; |
| 26 | + public static ToolBreakWarning instance; |
| 27 | + |
| 28 | + @Override |
| 29 | + public void onEnable() { |
| 30 | + // Sets the instance |
| 31 | + instance = this; |
| 32 | + |
| 33 | + getApi().getEventService().registerListener(new ChatEvent()); |
| 34 | + getApi().getEventService().registerListener(new OnTickEvent()); |
| 35 | + getApi().registerModule(new DurabilityModule()); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public void loadConfig() { |
| 40 | + enabled = !getConfig().has("enabled") || getConfig().get("enabled").getAsBoolean(); |
| 41 | + format = getConfig().has("format") ? getConfig().get("format").getAsBoolean() : format; |
| 42 | + debug = getConfig().has("debug") ? getConfig().get("debug").getAsBoolean() : debug; |
| 43 | + warnMsg = getConfig().has("warnmsg") ? getConfig().get("warnmsg").getAsString() : warnMsg; |
| 44 | + |
| 45 | + lastHitWarn = getConfig().has("lastHitWarn") ? getConfig().get("lastHitWarn").getAsBoolean() : lastHitWarn; |
| 46 | + warnPercentageSword = getConfig().has("sword") ? getConfig().get("sword").getAsInt() : warnPercentageSword; |
| 47 | + warnPercentagePickaxe = getConfig().has("pick") ? getConfig().get("pick").getAsInt() : warnPercentagePickaxe; |
| 48 | + warnPercentageAxe = getConfig().has("axe") ? getConfig().get("axe").getAsInt() : warnPercentageAxe; |
| 49 | + warnPercentageShovel = getConfig().has("shovel") ? getConfig().get("shovel").getAsInt() : warnPercentageShovel; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + protected void fillSettings(List<SettingsElement> list) { |
| 54 | + BooleanElement formatBool = new BooleanElement("Format Numbers", new ControlElement.IconData(new ResourceLocation("tbw/textures/format.png")), accepted -> { |
| 55 | + format = accepted; |
| 56 | + |
| 57 | + getConfig().addProperty("format", format); |
| 58 | + saveConfig(); |
| 59 | + }, format); |
| 60 | + |
| 61 | + BooleanElement warnOnLastHit = new BooleanElement("Warn on last hit", new ControlElement.IconData(new ResourceLocation("tbw/textures/0p.png")), accepted -> { |
| 62 | + lastHitWarn = accepted; |
| 63 | + |
| 64 | + getConfig().addProperty("lastHitWarn", lastHitWarn); |
| 65 | + saveConfig(); |
| 66 | + }, lastHitWarn); |
| 67 | + |
| 68 | + BooleanElement debugBool = new BooleanElement("Debug Mode (Development Feature)", new ControlElement.IconData(new ResourceLocation("tbw/textures/matrix.png")), accepted -> { |
| 69 | + debug = accepted; |
| 70 | + |
| 71 | + getConfig().addProperty("debug", debug); |
| 72 | + saveConfig(); |
| 73 | + }, debug); |
| 74 | + |
| 75 | + StringElement warnmsg = new StringElement("Warn Message", new ControlElement.IconData(Material.REDSTONE_TORCH), warnMsg, accepted -> { |
| 76 | + warnMsg = accepted; |
| 77 | + |
| 78 | + getConfig().addProperty("msg", warnMsg); |
| 79 | + saveConfig(); |
| 80 | + }); |
| 81 | + |
| 82 | + SliderElement swordSlider = new SliderElement("Sword Warn Percentage", |
| 83 | + new ControlElement.IconData(Material.IRON_SWORD), warnPercentageSword); |
| 84 | + SliderElement pickSlider = new SliderElement("Pickaxe Warn Percentage", |
| 85 | + new ControlElement.IconData(Material.IRON_PICKAXE), warnPercentagePickaxe); |
| 86 | + SliderElement axeSlider = new SliderElement("Axe Warn Percentage", |
| 87 | + new ControlElement.IconData(Material.IRON_AXE), warnPercentageAxe); |
| 88 | + SliderElement spadeSlider = new SliderElement("Shovel Warn Percentage", |
| 89 | + new ControlElement.IconData(Material.IRON_SHOVEL), warnPercentageShovel); |
| 90 | + |
| 91 | + |
| 92 | + BooleanElement enabledBool = new BooleanElement("Enabled", new ControlElement.IconData(Material.LEVER), accepted -> { |
| 93 | + enabled = accepted; |
| 94 | + |
| 95 | + formatBool.setBlocked(!enabled); |
| 96 | + formatBool.setHoverable(enabled); |
| 97 | + warnOnLastHit.setBlocked(!enabled); |
| 98 | + warnOnLastHit.setHoverable(enabled); |
| 99 | + debugBool.setBlocked(!enabled); |
| 100 | + debugBool.setHoverable(enabled); |
| 101 | + warnmsg.setBlocked(!enabled); |
| 102 | + warnmsg.setHoverable(enabled); |
| 103 | + swordSlider.setBlocked(!enabled); |
| 104 | + swordSlider.setHoverable(enabled); |
| 105 | + pickSlider.setBlocked(!enabled); |
| 106 | + pickSlider.setHoverable(enabled); |
| 107 | + axeSlider.setBlocked(!enabled); |
| 108 | + axeSlider.setHoverable(enabled); |
| 109 | + spadeSlider.setBlocked(!enabled); |
| 110 | + spadeSlider.setHoverable(enabled); |
| 111 | + |
| 112 | + getConfig().addProperty("enabled", enabled); |
| 113 | + saveConfig(); |
| 114 | + }, enabled); |
| 115 | + |
| 116 | + formatBool.setDescriptionText("Unformatted Number: 1561\nFormatted Number: 1.561"); |
| 117 | + |
| 118 | + debugBool.setDescriptionText("Sends a message in the chat every tick you're holding a tool."); |
| 119 | + |
| 120 | + warnOnLastHit.setDescriptionText("Warns you when your tool is at 0 durability"); |
| 121 | + |
| 122 | + { |
| 123 | + // Setting the slider's min & max values |
| 124 | + swordSlider.setRange(1, 25); |
| 125 | + |
| 126 | + // Setting slider steps |
| 127 | + swordSlider.setSteps(1); |
| 128 | + |
| 129 | + // Adding change listener |
| 130 | + swordSlider.addCallback(accepted -> { |
| 131 | + warnPercentageSword = accepted; |
| 132 | + |
| 133 | + getConfig().addProperty("sword", warnPercentageSword); |
| 134 | + saveConfig(); |
| 135 | + }); |
| 136 | + } |
| 137 | + |
| 138 | + { |
| 139 | + // Setting the slider's min & max values |
| 140 | + pickSlider.setRange(1, 25); |
| 141 | + |
| 142 | + // Setting slider steps |
| 143 | + pickSlider.setSteps(1); |
| 144 | + |
| 145 | + // Adding change listener |
| 146 | + pickSlider.addCallback(accepted -> { |
| 147 | + warnPercentagePickaxe = accepted; |
| 148 | + |
| 149 | + getConfig().addProperty("pick", warnPercentagePickaxe); |
| 150 | + saveConfig(); |
| 151 | + }); |
| 152 | + } |
| 153 | + |
| 154 | + { |
| 155 | + // Setting the slider's min & max values |
| 156 | + axeSlider.setRange(1, 25); |
| 157 | + |
| 158 | + // Setting slider steps |
| 159 | + axeSlider.setSteps(1); |
| 160 | + |
| 161 | + // Adding change listener |
| 162 | + axeSlider.addCallback(accepted -> { |
| 163 | + warnPercentageAxe = accepted; |
| 164 | + |
| 165 | + getConfig().addProperty("axe", warnPercentageAxe); |
| 166 | + saveConfig(); |
| 167 | + }); |
| 168 | + } |
| 169 | + |
| 170 | + { |
| 171 | + // Setting the slider's min & max values |
| 172 | + spadeSlider.setRange(1, 25); |
| 173 | + |
| 174 | + // Setting slider steps |
| 175 | + spadeSlider.setSteps(1); |
| 176 | + |
| 177 | + // Adding change listener |
| 178 | + spadeSlider.addCallback(accepted -> { |
| 179 | + warnPercentageShovel = accepted; |
| 180 | + |
| 181 | + getConfig().addProperty("shovel", warnPercentageShovel); |
| 182 | + saveConfig(); |
| 183 | + }); |
| 184 | + } |
| 185 | + |
| 186 | + // Adding setting |
| 187 | + list.add(new HeaderElement("General")); |
| 188 | + list.add(enabledBool); |
| 189 | + list.add(formatBool); |
| 190 | + list.add(warnOnLastHit); |
| 191 | + list.add(debugBool); |
| 192 | + list.add(new HeaderElement("\u00A7cWarn Settings")); |
| 193 | + list.add(warnmsg); |
| 194 | + list.add(swordSlider); |
| 195 | + list.add(pickSlider); |
| 196 | + list.add(axeSlider); |
| 197 | + list.add(spadeSlider); |
| 198 | + } |
| 199 | + |
| 200 | + public static ToolBreakWarning getMain() { |
| 201 | + return instance; |
| 202 | + } |
| 203 | +} |
0 commit comments