NEW core runtracked impl + rewrite chat listeners
thanks chipmunk for the new implementation i was so dumb and in one of my old bots i have that implementation but it wasn't related to tracked core though, it was related to interactions
This commit is contained in:
parent
4c13e91d5f
commit
73c73a2354
17 changed files with 179 additions and 141 deletions
|
@ -1,17 +1,12 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CommandBlockCommand extends Command {
|
||||
|
@ -30,22 +25,14 @@ public class CommandBlockCommand extends Command {
|
|||
public Component execute(CommandContext context) throws CommandException {
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final CompletableFuture<CompoundTag> future = bot.core.runTracked(context.getString(true, true));
|
||||
final CompletableFuture<Component> future = bot.core.runTracked(context.getString(true, true));
|
||||
|
||||
if (future == null) return null;
|
||||
|
||||
future.thenApply(tags -> {
|
||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||
future.thenApply(output -> {
|
||||
context.sendOutput(output);
|
||||
|
||||
final StringTag lastOutput = tags.get("LastOutput");
|
||||
|
||||
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||
|
||||
final List<Component> children = output.children();
|
||||
|
||||
context.sendOutput(Component.join(JoinConfiguration.separator(Component.space()), children));
|
||||
|
||||
return tags;
|
||||
return output;
|
||||
});
|
||||
|
||||
return null;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
|
@ -21,7 +19,6 @@ import net.kyori.adventure.text.JoinConfiguration;
|
|||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
|
@ -97,7 +94,7 @@ public class MailCommand extends Command {
|
|||
throw new CommandException(Component.text("You are sending too many mails!"));
|
||||
}
|
||||
|
||||
final CompletableFuture<CompoundTag> future = bot.core.runTracked(
|
||||
final CompletableFuture<Component> future = bot.core.runTracked(
|
||||
"minecraft:data get entity " +
|
||||
UUIDUtilities.selector(sender.profile.getId()) +
|
||||
" SelectedItem.tag.message"
|
||||
|
@ -107,13 +104,7 @@ public class MailCommand extends Command {
|
|||
throw new CommandException(Component.text("There was an error while sending your mail"));
|
||||
}
|
||||
|
||||
future.thenApply(tags -> {
|
||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||
|
||||
final StringTag lastOutput = tags.get("LastOutput");
|
||||
|
||||
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||
|
||||
future.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
if (
|
||||
|
@ -124,14 +115,14 @@ public class MailCommand extends Command {
|
|||
.equals("arguments.nbtpath.nothing_found")
|
||||
) {
|
||||
context.sendOutput(Component.text("Player has no `message` NBT tag in the selected item").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
final String value = ComponentUtilities.stringify(((TranslatableComponent) children.get(0)).args().get(1));
|
||||
|
||||
if (!value.startsWith("\"") && !value.endsWith("\"") && !value.startsWith("'") && !value.endsWith("'")) {
|
||||
context.sendOutput(Component.text("`message` NBT is not a string").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -152,7 +143,7 @@ public class MailCommand extends Command {
|
|||
Component.text("Mail sent!").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))
|
||||
);
|
||||
|
||||
return tags;
|
||||
return output;
|
||||
});
|
||||
}
|
||||
case "read" -> {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.Main;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
|
@ -20,7 +18,6 @@ import net.kyori.adventure.text.TranslatableComponent;
|
|||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
@ -203,7 +200,7 @@ public class MusicCommand extends Command {
|
|||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final CompletableFuture<CompoundTag> future = bot.core.runTracked(
|
||||
final CompletableFuture<Component> future = bot.core.runTracked(
|
||||
"minecraft:data get entity " +
|
||||
UUIDUtilities.selector(context.sender.profile.getId()) +
|
||||
" SelectedItem.tag.data"
|
||||
|
@ -213,13 +210,7 @@ public class MusicCommand extends Command {
|
|||
throw new CommandException(Component.text("There was an error while getting your data"));
|
||||
}
|
||||
|
||||
future.thenApply(tags -> {
|
||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||
|
||||
final StringTag lastOutput = tags.get("LastOutput");
|
||||
|
||||
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||
|
||||
future.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
if (
|
||||
|
@ -230,14 +221,14 @@ public class MusicCommand extends Command {
|
|||
.equals("arguments.nbtpath.nothing_found")
|
||||
) {
|
||||
context.sendOutput(Component.text("Player has no `data` NBT tag in the selected item").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
final String value = ComponentUtilities.stringify(((TranslatableComponent) children.get(0)).args().get(1));
|
||||
|
||||
if (!value.startsWith("\"") && !value.endsWith("\"") && !value.startsWith("'") && !value.endsWith("'")) {
|
||||
context.sendOutput(Component.text("`data` NBT is not a string").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -253,7 +244,7 @@ public class MusicCommand extends Command {
|
|||
context.sendOutput(Component.text("Invalid base64 in the selected item").color(NamedTextColor.RED));
|
||||
}
|
||||
|
||||
return tags;
|
||||
return output;
|
||||
});
|
||||
|
||||
return null;
|
||||
|
@ -266,7 +257,7 @@ public class MusicCommand extends Command {
|
|||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final CompletableFuture<CompoundTag> future = bot.core.runTracked(
|
||||
final CompletableFuture<Component> future = bot.core.runTracked(
|
||||
"minecraft:data get entity " +
|
||||
UUIDUtilities.selector(context.sender.profile.getId()) +
|
||||
" SelectedItem.tag.SongItemData.SongData"
|
||||
|
@ -276,13 +267,7 @@ public class MusicCommand extends Command {
|
|||
throw new CommandException(Component.text("There was an error while getting your data"));
|
||||
}
|
||||
|
||||
future.thenApply(tags -> {
|
||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||
|
||||
final StringTag lastOutput = tags.get("LastOutput");
|
||||
|
||||
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||
|
||||
future.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
if (
|
||||
|
@ -293,14 +278,14 @@ public class MusicCommand extends Command {
|
|||
.equals("arguments.nbtpath.nothing_found")
|
||||
) {
|
||||
context.sendOutput(Component.text("Player has no SongItemData -> SongData NBT tag in the selected item").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
final String value = ComponentUtilities.stringify(((TranslatableComponent) children.get(0)).args().get(1));
|
||||
|
||||
if (!value.startsWith("\"") && !value.endsWith("\"") && !value.startsWith("'") && !value.endsWith("'")) {
|
||||
context.sendOutput(Component.text("NBT is not a string").color(NamedTextColor.RED));
|
||||
return tags;
|
||||
return output;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -316,7 +301,7 @@ public class MusicCommand extends Command {
|
|||
context.sendOutput(Component.text("Invalid song data in the selected item").color(NamedTextColor.RED));
|
||||
}
|
||||
|
||||
return tags;
|
||||
return output;
|
||||
});
|
||||
|
||||
return null;
|
||||
|
|
|
@ -35,8 +35,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
|||
bot.players.addListener(this);
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
AuthPlugin.this.systemMessageReceived(component, isCommandSuggestions, isAuth, isImposterFormat);
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
return AuthPlugin.this.systemMessageReceived(component);
|
||||
}
|
||||
});
|
||||
bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS);
|
||||
|
@ -84,15 +84,17 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
|||
started = false;
|
||||
}
|
||||
|
||||
private void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat) {
|
||||
private boolean systemMessageReceived (Component component) {
|
||||
try {
|
||||
if (isCommandSuggestions || !isAuth || isImposterFormat) return;
|
||||
if (!(component instanceof TextComponent idComponent)) return true;
|
||||
|
||||
if (!idComponent.content().equals(id)) return true;
|
||||
|
||||
final List<Component> children = component.children();
|
||||
|
||||
if (children.size() != 1) return;
|
||||
if (children.size() != 1) return true;
|
||||
|
||||
if (!(children.get(0) instanceof TextComponent)) return;
|
||||
if (!(children.get(0) instanceof TextComponent)) return true;
|
||||
|
||||
final String inputHash = ((TextComponent) children.get(0)).content();
|
||||
|
||||
|
@ -107,7 +109,11 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
|||
bot.logger.custom(Component.text("Auth").color(NamedTextColor.RED), Component.text("Authenticating with real hash " + hash + " and user hash " + inputHash));
|
||||
|
||||
hasCorrectHash = inputHash.equals(hash);
|
||||
|
||||
return false;
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void check() {
|
||||
|
|
|
@ -33,14 +33,14 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playerMessageReceived (PlayerMessage message) {
|
||||
public boolean playerMessageReceived (PlayerMessage message) {
|
||||
try {
|
||||
if (message.sender.profile.getId().equals(bot.profile.getId())) return;
|
||||
if (message.sender.profile.getId().equals(bot.profile.getId())) return true;
|
||||
} catch (Exception ignored) {} // kinda sus ngl
|
||||
|
||||
final Component displayNameComponent = message.displayName;
|
||||
final Component messageComponent = message.contents;
|
||||
if (displayNameComponent == null || messageComponent == null) return;
|
||||
if (displayNameComponent == null || messageComponent == null) return true;
|
||||
|
||||
final String displayName = ComponentUtilities.stringify(displayNameComponent);
|
||||
final String contents = ComponentUtilities.stringify(messageComponent);
|
||||
|
@ -52,7 +52,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.Listener {
|
|||
prefix = eachPrefix;
|
||||
}
|
||||
|
||||
if (prefix == null) return;
|
||||
if (prefix == null) return true;
|
||||
|
||||
final String commandString = contents.substring(prefix.length());
|
||||
|
||||
|
@ -63,6 +63,8 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.Listener {
|
|||
|
||||
if (output != null) context.sendOutput(output);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void commandSpyMessageReceived (PlayerEntry sender, String command) {
|
||||
|
|
|
@ -92,25 +92,19 @@ public class ChatPlugin extends Bot.Listener {
|
|||
if (playerMessage != null) break;
|
||||
}
|
||||
|
||||
boolean isCommandSuggestions = false;
|
||||
boolean isAuth = false;
|
||||
if (component instanceof TextComponent t_component) {
|
||||
final String id = t_component.content();
|
||||
|
||||
if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true;
|
||||
else if (id.equals(bot.auth.id)) isAuth = true;
|
||||
}
|
||||
|
||||
final boolean isImposterFormat = bot.formatChecker.isImposterFormat(component);
|
||||
|
||||
final String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
if (!isCommandSuggestions && !isAuth) listener.systemMessageReceived(component, string, ansi);
|
||||
listener.systemMessageReceived(component, isCommandSuggestions, isAuth, isImposterFormat, string, ansi);
|
||||
final boolean bool1 = listener.systemMessageReceived(component, string, ansi);
|
||||
|
||||
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
||||
if (!bool1) break;
|
||||
|
||||
if (playerMessage != null) {
|
||||
final boolean bool2 = listener.playerMessageReceived(playerMessage);
|
||||
|
||||
if (!bool2) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +144,9 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final String translation = getTranslationByChatType(packet.getChatType());
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.playerMessageReceived(playerMessage);
|
||||
final boolean bool = listener.playerMessageReceived(playerMessage);
|
||||
|
||||
if (!bool) break;
|
||||
|
||||
if (translation != null && unsignedContent == null) {
|
||||
TranslatableComponent component = Component.translatable(translation);
|
||||
|
@ -168,12 +164,16 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
listener.systemMessageReceived(component, string, ansi);
|
||||
final boolean _bool = listener.systemMessageReceived(component, string, ansi);
|
||||
|
||||
if (!_bool) break;
|
||||
} else {
|
||||
final String string = ComponentUtilities.stringify(unsignedContent);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(unsignedContent);
|
||||
|
||||
listener.systemMessageReceived(unsignedContent, string, ansi);
|
||||
final boolean _bool = listener.systemMessageReceived(unsignedContent, string, ansi);
|
||||
|
||||
if (!_bool) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,9 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final String ansi = ComponentUtilities.stringifyAnsi(translatableComponent);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.systemMessageReceived(translatableComponent, string, ansi);
|
||||
final boolean bool = listener.systemMessageReceived(translatableComponent, string, ansi);
|
||||
|
||||
if (!bool) break;
|
||||
}
|
||||
|
||||
for (ChatParser parser : chatParsers) {
|
||||
|
@ -222,7 +224,9 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final PlayerMessage playerMessage = new PlayerMessage(parsed.sender, packet.getName(), parsed.contents);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.playerMessageReceived(playerMessage);
|
||||
final boolean bool = listener.playerMessageReceived(playerMessage);
|
||||
|
||||
if (!bool) break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -234,9 +238,13 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.playerMessageReceived(playerMessage);
|
||||
final boolean bool1 = listener.playerMessageReceived(playerMessage);
|
||||
|
||||
listener.systemMessageReceived(component, string, ansi);
|
||||
if (!bool1) break;
|
||||
|
||||
final boolean bool2 = listener.systemMessageReceived(component, string, ansi);
|
||||
|
||||
if (!bool2) break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -366,8 +374,7 @@ public class ChatPlugin extends Bot.Listener {
|
|||
public void addListener (Listener listener) { listeners.add(listener); }
|
||||
|
||||
public static class Listener {
|
||||
public void playerMessageReceived (PlayerMessage message) {}
|
||||
public void systemMessageReceived (Component component, String string, String ansi) {}
|
||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {}
|
||||
public boolean playerMessageReceived (PlayerMessage message) { return true; }
|
||||
public boolean systemMessageReceived (Component component, String string, String ansi) { return true; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CommandSpyPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
TextComponent textComponent;
|
||||
|
||||
try {
|
||||
|
@ -37,19 +37,21 @@ public class CommandSpyPlugin extends ChatPlugin.Listener {
|
|||
textComponent.style().isEmpty()
|
||||
) &&
|
||||
children.size() < 2
|
||||
) return;
|
||||
) return true;
|
||||
|
||||
if (!((TextComponent) children.get(0)).content().equals(": ")) return;
|
||||
if (!((TextComponent) children.get(0)).content().equals(": ")) return true;
|
||||
|
||||
final String username = textComponent.content();
|
||||
final String command = ComponentUtilities.stringify(children.get(1));
|
||||
|
||||
final PlayerEntry sender = bot.players.getEntry(username);
|
||||
|
||||
if (sender == null) return;
|
||||
if (sender == null) return true;
|
||||
|
||||
for (Listener listener : listeners) listener.commandReceived(sender, command);
|
||||
} catch (ClassCastException ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addListener (Listener listener) { listeners.add(listener); }
|
||||
|
|
|
@ -20,13 +20,15 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
if (!isCommandSuggestions) return;
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
if (!(component instanceof TextComponent idComponent)) return true;
|
||||
|
||||
if (!idComponent.content().equals(id)) return true;
|
||||
|
||||
try {
|
||||
final List<Component> children = component.children();
|
||||
|
||||
if (children.size() != 1) return;
|
||||
if (children.size() != 1) return true;
|
||||
|
||||
final String player = ((TextComponent) children.get(0)).content();
|
||||
|
||||
|
@ -49,6 +51,10 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
bot.chat.tellraw(Component.join(JoinConfiguration.noSeparators(), output), player);
|
||||
|
||||
return false;
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
|
|||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockUpdatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundSectionBlocksUpdatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundTagQueryPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundBlockEntityTagQuery;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
|
@ -23,6 +21,11 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.MathUtilities;
|
||||
import net.kyori.adventure.text.BlockNBTComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -51,7 +54,9 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
public Vector3i block = null;
|
||||
|
||||
private int nextTransactionId = 0;
|
||||
private final Map<Integer, CompletableFuture<CompoundTag>> transactions = new HashMap<>();
|
||||
private final Map<Integer, CompletableFuture<Component>> transactions = new HashMap<>();
|
||||
|
||||
private final List<Double> secrets = new ArrayList<>();
|
||||
|
||||
private int commandsPerSecond = 0;
|
||||
|
||||
|
@ -101,12 +106,18 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundTagQueryPacket) CorePlugin.this.packetReceived((ClientboundTagQueryPacket) packet);
|
||||
else if (packet instanceof ClientboundBlockUpdatePacket) CorePlugin.this.packetReceived((ClientboundBlockUpdatePacket) packet);
|
||||
if (packet instanceof ClientboundBlockUpdatePacket) CorePlugin.this.packetReceived((ClientboundBlockUpdatePacket) packet);
|
||||
else if (packet instanceof ClientboundSectionBlocksUpdatePacket) CorePlugin.this.packetReceived((ClientboundSectionBlocksUpdatePacket) packet);
|
||||
else if (packet instanceof ClientboundLevelChunkWithLightPacket) CorePlugin.this.packetReceived((ClientboundLevelChunkWithLightPacket) packet);
|
||||
}
|
||||
});
|
||||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
return CorePlugin.this.systemMessageReceived(component);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasRateLimit () {
|
||||
|
@ -168,30 +179,70 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<CompoundTag> runTracked (String command) {
|
||||
final Vector3i placeBlock = Vector3i.from(
|
||||
bot.position.position.getX(),
|
||||
bot.position.position.getY() - 1,
|
||||
bot.position.position.getZ()
|
||||
);
|
||||
|
||||
runPlaceBlock(command);
|
||||
|
||||
// thanks chipmunk for this new tellraw method :3
|
||||
public CompletableFuture<Component> runTracked (String command) {
|
||||
if (!bot.options.useCore) return null;
|
||||
|
||||
final Vector3i coreBlock = block;
|
||||
|
||||
run(command);
|
||||
|
||||
final int transactionId = nextTransactionId++;
|
||||
|
||||
// promises are renamed to future lmao
|
||||
final CompletableFuture<CompoundTag> future = new CompletableFuture<>();
|
||||
final CompletableFuture<Component> future = new CompletableFuture<>();
|
||||
transactions.put(transactionId, future);
|
||||
|
||||
final Runnable afterTick = () -> bot.session.send(new ServerboundBlockEntityTagQuery(transactionId, placeBlock));
|
||||
final double secret = Math.random(); // it is uh bad whatever
|
||||
secrets.add(secret);
|
||||
|
||||
bot.executor.schedule(afterTick, 50, TimeUnit.MILLISECONDS);
|
||||
bot.chat.tellraw(
|
||||
Component
|
||||
.text(secret)
|
||||
.append(Component.text(transactionId))
|
||||
.append(
|
||||
Component.blockNBT(
|
||||
"LastOutput",
|
||||
|
||||
// is there a better way of doing this?
|
||||
BlockNBTComponent.Pos.fromString(
|
||||
coreBlock.getX() + " " +
|
||||
coreBlock.getY() + " " +
|
||||
coreBlock.getZ()
|
||||
)
|
||||
)
|
||||
),
|
||||
bot.profile.getId()
|
||||
);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
private boolean systemMessageReceived (Component component) {
|
||||
if (!(component instanceof TextComponent textComponent)) return true;
|
||||
|
||||
try {
|
||||
if (!secrets.contains(Double.parseDouble(textComponent.content()))) return true;
|
||||
|
||||
final List<Component> children = component.children();
|
||||
|
||||
if (children.size() != 2) return true;
|
||||
|
||||
final int transactionId = Integer.parseInt(((TextComponent) children.get(0)).content());
|
||||
|
||||
if (!transactions.containsKey(transactionId)) return true;
|
||||
|
||||
final CompletableFuture<Component> future = transactions.get(transactionId);
|
||||
|
||||
final String stringLastOutput = ((TextComponent) children.get(1)).content();
|
||||
|
||||
future.complete(Component.join(JoinConfiguration.separator(Component.space()), GsonComponentSerializer.gson().deserialize(stringLastOutput).children()));
|
||||
|
||||
return false;
|
||||
} catch (ClassCastException | NumberFormatException ignored) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void runPlaceBlock (String command) {
|
||||
if (!ready || !bot.options.useCore) return;
|
||||
|
||||
|
@ -226,10 +277,6 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1));
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundTagQueryPacket packet) {
|
||||
transactions.get(packet.getTransactionId()).complete(packet.getNbt());
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundBlockUpdatePacket packet) {
|
||||
final BlockChangeEntry entry = packet.getEntry();
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public class DiscordPlugin {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived (Component component, String string, String ansi) {
|
||||
public boolean systemMessageReceived (Component component, String string, String ansi) {
|
||||
if (string.length() > 2048) {
|
||||
sendMessage(CodeBlockUtilities.escape(string), channelId);
|
||||
} else {
|
||||
|
@ -94,6 +94,8 @@ public class DiscordPlugin {
|
|||
channelId
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,8 +37,10 @@ public class FilterPlugin extends PlayersPlugin.Listener {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void playerMessageReceived(PlayerMessage message) {
|
||||
public boolean playerMessageReceived(PlayerMessage message) {
|
||||
FilterPlugin.this.playerMessageReceived(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -43,10 +43,12 @@ public class FormatCheckerPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
if (!isImposterFormat) return;
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
if (!isImposterFormat(component)) return true;
|
||||
|
||||
bot.chat.tellraw(Component.text("Possible fake ChomeNS custom chat").style(Style.style(TextDecoration.ITALIC)).color(NamedTextColor.GRAY));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isImposterFormat (Component component) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
|
@ -10,9 +8,8 @@ import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
|||
import land.chipmunk.chayapak.chomens_bot.util.PersistentDataUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -43,29 +40,23 @@ public class IPFilterPlugin extends PlayersPlugin.Listener {
|
|||
}
|
||||
|
||||
private void check (PlayerEntry target) {
|
||||
final CompletableFuture<CompoundTag> future = bot.core.runTracked("essentials:seen " + target.profile.getIdAsString());
|
||||
final CompletableFuture<Component> future = bot.core.runTracked("essentials:seen " + target.profile.getIdAsString());
|
||||
|
||||
if (future == null) return;
|
||||
|
||||
future.thenApply(tags -> {
|
||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||
|
||||
final StringTag lastOutput = tags.get("LastOutput");
|
||||
|
||||
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||
|
||||
future.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
String stringified = ComponentUtilities.stringify(Component.join(JoinConfiguration.separator(Component.space()), children));
|
||||
|
||||
if (!stringified.startsWith(" - IP Address: ")) return tags;
|
||||
if (!stringified.startsWith(" - IP Address: ")) return output;
|
||||
|
||||
stringified = stringified.substring(" - IP Address: ".length());
|
||||
if (stringified.startsWith("/")) stringified = stringified.substring(1);
|
||||
|
||||
handleIP(stringified, target);
|
||||
|
||||
return tags;
|
||||
return output;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,10 @@ public class IRCPlugin extends IRCMessageLoop {
|
|||
public void loadedPlugins() {
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void playerMessageReceived(PlayerMessage message) {
|
||||
public boolean playerMessageReceived(PlayerMessage message) {
|
||||
IRCPlugin.this.playerMessageReceived(bot, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -103,11 +103,13 @@ public class LoggerPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
if (logToConsole) {
|
||||
log(ansi, false, true);
|
||||
}
|
||||
|
||||
log(string, true, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class SelfCarePlugin extends Bot.Listener {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
public boolean systemMessageReceived(Component component, String string, String ansi) {
|
||||
if (string.equals("Successfully enabled CommandSpy")) cspy = true;
|
||||
else if (string.equals("Successfully disabled CommandSpy")) cspy = false;
|
||||
|
||||
|
@ -72,6 +72,8 @@ public class SelfCarePlugin extends Bot.Listener {
|
|||
else if (string.equals("Successfully set your username to \"" + bot.username + "\"")) username = true;
|
||||
else if (string.startsWith("You already have the username \"")) username = true;
|
||||
else if (string.startsWith("Successfully set your username to \"")) username = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -21,8 +21,10 @@ public class WhitelistPlugin extends PlayersPlugin.Listener {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void playerMessageReceived(PlayerMessage message) {
|
||||
public boolean playerMessageReceived(PlayerMessage message) {
|
||||
WhitelistPlugin.this.playerMessageReceived(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue