mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 21:06:16 +00:00
refactor: merge self-care ticks into one so no spam too
This commit is contained in:
parent
051a2b2f27
commit
2f7b1268c6
1 changed files with 10 additions and 31 deletions
|
|
@ -17,9 +17,8 @@ import java.util.TimerTask;
|
||||||
import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand;
|
import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand;
|
||||||
|
|
||||||
public class SelfCare implements Listener {
|
public class SelfCare implements Listener {
|
||||||
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config?
|
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 500L); // make the intervals in config?
|
||||||
public final long interval;
|
public final long interval;
|
||||||
public final long chatInterval;
|
|
||||||
private final MinecraftClient client;
|
private final MinecraftClient client;
|
||||||
public boolean opEnabled = ChipmunkMod.CONFIG.selfCare.op;
|
public boolean opEnabled = ChipmunkMod.CONFIG.selfCare.op;
|
||||||
public boolean gamemodeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode;
|
public boolean gamemodeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode;
|
||||||
|
|
@ -28,15 +27,13 @@ public class SelfCare implements Listener {
|
||||||
public boolean hasSkin = false;
|
public boolean hasSkin = false;
|
||||||
private int gameMode;
|
private int gameMode;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private Timer chatTimer;
|
|
||||||
private boolean cspy = false;
|
private boolean cspy = false;
|
||||||
|
|
||||||
public SelfCare (final MinecraftClient client, final long interval, final long chatInterval) {
|
public SelfCare (final MinecraftClient client, final long interval) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
this.chatInterval = chatInterval;
|
|
||||||
|
|
||||||
this.skin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername; // can this be null?
|
this.skin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername;
|
||||||
|
|
||||||
ListenerManager.addListener(this);
|
ListenerManager.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
@ -51,28 +48,17 @@ public class SelfCare implements Listener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final TimerTask chatTask = new TimerTask() {
|
|
||||||
public void run () {
|
|
||||||
chatTick();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
chatTimer = new Timer();
|
|
||||||
|
|
||||||
timer.schedule(task, interval, interval);
|
timer.schedule(task, interval, interval);
|
||||||
chatTimer.schedule(chatTask, chatInterval, chatInterval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup () {
|
public void cleanup () {
|
||||||
if (timer == null || chatTimer == null) return;
|
if (timer == null) return;
|
||||||
|
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
timer.purge();
|
timer.purge();
|
||||||
|
|
||||||
chatTimer.cancel();
|
|
||||||
chatTimer.purge();
|
|
||||||
|
|
||||||
gameMode = -1;
|
gameMode = -1;
|
||||||
|
|
||||||
hasSkin = false;
|
hasSkin = false;
|
||||||
|
|
@ -104,19 +90,12 @@ public class SelfCare implements Listener {
|
||||||
|
|
||||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op"))
|
if (player != null && !player.hasPermissionLevel(2) && opEnabled && serverHasCommand("op"))
|
||||||
networkHandler.sendChatCommand("op @s[type=player]");
|
networkHandler.sendChatCommand("op @s[type=player]");
|
||||||
else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
|
else if (gameMode != 1 && gamemodeEnabled)
|
||||||
}
|
networkHandler.sendChatCommand("gamemode creative");
|
||||||
|
else if (!cspy && cspyEnabled && serverHasCommand("c"))
|
||||||
public void chatTick () {
|
networkHandler.sendChatCommand("c on");
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
else if (!hasSkin && !skin.equalsIgnoreCase("off"))
|
||||||
|
networkHandler.sendChatCommand("skin " + skin);
|
||||||
if (networkHandler == null) return;
|
|
||||||
|
|
||||||
if (!cspy && cspyEnabled) {
|
|
||||||
if (serverHasCommand("c")) networkHandler.sendChatCommand("c on");
|
|
||||||
} else if (!hasSkin && !skin.equals("off")) {
|
|
||||||
if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue