diff options
author | syeyoung <cyong06@naver.com> | 2021-03-01 22:36:06 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-03-01 22:36:06 +0900 |
commit | c8f4ff4acbd9c723e87b519b8516558a5ca97a65 (patch) | |
tree | 856f5a806bce55387f1c70e37544a4ab0419f411 /src/main/java/kr | |
parent | ca37e92e857b8de791f9ddea16743c4139fe9880 (diff) | |
download | Skyblock-Dungeons-Guide-c8f4ff4acbd9c723e87b519b8516558a5ca97a65.tar.gz Skyblock-Dungeons-Guide-c8f4ff4acbd9c723e87b519b8516558a5ca97a65.tar.bz2 Skyblock-Dungeons-Guide-c8f4ff4acbd9c723e87b519b8516558a5ca97a65.zip |
stomp!
Diffstat (limited to 'src/main/java/kr')
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/e.java | 41 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java | 12 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/events/StompConnectedEvent.java | 12 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java | 2 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java (renamed from src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java) | 31 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/listener/StompConnectedListener.java | 7 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java | 3 |
7 files changed, 85 insertions, 23 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index 684d2fe9..98fac826 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -6,6 +6,7 @@ import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; import kr.syeyoung.dungeonsguide.eventlistener.DungeonListener; import kr.syeyoung.dungeonsguide.eventlistener.FeatureListener; import kr.syeyoung.dungeonsguide.eventlistener.PacketListener; +import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.stomp.CloseListener; import kr.syeyoung.dungeonsguide.stomp.StompClient; @@ -38,6 +39,9 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Map; import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class e implements c, CloseListener { @@ -66,12 +70,6 @@ public class e implements c, CloseListener { public void init(FMLInitializationEvent event) { ProgressManager.ProgressBar progressbar = ProgressManager.push("DungeonsGuide", 4); - progressbar.step("Opening connection"); - try { - stompConnection = new StompClient(new URI("wss://dungeonsguide.kro.kr/ws"), authenticator.c(), this); - } catch (Exception e) { - throw new RuntimeException(e); - } progressbar.step("Registering Events & Commands"); @@ -114,7 +112,16 @@ public class e implements c, CloseListener { } Keybinds.register(); - progressbar.step("Downloading Roomdatas"); + + progressbar.step("Opening connection"); + try { + stompConnection = new StompClient(new URI("wss://dungeonsguide.kro.kr/ws"), authenticator.c(), this); + } catch (Exception e) { + throw new RuntimeException(e); + } + + + progressbar.step("Loading Config"); try { Config.loadConfig( null ); } catch (IOException e) { @@ -154,11 +161,25 @@ public class e implements c, CloseListener { public static e getDungeonsGuide() { return dungeonsGuide; } - + ScheduledExecutorService ex = Executors.newScheduledThreadPool(2); @Override public void onClose(int code, String reason, boolean remote) { System.out.println("Stomp Connection closed, trying to reconnect - "+reason+ " - "+code); -// stompConnection = new StompClient(new URL("wss://dungeonsguide.kro.kr/ws").toURI(), authenticator.c(), this); -// Minecraft.getMinecraft(). + connectStomp(); + } + + public void connectStomp() { + ex.schedule(new Runnable() { + @Override + public void run() { + try { + stompConnection = new StompClient(new URI("wss://dungeonsguide.kro.kr/ws"), authenticator.c(), e.this); + MinecraftForge.EVENT_BUS.post(new StompConnectedEvent(stompConnection)); + } catch (Exception e) { + e.printStackTrace(); + connectStomp(); + } + } + }, 5L, TimeUnit.SECONDS); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java index 70393e3c..644535a9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java @@ -36,6 +36,18 @@ public class FeatureListener { } } @SubscribeEvent + public void onStomp(StompConnectedEvent stompConnectedEvent) { + try { + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature instanceof StompConnectedListener) { + ((StompConnectedListener) abstractFeature).onStompConnected(stompConnectedEvent); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + @SubscribeEvent public void onRender(RenderLivingEvent.Pre preRender) { try { SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/events/StompConnectedEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/events/StompConnectedEvent.java new file mode 100644 index 00000000..69b2d3ff --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/events/StompConnectedEvent.java @@ -0,0 +1,12 @@ +package kr.syeyoung.dungeonsguide.events; + +import kr.syeyoung.dungeonsguide.stomp.StompInterface; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Data +@AllArgsConstructor +public class StompConnectedEvent extends Event { + private StompInterface stompInterface; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index fa1b3c92..c758bc25 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -66,7 +66,7 @@ public class FeatureRegistry { public static final FeatureRepartyCommand ETC_REPARTY = register(new FeatureRepartyCommand()); public static final FeatureDecreaseExplosionSound ETC_EXPLOSION_SOUND = register(new FeatureDecreaseExplosionSound()); public static final FeatureAutoAcceptReparty ETC_AUTO_ACCEPT_REPARTY = register(new FeatureAutoAcceptReparty()); - public static final FeatureBlah ETC_TEST = register(new FeatureBlah()); + public static final FeatureUpdateAlarm ETC_TEST = register(new FeatureUpdateAlarm()); public static final SimpleFeature FIX_SPIRIT_BOOTS = register(new SimpleFeature("Fixes", "Spirit Boots Fixer", "Fix Spirit boots messing up with inventory", "fixes.spirit", true)); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java index 16c99db2..85bb3398 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java @@ -1,7 +1,9 @@ package kr.syeyoung.dungeonsguide.features.impl.etc; import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; import kr.syeyoung.dungeonsguide.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.features.listener.StompConnectedListener; import kr.syeyoung.dungeonsguide.features.listener.TickListener; import kr.syeyoung.dungeonsguide.stomp.StompInterface; import kr.syeyoung.dungeonsguide.stomp.StompMessageHandler; @@ -13,26 +15,31 @@ import net.minecraft.util.ChatComponentText; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -public class FeatureBlah extends SimpleFeature implements StompMessageHandler, TickListener { - public FeatureBlah() { - super("ETC", "TEST","test.test"); - e.getDungeonsGuide().getStompConnection().subscribe(StompSubscription.builder() - .destination("/topic/updates") - .ackMode(StompSubscription.AckMode.AUTO) - .stompMessageHandler(this).build()); +public class FeatureUpdateAlarm extends SimpleFeature implements StompConnectedListener, StompMessageHandler, TickListener { + public FeatureUpdateAlarm() { + super("ETC", "Update Alarm","Show a warning on chat when new update has bnee released.", "etc.updatealarm", true); } - Queue<StompPayload> stompPayloadQueue = new ConcurrentLinkedQueue<StompPayload>(); + private StompPayload stompPayload; @Override public void handle(StompInterface stompInterface, StompPayload stompPayload) { - stompPayloadQueue.add(stompPayload); + this.stompPayload = stompPayload; } - @Override public void onTick() { - while (!stompPayloadQueue.isEmpty()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(stompPayloadQueue.poll().payload())); + if (stompPayload != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(stompPayload.payload())); + stompPayload = null; + Minecraft.getMinecraft().thePlayer.playSound("random.successful_hit", 1f,1f); } } + + @Override + public void onStompConnected(StompConnectedEvent event) { + event.getStompInterface().subscribe(StompSubscription.builder() + .destination("/topic/updates") + .ackMode(StompSubscription.AckMode.AUTO) + .stompMessageHandler(this).build()); + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/listener/StompConnectedListener.java b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/StompConnectedListener.java new file mode 100644 index 00000000..696336d3 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/StompConnectedListener.java @@ -0,0 +1,7 @@ +package kr.syeyoung.dungeonsguide.features.listener; + +import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; + +public interface StompConnectedListener { + void onStompConnected(StompConnectedEvent event); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java index 9476241c..eb5b1735 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java @@ -1,5 +1,6 @@ package kr.syeyoung.dungeonsguide.stomp; +import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import lombok.Data; import lombok.Singular; import lombok.experimental.Accessors; @@ -36,11 +37,13 @@ public class StompPayload { if (payload != null) sb.append(payload); sb.append((char) 0); + if (FeatureRegistry.DEBUG.isEnabled()) System.out.println("Probably sending "+sb.toString()); return sb.toString(); } public static StompPayload parse(String payload) { + if (FeatureRegistry.DEBUG.isEnabled()) System.out.println("Parsing "+payload); Scanner scanner = new Scanner(payload); StompPayload stompPayload = new StompPayload(); |