From 82b5259b443cb16eb1a1afa1bfb4361140ef4085 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 17 Aug 2023 17:35:10 +0700 Subject: [PATCH] icu slef care --- .../chipmunkmod/commands/SelfCareCommand.java | 11 +++++++++ .../chipmunkmod/modules/SelfCare.java | 24 +++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java index d80e00f..8aa3cc9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java @@ -37,6 +37,13 @@ public class SelfCareCommand { .executes(m -> setSelfCare(m, "cspy")) ) ) + .then( + literal("icu") + .then( + argument("boolean", bool()) + .executes(m -> setSelfCare(m, "icu")) + ) + ) ); } @@ -58,6 +65,10 @@ public class SelfCareCommand { SelfCare.INSTANCE.cspyEnabled = bool; source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled"))); } + case "icu" -> { + SelfCare.INSTANCE.icuEnabled = bool; + source.sendFeedback(Text.literal("The iControlU self care is now " + (bool ? "enabled" : "disabled"))); + } } return Command.SINGLE_SUCCESS; diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java index 3fc5aff..8bd3d50 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java @@ -9,6 +9,7 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; import net.minecraft.text.Text; import java.util.Timer; @@ -24,17 +25,20 @@ public class SelfCare extends Listener { public boolean opEnabled = true; public boolean gamemodeEnabled = true; public boolean cspyEnabled = true; + public boolean icuEnabled = true; private int gameMode; public String skin; - private Timer timer = null; - private Timer chatTimer = null; + private Timer timer = new Timer(); + private Timer chatTimer = new Timer(); private boolean cspy = false; public boolean hasSkin = false; + private int positionPacketsPerSecond = 0; + public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config? public SelfCare (MinecraftClient client, long interval, long chatInterval) { @@ -62,9 +66,6 @@ public class SelfCare extends Listener { } }; - timer = new Timer(); - chatTimer = new Timer(); - timer.schedule(task, interval, interval); chatTimer.schedule(chatTask, chatInterval, chatInterval); } @@ -109,6 +110,7 @@ public class SelfCare extends Listener { if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); } else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative"); + else if (positionPacketsPerSecond >= 10 && icuEnabled) CommandCore.INSTANCE.run("sudo * icu stop"); } public void chatTick () { @@ -122,6 +124,7 @@ public class SelfCare extends Listener { public void packetReceived(Packet packet) { if (packet instanceof GameJoinS2CPacket) packetReceived((GameJoinS2CPacket) packet); else if (packet instanceof GameStateChangeS2CPacket) packetReceived((GameStateChangeS2CPacket) packet); + else if (packet instanceof PlayerPositionLookS2CPacket) packetReceived((PlayerPositionLookS2CPacket) packet); } public void packetReceived(GameJoinS2CPacket packet) { @@ -133,4 +136,15 @@ public class SelfCare extends Listener { gameMode = (int) packet.getValue(); } + + public void packetReceived(PlayerPositionLookS2CPacket packet) { + positionPacketsPerSecond++; + + timer.schedule(new TimerTask() { + @Override + public void run() { + positionPacketsPerSecond--; + } + }, 1000); + } }