From e578d454908f8ab8efc185cf3d34ba76521922bf Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 16 Jul 2023 18:36:23 +0700 Subject: [PATCH] bring back .selfcare it's so hard to toggle the self cares --- .../chipmunkmod/command/CommandManager.java | 1 + .../chipmunkmod/commands/SelfCareCommand.java | 65 +++++++++++++++++++ .../mixin/SharedConstantsMixin.java | 16 +++++ src/main/resources/chipmunkmod.mixins.json | 3 +- 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index 6e438f8..5861999 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -38,6 +38,7 @@ public class CommandManager { SayCommand.register(this.dispatcher); AutoSkinCommand.register(this.dispatcher); ReloadConfigCommand.register(this.dispatcher); + SelfCareCommand.register(this.dispatcher); } public void executeCommand (String command) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java new file mode 100644 index 0000000..d80e00f --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java @@ -0,0 +1,65 @@ +package land.chipmunk.chipmunkmod.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import land.chipmunk.chipmunkmod.modules.SelfCare; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.text.Text; + +import static com.mojang.brigadier.arguments.BoolArgumentType.bool; +import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; +import static land.chipmunk.chipmunkmod.command.CommandManager.argument; +import static land.chipmunk.chipmunkmod.command.CommandManager.literal; + +public class SelfCareCommand { + public static void register (CommandDispatcher dispatcher) { + dispatcher.register( + literal("selfcare") + .then( + literal("op") + .then( + argument("boolean", bool()) + .executes(m -> setSelfCare(m, "op")) + ) + ) + .then( + literal("gamemode") + .then( + argument("boolean", bool()) + .executes(m -> setSelfCare(m, "gamemode")) + ) + ) + .then( + literal("cspy") + .then( + argument("boolean", bool()) + .executes(m -> setSelfCare(m, "cspy")) + ) + ) + ); + } + + // setSelfCare is probably not a good name for this + public static int setSelfCare (CommandContext context, String type) { + final FabricClientCommandSource source = context.getSource(); + final boolean bool = getBool(context, "boolean"); + + switch (type) { + case "op" -> { + SelfCare.INSTANCE.opEnabled = bool; + source.sendFeedback(Text.literal("The op self care is now " + (bool ? "enabled" : "disabled"))); + } + case "gamemode" -> { + SelfCare.INSTANCE.gamemodeEnabled = bool; + source.sendFeedback(Text.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled"))); + } + case "cspy" -> { + SelfCare.INSTANCE.cspyEnabled = bool; + source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled"))); + } + } + + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java new file mode 100644 index 0000000..ac5e810 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java @@ -0,0 +1,16 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.SharedConstants; +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.CallbackInfoReturnable; + +@Mixin(SharedConstants.class) +public class SharedConstantsMixin { + @Inject(method = "isValidChar", at = @At("HEAD"), cancellable = true) + private static void isValidChar (char chr, CallbackInfoReturnable cir) { + cir.setReturnValue(chr >= ' ' && chr != '\u007f'); + cir.cancel(); + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 063bc82..53d3953 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -20,7 +20,8 @@ "TextMixin", "ClientConnectionInvoker", "ClientConnectionAccessor", - "PlayerListEntryAccessor" + "PlayerListEntryAccessor", + "SharedConstantsMixin" ], "injectors": { "defaultRequire": 1