fix self care + some improvements

This commit is contained in:
Chayapak 2023-07-06 19:05:48 +07:00
parent 143a47162d
commit 2452f555ef
3 changed files with 33 additions and 14 deletions

View file

@ -3,6 +3,7 @@ package land.chipmunk.chipmunkmod;
import com.google.gson.GsonBuilder;
import land.chipmunk.chipmunkmod.modules.KaboomCheck;
import land.chipmunk.chipmunkmod.modules.Players;
import land.chipmunk.chipmunkmod.modules.SelfCare;
import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter;
import net.fabricmc.api.ModInitializer;
import java.io.InputStream;
@ -46,6 +47,7 @@ public class ChipmunkMod implements ModInitializer {
Players.INSTANCE.init();
KaboomCheck.INSTANCE.init();
SelfCare.INSTANCE.init();
LOGGER.info("Loaded ChipmunkMod (chayapak's fork)");
}

View file

@ -7,13 +7,11 @@ import land.chipmunk.chipmunkmod.modules.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientDynamicRegistryType;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.util.telemetry.WorldSession;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.registry.CombinedDynamicRegistries;
import net.minecraft.resource.featuretoggle.FeatureSet;
@ -39,7 +37,7 @@ public class ClientPlayNetworkHandlerMixin {
KaboomCheck.INSTANCE.onJoin();
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
SelfCare.INSTANCE.init();
SelfCare.INSTANCE.onJoin();
LoopCrouch.INSTANCE.init();
SongPlayer.INSTANCE.coreReady();
RainbowName.INSTANCE.init();

View file

@ -3,11 +3,12 @@ package land.chipmunk.chipmunkmod.modules;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
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.text.Text;
import java.util.Timer;
@ -24,14 +25,16 @@ public class SelfCare extends Listener {
public boolean gamemodeEnabled = true;
public boolean cspyEnabled = true;
public String skin;
private int gameMode;
private boolean cspy = false;
public boolean hasSkin = false;
public String skin;
private Timer timer = null;
private Timer chatTimer = null;
private boolean cspy = false;
public boolean hasSkin = false;
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config?
public SelfCare (MinecraftClient client, long interval, long chatInterval) {
@ -44,7 +47,9 @@ public class SelfCare extends Listener {
ListenerManager.addListener(this);
}
public void init () {
public void init () {}
public void onJoin () {
final TimerTask task = new TimerTask() {
public void run () {
tick();
@ -57,8 +62,6 @@ public class SelfCare extends Listener {
}
};
if (timer != null || chatTimer != null) cleanup();
timer = new Timer();
chatTimer = new Timer();
@ -71,11 +74,11 @@ public class SelfCare extends Listener {
timer.cancel();
timer.purge();
timer = null;
chatTimer.cancel();
chatTimer.purge();
chatTimer = null;
gameMode = -1;
hasSkin = false;
// cspy too mabe?
@ -105,7 +108,7 @@ public class SelfCare extends Listener {
}
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
else if (client.player != null && !client.player.isCreative() && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
}
public void chatTick () {
@ -114,4 +117,20 @@ public class SelfCare extends Listener {
if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); }
else if (!hasSkin && !skin.equals("off")) { if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin); }
}
@Override
public void packetReceived(Packet<?> packet) {
if (packet instanceof GameJoinS2CPacket) packetReceived((GameJoinS2CPacket) packet);
else if (packet instanceof GameStateChangeS2CPacket) packetReceived((GameStateChangeS2CPacket) packet);
}
public void packetReceived(GameJoinS2CPacket packet) {
gameMode = packet.gameMode().getId();
}
public void packetReceived(GameStateChangeS2CPacket packet) {
if (packet.getReason() != GameStateChangeS2CPacket.GAME_MODE_CHANGED) return;
gameMode = (int) packet.getValue();
}
}