aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorÄkwav <16632490+Ekwav@users.noreply.github.com>2021-11-06 07:18:55 +0100
committerGitHub <noreply@github.com>2021-11-06 07:18:55 +0100
commit4725394c6e80e857f17c512c49d9181cb7a6c553 (patch)
tree0085bfed875f3ba3e0d09f7a0b4e0b8b7f4ee1e4 /src/main
parent9cd8209e52a257c06eccb570eca6b5f67448b2af (diff)
parente0e4f7eeba3dd3e158b2c5095804dee5ced925ae (diff)
downloadCOFL-4725394c6e80e857f17c512c49d9181cb7a6c553.tar.gz
COFL-4725394c6e80e857f17c512c49d9181cb7a6c553.tar.bz2
COFL-4725394c6e80e857f17c512c49d9181cb7a6c553.zip
Merge pull request #36 from Coflnet/feature/server-callbacks
Feature/server callbacks
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/torui/coflsky/EventRegistry.java185
1 files changed, 128 insertions, 57 deletions
diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java
index f7d708c..62f5a27 100644
--- a/src/main/java/de/torui/coflsky/EventRegistry.java
+++ b/src/main/java/de/torui/coflsky/EventRegistry.java
@@ -1,89 +1,160 @@
package de.torui.coflsky;
-import java.util.UUID;
+import java.time.LocalDateTime;
+import com.mojang.realmsclient.util.Pair;
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.network.WSClient;
import net.minecraft.client.Minecraft;
-import net.minecraft.server.MinecraftServer;
-import net.minecraft.server.gui.MinecraftServerGui;
-import net.minecraftforge.event.world.WorldEvent;
-import net.minecraftforge.fml.client.FMLClientHandler;
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import net.minecraftforge.client.event.RenderGameOverlayEvent;
+import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
-import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
-import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
-import net.minecraftforge.fml.common.network.FMLNetworkEvent;
-import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
-import net.minecraftforge.fml.server.FMLServerHandler;
-public class EventRegistry{
+public class EventRegistry {
-
@SubscribeEvent
- public void onConnectedToServerEvent(ClientConnectedToServerEvent event) {
- /* if(!event.isLocal ) {
- //String serverIP = Minecraft.getMinecraft().getCurrentServerData().serverIP;
-
- /* if(false && serverIP.equals("hypixel.net")) {
-
- }*
- //UUID.randomUUID().toString();
-
- //String id = FMLClientHandler.instance().getClient().thePlayer.getUniqueID().toString();
-
- String id = UUID.randomUUID().toString();//Minecraft.getMinecraft().thePlayer.getUniqueID().toString();
- System.out.println("PlayerUUID:" + id);
- CoflSky.PlayerUUID = id;
-
- System.out.println("Connected to server");
- CoflSky.Wrapper.start();
- System.out.println("CoflSky started");
- }*/
- }
-
- @SubscribeEvent
- public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) {
- System.out.println("Disconnected from server");
- CoflSky.Wrapper.stop();
- System.out.println("CoflSky stopped");
+ public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) {
+ if(CoflSky.Wrapper.isRunning) {
+ System.out.println("Disconnected from server");
+ CoflSky.Wrapper.stop();
+ System.out.println("CoflSky stopped");
+ }
}
-
-
-
+
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onEvent(KeyInputEvent event) {
- if(CoflSky.keyBindings[0].isPressed()) {
+ if (CoflSky.keyBindings[0].isPressed()) {
+ if (WSCommandHandler.lastOnClickEvent != null) {
- if(WSCommandHandler.lastOnClickEvent != null) {
-
String command = WSCommandHandler.lastOnClickEvent;
WSCommandHandler.lastOnClickEvent = null;
- WSCommandHandler.HandleCommand(new JsonStringCommand(CommandType.Execute, WSClient.gson.toJson(command)),
+ WSCommandHandler.HandleCommand(
+ new JsonStringCommand(CommandType.Execute, WSClient.gson.toJson(command)),
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, "Hello World", 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().toString());
+ }
+ }
+ 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 && last.first() != null) {
+ if(sce.message.getUnformattedText().startsWith("You claimed ")) {
+
+ AuctionData ad = new AuctionData();
+ ad.setItemId(last.second().first());
+ ad.setAuctionId("");
+ Command<AuctionData> data = new Command<>(CommandType.PurchaseConfirm, ad);
+ CoflSky.Wrapper.SendMessage(data);
+ System.out.println("PurchaseConfirm");
+ last = EMPTY;
+ }
+ else if(last.second().second().plusSeconds(10).isBefore(LocalDateTime.now())) {
+ last = EMPTY;
+ }
}
}
- /*@SubscribeEvent
-public void OnSomething(FMLNetworkEvent.ClientConnectedToServerEvent event) {
- System.out.println("Client connect to server from network");
-}
-
- @SubscribeEvent
- public void PlayerLoggedOut(PlayerLoggedOutEvent ploe) {
- //CoflSky.Wrapper.stop();
- System.out.println("COFLSKY disabled");
- }*/
+
+ public static long lastStartTime = Long.MAX_VALUE;
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void OnGuiClick(GuiScreenEvent.MouseInputEvent mie) {
+ if (CoflSky.Wrapper.isRunning) {
+ if (mie.gui instanceof GuiChest) { // verify that it's really a chest
+
+ 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") || chestName.equalsIgnoreCase("Ekwav")) {
+
+ 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()+200) < lastStartTime) {
+
+ if (heldItem.isItemEqual(GOLD_NUGGET)) {
+ AuctionData ad = new AuctionData();
+ ad.setItemId(itemUUID);
+ 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();
+ }
+ }
+
+ }
+
+ }
+ }
+ }
+
+ }
+
+ }
}