diff options
author | syeyoung <cyoung06@naver.com> | 2023-02-07 17:53:24 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-02-07 17:53:24 +0900 |
commit | 35d20f0197824ca68fa23ff154ad5a1ca8211334 (patch) | |
tree | d16b99f95ec57042dfcbf8fcaf3586965e3761b7 /mod/src | |
parent | 4fc9f6028bb6f8577d55104f4b56ff8a8434b198 (diff) | |
download | Skyblock-Dungeons-Guide-35d20f0197824ca68fa23ff154ad5a1ca8211334.tar.gz Skyblock-Dungeons-Guide-35d20f0197824ca68fa23ff154ad5a1ca8211334.tar.bz2 Skyblock-Dungeons-Guide-35d20f0197824ca68fa23ff154ad5a1ca8211334.zip |
- Freeze Detector
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src')
3 files changed, 82 insertions, 0 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 303caea8..b6e92feb 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -34,6 +34,7 @@ import kr.syeyoung.dungeonsguide.mod.discord.DiscordIntegrationManager; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonFacade; import kr.syeyoung.dungeonsguide.mod.events.annotations.EventHandlerRegistry; import kr.syeyoung.dungeonsguide.mod.events.listener.DungeonListener; +import kr.syeyoung.dungeonsguide.mod.events.listener.FreezeListener; import kr.syeyoung.dungeonsguide.mod.events.listener.PacketInjector; import kr.syeyoung.dungeonsguide.mod.events.listener.PacketListener; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; @@ -171,6 +172,8 @@ public class DungeonsGuide implements DGInterface { public void init(File f) { ProgressManager.ProgressBar progressbar = ProgressManager.push("DungeonsGuide", 4); + registerEventsForge(new FreezeListener()); + progressbar.step("Creating Configuration"); File configFile = new File(Main.getConfigDir(), "config.json"); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java index 239ee14e..2b15c5ff 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java @@ -124,6 +124,8 @@ public class CommandDgDebug extends CommandBase { } switch (args[0].toLowerCase()) { //Case Insensitive + case "freeze": + while(true); case "scoreboard": scoreboardCommand(); break; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/FreezeListener.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/FreezeListener.java new file mode 100644 index 00000000..4bafd78b --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/FreezeListener.java @@ -0,0 +1,77 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.events.listener; + +import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; + +public class FreezeListener implements Runnable { + public FreezeListener() { + t.start(); + } + private volatile long lastTick = Long.MAX_VALUE; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent tickEvent) { + lastTick = System.currentTimeMillis() + 5000; + + } + + + Thread t = new Thread(DungeonsGuide.THREAD_GROUP,this); + + @Override + public void run() { + while(!t.isInterrupted()) { + if (lastTick < System.currentTimeMillis()) { + + ThreadMXBean bean = ManagementFactory.getThreadMXBean(); + ThreadInfo[] infos = bean.dumpAllThreads(true, true); + String stacktrace = Arrays.stream(infos).map(Object::toString) + .collect(Collectors.joining()); + System.out.println(stacktrace); + + StringSelection selection = new StringSelection(stacktrace); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + + JOptionPane.showMessageDialog(null, "Your Minecraft Seems to be frozen!\nThreadump has been copied into your clipboard!", "DG Freeze Alert", JOptionPane.INFORMATION_MESSAGE); + + + } + try { + Thread.sleep(16); + } catch (InterruptedException e) { + break; + } + } + } +} |