From c8f4ff4acbd9c723e87b519b8516558a5ca97a65 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Mon, 1 Mar 2021 22:36:06 +0900 Subject: stomp! --- .../features/impl/etc/FeatureBlah.java | 38 ------------------ .../features/impl/etc/FeatureUpdateAlarm.java | 45 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java deleted file mode 100644 index 16c99db2..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureBlah.java +++ /dev/null @@ -1,38 +0,0 @@ -package kr.syeyoung.dungeonsguide.features.impl.etc; - -import kr.syeyoung.dungeonsguide.e; -import kr.syeyoung.dungeonsguide.features.SimpleFeature; -import kr.syeyoung.dungeonsguide.features.listener.TickListener; -import kr.syeyoung.dungeonsguide.stomp.StompInterface; -import kr.syeyoung.dungeonsguide.stomp.StompMessageHandler; -import kr.syeyoung.dungeonsguide.stomp.StompPayload; -import kr.syeyoung.dungeonsguide.stomp.StompSubscription; -import net.minecraft.client.Minecraft; -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()); - } - - Queue stompPayloadQueue = new ConcurrentLinkedQueue(); - @Override - public void handle(StompInterface stompInterface, StompPayload stompPayload) { - stompPayloadQueue.add(stompPayload); - } - - - @Override - public void onTick() { - while (!stompPayloadQueue.isEmpty()) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(stompPayloadQueue.poll().payload())); - } - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java new file mode 100644 index 00000000..85bb3398 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/etc/FeatureUpdateAlarm.java @@ -0,0 +1,45 @@ +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; +import kr.syeyoung.dungeonsguide.stomp.StompPayload; +import kr.syeyoung.dungeonsguide.stomp.StompSubscription; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +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); + } + + private StompPayload stompPayload; + @Override + public void handle(StompInterface stompInterface, StompPayload stompPayload) { + this.stompPayload = stompPayload; + } + + @Override + public void onTick() { + 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()); + } +} -- cgit