summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBuildTools <james.jenour@protonmail.com>2021-02-10 13:23:12 +0800
committerBuildTools <james.jenour@protonmail.com>2021-02-10 13:23:12 +0800
commita2292c332c22646bd177eaf3123ce31a74991e36 (patch)
tree18c130658f22bc79336a400fe3701a45efe166ff
parente782e847ccc0eadc4d6e58068ed36d30ce233899 (diff)
downloadNotEnoughUpdates-a2292c332c22646bd177eaf3123ce31a74991e36.tar.gz
NotEnoughUpdates-a2292c332c22646bd177eaf3123ce31a74991e36.tar.bz2
NotEnoughUpdates-a2292c332c22646bd177eaf3123ce31a74991e36.zip
improved locraw stuffs
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java19
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java30
-rw-r--r--src/main/resources/mixins.notenoughupdates.json3
3 files changed, 45 insertions, 7 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java
new file mode 100644
index 00000000..6b1065ea
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java
@@ -0,0 +1,19 @@
+package io.github.moulberry.notenoughupdates.mixins;
+
+import io.github.moulberry.notenoughupdates.util.SBInfo;
+import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.client.gui.GuiScreen;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(GuiScreen.class)
+public class MixinGuiScreen {
+
+ @Inject(method = "sendChatMessage(Ljava/lang/String;Z)V", at=@At("HEAD"))
+ public void onSendChatMessage(String message, boolean addToChat, CallbackInfo ci) {
+ SBInfo.getInstance().onSendChatMessage(message);
+ }
+
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
index 314096aa..a17c9ec9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
@@ -13,6 +13,7 @@ import net.minecraft.scoreboard.Scoreboard;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.event.world.WorldEvent;
+import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@@ -45,7 +46,9 @@ public class SBInfo {
return INSTANCE;
}
+ private long lastManualLocRaw = -1;
private long lastLocRaw = -1;
+ private long joinedWorld = -1;
private JsonObject locraw = null;
@SubscribeEvent
@@ -66,16 +69,26 @@ public class SBInfo {
lastLocRaw = -1;
locraw = null;
mode = null;
+ joinedWorld = System.currentTimeMillis();
lastOpenContainerName = null;
}
- @SubscribeEvent
+ private static final Pattern JSON_BRACKET_PATTERN = Pattern.compile("\\{.+}");
+
+ public void onSendChatMessage(String msg) {
+ if(msg.trim().startsWith("/locraw") || msg.trim().startsWith("/locraw ")) {
+ lastManualLocRaw = System.currentTimeMillis();
+ }
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
public void onChatMessage(ClientChatReceivedEvent event) {
- if(event.message.getUnformattedText().startsWith("{")) {
+ Matcher matcher = JSON_BRACKET_PATTERN.matcher(event.message.getUnformattedText());
+ if(matcher.find()) {
try {
- JsonObject obj = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(event.message.getUnformattedText(), JsonObject.class);
+ JsonObject obj = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(matcher.group(), JsonObject.class);
if(obj.has("server")) {
- if(true || System.currentTimeMillis() - lastLocRaw < 5000) event.setCanceled(true);
+ if(System.currentTimeMillis() - lastManualLocRaw > 5000) event.setCanceled(true);
if(obj.has("gametype") && obj.has("mode") && obj.has("map")) {
locraw = obj;
mode = locraw.get("mode").getAsString();
@@ -95,8 +108,13 @@ public class SBInfo {
}
public void tick() {
- if(Minecraft.getMinecraft().theWorld != null &&
- locraw == null && (System.currentTimeMillis() - lastLocRaw) > 20000) {
+ long currentTime = System.currentTimeMillis();
+
+ if(Minecraft.getMinecraft().thePlayer != null &&
+ Minecraft.getMinecraft().theWorld != null &&
+ locraw == null &&
+ (currentTime - joinedWorld) > 1000 &&
+ (currentTime - lastLocRaw) > 10000) {
lastLocRaw = System.currentTimeMillis();
NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw");
}
diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json
index 00df32a6..5a71282c 100644
--- a/src/main/resources/mixins.notenoughupdates.json
+++ b/src/main/resources/mixins.notenoughupdates.json
@@ -24,6 +24,7 @@
"MixinLayerCreeperCharge",
"MixinEffectRenderer",
"MixinRendererLivingEntity",
- "GuiEditSignAccessor"
+ "GuiEditSignAccessor",
+ "MixinGuiScreen"
]
} \ No newline at end of file