mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-12-30 04:56:52 +00:00
feat: use target game mode based on F3 + F4 instead of hardcoding creative (idea from ZenZoya, thank you!)
refactor: add some braces + change variable names in SelfCare to be less confusing
This commit is contained in:
parent
51f181ce69
commit
4142d41d64
3 changed files with 42 additions and 22 deletions
|
|
@ -28,10 +28,11 @@ public class AutoSkinCommand {
|
||||||
|
|
||||||
final String username = getString(context, "username");
|
final String username = getString(context, "username");
|
||||||
|
|
||||||
SelfCare.INSTANCE.skin = username;
|
SelfCare.INSTANCE.targetSkin = username;
|
||||||
|
|
||||||
if (username.equals("off")) source.sendFeedback(Text.literal("Successfully disabled auto skin"));
|
if (username.equals("off")) {
|
||||||
else {
|
source.sendFeedback(Text.literal("Successfully disabled auto skin"));
|
||||||
|
} else {
|
||||||
SelfCare.INSTANCE.hasSkin = false;
|
SelfCare.INSTANCE.hasSkin = false;
|
||||||
source.sendFeedback(Text.literal("Set your auto skin username to: " + username));
|
source.sendFeedback(Text.literal("Set your auto skin username to: " + username));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,15 +46,15 @@ public class SelfCareCommand {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "op" -> {
|
case "op" -> {
|
||||||
SelfCare.INSTANCE.opEnabled = bool;
|
SelfCare.INSTANCE.configOpEnabled = bool;
|
||||||
source.sendFeedback(Text.literal("The op self care is now " + (bool ? "enabled" : "disabled")));
|
source.sendFeedback(Text.literal("The op self care is now " + (bool ? "enabled" : "disabled")));
|
||||||
}
|
}
|
||||||
case "gamemode" -> {
|
case "gamemode" -> {
|
||||||
SelfCare.INSTANCE.gamemodeEnabled = bool;
|
SelfCare.INSTANCE.configGameModeEnabled = bool;
|
||||||
source.sendFeedback(Text.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled")));
|
source.sendFeedback(Text.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled")));
|
||||||
}
|
}
|
||||||
case "cspy" -> {
|
case "cspy" -> {
|
||||||
SelfCare.INSTANCE.cspyEnabled = bool;
|
SelfCare.INSTANCE.configCommandSpyEnabled = bool;
|
||||||
source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled")));
|
source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.command.DefaultPermissions;
|
import net.minecraft.command.DefaultPermissions;
|
||||||
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.network.packet.c2s.play.ChangeGameModeC2SPacket;
|
import net.minecraft.network.packet.c2s.play.ChangeGameModeC2SPacket;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.world.GameMode;
|
import net.minecraft.world.GameMode;
|
||||||
|
|
@ -15,18 +16,24 @@ 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());
|
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance());
|
||||||
|
|
||||||
private final MinecraftClient client;
|
private final MinecraftClient client;
|
||||||
public boolean opEnabled = ChipmunkMod.CONFIG.selfCare.op;
|
|
||||||
public boolean gamemodeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode;
|
public boolean configOpEnabled = ChipmunkMod.CONFIG.selfCare.op;
|
||||||
public boolean cspyEnabled = ChipmunkMod.CONFIG.selfCare.cspy;
|
public boolean configGameModeEnabled = ChipmunkMod.CONFIG.selfCare.gameMode;
|
||||||
public String skin;
|
public boolean configCommandSpyEnabled = ChipmunkMod.CONFIG.selfCare.cspy;
|
||||||
|
|
||||||
|
public GameMode targetGameMode = GameMode.CREATIVE;
|
||||||
|
|
||||||
|
public String targetSkin;
|
||||||
public boolean hasSkin = false;
|
public boolean hasSkin = false;
|
||||||
private boolean cspy = false;
|
|
||||||
|
private boolean isCommandSpyEnabled = false;
|
||||||
|
|
||||||
public SelfCare (final MinecraftClient client) {
|
public SelfCare (final MinecraftClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
this.skin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername;
|
this.targetSkin = ChipmunkMod.CONFIG.autoSkinUsername == null ? "off" : ChipmunkMod.CONFIG.autoSkinUsername;
|
||||||
|
|
||||||
ListenerManager.addListener(this);
|
ListenerManager.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
@ -36,17 +43,17 @@ public class SelfCare implements Listener {
|
||||||
|
|
||||||
public void cleanup () {
|
public void cleanup () {
|
||||||
hasSkin = false;
|
hasSkin = false;
|
||||||
cspy = false;
|
isCommandSpyEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void chatMessageReceived (final Text message) {
|
public void chatMessageReceived (final Text message) {
|
||||||
final String stringMessage = message.getString();
|
final String stringMessage = message.getString();
|
||||||
|
|
||||||
if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true;
|
if (stringMessage.equals("Successfully enabled CommandSpy")) isCommandSpyEnabled = true;
|
||||||
else if (stringMessage.equals("Successfully disabled CommandSpy")) cspy = false;
|
else if (stringMessage.equals("Successfully disabled CommandSpy")) isCommandSpyEnabled = false;
|
||||||
|
|
||||||
else if (stringMessage.equals("Successfully set your skin to " + skin + "'s")) hasSkin = true;
|
else if (stringMessage.equals("Successfully set your skin to " + targetSkin + "'s")) hasSkin = true;
|
||||||
else if (
|
else if (
|
||||||
stringMessage.equals("Successfully removed your skin") ||
|
stringMessage.equals("Successfully removed your skin") ||
|
||||||
stringMessage.startsWith("Successfully set your skin to ")
|
stringMessage.startsWith("Successfully set your skin to ")
|
||||||
|
|
@ -60,12 +67,16 @@ public class SelfCare implements Listener {
|
||||||
|
|
||||||
if (networkHandler == null || player == null) return;
|
if (networkHandler == null || player == null) return;
|
||||||
|
|
||||||
if (!player.getPermissions().hasPermission(DefaultPermissions.OWNERS) && opEnabled && serverHasCommand("op"))
|
if (
|
||||||
|
!player.getPermissions().hasPermission(DefaultPermissions.OWNERS)
|
||||||
|
&& configOpEnabled
|
||||||
|
&& serverHasCommand("op")
|
||||||
|
) {
|
||||||
networkHandler.sendChatCommand("op @s[type=player]");
|
networkHandler.sendChatCommand("op @s[type=player]");
|
||||||
else if (!player.isInCreativeMode() && gamemodeEnabled)
|
} else if (player.getGameMode() != targetGameMode && configGameModeEnabled) {
|
||||||
// ViaVersion will automatically convert this to `/gamemode creative`
|
// ViaVersion will automatically convert this to `/gamemode creative`
|
||||||
networkHandler.sendPacket(new ChangeGameModeC2SPacket(GameMode.CREATIVE));
|
networkHandler.sendPacket(new ChangeGameModeC2SPacket(targetGameMode));
|
||||||
else if (!cspy && cspyEnabled && serverHasCommand("c"))
|
} else if (!isCommandSpyEnabled && configCommandSpyEnabled && serverHasCommand("c")) {
|
||||||
if (
|
if (
|
||||||
!CommandCore.INSTANCE.ready
|
!CommandCore.INSTANCE.ready
|
||||||
|| !CommandCore.INSTANCE.runFillCommand
|
|| !CommandCore.INSTANCE.runFillCommand
|
||||||
|
|
@ -75,7 +86,15 @@ public class SelfCare implements Listener {
|
||||||
} else {
|
} else {
|
||||||
CommandCore.INSTANCE.run("c " + player.getUuidAsString() + " on");
|
CommandCore.INSTANCE.run("c " + player.getUuidAsString() + " on");
|
||||||
}
|
}
|
||||||
else if (!hasSkin && !skin.equalsIgnoreCase("off"))
|
} else if (!hasSkin && !targetSkin.equalsIgnoreCase("off")) {
|
||||||
networkHandler.sendChatCommand("skin " + skin);
|
networkHandler.sendChatCommand("skin " + targetSkin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void packetSent (final Packet<?> packet) {
|
||||||
|
if (packet instanceof ChangeGameModeC2SPacket (final GameMode mode)) {
|
||||||
|
targetGameMode = mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue