From de2ea64b5127570baa61ade6fd7a63416c8b7cb9 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Sat, 11 Nov 2023 21:37:07 +0900 Subject: No throwables (#436) * - fix error handling, don't use throwables like amateur Signed-off-by: syeyoung * - no need for hack to stop Signed-off-by: syeyoung * - gui error handling Signed-off-by: syeyoung --------- Signed-off-by: syeyoung --- .../launcher/gui/tooltip/NotificationManager.java | 44 +++--- .../launcher/guiv2/GuiScreenAdapter.java | 41 +++--- .../guiv2/xml/PropByPropParsedWidgetConverter.java | 2 + .../dungeonsguide/mod/chat/ChatProcessor.java | 2 +- .../dungeonsguide/mod/commands/CommandDgDebug.java | 6 +- .../mod/commands/CommandDungeonsGuide.java | 2 +- .../mod/cosmetics/CosmeticsManager.java | 4 +- .../mod/discord/DiscordIntegrationManager.java | 8 +- .../dungeon/roomedit/panes/ActionDisplayPane.java | 2 +- .../dungeon/roomedit/panes/GeneralEditPane.java | 2 +- .../dungeon/roomedit/panes/RoommatchingPane.java | 2 +- .../bombdefuse/RoomProcessorBombDefuseSolver.java | 2 +- .../events/annotations/EventHandlerRegistry.java | 4 +- .../mod/events/listener/PacketInjector.java | 2 +- .../discord/inviteViewer/PartyInviteViewer.java | 3 +- .../impl/discord/onlinealarm/PlayingDGAlarm.java | 3 +- .../features/impl/dungeon/FeaturePlayerESP.java | 4 +- .../features/impl/party/FeatureGoodParties.java | 2 +- .../FeatureViewPlayerStatsOnJoin.java | 2 +- .../kr/syeyoung/dungeonsguide/mod/gui/MGui.java | 41 +++--- .../mod/gui/elements/MKeyEditButton.java | 147 --------------------- .../dungeonsguide/mod/guiv2/GuiScreenAdapter.java | 42 +++--- .../guiv2/xml/PropByPropParsedWidgetConverter.java | 2 + .../dungeonsguide/mod/overlay/OverlayManager.java | 44 +++--- 24 files changed, 134 insertions(+), 279 deletions(-) delete mode 100755 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/gui/elements/MKeyEditButton.java diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/tooltip/NotificationManager.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/tooltip/NotificationManager.java index 7e4ccdce..517e20ac 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/tooltip/NotificationManager.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/tooltip/NotificationManager.java @@ -139,8 +139,8 @@ public class NotificationManager { private void keyTyped(char typedChar, int keyCode) throws IOException { try { view.keyPressed0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -148,8 +148,8 @@ public class NotificationManager { private void keyHeld(int keyCode, char typedChar) throws IOException { try { view.keyHeld0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -157,8 +157,8 @@ public class NotificationManager { private void keyReleased(int keyCode, char typedChar) throws IOException { try { view.keyReleased0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -167,8 +167,8 @@ public class NotificationManager { try { return view.mouseClicked0(mouseX, mouseY , mouseX, mouseY, mouseButton); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } return false; @@ -178,8 +178,8 @@ public class NotificationManager { try { view.mouseReleased0(mouseX, mouseY , mouseX, mouseY, state); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -188,8 +188,8 @@ public class NotificationManager { try { view.mouseClickMove0(mouseX, mouseY , mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -198,8 +198,8 @@ public class NotificationManager { try { view.mouseMoved0(mouseX, mouseY , mouseX, mouseY, true); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -215,7 +215,6 @@ public class NotificationManager { @SubscribeEvent(priority = EventPriority.HIGHEST) public void handleMouseInput(GuiScreenEvent.MouseInputEvent.Pre mouseInputEvent) throws IOException { - try { int i = Mouse.getEventX(); int j = this.mc.displayHeight - Mouse.getEventY(); int k = Mouse.getEventButton(); @@ -241,14 +240,14 @@ public class NotificationManager { this.mouseClickMove(i, j, this.eventButton, l); } if (lastX != i || lastY != j) { - try { EnumCursor prevCursor = view.getCurrentCursor(); view.setCursor(EnumCursor.DEFAULT); this.mouseMove(i, j); EnumCursor newCursor = view.getCurrentCursor(); + try { if (prevCursor != newCursor) Mouse.setNativeCursor(GLCursors.getCursor(newCursor)); } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + e.printStackTrace(); } } @@ -256,14 +255,15 @@ public class NotificationManager { int wheel = Mouse.getEventDWheel(); if (wheel != 0) { - boolean cancel = view.mouseScrolled0(i, j, i, j, wheel); - if (cancel) mouseInputEvent.setCanceled(true); + try { + boolean cancel = view.mouseScrolled0(i, j, i, j, wheel); + if (cancel) mouseInputEvent.setCanceled(true); + } catch (Exception e) { + e.printStackTrace(); + } } lastX = i; lastY = j; - } catch (Throwable e) { - e.printStackTrace(); - } } @SubscribeEvent(priority = EventPriority.HIGHEST) diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/GuiScreenAdapter.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/GuiScreenAdapter.java index 44dfb230..d6b2e496 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/GuiScreenAdapter.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/GuiScreenAdapter.java @@ -137,8 +137,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.keyPressed0(typedChar, keyCode); super.keyTyped(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -146,8 +146,8 @@ public class GuiScreenAdapter extends GuiScreen { public void keyHeld(int keyCode, char typedChar) throws IOException { try { view.keyHeld0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -155,8 +155,8 @@ public class GuiScreenAdapter extends GuiScreen { public void keyReleased(int keyCode, char typedChar) throws IOException { try { view.keyReleased0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -167,8 +167,8 @@ public class GuiScreenAdapter extends GuiScreen { super.mouseClicked(mouseX, mouseY, mouseButton); view.mouseClicked0(mouseX, mouseY , mouseX, mouseY, mouseButton); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -192,8 +192,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseReleased0(mouseX, mouseY , mouseX, mouseY, state); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -203,8 +203,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseClickMove0(mouseX, mouseY , mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -213,8 +213,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseMoved0(mouseX, mouseY , mouseX, mouseY, true); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -231,7 +231,6 @@ public class GuiScreenAdapter extends GuiScreen { @Override public void handleMouseInput() throws IOException { if (!isOpen) return; - try { int i = Mouse.getEventX(); int j = this.mc.displayHeight - Mouse.getEventY(); int k = Mouse.getEventButton(); @@ -256,15 +255,14 @@ public class GuiScreenAdapter extends GuiScreen { this.mouseClickMove(i, j, this.eventButton, l); } if (lastX != i || lastY != j) { - try { EnumCursor prevCursor = view.getCurrentCursor(); view.setCursor(EnumCursor.DEFAULT); this.mouseMove(i, j); EnumCursor newCursor = view.getCurrentCursor(); + try { if (prevCursor != newCursor) Mouse.setNativeCursor(GLCursors.getCursor(newCursor)); } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) e.printStackTrace(); } } @@ -272,13 +270,14 @@ public class GuiScreenAdapter extends GuiScreen { int wheel = Mouse.getEventDWheel(); if (wheel != 0) { - view.mouseScrolled0(i, j, i, j, wheel); + try { + view.mouseScrolled0(i, j, i, j, wheel); + } catch (Exception e) { + e.printStackTrace(); + } } lastX = i; lastY = j; - } catch (Throwable e) { - e.printStackTrace(); - } } public void handleKeyboardInput() throws IOException { diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/xml/PropByPropParsedWidgetConverter.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/xml/PropByPropParsedWidgetConverter.java index 8f6e2feb..32663151 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/xml/PropByPropParsedWidgetConverter.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/guiv2/xml/PropByPropParsedWidgetConverter.java @@ -81,6 +81,8 @@ public abstract class PropByPropParsedWidgetConverter. - */ - -package kr.syeyoung.dungeonsguide.mod.gui.elements; - -import kr.syeyoung.dungeonsguide.mod.gui.MPanel; -import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; -import kr.syeyoung.dungeonsguide.mod.utils.cursor.EnumCursor; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.settings.GameSettings; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; - -@Getter -@Setter -public class MKeyEditButton extends MPanel { - private int key; - private Runnable onKeyEdit; - - private Color foreground = Color.white; - private int background = RenderUtils.blendAlpha(0xFF141414, 0.08f); - private int hover = RenderUtils.blendAlpha(0xFF141414, 0.14f); - private int clicked = RenderUtils.blendAlpha(0xFF141414, 0.16f); - private int border = 0x0; - private int disabled =0xFF141414; - private int roundness = 0; - - private boolean enabled = true; - - @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { - Dimension bounds = getSize(); - - int bg = background; - if (!enabled) { - bg = disabled; - } else if (getTooltipsOpen() > 0) { - } else if (selected) { - bg = clicked; - } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) { - bg = hover; - } - if (roundness == 0) { - if (((border >> 24) & 0xFF) == 0) - Gui.drawRect(0, 0, getBounds().width, getBounds().height, bg); - else { - Gui.drawRect(0, 0, getBounds().width, getBounds().height, border); - Gui.drawRect(1, 1, getBounds().width - 1, getBounds().height - 1, bg); - } - } else { - if (((border >> 24) & 0xFF) == 0) - RenderUtils.drawRoundedRectangle(0, 0, getBounds().width, getBounds().height, roundness, Math.PI/8, bg); - else { - RenderUtils.drawRoundedRectangle(0, 0, getBounds().width, getBounds().height, roundness, Math.PI/8, border); - RenderUtils.drawRoundedRectangle(1, 1, getBounds().width-2, getBounds().height-2, roundness, Math.PI/8, bg); - } - GlStateManager.enableTexture2D(); - } - - String str = GameSettings.getKeyDisplayString(key); - if (selected) str = "> "+str+" <"; - FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; - int width = renderer.getStringWidth(str); - int x = (getBounds().width - width) / 2; - int y = (getBounds().height - renderer.FONT_HEIGHT) / 2 + 1; - - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - renderer.drawString(str, x,y, foreground.getRGB()); - } - - private boolean selected; - @Override - public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { - if (lastAbsClip.contains(absMouseX, absMouseY) && getTooltipsOpen() == 0) { - if (selected) { - key = -100 + mouseButton; - selected = false; - if (onKeyEdit != null) - onKeyEdit.run(); - } else { - selected = true; - } - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); - } else { - selected = false; - } - } - - @Override - public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { - - } - - - @Override - public void mouseMoved(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0) { - if (lastAbsClip.contains(absMouseX, absMouseY) && enabled) - setCursor(EnumCursor.POINTING_HAND); - } - - @Override - public void keyPressed(char typedChar, int keyCode) { - if (!selected) return; - if (keyCode == 1) { - key = 0; - } else if (keyCode != 0) { - key = keyCode; - } else if (typedChar > 0) { - key = typedChar + 256; - } - selected = false; - if (onKeyEdit != null) - onKeyEdit.run(); - throw new RuntimeException("hack to stop event propagation"); - } - - @Override - public Dimension getPreferredSize() { - return new Dimension(80, 15); - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java index 34d755cb..b1c26b37 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java @@ -151,8 +151,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.keyPressed0(typedChar, keyCode); super.keyTyped(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -160,8 +160,8 @@ public class GuiScreenAdapter extends GuiScreen { public void keyHeld(int keyCode, char typedChar) throws IOException { try { view.keyHeld0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -169,8 +169,8 @@ public class GuiScreenAdapter extends GuiScreen { public void keyReleased(int keyCode, char typedChar) throws IOException { try { view.keyReleased0(typedChar, keyCode); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -181,8 +181,8 @@ public class GuiScreenAdapter extends GuiScreen { super.mouseClicked(mouseX, mouseY, mouseButton); view.mouseClicked0(mouseX, mouseY , mouseX, mouseY, mouseButton); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -206,8 +206,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseReleased0(mouseX, mouseY , mouseX, mouseY, state); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -217,8 +217,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseClickMove0(mouseX, mouseY , mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -227,8 +227,8 @@ public class GuiScreenAdapter extends GuiScreen { try { view.mouseMoved0(mouseX, mouseY , mouseX, mouseY, true); - } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + } catch (Exception e) { + e.printStackTrace(); } } @@ -245,7 +245,6 @@ public class GuiScreenAdapter extends GuiScreen { @Override public void handleMouseInput() throws IOException { if (!isOpen) return; - try { int i = Mouse.getEventX(); int j = this.mc.displayHeight - Mouse.getEventY(); int k = Mouse.getEventButton(); @@ -270,14 +269,14 @@ public class GuiScreenAdapter extends GuiScreen { this.mouseClickMove(i, j, this.eventButton, l); } if (lastX != i || lastY != j) { - try { EnumCursor prevCursor = view.getCurrentCursor(); view.setCursor(EnumCursor.DEFAULT); this.mouseMove(i, j); EnumCursor newCursor = view.getCurrentCursor(); + try { if (prevCursor != newCursor) Mouse.setNativeCursor(GLCursors.getCursor(newCursor)); } catch (Throwable e) { - if (e.getMessage() == null || !e.getMessage().contains("hack to stop")) + e.printStackTrace(); } } @@ -285,13 +284,14 @@ public class GuiScreenAdapter extends GuiScreen { int wheel = Mouse.getEventDWheel(); if (wheel != 0) { - view.mouseScrolled0(i, j, i, j, wheel); + try { + view.mouseScrolled0(i, j, i, j, wheel); + } catch (Exception e) { + e.printStackTrace(); + } } lastX = i; lastY = j; - } catch (Throwable e) { - e.printStackTrace(); - } } public void handleKeyboardInput() throws IOException { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/PropByPropParsedWidgetConverter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/PropByPropParsedWidgetConverter.java index d0a907a2..ff42cd38 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/PropByPropParsedWidgetConverter.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/PropByPropParsedWidgetConverter.java @@ -81,6 +81,8 @@ public abstract class PropByPropParsedWidgetConverter