forked from afspiegeling/NitoriBot
semi working console
This commit is contained in:
Generated
+1
-1
@@ -5,7 +5,7 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="25 (3)" />
|
||||
<option name="gradleJvm" value="25" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "disabled",
|
||||
"java.compile.nullAnalysis.mode": "disabled",
|
||||
"java.refactoring.askBeforeRefactoring": true,
|
||||
"java.autobuild.enabled": false,
|
||||
"java.import.projectSelection": "manual",
|
||||
"java.server.launchMode": "Standard"
|
||||
}
|
||||
+7
-7
@@ -26,7 +26,7 @@ repositories {
|
||||
|
||||
maven("https://maven.maxhenkel.de/repository/public/")
|
||||
|
||||
maven("https://libraries.minecraft.net")
|
||||
// maven("https://libraries.minecraft.net")
|
||||
|
||||
/* maven("https://code.optmstc.dev/api/packages/kso/maven") {
|
||||
content {
|
||||
@@ -39,9 +39,8 @@ repositories {
|
||||
// maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
dependencies {
|
||||
implementation("org.geysermc.mcprotocollib:protocol:1.21.11-SNAPSHOT")
|
||||
implementation("org.geysermc.mcprotocollib:protocol:26.2-SNAPSHOT")
|
||||
implementation("org.slf4j:slf4j-api:2.0.13")
|
||||
implementation("org.tinylog:slf4j-tinylog:2.7.0")
|
||||
implementation("org.tinylog:tinylog-impl:2.7.0")
|
||||
@@ -50,11 +49,12 @@ dependencies {
|
||||
implementation("net.kyori:adventure-text-serializer-plain:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.26.1")
|
||||
implementation("com.mojang:brigadier:1.3.10")
|
||||
//implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.1-SNAPSHOT")
|
||||
// implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:3.1.1-SNAPSHOT")
|
||||
}
|
||||
implementation("net.dv8tion:JDA:6.4.1")
|
||||
implementation("de.connect2x.trixnity:trixnity-client:5.0.0")
|
||||
implementation("org.pircbotx:pircbotx:2.1")
|
||||
implementation("org.jline:jline:4.1.0")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("land.chipmunk.parker2991.nitoribot.Main")
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@
|
||||
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/9.4.0/userguide/multi_project_builds.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
rootProject.name = "NitoriBot"
|
||||
rootProject.name = "NitoriBot"
|
||||
@@ -1,8 +1,8 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.modules.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
public final ListenerManager ListenerManager = new ListenerManager();
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
|
||||
public boolean loggedIn = false;
|
||||
|
||||
@@ -60,24 +60,28 @@ public class Bot extends SessionAdapter {
|
||||
public RegistryModule registry;
|
||||
|
||||
public CommandManagerModule commandManager;
|
||||
//private ChatCommandHandlerModule ChatCommandHandler;
|
||||
|
||||
public void loadModules () {
|
||||
this.chat = new ChatModule(this);
|
||||
this.console = new ConsoleModule(this);
|
||||
// this.console = new ConsoleModule(this);
|
||||
this.selfcare = new SelfcareModule(this);
|
||||
this.position = new PositionModule(this);
|
||||
this.core = new CommandCoreModule(this);
|
||||
this.registry = new RegistryModule(this);
|
||||
this.players = new PlayerListModule(this);
|
||||
new LoggingModule(this);
|
||||
new ChatCommandHandlerModule(this);
|
||||
this.commandManager = new CommandManagerModule(this);
|
||||
new TextDisplayModule(this);
|
||||
}
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, Config config) {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
|
||||
this.console = new ConsoleModule(this);
|
||||
|
||||
connect();
|
||||
};
|
||||
|
||||
@@ -94,7 +98,6 @@ public class Bot extends SessionAdapter {
|
||||
session.addListener(this);
|
||||
loadModules();
|
||||
session.connect(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,19 +108,19 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
@Override
|
||||
public void packetSent (Session session, Packet packet) {
|
||||
for (Listener listener : ListenerManager.listeners) {
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetSent(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetError (PacketErrorEvent error) {
|
||||
System.out.println(error.getCause());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
for (Listener listener : ListenerManager.listeners) {
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
|
||||
@@ -127,7 +130,7 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
|
||||
public void getProfile (ClientboundLoginFinishedPacket packet) {
|
||||
//profile = packet.getProfile();
|
||||
profile = packet.getProfile();
|
||||
|
||||
loggedIn = true;
|
||||
}
|
||||
@@ -138,17 +141,19 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
ListenerManager.clearListener();
|
||||
//final Throwable cause = disconnectedEvent.getCause();
|
||||
Throwable cause = event.getCause();
|
||||
System.out.println(cause);
|
||||
listenerManager.clearListener();
|
||||
|
||||
loggedIn = false;
|
||||
|
||||
Component component = event.getReason();
|
||||
|
||||
String reason = ComponentUtil.componentToAnsi(component);
|
||||
Component host = Component.text(options.host + ":" + options.port);
|
||||
LoggerManager.RECONNECT(host, reason);
|
||||
|
||||
int reconnectDelay = options.reconnectDelay;
|
||||
|
||||
System.out.println(reason);
|
||||
//LoggerManager.RECONNECT(this, reason);
|
||||
|
||||
executor.schedule(() -> connect(), reconnectDelay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,42 @@ public class Config {
|
||||
public int z = 0;
|
||||
}
|
||||
|
||||
public static class CommandColors {
|
||||
public String primary = "blue";
|
||||
public String secondary = "aqua";
|
||||
public String tertiary = "dark_aqua";
|
||||
}
|
||||
|
||||
public static class HelpCommandColors {
|
||||
public String Public = "blue";
|
||||
public String trusted = "dark_aqua";
|
||||
public String admin = "aqua";
|
||||
public String owner = "light_purple";
|
||||
public String console = "dark_purple";
|
||||
}
|
||||
|
||||
public static class Console {
|
||||
public String prefix = "c.";
|
||||
}
|
||||
|
||||
public static class Colors {
|
||||
public String integer = "gold";
|
||||
public CommandColors commands = new CommandColors();
|
||||
public HelpCommandColors help = new HelpCommandColors();
|
||||
}
|
||||
|
||||
public Colors colors = new Colors();
|
||||
|
||||
public Core core = new Core();
|
||||
|
||||
public Console console = new Console();
|
||||
|
||||
public Options[] bots = new Options[]{};
|
||||
|
||||
public static class Options {
|
||||
public String host;
|
||||
public int port;
|
||||
public String serverName;
|
||||
public String username;
|
||||
public int reconnectDelay;
|
||||
public int selfcareInterval;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ErrorToString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
@@ -31,8 +29,6 @@ public class Main {
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
|
||||
public final Component host = Component.text("Nitori Jar");
|
||||
|
||||
public static Config config;
|
||||
|
||||
public final List<Bot> Bots = new ArrayList<>();
|
||||
@@ -43,7 +39,7 @@ public class Main {
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
if (!Files.exists(configPath)) {
|
||||
|
||||
LoggerManager.INFO(host, "config not found making config now");
|
||||
//LoggerManager.INFO(null, "config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");
|
||||
Files.copy(defaultConfig, Paths.get("config.yaml"));
|
||||
@@ -69,7 +65,7 @@ public class Main {
|
||||
};
|
||||
} catch (Exception e) {
|
||||
String Error = ErrorToString.errorToString(e);
|
||||
LoggerManager.ERROR(host, Error);
|
||||
// LoggerManager.ERROR(null, Error);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public class CommandSource {
|
||||
private Bot bot;
|
||||
|
||||
@@ -19,6 +22,19 @@ public class CommandSource {
|
||||
|
||||
|
||||
public void sendFeedback (Component message) {
|
||||
String convertToJson = ComponentUtil.componentToJSON(message);
|
||||
Vector3d playerPos = sender.position.position();
|
||||
// System.out.println(sender.position.position().getX());
|
||||
String formatCommand = String.format(
|
||||
"minecraft:summon text_display %s %s %s {tag:[%s], text:%s}",
|
||||
playerPos.getX(),
|
||||
playerPos.getY(),
|
||||
playerPos.getZ(),
|
||||
"NitoriBot",
|
||||
convertToJson
|
||||
);
|
||||
|
||||
// bot.core.run(formatCommand);
|
||||
String selector = String.format(
|
||||
"@p[nbt={UUID:%s}]",
|
||||
sender.entityUUID
|
||||
@@ -27,4 +43,4 @@ public class CommandSource {
|
||||
bot.chat.tellraw(selector, message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerProfileData {
|
||||
@@ -19,6 +21,9 @@ public class PlayerProfileData {
|
||||
public Component displayName;
|
||||
public boolean showHat;
|
||||
public int listOrder;
|
||||
public PlayerPositionData position;
|
||||
public int entityId;
|
||||
public String dimension;
|
||||
|
||||
public PlayerProfileData (
|
||||
UUID uuid,
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.logger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class LoggerManager {
|
||||
private static final DateTimeFormatter formatTime = DateTimeFormatter.ofPattern("hh:mm:ss");
|
||||
|
||||
private static final DateTimeFormatter formatDate = DateTimeFormatter.ofPattern("MM/dd/yyyy");
|
||||
|
||||
public static String prefix (Component type, Component host, String message) {
|
||||
Component component;
|
||||
|
||||
ZoneId timezone = ZoneId.of("America/Chicago");
|
||||
|
||||
ZonedDateTime ZoneDate = ZonedDateTime.now(timezone);
|
||||
LocalDate date = ZoneDate.toLocalDate();
|
||||
LocalTime time = ZoneDate.toLocalTime();
|
||||
|
||||
component = Component.translatable(
|
||||
"[%s %s %s] [%s] [%s] %s",
|
||||
Component.translatable(formatTime.format(time)).color(NamedTextColor.BLUE),
|
||||
Component.translatable(formatDate.format(date)).color(NamedTextColor.BLUE),
|
||||
type,
|
||||
Component.translatable(Thread.currentThread().getName()).color(NamedTextColor.BLUE),
|
||||
host,
|
||||
Component.translatable(message).color(NamedTextColor.WHITE)
|
||||
).color(NamedTextColor.DARK_BLUE);
|
||||
|
||||
return ComponentUtil.componentToAnsi(component);
|
||||
};
|
||||
|
||||
public static void LOG (Component host, String message) {
|
||||
Component type = Component.text("log").color(NamedTextColor.GOLD);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
};
|
||||
|
||||
public static void INFO (Component host, String message) {
|
||||
Component type = Component.text("info").color(NamedTextColor.GREEN);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
};
|
||||
|
||||
public static void COMMAND (Component host, String message) {
|
||||
Component type = Component.text("command").color(NamedTextColor.YELLOW);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
};
|
||||
|
||||
public static void WARN (Component host, String message) {
|
||||
Component type = Component.text("warn").color(NamedTextColor.YELLOW);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
};
|
||||
|
||||
public static void ERROR (Component host, String message) {
|
||||
Component type = Component.text("error").color(NamedTextColor.DARK_RED);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
};
|
||||
|
||||
public static void RECONNECT (Component host, String message) {
|
||||
Component type = Component.text("reconnect").color(NamedTextColor.AQUA);
|
||||
|
||||
System.out.println(prefix(type, host, message));
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -14,10 +14,6 @@ import java.util.List;
|
||||
public class ChatCommandHandlerModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public void sendFeedback (Component message, boolean broadcast) {
|
||||
bot.core.run("say meow");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsedMessage (Component message, PlayerMessageData data) {
|
||||
if (data.chatType != "minecraft:chat") return;
|
||||
@@ -32,8 +28,6 @@ public class ChatCommandHandlerModule extends Listener {
|
||||
String command = plainMessage.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(bot, data.sender);
|
||||
|
||||
Component testMessage = Component.text("hello world!");
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
|
||||
@@ -43,6 +37,6 @@ public class ChatCommandHandlerModule extends Listener {
|
||||
public ChatCommandHandlerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ChatModule extends Listener {
|
||||
public void systemChat (ClientboundSystemChatPacket packet) {
|
||||
final Component message = packet.getContent();
|
||||
|
||||
for (Listener listener : bot.ListenerManager.listeners) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.systemChatReceived(message);
|
||||
}
|
||||
}
|
||||
@@ -65,25 +65,8 @@ public class ChatModule extends Listener {
|
||||
getMessage
|
||||
);
|
||||
}
|
||||
/*
|
||||
parseMessage(message, {
|
||||
players: bot.players,
|
||||
getMessageAsPrismarine: bot.getMessageAsPrismarine,
|
||||
chatType: "minecraft:system_chat",
|
||||
}
|
||||
public PlayerProfileData sender;
|
||||
public Component contents;
|
||||
public String chatType;
|
||||
public Component senderName;
|
||||
*/
|
||||
// parseMessage(
|
||||
// message,
|
||||
//new PlayerMessageData(
|
||||
|
||||
//)
|
||||
//);
|
||||
|
||||
for (Listener listener : bot.ListenerManager.listeners) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.disguisedChatReceived(message);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +77,7 @@ public class ChatModule extends Listener {
|
||||
//final PlayerProfileData sender = bot.players.getPlayerUUID(packet.getSender());
|
||||
//System.out.println(packet.getSender());
|
||||
|
||||
for (Listener listener : bot.ListenerManager.listeners) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
}
|
||||
|
||||
@@ -107,8 +90,6 @@ public class ChatModule extends Listener {
|
||||
bot.players.getPlayerUUID(packet.getSender()).displayName
|
||||
)
|
||||
);
|
||||
//final PlayerMessage playerMessage = new PlayerMessage(sender, parsedFromMessage.contents(), "minecraft:chat", packet.getName());
|
||||
//parseMessage(unsignedContent, packet);
|
||||
}
|
||||
|
||||
public void parseMessage (Component message, PlayerMessageData data) {
|
||||
@@ -122,7 +103,7 @@ public class ChatModule extends Listener {
|
||||
|
||||
if (parsed == null) return;
|
||||
|
||||
for (Listener listener : bot.ListenerManager.listeners) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.parsedMessage(message, data);
|
||||
}
|
||||
|
||||
@@ -151,6 +132,12 @@ public class ChatModule extends Listener {
|
||||
);
|
||||
}
|
||||
|
||||
public void send (String message) {
|
||||
if (message.startsWith("/")) bot.chat.command(message.substring(1));
|
||||
|
||||
else bot.chat.message(message);
|
||||
}
|
||||
|
||||
public void tellraw (String selector, Component message) {
|
||||
bot.core.run("minecraft:tellraw " + selector + " " + GsonComponentSerializer.gson().serialize(message));
|
||||
}
|
||||
@@ -160,6 +147,6 @@ public class ChatModule extends Listener {
|
||||
|
||||
chatParsers.add(new KaboomChatParser(bot));
|
||||
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
};
|
||||
}
|
||||
@@ -1,14 +1,39 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.cloudburstmc.nbt.NbtType;
|
||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.TypedEntityData;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.TypedEntityData.TypedEntityDataBuilder;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.CommandBlockMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.CommandCoreAreaData;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PositionData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
public class CommandCoreModule extends Listener {
|
||||
private Bot bot;
|
||||
@@ -22,6 +47,8 @@ public class CommandCoreModule extends Listener {
|
||||
|
||||
public Vector3i position;
|
||||
|
||||
public Vector3i itemPosition;
|
||||
|
||||
public void move () {
|
||||
Vector3d botPos = bot.position.positionAsVector;
|
||||
position = Vector3i.from(
|
||||
@@ -30,10 +57,16 @@ public class CommandCoreModule extends Listener {
|
||||
Math.floor(botPos.getZ() / 16) * 16
|
||||
);
|
||||
|
||||
refill();
|
||||
itemPosition = Vector3i.from(
|
||||
botPos.getX(),
|
||||
botPos.getY() - 1,
|
||||
botPos.getZ()
|
||||
);
|
||||
|
||||
chatRefill();
|
||||
};
|
||||
|
||||
public void refill () {
|
||||
public void chatRefill () {
|
||||
Vector3i pos = position;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
@@ -58,6 +91,115 @@ public class CommandCoreModule extends Listener {
|
||||
bot.chat.command(command);
|
||||
}
|
||||
|
||||
public void itemRefill () {
|
||||
final NbtMapBuilder blockEntityTagBuilder = NbtMap.builder();
|
||||
|
||||
blockEntityTagBuilder.putString("Command", "say meow")
|
||||
.putByte("auto", (byte) 1)
|
||||
.putByte("TrackOutput", (byte) 1);
|
||||
|
||||
final NbtMap blockEntityTag = blockEntityTagBuilder.build();
|
||||
|
||||
final Map<DataComponentType<?>, DataComponent<?, ?>> map = new HashMap<>();
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
TypedEntityData.<BlockEntityType>builder()
|
||||
.type(BlockEntityType.COMMAND_BLOCK)
|
||||
.tag(blockEntityTag)
|
||||
.build()
|
||||
)
|
||||
);
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
DataComponentTypes.ITEM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
DataComponentTypes.CUSTOM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
|
||||
final DataComponents dataComponents = new DataComponents(map);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundSetCreativeModeSlotPacket(
|
||||
(short) 36,
|
||||
new ItemStack(
|
||||
454,
|
||||
64,
|
||||
dataComponents
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundPlayerActionPacket(
|
||||
PlayerAction.START_DIGGING,
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
0
|
||||
)
|
||||
);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundUseItemOnPacket(
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
Hand.MAIN_HAND,
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5f,
|
||||
false,
|
||||
false,
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
/*
|
||||
ServerboundUseItemOnPacket(
|
||||
Vector3i position,
|
||||
Direction face,
|
||||
Hand hand,
|
||||
float cursorX,
|
||||
float cursorY,
|
||||
float cursorZ,
|
||||
boolean insideBlock,
|
||||
boolean hitWorldBorder,
|
||||
int sequence
|
||||
)
|
||||
itemPosition,
|
||||
Direction.UP,
|
||||
Hand.MAIN_HAND,
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5f,
|
||||
false,
|
||||
1
|
||||
)
|
||||
*/
|
||||
//session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0));
|
||||
//
|
||||
/*
|
||||
session.send(
|
||||
new ServerboundUseItemOnPacket(temporaryBlockPosition, D
|
||||
irection.UP, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, 1));
|
||||
*/
|
||||
public Vector3i currentBlockRelative = Vector3i.from(0, 0, 0);
|
||||
|
||||
public PositionData currentBlock () {
|
||||
@@ -133,6 +275,6 @@ public class CommandCoreModule extends Listener {
|
||||
)
|
||||
);
|
||||
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,7 @@ public class CommandManagerModule {
|
||||
Component.translatable("command.failed").color(NamedTextColor.DARK_RED)
|
||||
);
|
||||
String Error = ErrorToString.errorToString(error);
|
||||
Component host = Component.text(bot.options.host + ":" + bot.options.port).color(NamedTextColor.BLUE);
|
||||
LoggerManager.ERROR(host, Error);
|
||||
LoggerManager.ERROR(bot, Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +1,53 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
//import org.jline
|
||||
import land.chipmunk.parker2991.nitoribot.Main;
|
||||
import org.jline.reader.*;
|
||||
import org.jline.terminal.*;
|
||||
|
||||
public class ConsoleModule extends Listener {
|
||||
import javax.sound.sampled.Line;
|
||||
import java.util.List;
|
||||
|
||||
public class ConsoleModule implements Completer {
|
||||
private Bot bot;
|
||||
|
||||
@Override
|
||||
public void playerChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
};
|
||||
private List<Bot> servers;
|
||||
|
||||
@Override
|
||||
public void disguisedChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
public LineReader reader;
|
||||
|
||||
public Terminal terminal;
|
||||
|
||||
public String server = "all";
|
||||
|
||||
public String readLine (String message) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
}
|
||||
|
||||
public void handleMessages (Component message) {
|
||||
final String host = bot.options.host;
|
||||
final int port = bot.options.port;
|
||||
String parsed = ComponentUtil.componentToAnsi(message);
|
||||
Component component = Component.text(host + ":" + port).color(NamedTextColor.BLUE);
|
||||
LoggerManager.LOG(component, parsed);
|
||||
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
|
||||
}
|
||||
|
||||
public void handleLine (String line) {
|
||||
|
||||
}
|
||||
public ConsoleModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
try {
|
||||
this.bot = bot;
|
||||
|
||||
bot.ListenerManager.addListener(this);
|
||||
this.servers = bot.bots;
|
||||
|
||||
terminal = TerminalBuilder.builder().build();
|
||||
|
||||
reader = LineReaderBuilder.builder().terminal(terminal).build();
|
||||
|
||||
Main.executorService.submit(() -> {
|
||||
while (true) {
|
||||
reader.readLine("> ");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LoggingModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
@Override
|
||||
public void playerChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void disguisedChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
}
|
||||
|
||||
public void handleMessages (Component _message) {
|
||||
final String host = bot.options.host;
|
||||
|
||||
final int port = bot.options.port;
|
||||
|
||||
String message = ComponentUtil.componentToAnsi(_message);
|
||||
LoggerManager.LOG(bot, message);
|
||||
}
|
||||
|
||||
public LoggingModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,47 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoRemovePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoUpdatePacket;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntry;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntryAction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoRemovePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoUpdatePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosRotPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundRemoveEntitiesPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundTeleportEntityPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityPositionSyncPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundEntityTagQuery;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundTagQueryPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.EnumSet;
|
||||
import java.util.UUID;
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerPositionData;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
// private final List<Listener> listeners = new ArrayList<>();
|
||||
public class PlayerListModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public final List<PlayerProfileData> list = new ArrayList<>();
|
||||
|
||||
public int transactionId = 0;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerInfoUpdatePacket) playerInfo((ClientboundPlayerInfoUpdatePacket) packet);
|
||||
else if (packet instanceof ClientboundPlayerInfoRemovePacket) playerRemove((ClientboundPlayerInfoRemovePacket) packet);
|
||||
else if (packet instanceof ClientboundAddEntityPacket) getPlayerPosition((ClientboundAddEntityPacket) packet);
|
||||
else if (packet instanceof ClientboundTagQueryPacket) queryPlayerData((ClientboundTagQueryPacket) packet);
|
||||
}
|
||||
|
||||
public void playerInfo (ClientboundPlayerInfoUpdatePacket packet) {
|
||||
@@ -46,14 +63,56 @@ public class PlayerListModule extends Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void queryPlayerData (ClientboundTagQueryPacket packet) {
|
||||
|
||||
}
|
||||
|
||||
public void getPlayerPosition (ClientboundAddEntityPacket packet) {
|
||||
if (packet.getType() == EntityType.PLAYER) {
|
||||
UUID uuid = packet.getUuid();
|
||||
|
||||
int entityId = packet.getEntityId();
|
||||
|
||||
Vector3d playerPosition = Vector3d.from(packet.getX(), packet.getY(), packet.getZ());
|
||||
|
||||
float yaw = packet.getYaw();
|
||||
|
||||
float pitch = packet.getPitch();
|
||||
|
||||
PlayerProfileData player = getPlayerUUID(uuid);
|
||||
|
||||
player.entityId = entityId;
|
||||
|
||||
player.position = new PlayerPositionData(pitch, yaw, playerPosition);
|
||||
|
||||
// bot.session.send(
|
||||
// new Server
|
||||
//)
|
||||
}
|
||||
}
|
||||
|
||||
public final PlayerProfileData getPlayerByEntityID (int entityId) {
|
||||
for (PlayerProfileData player : list) {
|
||||
if (player.entityId == entityId) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final PlayerProfileData getPlayerUUID (UUID uuid) {
|
||||
PlayerProfileData playerInfo = null;
|
||||
|
||||
for (PlayerProfileData player : list) {
|
||||
if (player.profile.getId().equals(uuid)) {
|
||||
return player;
|
||||
playerInfo = player;
|
||||
}
|
||||
};
|
||||
|
||||
return null;
|
||||
if (playerInfo == null) {};
|
||||
|
||||
return playerInfo;
|
||||
}
|
||||
|
||||
public final PlayerProfileData getDisplayName (Component displayName) {
|
||||
@@ -68,6 +127,7 @@ public class PlayerListModule extends Listener {
|
||||
|
||||
public void updateListed (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) return;
|
||||
|
||||
getPlayer.listed = player.isListed();
|
||||
@@ -122,6 +182,6 @@ public class PlayerListModule extends Listener {
|
||||
}
|
||||
|
||||
public PlayerListModule (Bot bot) {
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class PositionModule extends Listener {
|
||||
)
|
||||
);
|
||||
|
||||
for (Listener listener : bot.ListenerManager.listeners) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.botMoved();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,6 @@ public class PositionModule extends Listener {
|
||||
public PositionModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,6 @@ public class RegistryModule extends Listener {
|
||||
}
|
||||
|
||||
public RegistryModule (Bot bot) {
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class SelfcareModule extends Listener {
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
loadSelfcare();
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -11,7 +11,9 @@ import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
|
||||
public class GamemodeSelfcare extends Listener {
|
||||
public int gamemode = 1;
|
||||
@org.jetbrains.annotations.NotNull
|
||||
private final Bot bot;
|
||||
public int gamemode = 1;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
@@ -42,6 +44,7 @@ public class GamemodeSelfcare extends Listener {
|
||||
}
|
||||
|
||||
public GamemodeSelfcare (Bot bot) {
|
||||
bot.ListenerManager.addListener(this);
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-17
@@ -9,6 +9,8 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
|
||||
import static org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent.*;
|
||||
|
||||
|
||||
public class PermissionSelfcare extends Listener {
|
||||
public int level;
|
||||
@@ -27,28 +29,17 @@ public class PermissionSelfcare extends Listener {
|
||||
|
||||
if (permEntityId == botEntityId) {
|
||||
switch (event) {
|
||||
case EntityEvent.PLAYER_OP_PERMISSION_LEVEL_0:
|
||||
level = 0;
|
||||
break;
|
||||
case EntityEvent.PLAYER_OP_PERMISSION_LEVEL_1:
|
||||
level = 1;
|
||||
break;
|
||||
case EntityEvent.PLAYER_OP_PERMISSION_LEVEL_2:
|
||||
level = 2;
|
||||
break;
|
||||
case EntityEvent.PLAYER_OP_PERMISSION_LEVEL_3:
|
||||
level = 3;
|
||||
break;
|
||||
case EntityEvent.PLAYER_OP_PERMISSION_LEVEL_4:
|
||||
level = 4;
|
||||
break;
|
||||
default:
|
||||
case EntityEvent.PLAYER_SET_NO_PERMISSIONS -> level = 0;
|
||||
case EntityEvent.PLAYER_SET_MODERATOR -> level = 1;
|
||||
case EntityEvent.PLAYER_SET_GAMEMASTER -> level = 2;
|
||||
case EntityEvent.PLAYER_SET_ADMIN -> level = 3;
|
||||
case EntityEvent.PLAYER_SET_OWNER -> level = 4;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public PermissionSelfcare (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.ListenerManager.addListener(this);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user