diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:13:01 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:13:01 -0400 |
commit | bb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (patch) | |
tree | 617c91cced71f672662bddea6c540939cb9a3953 /src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java | |
parent | 91464c8f433e8bf323932ac956678971207b607e (diff) | |
download | SkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.tar.gz SkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.tar.bz2 SkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.zip |
Format
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java | 269 |
1 files changed, 150 insertions, 119 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index a31889e..7d06d99 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -19,6 +19,11 @@ import com.thatgravyboat.skyblockhud.overlay.OverlayHud; import com.thatgravyboat.skyblockhud.overlay.RPGHud; import com.thatgravyboat.skyblockhud.playerstats.ActionBarParsing; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.scoreboard.ScoreObjective; @@ -36,94 +41,108 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.input.Keyboard; -import java.awt.*; -import java.awt.datatransfer.StringSelection; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.Set; - @Mod(modid = SkyblockHud.MODID, version = SkyblockHud.VERSION) -public class SkyblockHud -{ - public static final String MODID = "skyblockhud"; - public static final String VERSION = "1.12"; +public class SkyblockHud { - public static SBHConfig config; + public static final String MODID = "skyblockhud"; + public static final String VERSION = "1.12"; - private File configFile; + public static SBHConfig config; - private static final Set<String> SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK","\u7A7A\u5C9B\u751F\u5B58"); + private File configFile; - private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); + private static final Set<String> SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet( + "SKYBLOCK", + "\u7A7A\u5C9B\u751F\u5B58" + ); - private static File configDirectory; + private final Gson gson = new GsonBuilder() + .setPrettyPrinting() + .excludeFieldsWithoutExposeAnnotation() + .create(); - @EventHandler - public void preInit(FMLPreInitializationEvent event){ - MinecraftForge.EVENT_BUS.register(this); - MinecraftForge.EVENT_BUS.register(new LeaderboardGetter()); - MinecraftForge.EVENT_BUS.register(new SeasonDateHandler()); - MinecraftForge.EVENT_BUS.register(new LocationHandler()); - MinecraftForge.EVENT_BUS.register(new IslandHandler()); - MinecraftForge.EVENT_BUS.register(new TimeHandler()); - MinecraftForge.EVENT_BUS.register(new CurrencyHandler()); - MinecraftForge.EVENT_BUS.register(new SlayerHandler()); - MinecraftForge.EVENT_BUS.register(new DungeonHandler()); - MinecraftForge.EVENT_BUS.register(new DwarvenMineHandler()); - MinecraftForge.EVENT_BUS.register(new FarmingIslandHandler()); - - /* DISABLE UNTIL NEW SYSTEM + private static File configDirectory; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new LeaderboardGetter()); + MinecraftForge.EVENT_BUS.register(new SeasonDateHandler()); + MinecraftForge.EVENT_BUS.register(new LocationHandler()); + MinecraftForge.EVENT_BUS.register(new IslandHandler()); + MinecraftForge.EVENT_BUS.register(new TimeHandler()); + MinecraftForge.EVENT_BUS.register(new CurrencyHandler()); + MinecraftForge.EVENT_BUS.register(new SlayerHandler()); + MinecraftForge.EVENT_BUS.register(new DungeonHandler()); + MinecraftForge.EVENT_BUS.register(new DwarvenMineHandler()); + MinecraftForge.EVENT_BUS.register(new FarmingIslandHandler()); + + /* DISABLE UNTIL NEW SYSTEM MinecraftForge.EVENT_BUS.register(new TrackerHandler()); MinecraftForge.EVENT_BUS.register(new KillTrackerHandler()); */ - MinecraftForge.EVENT_BUS.register(new HeldItemHandler()); - - ClientRegistry.registerKeyBinding(KeyBindings.map); - - MinecraftForge.EVENT_BUS.register(new ComponentHandler()); - MinecraftForge.EVENT_BUS.register(new ActionBarParsing()); - Commands.init(); - - configFile = new File(event.getModConfigurationDirectory(), "sbh-config.json"); - - if(configFile.exists()) { - try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { - config = gson.fromJson(reader, SBHConfig.class); - } catch(Exception ignored) { } - } - - - if(config == null) { - config = new SBHConfig(); - saveConfig(); - } - - configDirectory = event.getModConfigurationDirectory(); - - Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig)); - //Runtime.getRuntime().addShutdownHook(new Thread(() -> TrackerFileLoader.saveTrackerStatsFile(event.getModConfigurationDirectory()))); + MinecraftForge.EVENT_BUS.register(new HeldItemHandler()); + + ClientRegistry.registerKeyBinding(KeyBindings.map); + + MinecraftForge.EVENT_BUS.register(new ComponentHandler()); + MinecraftForge.EVENT_BUS.register(new ActionBarParsing()); + Commands.init(); + + configFile = + new File(event.getModConfigurationDirectory(), "sbh-config.json"); + + if (configFile.exists()) { + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader( + new FileInputStream(configFile), + StandardCharsets.UTF_8 + ) + ) + ) { + config = gson.fromJson(reader, SBHConfig.class); + } catch (Exception ignored) {} } - public void saveConfig() { - try { - configFile.createNewFile(); - - try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { - writer.write(gson.toJson(config)); - } - } catch(IOException ignored) {} + if (config == null) { + config = new SBHConfig(); + saveConfig(); } - @EventHandler - public void postInit(FMLPostInitializationEvent event){ - MinecraftForge.EVENT_BUS.register(new OverlayHud()); - MinecraftForge.EVENT_BUS.register(new RPGHud()); - MinecraftForge.EVENT_BUS.register(new DungeonOverlay()); - MinecraftForge.EVENT_BUS.register(new BossbarHandler()); - MinecraftForge.EVENT_BUS.register(new MapHandler()); - } - - /* DISABLE UNTIL NEW SYSTEM + configDirectory = event.getModConfigurationDirectory(); + + Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig)); + //Runtime.getRuntime().addShutdownHook(new Thread(() -> TrackerFileLoader.saveTrackerStatsFile(event.getModConfigurationDirectory()))); + } + + public void saveConfig() { + try { + configFile.createNewFile(); + + try ( + BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(configFile), + StandardCharsets.UTF_8 + ) + ) + ) { + writer.write(gson.toJson(config)); + } + } catch (IOException ignored) {} + } + + @EventHandler + public void postInit(FMLPostInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(new OverlayHud()); + MinecraftForge.EVENT_BUS.register(new RPGHud()); + MinecraftForge.EVENT_BUS.register(new DungeonOverlay()); + MinecraftForge.EVENT_BUS.register(new BossbarHandler()); + MinecraftForge.EVENT_BUS.register(new MapHandler()); + } + + /* DISABLE UNTIL NEW SYSTEM @EventHandler public void loadComplete(FMLLoadCompleteEvent event){ @@ -141,55 +160,67 @@ public class SkyblockHud */ - public static boolean hasSkyblockScoreboard() { - Minecraft mc = Minecraft.getMinecraft(); - - if (mc != null && mc.theWorld != null) { - Scoreboard scoreboard = mc.theWorld.getScoreboard(); - ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); - if (sidebarObjective != null) { - String objectiveName = sidebarObjective.getDisplayName().replaceAll("(?i)\\u00A7.", ""); - for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { - if (objectiveName.startsWith(skyblock)) { - return true; - } - } - } + public static boolean hasSkyblockScoreboard() { + Minecraft mc = Minecraft.getMinecraft(); + + if (mc != null && mc.theWorld != null) { + Scoreboard scoreboard = mc.theWorld.getScoreboard(); + ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); + if (sidebarObjective != null) { + String objectiveName = sidebarObjective + .getDisplayName() + .replaceAll("(?i)\\u00A7.", ""); + for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { + if (objectiveName.startsWith(skyblock)) { + return true; + } } - - return false; + } } - @SubscribeEvent - public void onTooltip(ItemTooltipEvent event){ - if (event.itemStack != null && Keyboard.isKeyDown(Keyboard.KEY_BACKSLASH)) { - try { - StringSelection clipboard = new StringSelection(event.itemStack.serializeNBT().toString()); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard); - } catch (Exception ignored) { - } - } + return false; + } + + @SubscribeEvent + public void onTooltip(ItemTooltipEvent event) { + if (event.itemStack != null && Keyboard.isKeyDown(Keyboard.KEY_BACKSLASH)) { + try { + StringSelection clipboard = new StringSelection( + event.itemStack.serializeNBT().toString() + ); + Toolkit + .getDefaultToolkit() + .getSystemClipboard() + .setContents(clipboard, clipboard); + } catch (Exception ignored) {} } - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onStatusBar(ClientChatReceivedEvent event){ - if (Utils.removeColor(event.message.getUnformattedText()).toLowerCase().trim().startsWith("your profile was changed to:")){ - MinecraftForge.EVENT_BUS.post(new ProfileSwitchedEvent()); - } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onStatusBar(ClientChatReceivedEvent event) { + if ( + Utils + .removeColor(event.message.getUnformattedText()) + .toLowerCase() + .trim() + .startsWith("your profile was changed to:") + ) { + MinecraftForge.EVENT_BUS.post(new ProfileSwitchedEvent()); } - - public static GuiScreen screenToOpen = null; - private static int screenTicks = 0; - - @SubscribeEvent - public void onClientTick(TickEvent.ClientTickEvent event){ - if (screenToOpen != null){ - screenTicks++; - if (screenTicks == 5){ - Minecraft.getMinecraft().displayGuiScreen(screenToOpen); - screenTicks = 0; - screenToOpen = null; - } - } + } + + public static GuiScreen screenToOpen = null; + private static int screenTicks = 0; + + @SubscribeEvent + public void onClientTick(TickEvent.ClientTickEvent event) { + if (screenToOpen != null) { + screenTicks++; + if (screenTicks == 5) { + Minecraft.getMinecraft().displayGuiScreen(screenToOpen); + screenTicks = 0; + screenToOpen = null; + } } + } } |