aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/torui/coflsky/commands/CommandType.java2
-rw-r--r--src/main/java/de/torui/coflsky/configuration/Configuration.java1
-rw-r--r--src/main/java/de/torui/coflsky/handlers/EventHandler.java90
-rw-r--r--src/main/java/de/torui/coflsky/handlers/EventRegistry.java106
-rw-r--r--src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java2
-rw-r--r--src/main/java/de/torui/coflsky/minecraft_integration/PlayerDataProvider.java28
6 files changed, 154 insertions, 75 deletions
diff --git a/src/main/java/de/torui/coflsky/commands/CommandType.java b/src/main/java/de/torui/coflsky/commands/CommandType.java
index d7de3b1..3f551f7 100644
--- a/src/main/java/de/torui/coflsky/commands/CommandType.java
+++ b/src/main/java/de/torui/coflsky/commands/CommandType.java
@@ -53,6 +53,8 @@ public enum CommandType {
chatBatch,
@SerializedName("uploadTab")
uploadTab,
+ @SerializedName("uploadScoreboard")
+ uploadScoreboard,
@SerializedName("getMods")
GetMods,
@SerializedName("proxy")
diff --git a/src/main/java/de/torui/coflsky/configuration/Configuration.java b/src/main/java/de/torui/coflsky/configuration/Configuration.java
index 58ca4fd..ed2de05 100644
--- a/src/main/java/de/torui/coflsky/configuration/Configuration.java
+++ b/src/main/java/de/torui/coflsky/configuration/Configuration.java
@@ -35,6 +35,7 @@ public class Configuration {
public boolean collectChatClicks;
public boolean collectLobbyChanges;
public boolean collectEntities;
+ public boolean collectLocation;
public boolean autoStart;
@Description("Wherever or not to send item descriptions for extending to the server")
public boolean extendDescriptions;
diff --git a/src/main/java/de/torui/coflsky/handlers/EventHandler.java b/src/main/java/de/torui/coflsky/handlers/EventHandler.java
index ad25159..52c7552 100644
--- a/src/main/java/de/torui/coflsky/handlers/EventHandler.java
+++ b/src/main/java/de/torui/coflsky/handlers/EventHandler.java
@@ -4,6 +4,8 @@ import de.torui.coflsky.CoflSky;
import de.torui.coflsky.commands.Command;
import de.torui.coflsky.commands.CommandType;
import de.torui.coflsky.configuration.Configuration;
+import de.torui.coflsky.minecraft_integration.PlayerDataProvider;
+import de.torui.coflsky.minecraft_integration.PlayerDataProvider.PlayerPosition;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.event.ClickEvent;
@@ -29,7 +31,7 @@ public class EventHandler {
private static String server = "";
public static void TabMenuData() {
- if (isInSkyblock && CoflSky.Wrapper.isRunning && Configuration.getInstance().collectTab){
+ if (isInSkyblock && CoflSky.Wrapper.isRunning && Configuration.getInstance().collectTab) {
List<String> tabdata = getTabList();
int size = tabdata.size() - 1;
for (int i = 0; i < tabdata.size(); i++) {
@@ -46,6 +48,13 @@ public class EventHandler {
CoflSky.Wrapper.SendMessage(data);
}
+ public static void UploadScoreboardData() {
+ if (!CoflSky.Wrapper.isRunning)
+ return;
+ Command<List<String>> data = new Command<>(CommandType.uploadScoreboard, getScoreboard());
+ CoflSky.Wrapper.SendMessage(data);
+ }
+
public static void ScoreboardData() {
String s;
try {
@@ -56,32 +65,38 @@ public class EventHandler {
return;
}
checkIfInSkyblock(s);
- if (isInSkyblock && CoflSky.Wrapper.isRunning) {
- List<String> scoreBoardLines = getScoreboard();
- int size = scoreBoardLines.size() - 1;
- boolean hasFoundCatacombs = false;
- for (int i = 0; i < scoreBoardLines.size(); i++) {
- String line = EnumChatFormatting.getTextWithoutFormattingCodes(scoreBoardLines.get(size - i).toLowerCase());
- if (line.contains("the catacombs")) {
- hasFoundCatacombs = true;
- }
- if (Configuration.getInstance().collectScoreboard) {
- ProcessScoreboard(line);
- }
+ if (!isInSkyblock || !CoflSky.Wrapper.isRunning)
+ return;
+ List<String> scoreBoardLines = getScoreboard();
+ int size = scoreBoardLines.size() - 1;
+ for (int i = 0; i < scoreBoardLines.size(); i++) {
+ String line = EnumChatFormatting.getTextWithoutFormattingCodes(scoreBoardLines.get(size - i).toLowerCase());
+ if (Configuration.getInstance().collectScoreboard) {
+ ProcessScoreboard(line);
}
- if (hasFoundCatacombs && !isInTheCatacombs) {
- Command<String> data = new Command<>(CommandType.set, "disableFlips true");
- CoflSky.Wrapper.SendMessage(data);
- isInTheCatacombs = true;
- }
- if (isInTheCatacombs && !hasFoundCatacombs) {
- Command<String> data = new Command<>(CommandType.set, "disableFlips false");
- CoflSky.Wrapper.SendMessage(data);
- isInTheCatacombs = false;
+ if (line.contains("⏣") && !line.equals(location)) {
+ location = line;
+ try {
+ Thread.sleep(20);
+ UploadLocation();
+ Thread.sleep(20);
+ UploadScoreboardData();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
}
+
+ private static void UploadLocation() {
+ if (!Configuration.getInstance().collectLocation)
+ return;
+ Command<PlayerPosition> data = new Command<>(CommandType.updateLocation,
+ PlayerDataProvider.getPlayerPosition());
+ CoflSky.Wrapper.SendMessage(data);
+ }
+
private static List<String> getScoreboard() {
ArrayList<String> scoreboardAsText = new ArrayList<>();
if (Minecraft.getMinecraft() == null || Minecraft.getMinecraft().theWorld == null) {
@@ -104,7 +119,7 @@ public class EventHandler {
ScorePlayerTeam scorePlayerTeam = scoreboard.getPlayersTeam(playerName);
String lineText = EnumChatFormatting.getTextWithoutFormattingCodes(
ScorePlayerTeam.formatPlayerName(scorePlayerTeam, line.getPlayerName()));
- scoreboardAsText.add(lineText.replace(line.getPlayerName(),""));
+ scoreboardAsText.add(lineText.replace(line.getPlayerName(), ""));
}
return scoreboardAsText;
}
@@ -120,39 +135,33 @@ public class EventHandler {
if (playerInfo.getDisplayName() != null) {
toDisplay = playerInfo.getDisplayName().getFormattedText();
} else {
- toDisplay = ScorePlayerTeam.formatPlayerName(playerInfo.getPlayerTeam(), playerInfo.getGameProfile().getName());
+ toDisplay = ScorePlayerTeam.formatPlayerName(playerInfo.getPlayerTeam(),
+ playerInfo.getGameProfile().getName());
}
tabListAsString.add(EnumChatFormatting.getTextWithoutFormattingCodes(toDisplay));
}
return tabListAsString;
}
+
private static void ProcessTabMenu(String line) {
- if (Configuration.getInstance().collectLobbyChanges && line.contains("server:")) {
+ if (line.contains("server:")) {
String server_ = line.split("server: ")[1];
if (!server.equals(server_)) {
server = server_;
- Command<String> data = new Command<>(CommandType.updateServer, server);
- CoflSky.Wrapper.SendMessage(data);
UploadTabData();
}
- } else if (line.contains("area:")) {
- String location_ = line.split("area: ")[1];
- if (!location.equals(location_)) {
- location = location_;
- Command<String> data = new Command<>(CommandType.updateLocation, location);
- CoflSky.Wrapper.SendMessage(data);
- }
}
}
+
private static void checkIfInSkyblock(String s) {
if (s.contains("SKYBLOCK") && !isInSkyblock) {
- if (config.autoStart){
+ if (config.autoStart) {
CoflSky.Wrapper.stop();
CoflSky.Wrapper.startConnection();
}
isInSkyblock = true;
} else if (!s.contains("SKYBLOCK") && isInSkyblock) {
- if (config.autoStart){
+ if (config.autoStart) {
CoflSky.Wrapper.stop();
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("connection to ")
.appendSibling(new ChatComponentText("C").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_BLUE)))
@@ -168,18 +177,21 @@ public class EventHandler {
isInSkyblock = false;
}
}
- private static void ProcessScoreboard(String line){
+
+ private static void ProcessScoreboard(String line) {
if (line.contains("purse") || line.contains("piggy")) {
long purse_ = 0;
try {
- purse_ = parseLong(line.split(" ")[1].replace(",", ""));
- } catch (NumberFormatException e) {
+ purse_ = parseLong(line.split(" ")[1].replace(",", "").split("\\.")[0]);
+ } catch (Exception e) {
e.printStackTrace();
+ System.out.println("unparsable purse: " + line);
}
if (purse != purse_) {
purse = purse_;
Command<Long> data = new Command<>(CommandType.updatePurse, purse);
CoflSky.Wrapper.SendMessage(data);
+ UploadLocation();
}
} else if (line.contains("bits")) {
long bits_ = 0;
diff --git a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
index 4bf800b..a88e703 100644
--- a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
+++ b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java
@@ -3,6 +3,7 @@ package de.torui.coflsky.handlers;
import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -67,7 +68,8 @@ public class EventRegistry {
if (WSCommandHandler.lastOnClickEvent != null) {
FlipData f = WSCommandHandler.flipHandler.fds.GetLastFlip();
if (f != null) {
- WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " false", Minecraft.getMinecraft().thePlayer);
+ WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " false",
+ Minecraft.getMinecraft().thePlayer);
}
}
@@ -78,7 +80,8 @@ public class EventRegistry {
FlipData f = WSCommandHandler.flipHandler.fds.GetHighestFlip();
if (f != null) {
- WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " true", Minecraft.getMinecraft().thePlayer);
+ WSCommandHandler.Execute("/cofl openAuctionGUI " + f.Id + " true",
+ Minecraft.getMinecraft().thePlayer);
EventRegistry.LastViewAuctionUUID = f.Id;
EventRegistry.LastViewAuctionInvocation = System.currentTimeMillis();
LastClick = System.currentTimeMillis();
@@ -96,12 +99,13 @@ public class EventRegistry {
}
@SideOnly(Side.CLIENT)
- //@SubscribeEvent
+ // @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);
+ mc.ingameGUI.drawString(Minecraft.getMinecraft().fontRendererObj,
+ "Flips in Pipeline:" + WSCommandHandler.flipHandler.fds.CurrentFlips(), 0, 0, Integer.MAX_VALUE);
}
}
@@ -110,38 +114,65 @@ public class EventRegistry {
ItemStack stack = inventory.getStackInSlot(13);
if (stack != null) {
try {
- String uuid = stack.serializeNBT().getCompoundTag("tag").getCompoundTag("ExtraAttributes").getString("uuid");
+ 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());
+ 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 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;
+ private LocalDateTime lastBatchStart = LocalDateTime.now();
+ private LinkedBlockingQueue<String> chatBatch = new LinkedBlockingQueue<String>();
@SubscribeEvent
public void HandleChatEvent(ClientChatReceivedEvent sce) {
- if (CoflSky.Wrapper.isRunning && Configuration.getInstance().collectChat) {
- chatThreadPool.submit(() -> {
+ if (!CoflSky.Wrapper.isRunning || !Configuration.getInstance().collectChat)
+ return;
+ chatThreadPool.submit(() -> {
+ try {
+
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);
+ if (!matchFound)
+ return;
+
+ chatBatch.add(msg);
+ // add 500ms to the last batch start time
+ long nanoSeconds = 500_000_000;
+ if (!lastBatchStart.plusNanos(nanoSeconds).isBefore(LocalDateTime.now())) {
+ System.out.println(msg + " was not sent because it was too soon");
+ return;
}
- });
- }
+ lastBatchStart = LocalDateTime.now();
+
+ new java.util.Timer().schedule(new java.util.TimerTask() {
+ @Override
+ public void run() {
+ System.out.println("Sending batch of " + chatBatch.size() + " messages");
+ Command<String[]> data = new Command<>(CommandType.chatBatch, chatBatch.toArray(new String[0]));
+ chatBatch.clear();
+ CoflSky.Wrapper.SendMessage(data);
+ }
+ }, 500);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
}
public static long lastStartTime = Long.MIN_VALUE;
@@ -152,9 +183,12 @@ public class EventRegistry {
@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;
+ 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
@@ -184,7 +218,7 @@ public class EventRegistry {
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*/;
+ lastStartTime = System.currentTimeMillis() + 200 /* ensure a small debounce */;
}
}
}
@@ -197,16 +231,19 @@ public class EventRegistry {
de.torui.coflsky.CountdownTimer.onRenderTick(event);
}
- int UpdateThisTick = 0;
+ long UpdateThisTick = 0;
- @SubscribeEvent(priority = EventPriority.LOWEST)
+ @SubscribeEvent(priority = EventPriority.LOW)
public void onTick(TickEvent.ClientTickEvent event) {
UpdateThisTick++;
- if (UpdateThisTick >= 200) UpdateThisTick = 0;
- if (UpdateThisTick == 0) {
+ if (UpdateThisTick % 200 == 0) {
tickThreadPool.submit(() -> {
- ScoreboardData();
- TabMenuData();
+ try {
+ ScoreboardData();
+ TabMenuData();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
});
}
}
@@ -215,16 +252,21 @@ public class EventRegistry {
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
+ // 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 (!config.extendedtooltips)
+ return;
+ if (descriptionHandler != null)
+ descriptionHandler.Close();
+ if (event.gui == null)
+ emptyTooltipData();
- if (!(event.gui instanceof GuiContainer)) return;
+ if (!(event.gui instanceof GuiContainer))
+ return;
new Thread(() -> {
try {
descriptionHandler = new DescriptionHandler();
@@ -237,8 +279,10 @@ public class EventRegistry {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onItemTooltipEvent(ItemTooltipEvent event) {
- if (!config.extendedtooltips) return;
- if (descriptionHandler == null) return;
+ if (!config.extendedtooltips)
+ return;
+ if (descriptionHandler == null)
+ return;
descriptionHandler.setTooltips(event);
}
}
diff --git a/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java b/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java
index cab0c15..9a4edea 100644
--- a/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java
+++ b/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java
@@ -86,7 +86,7 @@ public class CoflSessionManager {
}
public static boolean isValidSession(CoflSession session) {
- if(session.timestampCreated.plus(Duration.ofDays(14)).isAfter(ZonedDateTime.now())) {
+ if(session.timestampCreated.plus(Duration.ofDays(180)).isAfter(ZonedDateTime.now())) {
return true;
}
return false;
diff --git a/src/main/java/de/torui/coflsky/minecraft_integration/PlayerDataProvider.java b/src/main/java/de/torui/coflsky/minecraft_integration/PlayerDataProvider.java
index ede60ce..352aded 100644
--- a/src/main/java/de/torui/coflsky/minecraft_integration/PlayerDataProvider.java
+++ b/src/main/java/de/torui/coflsky/minecraft_integration/PlayerDataProvider.java
@@ -14,10 +14,20 @@ import net.minecraft.client.Minecraft;
public class PlayerDataProvider {
- private static class UUIDHelper {
- public String id;
- public String name;
- }
+ private static class UUIDHelper {
+ public String id;
+ public String name;
+ }
+
+ public static class PlayerPosition
+ {
+ public double X;
+ public double Y;
+ public double Z;
+ public float Yaw;
+ public float Pitch;
+
+ }
public static String getActivePlayerUUID() {
try {
@@ -65,5 +75,15 @@ public class PlayerDataProvider {
String username = Minecraft.getSessionInfo().get("X-Minecraft-Username");
return username;
}
+
+ public static PlayerPosition getPlayerPosition() {
+ PlayerPosition pos = new PlayerPosition();
+ pos.X = Minecraft.getMinecraft().thePlayer.posX;
+ pos.Y = Minecraft.getMinecraft().thePlayer.posY;
+ pos.Z = Minecraft.getMinecraft().thePlayer.posZ;
+ pos.Yaw = Minecraft.getMinecraft().thePlayer.rotationYaw;
+ pos.Pitch = Minecraft.getMinecraft().thePlayer.rotationPitch;
+ return pos;
+ }
}