section signs chomens bot validation

This commit is contained in:
Chayapak 2023-08-27 11:19:33 +07:00
parent 6a26456bc1
commit 198ec68b43

View file

@ -6,6 +6,7 @@ import land.chipmunk.chipmunkmod.Configuration;
import land.chipmunk.chipmunkmod.modules.CustomChat; import land.chipmunk.chipmunkmod.modules.CustomChat;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -69,6 +70,8 @@ public class BotValidationUtilities {
final MinecraftClient client = MinecraftClient.getInstance(); final MinecraftClient client = MinecraftClient.getInstance();
final ClientPlayerEntity player = client.player;
final String prefix = info.prefix; final String prefix = info.prefix;
final String key = info.key; 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?"); if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
@ -82,7 +85,25 @@ public class BotValidationUtilities {
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
String stringHash = Hexadecimal.encode(hash).substring(0, 16); String stringHash = Hexadecimal.encode(hash).substring(0, 16);
final String toSend = prefix + arguments[0] + " " + stringHash + " " + String.join(" ", Arrays.copyOfRange(arguments, 1, arguments.length)); final boolean shouldSectionSign = CustomChat.INSTANCE.enabled && player.hasPermissionLevel(2) && player.isCreative();
if (shouldSectionSign) {
stringHash = String.join("",
Arrays.stream(stringHash.split(""))
.map((letter) -> "§" + letter)
.toArray(String[]::new)
);
}
final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length);
final String toSend = prefix +
arguments[0] +
" " +
stringHash +
(shouldSectionSign ? "§r" : "") +
" " +
String.join(" ", restArguments);
CustomChat.INSTANCE.chat(toSend); CustomChat.INSTANCE.chat(toSend);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {