aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/torui/coflsky/handlers
diff options
context:
space:
mode:
authormatthias-luger <58751503+matthias-luger@users.noreply.github.com>2023-02-17 17:32:26 +0100
committerGitHub <noreply@github.com>2023-02-17 17:32:26 +0100
commit8f3bce7d6fe41e85f2654f7557bbb564305e58b5 (patch)
tree4bae9237e3c0b87bf27e5f590f4c0ca91b145cab /src/main/java/de/torui/coflsky/handlers
parente43d5685fdf0d436d5836d06c5d3f15da674e7df (diff)
downloadCOFL-8f3bce7d6fe41e85f2654f7557bbb564305e58b5.tar.gz
COFL-8f3bce7d6fe41e85f2654f7557bbb564305e58b5.tar.bz2
COFL-8f3bce7d6fe41e85f2654f7557bbb564305e58b5.zip
Add TFM Purchase UI to Mod (#78)
* Add TFM Purchase UI to Mod * fix up opening flips by hotkey fix up flip message in tfm ui * readded check if the auction should be drawn mod doesnt crash anymore if a non flip auction is opened * added /cofl set gui command changed gui title * added /fc toggle command dont store toggle locally * rename purchaseOverlay config removed unused code renamed gui command to /cofl set ahbuygui * fix message not available if flip opened by mouse fix old message shown for non flip auctions * added /cofl setGui command added cofl purchase gui * Add sound on flip * Fixed new flip sound Optimized cofl gui Removed flickering of default mc gui Move mouse to middle on screen open * remove unused code * remove debug code * don't open guis if not in skyblock * fix sound being null * fix bed flips fix opening /cofl blocked * remove logging * Rewrote cofl gui to render before the chest gui opens * - fix bed flips - invalidate best flips after open * - fix scrolling * - fix description not updating - case insensitive commands - fix up , at the end of the message * - add gui if item was already bought - fix bug that invalidated too many flips - added missing "break" * fix merge error * add .vscode to gitignore formatting * fix formatting issue * - remove comment - remove emty line
Diffstat (limited to 'src/main/java/de/torui/coflsky/handlers')
-rw-r--r--src/main/java/de/torui/coflsky/handlers/EventRegistry.java394
1 files changed, 198 insertions, 196 deletions
diff --git a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
index 354dfb9..4bf800b 100644
--- a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
+++ b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
@@ -7,14 +7,13 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.mojang.realmsclient.util.Pair;
-
import de.torui.coflsky.CoflSky;
-import de.torui.coflsky.FlipHandler.Flip;
import de.torui.coflsky.WSCommandHandler;
import de.torui.coflsky.commands.Command;
import de.torui.coflsky.commands.CommandType;
import de.torui.coflsky.commands.JsonStringCommand;
import de.torui.coflsky.commands.models.AuctionData;
+import de.torui.coflsky.commands.models.FlipData;
import de.torui.coflsky.configuration.Configuration;
import de.torui.coflsky.network.WSClient;
import net.minecraft.client.Minecraft;
@@ -44,199 +43,202 @@ import static de.torui.coflsky.handlers.DescriptionHandler.*;
import static de.torui.coflsky.handlers.EventHandler.*;
public class EventRegistry {
- public static Pattern chatpattern = Pattern.compile("a^", Pattern.CASE_INSENSITIVE);
- public final ExecutorService chatThreadPool = Executors.newFixedThreadPool(2);
- public final ExecutorService tickThreadPool = Executors.newFixedThreadPool(2);
- @SubscribeEvent
- public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) {
- if(CoflSky.Wrapper.isRunning) {
- System.out.println("Disconnected from server");
- CoflSky.Wrapper.stop();
- System.out.println("CoflSky stopped");
- }
- }
-
- public long LastClick = System.currentTimeMillis();
- private DescriptionHandler descriptionHandler;
-
- @SideOnly(Side.CLIENT)
- @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
- public void onKeyEvent(KeyInputEvent event) {
-
- if (CoflSky.keyBindings[0].isPressed()) {
- if (WSCommandHandler.lastOnClickEvent != null) {
-
- String command = WSCommandHandler.lastOnClickEvent;
- WSCommandHandler.lastOnClickEvent = null;
- WSCommandHandler.HandleCommand(
- new JsonStringCommand(CommandType.Execute, WSClient.gson.toJson(command)),
- Minecraft.getMinecraft().thePlayer);
- }
-
- }
- if(CoflSky.keyBindings[1].isKeyDown()) {
- if((System.currentTimeMillis() - LastClick) >= 300) {
-
- Flip f = WSCommandHandler.flipHandler.fds.GetHighestFlip();
-
- if(f != null) {
- WSCommandHandler.Execute("/viewauction " + f.id, null);
- LastClick = System.currentTimeMillis();
- String command = WSClient.gson.toJson("/viewauction " + f.id);
- WSCommandHandler.flipHandler.fds.InvalidateFlip(f);
-
- WSCommandHandler.Execute("/cofl track besthotkey " + f.id, Minecraft.getMinecraft().thePlayer);
- CoflSky.Wrapper.SendMessage(new JsonStringCommand(CommandType.Clicked, command));
- } else {
- // only display message once (if this is the key down event)
- if(CoflSky.keyBindings[1].isPressed())
- WSCommandHandler.Execute("/cofl dialog nobestflip", Minecraft.getMinecraft().thePlayer);
- }
- }
- }
- }
-
- @SideOnly(Side.CLIENT)
- //@SubscribeEvent
- public void DrawOntoGUI(RenderGameOverlayEvent rgoe) {
-
- if (rgoe.type == ElementType.CROSSHAIRS) {
- Minecraft mc = Minecraft.getMinecraft();
- mc.ingameGUI.drawString(Minecraft.getMinecraft().fontRendererObj, "Flips in Pipeline:" + WSCommandHandler.flipHandler.fds.CurrentFlips(), 0, 0, Integer.MAX_VALUE);
- }
- }
-
- public static String ExtractUuidFromInventory(IInventory inventory) {
-
- ItemStack stack = inventory.getStackInSlot(13);
- if (stack != null) {
- try {
- String uuid = stack.serializeNBT().getCompoundTag("tag").getCompoundTag("ExtraAttributes")
- .getString("uuid");
- if (uuid.length() == 0) {
- throw new Exception();
- }
- System.out.println("Item has the UUID: " + uuid);
- return uuid;
- } catch (Exception e) {
- System.out.println("Clicked item " + stack.getDisplayName() + " has the following meta: "
- + stack.serializeNBT());
- }
- }
- return "";
- }
-
- public static ItemStack GOLD_NUGGET = new ItemStack(
- Item.itemRegistry.getObject(new ResourceLocation("minecraft:gold_nugget")));
-
- public static final Pair<String, Pair<String, LocalDateTime>> EMPTY = Pair.of(null, Pair.of("",LocalDateTime.MIN));
- public static Pair<String, Pair<String, LocalDateTime>> last = EMPTY;
-
- @SubscribeEvent
- public void HandleChatEvent(ClientChatReceivedEvent sce) {
- if(CoflSky.Wrapper.isRunning && Configuration.getInstance().collectChat) {
- chatThreadPool.submit(() -> {
- String msg = sce.message.getUnformattedText();
- Matcher matcher = chatpattern.matcher(msg);
- boolean matchFound = matcher.find();
- if (matchFound) {
- Command<String[]> data = new Command<>(CommandType.chatBatch, new String[]{msg});
- CoflSky.Wrapper.SendMessage(data);
- }
- });
- }
-
- }
-
- public static long lastStartTime = Long.MIN_VALUE;
-
- public static long LastViewAuctionInvocation = Long.MIN_VALUE;
- public static String LastViewAuctionUUID =null;
-
- @SideOnly(Side.CLIENT)
- @SubscribeEvent
- public void OnGuiClick(GuiScreenEvent.MouseInputEvent mie) {
- if (!CoflSky.Wrapper.isRunning) return;
- if (!(mie.gui instanceof GuiChest)) return; // verify that it's really a chest
- if (!(((GuiChest) mie.gui).inventorySlots instanceof ContainerChest)) return;
- ContainerChest chest = (ContainerChest) ((GuiChest) mie.gui).inventorySlots;
- IInventory inv = chest.getLowerChestInventory();
- if (inv.hasCustomName()) { // verify that the chest actually has a custom name
- String chestName = inv.getName();
- if (chestName.equalsIgnoreCase("BIN Auction View")) {
-
- ItemStack heldItem = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
-
- if (heldItem != null) {
- System.out.println("Clicked on: " + heldItem.getItem().getRegistryName());
-
- String itemUUID = ExtractUuidFromInventory(inv);
-
- if(System.currentTimeMillis() > lastStartTime) {
-
- if (heldItem.isItemEqual(GOLD_NUGGET)) {
- AuctionData ad = new AuctionData();
- ad.setItemId(itemUUID);
-
- if((LastViewAuctionInvocation+60*1000) >= System.currentTimeMillis()) {
- ad.setAuctionId(LastViewAuctionUUID);
- } else {
- ad.setAuctionId("");
- }
-
- Command<AuctionData> data = new Command<>(CommandType.PurchaseStart, ad);
- CoflSky.Wrapper.SendMessage(data);
- System.out.println("PurchaseStart");
- last = Pair.of("You claimed ", Pair.of(itemUUID, LocalDateTime.now()));
- lastStartTime = System.currentTimeMillis() + 200 /*ensure a small debounce*/;
- }
- }
- }
- }
- }
- }
-
- @SubscribeEvent
+ public static Pattern chatpattern = Pattern.compile("a^", Pattern.CASE_INSENSITIVE);
+ public final ExecutorService chatThreadPool = Executors.newFixedThreadPool(2);
+ public final ExecutorService tickThreadPool = Executors.newFixedThreadPool(2);
+
+ @SubscribeEvent
+ public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) {
+ if (CoflSky.Wrapper.isRunning) {
+ System.out.println("Disconnected from server");
+ CoflSky.Wrapper.stop();
+ System.out.println("CoflSky stopped");
+ }
+ }
+
+ public long LastClick = System.currentTimeMillis();
+ private DescriptionHandler descriptionHandler;
+
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
+ public void onKeyEvent(KeyInputEvent event) {
+
+ if (CoflSky.keyBindings[0].isPressed()) {
+ if (WSCommandHandler.lastOnClickEvent != null) {
+ FlipData f = WSCommandHandler.flipHandler.fds.GetLastFlip();
+ if (f != null) {
+ WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " false", Minecraft.getMinecraft().thePlayer);
+ }
+ }
+
+ }
+ if (CoflSky.keyBindings[1].isKeyDown()) {
+ if ((System.currentTimeMillis() - LastClick) >= 300) {
+
+ FlipData f = WSCommandHandler.flipHandler.fds.GetHighestFlip();
+
+ if (f != null) {
+ WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " true", Minecraft.getMinecraft().thePlayer);
+ EventRegistry.LastViewAuctionUUID = f.Id;
+ EventRegistry.LastViewAuctionInvocation = System.currentTimeMillis();
+ LastClick = System.currentTimeMillis();
+ String command = WSClient.gson.toJson("/viewauction " + f.Id);
+
+ CoflSky.Wrapper.SendMessage(new JsonStringCommand(CommandType.Clicked, command));
+ WSCommandHandler.Execute("/cofl track besthotkey " + f.Id, Minecraft.getMinecraft().thePlayer);
+ } else {
+ // only display message once (if this is the key down event)
+ if (CoflSky.keyBindings[1].isPressed())
+ WSCommandHandler.Execute("/cofl dialog nobestflip", Minecraft.getMinecraft().thePlayer);
+ }
+ }
+ }
+ }
+
+ @SideOnly(Side.CLIENT)
+ //@SubscribeEvent
+ public void DrawOntoGUI(RenderGameOverlayEvent rgoe) {
+
+ if (rgoe.type == ElementType.CROSSHAIRS) {
+ Minecraft mc = Minecraft.getMinecraft();
+ mc.ingameGUI.drawString(Minecraft.getMinecraft().fontRendererObj, "Flips in Pipeline:" + WSCommandHandler.flipHandler.fds.CurrentFlips(), 0, 0, Integer.MAX_VALUE);
+ }
+ }
+
+ public static String ExtractUuidFromInventory(IInventory inventory) {
+
+ ItemStack stack = inventory.getStackInSlot(13);
+ if (stack != null) {
+ try {
+ String uuid = stack.serializeNBT().getCompoundTag("tag").getCompoundTag("ExtraAttributes").getString("uuid");
+ if (uuid.length() == 0) {
+ throw new Exception();
+ }
+ System.out.println("Item has the UUID: " + uuid);
+ return uuid;
+ } catch (Exception e) {
+ System.out.println("Clicked item " + stack.getDisplayName() + " has the following meta: " + stack.serializeNBT());
+ }
+ }
+ return "";
+ }
+
+ public static ItemStack GOLD_NUGGET = new ItemStack(Item.itemRegistry.getObject(new ResourceLocation("minecraft:gold_nugget")));
+
+ public static final Pair<String, Pair<String, LocalDateTime>> EMPTY = Pair.of(null, Pair.of("", LocalDateTime.MIN));
+ public static Pair<String, Pair<String, LocalDateTime>> last = EMPTY;
+
+ @SubscribeEvent
+ public void HandleChatEvent(ClientChatReceivedEvent sce) {
+ if (CoflSky.Wrapper.isRunning && Configuration.getInstance().collectChat) {
+ chatThreadPool.submit(() -> {
+ String msg = sce.message.getUnformattedText();
+ Matcher matcher = chatpattern.matcher(msg);
+ boolean matchFound = matcher.find();
+ if (matchFound) {
+ Command<String[]> data = new Command<>(CommandType.chatBatch, new String[]{msg});
+ CoflSky.Wrapper.SendMessage(data);
+ }
+ });
+ }
+
+ }
+
+ public static long lastStartTime = Long.MIN_VALUE;
+
+ public static long LastViewAuctionInvocation = Long.MIN_VALUE;
+ public static String LastViewAuctionUUID = null;
+
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void OnGuiClick(GuiScreenEvent.MouseInputEvent mie) {
+ if (!CoflSky.Wrapper.isRunning) return;
+ if (!(mie.gui instanceof GuiChest)) return; // verify that it's really a chest
+ if (!(((GuiChest) mie.gui).inventorySlots instanceof ContainerChest)) return;
+ ContainerChest chest = (ContainerChest) ((GuiChest) mie.gui).inventorySlots;
+ IInventory inv = chest.getLowerChestInventory();
+ if (inv.hasCustomName()) { // verify that the chest actually has a custom name
+ String chestName = inv.getName();
+ if (chestName.equalsIgnoreCase("BIN Auction View")) {
+
+ ItemStack heldItem = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
+
+ if (heldItem != null) {
+ System.out.println("Clicked on: " + heldItem.getItem().getRegistryName());
+
+ String itemUUID = ExtractUuidFromInventory(inv);
+
+ if (System.currentTimeMillis() > lastStartTime) {
+
+ if (heldItem.isItemEqual(GOLD_NUGGET)) {
+ AuctionData ad = new AuctionData();
+ ad.setItemId(itemUUID);
+
+ if ((LastViewAuctionInvocation + 60 * 1000) >= System.currentTimeMillis()) {
+ ad.setAuctionId(LastViewAuctionUUID);
+ } else {
+ ad.setAuctionId("");
+ }
+
+ Command<AuctionData> data = new Command<>(CommandType.PurchaseStart, ad);
+ CoflSky.Wrapper.SendMessage(data);
+ System.out.println("PurchaseStart");
+ last = Pair.of("You claimed ", Pair.of(itemUUID, LocalDateTime.now()));
+ lastStartTime = System.currentTimeMillis() + 200 /*ensure a small debounce*/;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
public void OnRenderTick(TickEvent.RenderTickEvent event) {
- de.torui.coflsky.CountdownTimer.onRenderTick(event);
- }
-
- int UpdateThisTick = 0;
- @SubscribeEvent(priority = EventPriority.LOWEST)
- public void onTick(TickEvent.ClientTickEvent event) {
- UpdateThisTick++;
- if (UpdateThisTick >= 200) UpdateThisTick = 0;
- if (UpdateThisTick == 0) {
- tickThreadPool.submit(() -> {
- ScoreboardData();
- TabMenuData();
- });
- }
- }
-
- @SubscribeEvent(priority = EventPriority.LOWEST)
- public void onGuiOpen(GuiOpenEvent event) {
- if (!config.extendedtooltips) return;
- if(descriptionHandler != null)
- descriptionHandler.Close();
- if(event.gui == null)
- emptyTooltipData();
-
- if (!(event.gui instanceof GuiContainer)) return;
- new Thread(() -> {
- try {
- descriptionHandler = new DescriptionHandler();
- descriptionHandler.loadDescriptionAndListenForChanges(event);
- } catch (Exception e)
- {
- System.out.println("failed to update description " + e);
- }
- }).start();
- }
- @SubscribeEvent(priority = EventPriority.HIGHEST)
- public void onItemTooltipEvent(ItemTooltipEvent event) {
- if (!config.extendedtooltips) return;
- if(descriptionHandler == null) return;
- descriptionHandler.setTooltips(event);
- }
+ de.torui.coflsky.CountdownTimer.onRenderTick(event);
+ }
+
+ int UpdateThisTick = 0;
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public void onTick(TickEvent.ClientTickEvent event) {
+ UpdateThisTick++;
+ if (UpdateThisTick >= 200) UpdateThisTick = 0;
+ if (UpdateThisTick == 0) {
+ tickThreadPool.submit(() -> {
+ ScoreboardData();
+ TabMenuData();
+ });
+ }
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public void onGuiOpen(GuiOpenEvent event) {
+
+ // if gui is null, a gui was closed
+ // therefore clear the lastClickFlipMessage, so it doesn't show on other auctions
+ if (event.gui == null) {
+ WSCommandHandler.flipHandler.lastClickedFlipMessage = "";
+ }
+
+ if (!config.extendedtooltips) return;
+ if (descriptionHandler != null) descriptionHandler.Close();
+ if (event.gui == null) emptyTooltipData();
+
+ if (!(event.gui instanceof GuiContainer)) return;
+ new Thread(() -> {
+ try {
+ descriptionHandler = new DescriptionHandler();
+ descriptionHandler.loadDescriptionAndListenForChanges(event);
+ } catch (Exception e) {
+ System.out.println("failed to update description " + e);
+ }
+ }).start();
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ public void onItemTooltipEvent(ItemTooltipEvent event) {
+ if (!config.extendedtooltips) return;
+ if (descriptionHandler == null) return;
+ descriptionHandler.setTooltips(event);
+ }
}