diff options
author | syeyoung <cyoung06@naver.com> | 2022-11-17 19:19:49 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2022-11-17 19:19:49 +0900 |
commit | 7a698d3d7e06684419c1c7a99cd59f41fee99524 (patch) | |
tree | cc4596d4176e28741542e677d1243eae44c3b0e6 /mod/src/main/java/kr/syeyoung | |
parent | f033c34b2e2a7824df41ea750b66b21685462279 (diff) | |
download | Skyblock-Dungeons-Guide-7a698d3d7e06684419c1c7a99cd59f41fee99524.tar.gz Skyblock-Dungeons-Guide-7a698d3d7e06684419c1c7a99cd59f41fee99524.tar.bz2 Skyblock-Dungeons-Guide-7a698d3d7e06684419c1c7a99cd59f41fee99524.zip |
- Transformer to inject custom ASMEventHandler to handle classloader inconsistency issue
- Transformer to transform Event classes, because FML for some reason injects some stuff
- Move all event registration into DungeonsGuide.java
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
10 files changed, 55 insertions, 48 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index 912e3ebc..52515a38 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -30,6 +30,7 @@ import kr.syeyoung.dungeonsguide.mod.config.Config; import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticsManager; import kr.syeyoung.dungeonsguide.mod.discord.rpc.RichPresenceManager; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonFacade; +import kr.syeyoung.dungeonsguide.mod.events.listener.DungeonListener; import kr.syeyoung.dungeonsguide.mod.events.listener.FeatureListener; import kr.syeyoung.dungeonsguide.mod.events.listener.PacketListener; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; @@ -58,6 +59,7 @@ import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -91,9 +93,17 @@ public class DungeonsGuide implements DGInterface { CommandReparty commandReparty; + private List<Object> registeredListeners = new ArrayList<>(); + public void registerEventsForge(Object object) { + registeredListeners.add(object); + MinecraftForge.EVENT_BUS.register(object); + } public void init(File f) { + ClassLoader orignalLoader = Thread.currentThread().getContextClassLoader(); + + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); ProgressManager.ProgressBar progressbar = ProgressManager.push("DungeonsGuide", 4); progressbar.step("Creating Configuration"); @@ -115,18 +125,19 @@ public class DungeonsGuide implements DGInterface { e.printStackTrace(); } - MinecraftForge.EVENT_BUS.register(this); + registerEventsForge(this); progressbar.step("Registering Events & Commands"); skyblockStatus = new SkyblockStatus(); - MinecraftForge.EVENT_BUS.register(skyblockStatus); - + registerEventsForge(skyblockStatus); + registerEventsForge(ChatTransmitter.INSTANCE); + registerEventsForge(new BlockCache()); + registerEventsForge(TitleRender.getInstance()); (new FeatureRegistry()).init(); - new ChatTransmitter(); try { Set<String> invalid = ReflectionHelper.getPrivateValue(LaunchClassLoader.class, (LaunchClassLoader) Main.class.getClassLoader(), "invalidClasses"); @@ -139,7 +150,9 @@ public class DungeonsGuide implements DGInterface { this.blockCache = new BlockCache(); + registerEventsForge(new DungeonListener()); this.dungeonFacade = new DungeonFacade(); + dungeonFacade.init(); @@ -152,24 +165,24 @@ public class DungeonsGuide implements DGInterface { ClientCommandHandler.instance.registerCommand(commandDungeonsGuide); ClientCommandHandler.instance.registerCommand(command); - MinecraftForge.EVENT_BUS.register(command); - MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); + registerEventsForge(command); + registerEventsForge(commandDungeonsGuide); - MinecraftForge.EVENT_BUS.register(commandReparty = new CommandReparty()); + registerEventsForge(commandReparty = new CommandReparty()); - MinecraftForge.EVENT_BUS.register(new FeatureListener()); - MinecraftForge.EVENT_BUS.register(new PacketListener()); - MinecraftForge.EVENT_BUS.register(new Keybinds()); + registerEventsForge(new FeatureListener()); + registerEventsForge(new PacketListener()); + registerEventsForge(new Keybinds()); - MinecraftForge.EVENT_BUS.register(PartyManager.INSTANCE); - MinecraftForge.EVENT_BUS.register(ChatProcessor.INSTANCE); - MinecraftForge.EVENT_BUS.register(StaticResourceCache.INSTANCE); + registerEventsForge(PartyManager.INSTANCE); + registerEventsForge(ChatProcessor.INSTANCE); + registerEventsForge(StaticResourceCache.INSTANCE); - MinecraftForge.EVENT_BUS.register(new AhUtils()); + registerEventsForge(new AhUtils()); progressbar.step("Opening connection"); - MinecraftForge.EVENT_BUS.register(cosmeticsManager = new CosmeticsManager()); + registerEventsForge(cosmeticsManager = new CosmeticsManager()); progressbar.step("Loading Config"); @@ -187,20 +200,20 @@ public class DungeonsGuide implements DGInterface { System.setProperty("dg.safe", "true"); } - MinecraftForge.EVENT_BUS.register(RichPresenceManager.INSTANCE); + registerEventsForge(RichPresenceManager.INSTANCE); TimeScoreUtil.init(); ProgressManager.pop(progressbar); + Thread.currentThread().setContextClassLoader(orignalLoader); } @Override public void unload() { // have FUN! - -// bar.step("Instantiating..."); -// partialLoad(obtainLoader(configuration)); - throw new UnsupportedOperationException("Who the heck registered events in features?? This will stay unsupported for now"); + for (Object registeredListener : registeredListeners) { + MinecraftForge.EVENT_BUS.unregister(registeredListener); + } } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/chat/ChatTransmitter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/chat/ChatTransmitter.java index bfdbd5db..8a50211d 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/chat/ChatTransmitter.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/chat/ChatTransmitter.java @@ -17,9 +17,8 @@ public class ChatTransmitter { public static final String PREFIX = "§eDungeons Guide §7:: "; public static String prefix = "§eDungeons Guide §7:: "; - public ChatTransmitter() { - MinecraftForge.EVENT_BUS.register(this); - } + + public static ChatTransmitter INSTANCE = new ChatTransmitter(); static Queue<ChatComponentText> receiveQueue = new ConcurrentLinkedQueue<>(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDungeonsGuide.java index 9b9811cd..5c65424e 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDungeonsGuide.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.mod.commands; +import kr.syeyoung.dungeonsguide.launcher.Main; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.config.guiconfig.GuiConfigV2; @@ -139,17 +140,20 @@ public class CommandDungeonsGuide extends CommandBase { sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §c" + args[1] + " is not valid number.")); } } + } else if (args[0].equals("reload")) { + Main.getMain().reloadWithoutStacktraceReference(Main.getMain().getCurrentLoader()); } else { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg §7-§fOpens configuration gui")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg gui §7-§fOpens configuration gui")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg help §7-§fShows command help")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reloadah §7-§f Reloads price data from server.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reparty §7-§f Reparty.")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg asktojoin or /dg atj §7-§f Toggle ask to join §cRequires Discord Rich Presence enabled. (/dg -> Advanced)")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg partymax [number] or /dg pm [number] §7-§f Sets partymax §7(maximum amount people in party, for discord rpc)")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg pv [ign] §7-§f Profile Viewer")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg pvall §7-§f Profile Viewer For all people on party")); - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg purge §7-§f Purge api cache.")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg §7-§fOpens configuration gui")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg gui §7-§fOpens configuration gui")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg help §7-§fShows command help")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reloadah §7-§f Reloads price data from server.")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reparty §7-§f Reparty.")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg asktojoin or /dg atj §7-§f Toggle ask to join §cRequires Discord Rich Presence enabled. (/dg -> Advanced)")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg partymax [number] or /dg pm [number] §7-§f Sets partymax §7(maximum amount people in party, for discord rpc)")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg pv [ign] §7-§f Profile Viewer")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg pvall §7-§f Profile Viewer For all people on party")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg purge §7-§f Purge api cache.")); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg reload §7-§f Reload Current Version of Dungeons Guide. Auto update versions will not be updated.")); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonFacade.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonFacade.java index 434d3998..76fc482e 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonFacade.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonFacade.java @@ -6,6 +6,7 @@ import kr.syeyoung.dungeonsguide.mod.events.listener.DungeonListener; import lombok.Getter; import lombok.Setter; import net.minecraftforge.common.MinecraftForge; +import org.apache.logging.log4j.ThreadContext; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -22,9 +23,6 @@ public class DungeonFacade { private DungeonContext context; public void init() { - DungeonListener dgEventListener = new DungeonListener(); - MinecraftForge.EVENT_BUS.register(dgEventListener); - try { DungeonRoomInfoRegistry.loadAll(Main.getConfigDir()); } catch (BadPaddingException | InvalidKeyException | NoSuchPaddingException | IllegalBlockSizeException | diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPepole.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPepole.java index cc2f911a..bd495225 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPepole.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPepole.java @@ -56,7 +56,6 @@ public class FeatureTestPepole extends GuiFeature implements ChatListener, Dunge addParameter("scale", new FeatureParameter<>("scale", "Scale", "Scale", 2.0f, "float", nval -> this.scale = nval)); - MinecraftForge.EVENT_BUS.register(this); // (new Thread(() -> { // while (true){ diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/etc/FeatureEpicCountdown.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/etc/FeatureEpicCountdown.java index f88b2884..70af9397 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/etc/FeatureEpicCountdown.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/etc/FeatureEpicCountdown.java @@ -5,6 +5,7 @@ import kr.syeyoung.dungeonsguide.mod.chat.ChatProcessResult; import kr.syeyoung.dungeonsguide.mod.chat.ChatProcessor; import kr.syeyoung.dungeonsguide.mod.features.FeatureParameter; import kr.syeyoung.dungeonsguide.mod.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.mod.features.listener.TickListener; import kr.syeyoung.dungeonsguide.mod.utils.ScoreBoardUtils; import kr.syeyoung.dungeonsguide.mod.utils.TextUtils; import kr.syeyoung.dungeonsguide.mod.utils.TitleRender; @@ -23,7 +24,7 @@ import static kr.syeyoung.dungeonsguide.mod.chat.ChatProcessResult.REMOVE_CHAT; /** * CREDITS FOR THE COUNTDOWN SOUNDTRACK: <a href="https://www.youtube.com/watch?v=acCqrA-JxAw">...</a> */ -public class FeatureEpicCountdown extends SimpleFeature { +public class FeatureEpicCountdown extends SimpleFeature implements TickListener { static volatile long updatedAt; static volatile int secondsLeft; @@ -40,7 +41,6 @@ public class FeatureEpicCountdown extends SimpleFeature { lastSec = GO_TEXT; ChatProcessor.INSTANCE.subscribe(FeatureEpicCountdown::processChat); - MinecraftForge.EVENT_BUS.register(this); } public static ChatProcessResult processChat(String txt, Map<String, Object> context) { @@ -87,8 +87,8 @@ public class FeatureEpicCountdown extends SimpleFeature { String lastSec; @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent e){ - if(e.phase != TickEvent.Phase.START || !isEnabled() || !DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnDungeon()) return; + public void onTick(){ + if(!isEnabled() || !DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnDungeon()) return; ScoreBoardUtils.forEachLineClean(line -> { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java index 84705a1d..d23debc2 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java @@ -131,7 +131,7 @@ public class StompClient extends WebSocketClient { if (heartbeat != null) heartbeat.cancel(true); MinecraftForge.EVENT_BUS.post(new StompDiedEvent(code, reason, remote)); - + StompManager.getInstance().onStompDied(new StompDiedEvent(code, reason, remote)); } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java index e7248484..d430e586 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java @@ -21,7 +21,6 @@ public class StompManager { public static StompManager getInstance() { if (instance == null) { instance = new StompManager(); - MinecraftForge.EVENT_BUS.register(instance); } return instance; } @@ -48,7 +47,6 @@ public class StompManager { ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor(); - @SubscribeEvent public void onStompDied(StompDiedEvent event) { logger.info("Stomp Connection closed, trying to reconnect - {} - {}", event.reason, event.code); connectStomp(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java index b8313778..366e09a0 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java @@ -15,9 +15,6 @@ import org.jetbrains.annotations.NotNull; import java.util.concurrent.TimeUnit; public class BlockCache { - public BlockCache() { - MinecraftForge.EVENT_BUS.register(this); - } @SuppressWarnings("UnstableApiUsage") private final LoadingCache<BlockPos, IBlockState> cache = CacheBuilder.newBuilder() diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java index dfc0b0a1..3b8fe964 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java @@ -27,7 +27,6 @@ public class TitleRender { } private TitleRender() { - MinecraftForge.EVENT_BUS.register(this); } protected static int titlesTimer; |