forked from ChomeNS/chipmunkmod
Readded selfcare command + other selfcare fixes
This commit is contained in:
parent
4dbf7925cc
commit
8b6b7b71fc
9 changed files with 136 additions and 27 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<FabricClientCommandSource> 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<String> 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")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,11 @@ public abstract class Option<ValueType> {
|
|||
optionValue = defaultValue;
|
||||
}
|
||||
|
||||
public ModuleMemory.Option<ValueType> toMemoryOption() {return new ModuleMemory.Option<>(name, optionValue);}
|
||||
public Class<ValueType> getType() {return (Class<ValueType>) 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);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ public class BooleanCheckboxOption extends Option<Boolean> {
|
|||
|
||||
@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<Boolean> {
|
|||
return Boolean.toString(optionValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOptionValue(Boolean optionValue) {
|
||||
this.optionValue = optionValue;
|
||||
this.checkboxWidget.checked = optionValue;
|
||||
}
|
||||
|
||||
public interface RunnableWithParameter<T> {
|
||||
void run(T value);
|
||||
}
|
||||
|
|
|
@ -56,11 +56,17 @@ public class DoubleSliderOption extends Option<Double> {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,12 @@ public class IntSliderOption extends Option<Integer> {
|
|||
|
||||
@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();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,12 @@ public class StringOption extends Option<String> {
|
|||
|
||||
@Override
|
||||
public void setValueFromString(String string) {
|
||||
optionValue = string; // pro conversion
|
||||
setOptionValue(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOptionValue(String optionValue) {
|
||||
this.optionValue = optionValue;
|
||||
textFieldWidget.setText(optionValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
};
|
||||
};*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue