diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index 4fb5f01..febcbab 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -37,8 +37,8 @@ public class CommandManager { SayCommand.register(this.dispatcher); AutoSkinCommand.register(this.dispatcher); ReloadConfigCommand.register(this.dispatcher); -// LoopCrouchCommand.register(this.dispatcher); // ^??????????????????? DebugCommand.register(this.dispatcher); + SelfCareCommand.register(this.dispatcher); ClearAntiChatSpamQueueCommand.register(this.dispatcher); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java index 8aa3cc9..3b2b6a4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/SelfCareCommand.java @@ -1,11 +1,27 @@ package land.chipmunk.chipmunkmod.commands; +import com.mojang.authlib.GameProfile; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.SuggestionContext; +import land.chipmunk.chipmunkmod.ChipmunkMod; +import land.chipmunk.chipmunkmod.Configuration; import land.chipmunk.chipmunkmod.modules.SelfCare; +import land.chipmunk.chipmunkmod.testclient.modules.anti_annoyances.SelfCareModule; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.client.network.ServerInfo; +import net.minecraft.server.ServerMetadata; import net.minecraft.text.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; import static com.mojang.brigadier.arguments.BoolArgumentType.bool; import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; @@ -13,6 +29,8 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.literal; public class SelfCareCommand { + private static final Logger log = LoggerFactory.getLogger(SelfCareCommand.class); + public static void register (CommandDispatcher dispatcher) { dispatcher.register( literal("selfcare") @@ -44,6 +62,57 @@ public class SelfCareCommand { .executes(m -> setSelfCare(m, "icu")) ) ) + .then( + literal("skin") + .then( + argument("skin", StringArgumentType.string()) + .executes(context -> { + final FabricClientCommandSource source = context.getSource(); + final String skin = StringArgumentType.getString(context, "skin"); + + SelfCare.INSTANCE.hasSkin = false; + SelfCare.INSTANCE.skin = skin; + if(skin.equals("off")) { + SelfCareModule.instance.skinOption.setOptionValue(false); + source.sendFeedback(Text.literal("Disabled skin self care")); + } else { + SelfCareModule.instance.skinOption.setOptionValue(true); + SelfCareModule.instance.skinUsernameOption.setOptionValue(skin); + source.sendFeedback(Text.literal("Skin self care enabled for " + skin + "'s skin")); + } + + return Command.SINGLE_SUCCESS; + }) + .suggests((context, builder) -> { + List possibilities = new ArrayList<>(); + possibilities.add("off"); + + String currentContext; + try { + currentContext = StringArgumentType.getString(context, "skin"); + } catch(IllegalArgumentException e) { + currentContext = ""; + } + ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); + if(networkHandler == null) { + // probably impossible, but can't hurt having this + possibilities.add(ChipmunkMod.CONFIG.defaultUsername); + } else { + for(PlayerListEntry player : networkHandler.getPlayerList()) { + log.info("Found possibility {}", player.getProfile().getName()); + possibilities.add(player.getProfile().getName()); + } + } + + for(String possibility : possibilities) { + if(possibility.toLowerCase().startsWith(currentContext.toLowerCase())) { + builder.suggest(possibility); + } + } + return builder.buildFuture(); + }) + ) + ) ); } @@ -55,18 +124,22 @@ public class SelfCareCommand { switch (type) { case "op" -> { SelfCare.INSTANCE.opEnabled = bool; + SelfCareModule.instance.opOption.setOptionValue(bool); source.sendFeedback(Text.literal("The op self care is now " + (bool ? "enabled" : "disabled"))); } case "gamemode" -> { SelfCare.INSTANCE.gamemodeEnabled = bool; + SelfCareModule.instance.gmcOption.setOptionValue(bool); source.sendFeedback(Text.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled"))); } case "cspy" -> { SelfCare.INSTANCE.cspyEnabled = bool; + SelfCareModule.instance.cspyOption.setOptionValue(bool); source.sendFeedback(Text.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled"))); } case "icu" -> { SelfCare.INSTANCE.icuEnabled = bool; + SelfCareModule.instance.icuOption.setOptionValue(bool); source.sendFeedback(Text.literal("The iControlU self care is now " + (bool ? "enabled" : "disabled"))); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/Option.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/Option.java index d65f369..adf9a1c 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/Option.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/Option.java @@ -13,9 +13,11 @@ public abstract class Option { optionValue = defaultValue; } - public ModuleMemory.Option toMemoryOption() {return new ModuleMemory.Option<>(name, optionValue);} public Class getType() {return (Class) optionValue.getClass();} // ignore this error intellij has the stupid + + // these two should match perfectly, meaning that setValueFromString(getValueAsString()); should do nothing public abstract void setValueFromString(String string); public abstract String getValueAsString(); - // these two should match perfectly, meaning that setValueFromString(getValueAsString()); should do nothing + + public abstract void setOptionValue(ValueType optionValue); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java index 201773d..afa8755 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/BooleanCheckboxOption.java @@ -37,8 +37,7 @@ public class BooleanCheckboxOption extends Option { @Override public void setValueFromString(String string) { - optionValue = Boolean.valueOf(string); - checkboxWidget.checked = optionValue; + setOptionValue(Boolean.valueOf(string)); } @Override @@ -46,6 +45,12 @@ public class BooleanCheckboxOption extends Option { return Boolean.toString(optionValue); } + @Override + public void setOptionValue(Boolean optionValue) { + this.optionValue = optionValue; + this.checkboxWidget.checked = optionValue; + } + public interface RunnableWithParameter { void run(T value); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/DoubleSliderOption.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/DoubleSliderOption.java index 6cd0cc6..c8ede92 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/DoubleSliderOption.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/DoubleSliderOption.java @@ -56,11 +56,17 @@ public class DoubleSliderOption extends Option { } public void setValueFromString(String string) { - optionValue = Double.valueOf(string); - sliderWidget.value = (optionValue - minValue) / (maxValue - minValue); - sliderWidget.updateMessage(); + setOptionValue(Double.valueOf(string)); } + public String getValueAsString() { return Double.toString(optionValue); } + + @Override + public void setOptionValue(Double optionValue) { + this.optionValue = optionValue; + sliderWidget.value = (optionValue - minValue) / (maxValue - minValue); + sliderWidget.updateMessage(); + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/IntSliderOption.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/IntSliderOption.java index 1b4fc78..f5e0ab4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/IntSliderOption.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/IntSliderOption.java @@ -38,7 +38,12 @@ public class IntSliderOption extends Option { @Override public void setValueFromString(String string) { - optionValue = Integer.valueOf(string); + this.setOptionValue(Integer.valueOf(string)); + } + + @Override + public void setOptionValue(Integer optionValue) { + this.optionValue = optionValue; sliderWidget.value = (double) (optionValue - minValue) / (maxValue - minValue); sliderWidget.updateMessage(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/StringOption.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/StringOption.java index 8ceae48..86bc81e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/StringOption.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/gui/components/options/StringOption.java @@ -30,7 +30,12 @@ public class StringOption extends Option { @Override public void setValueFromString(String string) { - optionValue = string; // pro conversion + setOptionValue(string); + } + + @Override + public void setOptionValue(String optionValue) { + this.optionValue = optionValue; textFieldWidget.setText(optionValue); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/anti_annoyances/SelfCareModule.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/anti_annoyances/SelfCareModule.java index 60cd1d8..f12ca85 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/anti_annoyances/SelfCareModule.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/anti_annoyances/SelfCareModule.java @@ -8,45 +8,55 @@ import land.chipmunk.chipmunkmod.testclient.gui.components.options.StringOption; public class SelfCareModule extends Module { public static SelfCareModule instance = new SelfCareModule(); - BooleanCheckboxOption opOption = new BooleanCheckboxOption( + public BooleanCheckboxOption opOption = new BooleanCheckboxOption( "OP", SelfCare.INSTANCE.opEnabled, value -> SelfCare.INSTANCE.opEnabled = value ); - BooleanCheckboxOption gmcOption = new BooleanCheckboxOption( + public BooleanCheckboxOption gmcOption = new BooleanCheckboxOption( "Creative mode", SelfCare.INSTANCE.gamemodeEnabled, value -> SelfCare.INSTANCE.gamemodeEnabled = value ); - BooleanCheckboxOption cspyOption = new BooleanCheckboxOption( + public BooleanCheckboxOption cspyOption = new BooleanCheckboxOption( "Command spy", SelfCare.INSTANCE.cspyEnabled, value -> SelfCare.INSTANCE.cspyEnabled = value ); - StringOption skinUsernameOption = new StringOption( - "Skin's username", - ChipmunkMod.CONFIG.defaultUsername, - s -> { - SelfCare.INSTANCE.hasSkin = false; + public BooleanCheckboxOption icuOption = new BooleanCheckboxOption( + "ICU", + SelfCare.INSTANCE.icuEnabled, + value -> SelfCare.INSTANCE.icuEnabled = value + ); + // split because skinUsernameOption and skinOption need to reference each other in their onChanged + public StringOption skinUsernameOption; + public BooleanCheckboxOption skinOption = new BooleanCheckboxOption( + "Skin", + SelfCare.INSTANCE.skin.equals("off"), + value -> { + SelfCare.INSTANCE.skin = value ? skinUsernameOption.optionValue : "off"; } ); - BooleanCheckboxOption skinOption = new BooleanCheckboxOption( - "Skin", - SelfCare.INSTANCE.skin.equals("off") -// value -> { -// SelfCare.INSTANCE.skin = value ? skinUsernameOption.optionValue : "off"; -// } - ); + public SelfCareModule() { super("Self care"); + skinUsernameOption = new StringOption( + "Skin's username", + ChipmunkMod.CONFIG.defaultUsername, + s -> { + SelfCare.INSTANCE.hasSkin = false; + SelfCare.INSTANCE.skin = skinOption.optionValue ? s : "off"; + } + ); withOption(opOption); withOption(gmcOption); withOption(cspyOption); + withOption(icuOption); withOption(skinOption); withOption(skinUsernameOption); - endTickRunnable = () -> { + /*endTickRunnable = () -> { // make it update the skin self acre username SelfCare.INSTANCE.skin = skinOption.optionValue ? skinUsernameOption.optionValue : "off"; - }; + };*/ } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/fun/RainbowNameModule.java b/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/fun/RainbowNameModule.java index 26ca124..cad60e0 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/fun/RainbowNameModule.java +++ b/src/main/java/land/chipmunk/chipmunkmod/testclient/modules/fun/RainbowNameModule.java @@ -53,6 +53,9 @@ public class RainbowNameModule extends Module { public String getValueAsString() { return "null"; } + + @Override + public void setOptionValue(Void optionValue) { } } public static class MutableTextWidget extends TextWidget {