add (broken) stuff fix stuff
uhhhhh whats going on with hashing i can't figure it out !!!! please fix ..,..... :((
This commit is contained in:
parent
eb50982a9a
commit
7e1931f9b5
9 changed files with 158 additions and 27 deletions
|
@ -30,18 +30,18 @@ public class Bot {
|
|||
|
||||
@Getter private Session session;
|
||||
|
||||
@Getter private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
@Getter private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(69);
|
||||
|
||||
@Getter private final ChatPlugin chat = new ChatPlugin(this);
|
||||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||
@Getter private final SelfCarePlugin selfCare = new SelfCarePlugin(this);
|
||||
@Getter @Setter private ConsolePlugin console;
|
||||
@Getter private final PositionPlugin position = new PositionPlugin(this);
|
||||
@Getter private final CorePlugin core = new CorePlugin(this);
|
||||
@Getter private final CommandHandlerPlugin commandHandler = new CommandHandlerPlugin();
|
||||
@Getter private final ChatCommandHandlerPlugin chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
@Getter private final HashingPlugin hashing = new HashingPlugin(this);
|
||||
@Getter private final MusicPlayerPlugin music = new MusicPlayerPlugin(this);
|
||||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||
@Getter private final ChatPlugin chat;
|
||||
@Getter private final SelfCarePlugin selfCare;
|
||||
@Getter private final PositionPlugin position;
|
||||
@Getter private final CorePlugin core;
|
||||
@Getter private final CommandHandlerPlugin commandHandler;
|
||||
@Getter private final ChatCommandHandlerPlugin chatCommandHandler;
|
||||
@Getter private final HashingPlugin hashing;
|
||||
@Getter private final MusicPlayerPlugin music;
|
||||
|
||||
public Bot (String host, int port, String _username, List<Bot> allBots, Configuration config) {
|
||||
this.host = host;
|
||||
|
@ -50,6 +50,15 @@ public class Bot {
|
|||
this.allBots = allBots;
|
||||
this.config = config;
|
||||
|
||||
chat = new ChatPlugin(this);
|
||||
selfCare = new SelfCarePlugin(this);
|
||||
position = new PositionPlugin(this);
|
||||
core = new CorePlugin(this);
|
||||
commandHandler = new CommandHandlerPlugin();
|
||||
chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
hashing = new HashingPlugin(this);
|
||||
music = new MusicPlayerPlugin(this);
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BotVisibilityCommand implements Command {
|
||||
public String name() { return "botvisibility"; }
|
||||
|
||||
public String description() {
|
||||
return "Changes the bot's visibility";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<hash> <true|false>");
|
||||
usages.add("<hash> <on|off>");
|
||||
usages.add("<hash>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public List<String> alias() {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
aliases.add("botvis");
|
||||
aliases.add("togglevis");
|
||||
aliases.add("togglevisibility");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
if (args[0] == null) {
|
||||
final boolean visibility = bot.selfCare().visibility();
|
||||
bot.selfCare().visibility(!visibility);
|
||||
|
||||
final NamedTextColor greenOrGold = bot.selfCare().visibility() ? NamedTextColor.GREEN : NamedTextColor.GOLD;
|
||||
final String visibleOrInvisible = bot.selfCare().visibility() ? "visible" : "invisible";
|
||||
final String disableOrEnable = bot.selfCare().visibility() ? "disable" : "enable";
|
||||
bot.chat().send("/essentials:vanish " + disableOrEnable);
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("The bot's visibility is now "))
|
||||
.append(Component.text(visibleOrInvisible).color(greenOrGold))
|
||||
);
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "on", "true" -> {
|
||||
bot.selfCare().visibility(true);
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("The bot's visibility is now "))
|
||||
.append(Component.text("visible").color(NamedTextColor.GREEN))
|
||||
);
|
||||
}
|
||||
case "off", "false" -> {
|
||||
bot.selfCare().visibility(false);
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("The bot's visibility is now "))
|
||||
.append(Component.text("invisible").color(NamedTextColor.GOLD))
|
||||
);
|
||||
}
|
||||
default -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -230,7 +230,7 @@ public class MusicCommand implements Command {
|
|||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("Queue: ").color(NamedTextColor.GREEN))
|
||||
.append(Component.join(JoinConfiguration.separator(Component.space()), queueWithNames))
|
||||
.append(Component.join(JoinConfiguration.separator(Component.text(", ")), queueWithNames).color(NamedTextColor.AQUA))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public class CommandHandlerPlugin {
|
|||
registerCommand(new ValidateCommand());
|
||||
registerCommand(new MusicCommand());
|
||||
registerCommand(new RandomTeleportCommand());
|
||||
registerCommand(new BotVisibilityCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (Command command) {
|
||||
|
|
|
@ -2,10 +2,11 @@ package me.chayapak1.chomensbot_mabe.plugins;
|
|||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import me.chayapak1.chomensbot_mabe.util.Hexadecimal;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HashingPlugin {
|
||||
|
@ -16,21 +17,29 @@ public class HashingPlugin {
|
|||
|
||||
public HashingPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.executor().schedule(this::update, 2, TimeUnit.SECONDS);
|
||||
|
||||
bot.executor().scheduleAtFixedRate(this::update, 1000 * 2, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void update () {
|
||||
final String normalHashKey = bot.config().keys().get("normalKey");
|
||||
final String ownerHashKey = bot.config().keys().get("ownerKey");
|
||||
|
||||
final String hashValue = System.currentTimeMillis() / 10_000 + normalHashKey;
|
||||
hash = Hashing.sha256()
|
||||
.hashString(hashValue, StandardCharsets.UTF_8)
|
||||
.toString().substring(0, 16);
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
||||
|
||||
final String ownerHashValue = System.currentTimeMillis() / 10_000 + ownerHashKey;
|
||||
ownerHash = Hashing.sha256()
|
||||
.hashString(ownerHashValue, StandardCharsets.UTF_8)
|
||||
.toString().substring(0, 16);
|
||||
// messy
|
||||
String normalHashInput = time + normalHashKey;
|
||||
byte[] normalHashByteHash = md.digest(normalHashInput.getBytes(StandardCharsets.UTF_8));
|
||||
hash = Hexadecimal.encode(normalHashByteHash).substring(0, 16);
|
||||
|
||||
String ownerHashInput = time + ownerHashKey;
|
||||
byte[] ownerHashByteHash = md.digest(ownerHashInput.getBytes(StandardCharsets.UTF_8));
|
||||
ownerHash = Hexadecimal.encode(ownerHashByteHash).substring(0, 16);
|
||||
|
||||
bot.logger().log("normal hash input " + normalHashInput + " owner " + ownerHashInput);
|
||||
bot.logger().log(hash + " " + ownerHash);
|
||||
} catch (NoSuchAlgorithmException ignored) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -169,12 +170,20 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
}
|
||||
|
||||
public Component generateBossbar () {
|
||||
final DecimalFormat formatter = new DecimalFormat("#,###");
|
||||
|
||||
Component component = Component.empty()
|
||||
.append(Component.empty().append(currentSong.name).color(NamedTextColor.GREEN))
|
||||
.append(Component.text(" | ").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.translatable("%s / %s", formatTime(currentSong.time).color(NamedTextColor.GRAY), formatTime(currentSong.length).color(NamedTextColor.GRAY)).color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.text(" | ").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.translatable("%s / %s", Component.text(currentSong.position, NamedTextColor.GRAY), Component.text(currentSong.size(), NamedTextColor.GRAY)).color(NamedTextColor.DARK_GRAY));
|
||||
.append(
|
||||
Component.translatable(
|
||||
"%s / %s",
|
||||
Component.text(formatter.format(currentSong.position), NamedTextColor.GRAY),
|
||||
Component.text(formatter.format(currentSong.size()), NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY)
|
||||
);
|
||||
|
||||
if (currentSong.paused) {
|
||||
return component
|
||||
|
|
|
@ -16,6 +16,8 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.Configuration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -28,6 +30,8 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
|
||||
private ScheduledFuture<?> futureTask;
|
||||
|
||||
@Getter @Setter boolean visibility = false;
|
||||
|
||||
private int entityId;
|
||||
private GameMode gamemode;
|
||||
private int permissionLevel;
|
||||
|
@ -79,7 +83,7 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
if (selfCares.gamemode() && gamemode != GameMode.CREATIVE) bot.chat().send("/minecraft:gamemode creative @s[type=player]");
|
||||
else if (selfCares.op() && permissionLevel < 2) bot.chat().send("/minecraft:op @s[type=player]");
|
||||
else if (selfCares.cspy() && !cspy) bot.chat().send("/commandspy:commandspy on");
|
||||
else if (selfCares.vanish() && !vanish) bot.chat().send("/essentials:vanish enable");
|
||||
else if (selfCares.vanish() && !vanish && !visibility) bot.chat().send("/essentials:vanish enable");
|
||||
else if (selfCares.nickname() && !nickname) bot.chat().send("/essentials:nickname off");
|
||||
else if (selfCares.socialspy() && !socialspy) bot.chat().send("/essentials:socialspy enable");
|
||||
else if (selfCares.mute() && muted) bot.chat().send("/essentials:mute " + bot.username());
|
||||
|
|
|
@ -108,7 +108,7 @@ public class ComponentUtilities {
|
|||
if (message instanceof TextComponent) return stringifyPartially((TextComponent) message, motd, ansi);
|
||||
if (message instanceof TranslatableComponent) return stringifyPartially((TranslatableComponent) message, motd, ansi);
|
||||
if (message instanceof SelectorComponent) return stringifyPartially((SelectorComponent) message, motd, ansi);
|
||||
if (message instanceof KeybindComponent) return stringifyPartially((KeybindComponent) message);
|
||||
if (message instanceof KeybindComponent) return stringifyPartially((KeybindComponent) message, motd, ansi);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@ -211,9 +211,9 @@ public class ComponentUtilities {
|
|||
return color + message.pattern(); // * Client-side selector components are equivalent to text ones, and do NOT list entities.
|
||||
}
|
||||
|
||||
public static String stringifyPartially (KeybindComponent message) {
|
||||
public static String stringifyPartially (KeybindComponent message, boolean motd, boolean ansi) {
|
||||
String keybind = message.keybind();
|
||||
Component component = keybinds.containsKey(keybind) ? Component.translatable(keybind) : Component.text(keybind); // TODO: Fix some keys like `key.keyboard.a`
|
||||
return stringifyPartially(component, false, false);
|
||||
return stringifyPartially(component, motd, ansi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package me.chayapak1.chomensbot_mabe.util;
|
||||
|
||||
public interface Hexadecimal {
|
||||
static String encode (byte b) {
|
||||
return "" + Character.forDigit((b >> 4) & 0xF, 16) + Character.forDigit((b & 0xF), 16);
|
||||
}
|
||||
|
||||
static String encode (byte[] array) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < array.length; i++) sb.append(encode(array[i]));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// TODO: Decode
|
||||
}
|
||||
|
Loading…
Reference in a new issue