add and fix stuff about chomens bot
15 files modified basically this fixes and improves the command suggestion and make the validation automatic
This commit is contained in:
parent
0aedbff525
commit
1b7ace7aa8
15 changed files with 336 additions and 248 deletions
|
@ -53,7 +53,7 @@ public class CommandManager {
|
||||||
if (context != null) commandSource.sendError(context);
|
if (context != null) commandSource.sendError(context);
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
commandSource.sendError(e.getTextMessage());
|
commandSource.sendError(e.getTextMessage());
|
||||||
} catch (RuntimeException e) {
|
} catch (Exception e) {
|
||||||
commandSource.sendError(Text.of(e.getMessage()));
|
commandSource.sendError(Text.of(e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,141 +1,28 @@
|
||||||
package land.chipmunk.chipmunkmod.commands;
|
package land.chipmunk.chipmunkmod.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
|
||||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
import java.util.Arrays;
|
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||||
import java.math.BigInteger;
|
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||||
import java.nio.charset.StandardCharsets;
|
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||||
import java.security.MessageDigest;
|
import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
|
||||||
import land.chipmunk.chipmunkmod.Configuration;
|
|
||||||
import land.chipmunk.chipmunkmod.util.Hexadecimal;
|
|
||||||
|
|
||||||
public class ValidateCommand {
|
public class ValidateCommand {
|
||||||
private static final SimpleCommandExceptionType UNSPECIFIED_KEY = new SimpleCommandExceptionType(Text.literal("The key of the bot is unspecified (null), did you incorrectly add it to your config?"));
|
|
||||||
|
|
||||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("validate")
|
literal("validate")
|
||||||
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(c))))
|
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))
|
||||||
.then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(c))))
|
.then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(getString(c, "command")))))
|
||||||
// .then(literal("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(c))))
|
// .then(literal("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(getString(c, "command")))))
|
||||||
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> chomens(c))))
|
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> {
|
||||||
.then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(c))))
|
c.getSource().sendFeedback(Text.literal("Warning: Manual ChomeNS Bot validation is deprecated"));
|
||||||
|
|
||||||
|
return chomens(getString(c, "command"));
|
||||||
|
})))
|
||||||
|
.then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(getString(c, "command")))))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int hbot (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
|
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.hbot;
|
|
||||||
final String command = getString(context, "command");
|
|
||||||
final MinecraftClient client = context.getSource().getClient();
|
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
|
||||||
|
|
||||||
final String prefix = info.prefix;
|
|
||||||
final String key = info.key;
|
|
||||||
if (key == null) throw UNSPECIFIED_KEY.create();
|
|
||||||
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
||||||
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
|
||||||
String input = command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key;
|
|
||||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
|
||||||
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
|
||||||
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
|
||||||
|
|
||||||
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int sbot (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
|
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot;
|
|
||||||
final String command = getString(context, "command");
|
|
||||||
final MinecraftClient client = context.getSource().getClient();
|
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
|
||||||
|
|
||||||
final String prefix = info.prefix;
|
|
||||||
final String key = info.key;
|
|
||||||
if (key == null) throw UNSPECIFIED_KEY.create();
|
|
||||||
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
||||||
String time = String.valueOf(System.currentTimeMillis() / 20000);
|
|
||||||
String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + client.player.getName() + ";" + time + ";" + key;
|
|
||||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
|
||||||
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
|
||||||
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
|
||||||
|
|
||||||
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int chomens (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
|
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens;
|
|
||||||
final String command = getString(context, "command");
|
|
||||||
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
|
|
||||||
|
|
||||||
final String prefix = info.prefix;
|
|
||||||
final String key = info.key;
|
|
||||||
if (key == null) throw UNSPECIFIED_KEY.create();
|
|
||||||
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
||||||
String time = String.valueOf(System.currentTimeMillis() / 5_000);
|
|
||||||
String input = time + key;
|
|
||||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
|
||||||
String stringHash = Hexadecimal.encode(hash).substring(0, 16);
|
|
||||||
|
|
||||||
String[] arguments = command.split(" ");
|
|
||||||
networkHandler.sendChatMessage(prefix + arguments[0] + " " + stringHash + " " + String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length)));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int kittycorp (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
|
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp;
|
|
||||||
final String command = getString(context, "command");
|
|
||||||
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
|
|
||||||
|
|
||||||
final String prefix = info.prefix;
|
|
||||||
final String key = info.key;
|
|
||||||
if (key == null) throw UNSPECIFIED_KEY.create();
|
|
||||||
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
|
||||||
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
|
||||||
String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + time + ";" + key;
|
|
||||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
|
||||||
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
|
||||||
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
|
||||||
|
|
||||||
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new SimpleCommandExceptionType(Text.literal(e.getMessage())).create();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package land.chipmunk.chipmunkmod.data;
|
||||||
|
|
||||||
|
public class ChomeNSBotCommand {
|
||||||
|
public final String name;
|
||||||
|
public final TrustLevel trustLevel;
|
||||||
|
|
||||||
|
public ChomeNSBotCommand (
|
||||||
|
String name,
|
||||||
|
TrustLevel trustLevel
|
||||||
|
) {
|
||||||
|
this.name = name;
|
||||||
|
this.trustLevel = trustLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TrustLevel {
|
||||||
|
PUBLIC,
|
||||||
|
TRUSTED,
|
||||||
|
OWNER
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,4 +9,8 @@ public class Listener {
|
||||||
public void packetReceived (Packet<?> packet) {}
|
public void packetReceived (Packet<?> packet) {}
|
||||||
|
|
||||||
public void packetSent (Packet<?> packet) {}
|
public void packetSent (Packet<?> packet) {}
|
||||||
|
|
||||||
|
public void coreReady () {}
|
||||||
|
|
||||||
|
public void coreMoved () {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
package land.chipmunk.chipmunkmod.mixin;
|
package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
|
||||||
import land.chipmunk.chipmunkmod.listeners.Listener;
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import land.chipmunk.chipmunkmod.modules.ChatInputGlobals;
|
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||||
import land.chipmunk.chipmunkmod.modules.RainbowName;
|
import land.chipmunk.chipmunkmod.modules.RainbowName;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.minecraft.client.gui.hud.MessageIndicator;
|
import net.minecraft.client.gui.hud.MessageIndicator;
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
|
||||||
import net.minecraft.command.CommandSource;
|
|
||||||
import net.minecraft.network.message.MessageSignatureData;
|
import net.minecraft.network.message.MessageSignatureData;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableTextContent;
|
import net.minecraft.text.TranslatableTextContent;
|
||||||
|
@ -18,8 +14,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(net.minecraft.client.gui.hud.ChatHud.class)
|
@Mixin(net.minecraft.client.gui.hud.ChatHud.class)
|
||||||
public class ChatHudMixin {
|
public class ChatHudMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", cancellable = true)
|
||||||
|
@ -43,40 +37,9 @@ public class ChatHudMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final List<Text> children = message.getSiblings();
|
if (((TextComponent) message.asComponent().children().get(0)).content().equals(ChomeNSBotCommandSuggestions.ID)) {
|
||||||
|
ci.cancel();
|
||||||
if (children.size() == 0) return;
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
if (!children.get(0).getString().equals("chomens_bot_command_suggestion")) return;
|
|
||||||
|
|
||||||
ci.cancel();
|
|
||||||
|
|
||||||
final String[] matches = children.subList(2, children.size())
|
|
||||||
.stream()
|
|
||||||
.map(Text::getString)
|
|
||||||
.toArray(String[]::new);
|
|
||||||
|
|
||||||
if (!(MinecraftClient.getInstance().currentScreen instanceof ChatScreen chatScreen)) return;
|
|
||||||
|
|
||||||
final ChatScreenAccessor chatScreenAccessor = (ChatScreenAccessor) chatScreen;
|
|
||||||
|
|
||||||
final ChatInputSuggestorAccessor chatInputSuggestorAccessor = (ChatInputSuggestorAccessor) chatScreenAccessor.chatInputSuggestor();
|
|
||||||
|
|
||||||
chatInputSuggestorAccessor.setPendingSuggestions(
|
|
||||||
CommandSource.suggestMatching(
|
|
||||||
matches,
|
|
||||||
new SuggestionsBuilder(
|
|
||||||
ChatInputGlobals.textUpToCursor,
|
|
||||||
ChipmunkMod.CONFIG.bots.chomens.prefix.length()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
chatInputSuggestorAccessor.pendingSuggestions().thenRun(() -> {
|
|
||||||
if (!chatInputSuggestorAccessor.pendingSuggestions().isDone()) return;
|
|
||||||
|
|
||||||
((ChatScreenAccessor) chatScreen).chatInputSuggestor().show(true);
|
|
||||||
});
|
|
||||||
} catch (ClassCastException | NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package land.chipmunk.chipmunkmod.mixin;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
|
||||||
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Mixin(ChatInputSuggestor.class)
|
|
||||||
public interface ChatInputSuggestorAccessor {
|
|
||||||
@Accessor("pendingSuggestions")
|
|
||||||
CompletableFuture<Suggestions> pendingSuggestions ();
|
|
||||||
|
|
||||||
@Accessor("pendingSuggestions")
|
|
||||||
void setPendingSuggestions (CompletableFuture<Suggestions> pendingSuggestions);
|
|
||||||
}
|
|
|
@ -3,18 +3,16 @@ package land.chipmunk.chipmunkmod.mixin;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||||
import land.chipmunk.chipmunkmod.modules.ChatInputGlobals;
|
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
||||||
import land.chipmunk.chipmunkmod.modules.CommandCore;
|
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||||
import land.chipmunk.chipmunkmod.modules.TransactionManager;
|
|
||||||
import land.chipmunk.chipmunkmod.util.UUIDUtilities;
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
import net.minecraft.command.CommandSource;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
@ -38,6 +36,11 @@ public class ChatInputSuggestorMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
public void show (boolean narrateFirstSuggestion) {}
|
public void show (boolean narrateFirstSuggestion) {}
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private static int getStartOfCurrentWord (String input) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Mutable
|
@Mutable
|
||||||
@Final
|
@Final
|
||||||
@Shadow
|
@Shadow
|
||||||
|
@ -47,8 +50,6 @@ public class ChatInputSuggestorMixin {
|
||||||
textField = null;
|
textField = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int transactionId = 0;
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "refresh()V")
|
@Inject(at = @At("TAIL"), method = "refresh()V")
|
||||||
public void refresh (CallbackInfo ci) {
|
public void refresh (CallbackInfo ci) {
|
||||||
if (slashOptional) return;
|
if (slashOptional) return;
|
||||||
|
@ -62,28 +63,27 @@ public class ChatInputSuggestorMixin {
|
||||||
|
|
||||||
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
|
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
|
||||||
|
|
||||||
if (text.startsWith(chomeNSPrefix) && player != null) {
|
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
|
||||||
final String textUpToCursor = text.substring(chomeNSPrefix.length(), Math.max(chomeNSPrefix.length(), cursor));
|
final String textUpToCursor = text.substring(0, cursor);
|
||||||
|
|
||||||
ChatInputGlobals.text = text;
|
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
|
||||||
ChatInputGlobals.cursor = cursor;
|
.stream()
|
||||||
ChatInputGlobals.textUpToCursor = textUpToCursor;
|
.map((command) -> command.name)
|
||||||
|
.toList();
|
||||||
|
|
||||||
final String selfSelector = UUIDUtilities.selector(player.getUuid());
|
pendingSuggestions = CommandSource.suggestMatching(
|
||||||
|
commands,
|
||||||
TransactionManager.INSTANCE.nextTransactionId();
|
new SuggestionsBuilder(
|
||||||
|
textUpToCursor,
|
||||||
final Component component = Component
|
getStartOfCurrentWord(textUpToCursor)
|
||||||
.text("chomens_bot_command_suggestion")
|
)
|
||||||
.append(Component.text(transactionId))
|
|
||||||
.append(Component.text(selfSelector))
|
|
||||||
.append(Component.text(textUpToCursor));
|
|
||||||
|
|
||||||
CommandCore.INSTANCE.run(
|
|
||||||
"minecraft:tellraw @a[tag=chomens_bot] " + GsonComponentSerializer.gson().serialize(component)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
transactionId++;
|
pendingSuggestions.thenRun(() -> {
|
||||||
|
if (!pendingSuggestions.isDone()) return;
|
||||||
|
|
||||||
|
show(true);
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package land.chipmunk.chipmunkmod.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(ChatScreen.class)
|
|
||||||
public interface ChatScreenAccessor {
|
|
||||||
@Accessor("chatInputSuggestor")
|
|
||||||
ChatInputSuggestor chatInputSuggestor ();
|
|
||||||
}
|
|
|
@ -2,7 +2,10 @@ package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||||
|
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
||||||
|
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||||
import land.chipmunk.chipmunkmod.modules.CustomChat;
|
import land.chipmunk.chipmunkmod.modules.CustomChat;
|
||||||
|
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
|
||||||
import land.chipmunk.chipmunkmod.util.Webhook;
|
import land.chipmunk.chipmunkmod.util.Webhook;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
||||||
|
@ -12,12 +15,14 @@ import net.minecraft.text.MutableText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(net.minecraft.client.gui.screen.ChatScreen.class)
|
@Mixin(net.minecraft.client.gui.screen.ChatScreen.class)
|
||||||
public class ChatScreenMixin extends Screen {
|
public class ChatScreenMixin extends Screen {
|
||||||
|
@ -28,6 +33,8 @@ public class ChatScreenMixin extends Screen {
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "sendMessage", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "sendMessage", cancellable = true)
|
||||||
public void sendMessage(String chatText, boolean addToHistory, CallbackInfoReturnable<Boolean> cir) {
|
public void sendMessage(String chatText, boolean addToHistory, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (addToHistory) MinecraftClient.getInstance().inGameHud.getChatHud().addToMessageHistory(chatText);
|
||||||
|
|
||||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||||
|
|
||||||
if (ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith(ChipmunkMod.CONFIG.bots.testbot.prefix)) {
|
if (ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith(ChipmunkMod.CONFIG.bots.testbot.prefix)) {
|
||||||
|
@ -41,19 +48,32 @@ public class ChatScreenMixin extends Screen {
|
||||||
e.printStackTrace();
|
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();
|
||||||
|
|
||||||
|
if (moreOrTrustedCommands.contains(chatText.toLowerCase().split("\\s")[0])) {
|
||||||
|
try {
|
||||||
|
BotValidationUtilities.chomens(chatText.substring(ChipmunkMod.CONFIG.bots.chomens.prefix.length()));
|
||||||
|
|
||||||
|
cir.setReturnValue(true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatText.startsWith(commandManager.prefix)) {
|
if (chatText.startsWith(commandManager.prefix)) {
|
||||||
commandManager.executeCommand(chatText.substring(commandManager.prefix.length()));
|
commandManager.executeCommand(chatText.substring(commandManager.prefix.length()));
|
||||||
|
|
||||||
if (addToHistory) MinecraftClient.getInstance().inGameHud.getChatHud().addToMessageHistory(chatText);
|
|
||||||
|
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
} else if (!chatText.startsWith("/")) {
|
} else if (!chatText.startsWith("/")) {
|
||||||
CustomChat.INSTANCE.chat(chatText);
|
CustomChat.INSTANCE.chat(chatText);
|
||||||
|
|
||||||
if (addToHistory) MinecraftClient.getInstance().inGameHud.getChatHud().addToMessageHistory(chatText);
|
|
||||||
|
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,6 +106,7 @@ public class ChatScreenMixin extends Screen {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
private void onChatFieldUpdate(String chatText) {
|
private void onChatFieldUpdate(String chatText) {
|
||||||
String string = this.chatField.getText();
|
String string = this.chatField.getText();
|
||||||
this.chatInputSuggestor.setWindowActive(!string.equals(this.originalChatText));
|
this.chatInputSuggestor.setWindowActive(!string.equals(this.originalChatText));
|
||||||
|
|
|
@ -38,8 +38,10 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
KaboomCheck.INSTANCE.onJoin();
|
KaboomCheck.INSTANCE.onJoin();
|
||||||
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
|
CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess);
|
||||||
SelfCare.INSTANCE.onJoin();
|
SelfCare.INSTANCE.onJoin();
|
||||||
|
CommandCore.INSTANCE.init();
|
||||||
SongPlayer.INSTANCE.coreReady();
|
SongPlayer.INSTANCE.coreReady();
|
||||||
RainbowName.INSTANCE.init();
|
RainbowName.INSTANCE.init();
|
||||||
|
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package land.chipmunk.chipmunkmod.modules;
|
|
||||||
|
|
||||||
// bad
|
|
||||||
public class ChatInputGlobals {
|
|
||||||
public static String text = "";
|
|
||||||
public static int cursor;
|
|
||||||
public static String textUpToCursor = "";
|
|
||||||
}
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
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.TextComponent;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
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 Component component = message.asComponent();
|
||||||
|
|
||||||
|
final List<Component> children = component.children();
|
||||||
|
|
||||||
|
if (children.size() == 0) return;
|
||||||
|
|
||||||
|
final TextComponent textComponent = (TextComponent) children.get(0);
|
||||||
|
|
||||||
|
if (!textComponent.content().equals(ID)) return;
|
||||||
|
|
||||||
|
commands = children.subList(1, children.size())
|
||||||
|
.stream()
|
||||||
|
.map(
|
||||||
|
(eachCum) ->
|
||||||
|
new ChomeNSBotCommand(
|
||||||
|
ChipmunkMod.CONFIG.bots.chomens.prefix + ((TextComponent) eachCum).content(),
|
||||||
|
ChomeNSBotCommand.TrustLevel.valueOf(((TextComponent) eachCum.children().get(0)).content())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,14 +4,18 @@ import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.data.BlockArea;
|
import land.chipmunk.chipmunkmod.data.BlockArea;
|
||||||
|
|
||||||
|
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.packet.c2s.play.UpdateCommandBlockC2SPacket;
|
import net.minecraft.network.packet.c2s.play.UpdateCommandBlockC2SPacket;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -23,6 +27,8 @@ public class CommandCore {
|
||||||
public BlockArea relativeArea;
|
public BlockArea relativeArea;
|
||||||
public BlockPos currentBlockRelative;
|
public BlockPos currentBlockRelative;
|
||||||
|
|
||||||
|
private Timer timer;
|
||||||
|
|
||||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea);
|
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea);
|
||||||
|
|
||||||
public CommandCore (MinecraftClient client, BlockArea relativeArea) {
|
public CommandCore (MinecraftClient client, BlockArea relativeArea) {
|
||||||
|
@ -30,16 +36,34 @@ public class CommandCore {
|
||||||
this.relativeArea = relativeArea;
|
this.relativeArea = relativeArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void init () {
|
||||||
|
if (timer != null) {
|
||||||
|
cleanup();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TimerTask task = new TimerTask() {
|
||||||
|
public void run () {
|
||||||
|
tick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
timer = new Timer();
|
||||||
|
|
||||||
|
timer.schedule(task, 50, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tick () {
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (networkHandler == null) cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadRelativeArea () {
|
public void reloadRelativeArea () {
|
||||||
relativeArea = ChipmunkMod.CONFIG.core.relativeArea;
|
relativeArea = ChipmunkMod.CONFIG.core.relativeArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move (Vec3d position) {
|
public void move (Vec3d position) {
|
||||||
if (!ready) {
|
|
||||||
ready = true;
|
|
||||||
// for (Listener listener : listeners) listener.ready();
|
|
||||||
}
|
|
||||||
|
|
||||||
origin = new BlockPos(
|
origin = new BlockPos(
|
||||||
((int) position.getX() / 16) * 16,
|
((int) position.getX() / 16) * 16,
|
||||||
0, // TODO: Use the actual bottom of the world instead of hardcoding to 0
|
0, // TODO: Use the actual bottom of the world instead of hardcoding to 0
|
||||||
|
@ -48,6 +72,13 @@ public class CommandCore {
|
||||||
|
|
||||||
if (currentBlockRelative == null) currentBlockRelative = new BlockPos(relativeArea.start);
|
if (currentBlockRelative == null) currentBlockRelative = new BlockPos(relativeArea.start);
|
||||||
refill();
|
refill();
|
||||||
|
|
||||||
|
for (Listener listener : ListenerManager.listeners) listener.coreMoved();
|
||||||
|
if (!ready) {
|
||||||
|
ready = true;
|
||||||
|
|
||||||
|
for (Listener listener : ListenerManager.listeners) listener.coreReady();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refill () {
|
public void refill () {
|
||||||
|
@ -131,8 +162,7 @@ public class CommandCore {
|
||||||
|
|
||||||
final TimerTask queryTask = new TimerTask() {
|
final TimerTask queryTask = new TimerTask() {
|
||||||
public void run () {
|
public void run () {
|
||||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(currentBlock,
|
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(currentBlock, future::complete);
|
||||||
future::complete);
|
|
||||||
|
|
||||||
timer.cancel(); // ? Is this necesary?
|
timer.cancel(); // ? Is this necesary?
|
||||||
timer.purge();
|
timer.purge();
|
||||||
|
@ -145,6 +175,11 @@ public class CommandCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanup () {
|
public void cleanup () {
|
||||||
|
if (timer == null) return;
|
||||||
|
|
||||||
|
timer.cancel();
|
||||||
|
timer.purge();
|
||||||
|
|
||||||
origin = null;
|
origin = null;
|
||||||
currentBlockRelative = null;
|
currentBlockRelative = null;
|
||||||
ready = false;
|
ready = false;
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
package land.chipmunk.chipmunkmod.util;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
|
import land.chipmunk.chipmunkmod.Configuration;
|
||||||
|
import land.chipmunk.chipmunkmod.modules.CustomChat;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class BotValidationUtilities {
|
||||||
|
public static int hbot (String command) throws RuntimeException {
|
||||||
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.hbot;
|
||||||
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
final String prefix = info.prefix;
|
||||||
|
final String key = info.key;
|
||||||
|
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
||||||
|
String input = command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key;
|
||||||
|
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
|
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
||||||
|
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
||||||
|
|
||||||
|
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int sbot (String command) throws RuntimeException {
|
||||||
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot;
|
||||||
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
final String prefix = info.prefix;
|
||||||
|
final String key = info.key;
|
||||||
|
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
String time = String.valueOf(System.currentTimeMillis() / 20000);
|
||||||
|
String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + client.player.getName() + ";" + time + ";" + key;
|
||||||
|
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
|
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
||||||
|
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
||||||
|
|
||||||
|
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int chomens (String command) throws RuntimeException {
|
||||||
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens;
|
||||||
|
|
||||||
|
final String prefix = info.prefix;
|
||||||
|
final String key = info.key;
|
||||||
|
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
String time = String.valueOf(System.currentTimeMillis() / 5_000);
|
||||||
|
String input = time + key;
|
||||||
|
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
|
String stringHash = Hexadecimal.encode(hash).substring(0, 16);
|
||||||
|
|
||||||
|
String[] arguments = command.split(" ");
|
||||||
|
|
||||||
|
final String toSend = prefix + arguments[0] + " " + stringHash + " " + String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length));
|
||||||
|
|
||||||
|
CustomChat.INSTANCE.chat(toSend);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int kittycorp (String command) throws RuntimeException {
|
||||||
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp;
|
||||||
|
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
|
||||||
|
|
||||||
|
final String prefix = info.prefix;
|
||||||
|
final String key = info.key;
|
||||||
|
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
||||||
|
String input = prefix + command.replaceAll("&[0-9a-fklmnorx]", "") + ";" + time + ";" + key;
|
||||||
|
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
|
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
||||||
|
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
||||||
|
|
||||||
|
networkHandler.sendChatMessage(prefix + command + " " + stringHash);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,7 @@
|
||||||
"client": [
|
"client": [
|
||||||
"ChatHudMixin",
|
"ChatHudMixin",
|
||||||
"ChatInputSuggestorMixin",
|
"ChatInputSuggestorMixin",
|
||||||
"ChatInputSuggestorAccessor",
|
|
||||||
"ChatScreenMixin",
|
"ChatScreenMixin",
|
||||||
"ChatScreenAccessor",
|
|
||||||
"ClientConnectionMixin",
|
"ClientConnectionMixin",
|
||||||
"ClientPlayerEntityMixin",
|
"ClientPlayerEntityMixin",
|
||||||
"ClientPlayNetworkHandlerAccessor",
|
"ClientPlayNetworkHandlerAccessor",
|
||||||
|
|
Loading…
Reference in a new issue