Remove the crhomebook

This commit is contained in:
7cc5c4f330d47060 2024-10-24 20:43:42 -04:00
parent 9b5d92c008
commit 656ec359c7
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
4 changed files with 2 additions and 177 deletions

View file

@ -6,7 +6,6 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.TextFieldWidget;
@ -57,28 +56,7 @@ public class ChatInputSuggestorMixin {
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
final String textUpToCursor = text.substring(0, cursor);
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
.stream()
.map((command) -> command.name)
.toList();
pendingSuggestions = CommandSource.suggestMatching(
commands,
new SuggestionsBuilder(
textUpToCursor,
getStartOfCurrentWord(textUpToCursor)
)
);
pendingSuggestions.thenRun(() -> {
if (!pendingSuggestions.isDone()) return;
show(true);
});
} else if (cursor > commandManager.prefix.length() && text.startsWith(commandManager.prefix)) {
if (cursor > commandManager.prefix.length() && text.startsWith(commandManager.prefix)) {
final StringReader reader = new StringReader(text);
reader.setCursor(commandManager.prefix.length()); // Skip the prefix

View file

@ -3,7 +3,6 @@ package land.chipmunk.chipmunkmod.mixin;
import com.google.gson.JsonObject;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
@ -38,66 +37,6 @@ public class ChatScreenMixin extends Screen {
client.inGameHud.getChatHud().addToMessageHistory(chatText);
}
if (ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith(ChipmunkMod.CONFIG.bots.testbot.prefix)) {
ChipmunkMod.executorService.submit(() -> {
try {
final URL url = new URL(ChipmunkMod.CONFIG.bots.testbot.webhookUrl);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("User-Agent", "ChipmunkMod");
connection.setDoOutput(true);
connection.setRequestMethod("POST");
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("username", "ChipmunkMod UwU");
jsonObject.addProperty("content", MinecraftClient.getInstance().getSession().getUsername());
final OutputStream stream = connection.getOutputStream();
stream.write(jsonObject.toString().getBytes());
stream.flush();
stream.close();
connection.getInputStream().close();
connection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
});
} else if (chatText.startsWith(ChipmunkMod.CONFIG.bots.chomens.prefix)) {
final List<ChomeNSBotCommand> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands;
final List<String> moreOrTrustedCommands = commands.stream()
.filter((command) -> command.trustLevel != ChomeNSBotCommand.TrustLevel.PUBLIC)
.map((command) -> command.name.toLowerCase())
.toList();
final List<String> aliases = new ArrayList<>();
for (ChomeNSBotCommand command : commands) {
if (command.trustLevel == ChomeNSBotCommand.TrustLevel.PUBLIC) continue;
aliases.addAll(command.aliases);
}
final String chatCommand = chatText.toLowerCase().split("\\s")[0];
final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length();
if (
moreOrTrustedCommands.contains(chatCommand) ||
aliases.contains(chatCommand.substring(prefixLength))
) {
try {
BotValidationUtilities.chomens(chatText.substring(prefixLength));
cir.cancel();
return;
} catch (Exception ignored) {}
}
}
if (client == null) return;
if (chatText.startsWith("/")) {

View file

@ -52,7 +52,6 @@ public class ClientPlayNetworkHandlerMixin {
CommandCore.INSTANCE.init();
SongPlayer.INSTANCE.coreReady();
RainbowName.INSTANCE.init();
ChomeNSBotCommandSuggestions.INSTANCE.init();
ChomeNSAuth.INSTANCE.init();
CustomChat.INSTANCE.init();
}
@ -84,10 +83,9 @@ public class ClientPlayNetworkHandlerMixin {
}
try {
final String suggestionId = message.getSiblings().getFirst().getString();
final String authId = ((PlainTextContent) message.getContent()).string();
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) {
if (authId.equals(ChomeNSAuth.INSTANCE.id)) {
ci.cancel();
}
} catch (Exception ignored) {}

View file

@ -1,90 +0,0 @@
package land.chipmunk.chipmunkmod.modules;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import land.chipmunk.chipmunkmod.util.UUIDUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.PlainTextContent;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
public class ChomeNSBotCommandSuggestions extends Listener {
public static final String ID = "chomens_bot_request_command_suggestion";
public static ChomeNSBotCommandSuggestions INSTANCE = new ChomeNSBotCommandSuggestions(MinecraftClient.getInstance());
private final MinecraftClient client;
public List<ChomeNSBotCommand> commands = new ArrayList<>();
public ChomeNSBotCommandSuggestions (MinecraftClient client) {
this.client = client;
ListenerManager.addListener(this);
}
public void init () {}
@Override
public void coreMoved () { forceRequest(); }
public void forceRequest () {
final ClientPlayerEntity player = client.player;
if (player == null) return;
final String selector = UUIDUtilities.selector(player.getUuid());
final Component component = Component
.text(ID)
.append(Component.text(selector));
final String serialized = GsonComponentSerializer.gson().serialize(component);
CommandCore.INSTANCE.run("tellraw @a[tag=chomens_bot] " + serialized);
}
@Override
public void chatMessageReceived(Text message) {
try {
final List<Text> children = message.getSiblings();
if (children.isEmpty()) return;
final Text textComponent = children.getFirst();
if (!textComponent.getString().equals(ID)) return;
commands = children.subList(1, children.size())
.stream()
.map(
(eachComponent) -> {
final ChomeNSBotCommand command = new ChomeNSBotCommand(
ChipmunkMod.CONFIG.bots.chomens.prefix + ((PlainTextContent) eachComponent.getContent()).string(),
ChomeNSBotCommand.TrustLevel.valueOf(eachComponent.getSiblings().getFirst().getString())
);
if (!Boolean.parseBoolean(eachComponent.getSiblings().get(1).getString())) return command;
final List<Text> subList = eachComponent.getSiblings().subList(2, eachComponent.getSiblings().size());
for (Text aliasComponent : subList) {
final String alias = aliasComponent.getString();
command.aliases.add(alias);
}
return command;
}
)
.toList();
} catch (Exception ignored) {}
}
}