v9.0.0-alpha build: 5250

This commit is contained in:
Parker2991
2026-08-27 08:40:04 -05:00
parent b0ce56d5c1
commit 9dce8155bd
28 changed files with 674 additions and 130 deletions
+3 -1
View File
@@ -36,7 +36,7 @@ repositories {
//maven("https://libraries.minecraft.net")
// maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
}
dependencies {
@@ -53,8 +53,10 @@ dependencies {
implementation("de.connect2x.trixnity:trixnity-client:5.0.0")
implementation("org.pircbotx:pircbotx:2.1")
implementation("org.jline:jline:4.1.0")
implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.2")
}
application {
mainClass.set("land.chipmunk.parker2991.nitoribot.Main")
}
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
@@ -1,11 +1,12 @@
package land.chipmunk.parker2991.nitoribot;
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
import land.chipmunk.parker2991.nitoribot.logger.Logger;
import land.chipmunk.parker2991.nitoribot.modules.*;
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
import land.chipmunk.parker2991.nitoribot.listeners.*;
import net.kyori.adventure.text.Component;
import org.geysermc.mcprotocollib.network.ProxyInfo;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
@@ -16,13 +17,24 @@ import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.auth.GameProfile;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
import java.io.*;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.Scanner;
import java.nio.file.Paths;
import java.util.Map;
public class Bot extends SessionAdapter {
public final ListenerManager listenerManager = new ListenerManager();
@@ -61,18 +73,53 @@ public class Bot extends SessionAdapter {
public CommandManagerModule commandManager;
public ExtrasMessagingModule extrasMessaging;
public MCServerModule mcServer;
public ProxyInfo randomProxyIp () throws IOException {
String result = null; // stub
Path proxiesPath = Paths.get("proxies.txt");
int countLines = Math.round(
Files.lines(proxiesPath).count()
);
Random random = new Random();
int randomIndex = random.nextInt(countLines);
String[] getIp = Files.lines(proxiesPath)
.skip(randomIndex)
.findAny()
.get()
.split(":");
String ip = getIp[0];
int port = new Integer(getIp[1]);
return new ProxyInfo(
ProxyInfo.Type.SOCKS5,
new InetSocketAddress(ip, port)
);
}
public void loadModules () {
this.chat = new ChatModule(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);
try {
this.chat = new ChatModule(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);
this.extrasMessaging = new ExtrasMessagingModule(this);
new TextDisplayModule(this);
this.mcServer = new MCServerModule(this);
} catch (Exception e) {}
}
public Bot (Config.Options options, List<Bot> bots, Config config) {
@@ -80,24 +127,33 @@ public class Bot extends SessionAdapter {
this.bots = bots;
this.config = config;
this.console = new ConsoleModule(this);
connect();
try {
connect();
} catch (Exception e) {}
};
public void connect () {
public void connect () throws IOException {
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
session = ClientNetworkSessionFactory.factory()
if (options.useProxy) session = ClientNetworkSessionFactory.factory()
.setAddress(
options.host,
options.port
)
.setProxy(randomProxyIp())
.setProtocol(protocol)
.create();
else session = ClientNetworkSessionFactory.factory()
.setAddress(
options.host,
options.port
)
.setProtocol(protocol)
.create();
session.addListener(this);
loadModules();
session.connect(false);
session.connect(false);
}
@Override
@@ -106,6 +162,8 @@ public class Bot extends SessionAdapter {
session.disconnect(reason);
}
// ServerboundPlayerLoadedPacket
@Override
public void packetSent (Session session, Packet packet) {
for (Listener listener : listenerManager.listeners) {
@@ -115,20 +173,30 @@ public class Bot extends SessionAdapter {
@Override
public void packetError (PacketErrorEvent error) {
error.setSuppress(true);
}
@Override
public void packetReceived (Session session, Packet packet) {
for (Listener listener : listenerManager.listeners) {
listener.packetReceived(session, packet);
}
try {
if (packet instanceof ClientboundLoginPacket) this.session.send(
ServerboundPlayerLoadedPacket.INSTANCE
);
if (packet instanceof ClientboundLoginFinishedPacket) getProfile((ClientboundLoginFinishedPacket) packet);
else if (packet instanceof ClientboundLoginPacket) getEntityId((ClientboundLoginPacket) packet);
if (packet instanceof ServerboundPlayerLoadedPacket) {
System.out.println(packet);
}
for (Listener listener : listenerManager.listeners) {
listener.packetReceived(session, packet);
}
if (packet instanceof ClientboundLoginFinishedPacket) getProfile((ClientboundLoginFinishedPacket) packet);
else if (packet instanceof ClientboundLoginPacket) getEntityId((ClientboundLoginPacket) packet);
} catch (Exception e) { }
}
public void getProfile (ClientboundLoginFinishedPacket packet) {
profile = packet.getProfile();
@@ -148,12 +216,17 @@ public class Bot extends SessionAdapter {
Component component = event.getReason();
String reason = ComponentUtil.componentToAnsi(component);
int reconnectDelay = options.reconnectDelay;
System.out.println(reason);
//LoggerManager.RECONNECT(this, reason);
Logger.RECONNECT(this, reason);
executor.schedule(() -> connect(), reconnectDelay, TimeUnit.MILLISECONDS);
executor.schedule(() -> {
try {
connect();
} catch (IOException e) {
throw new RuntimeException(e);
}
}, reconnectDelay, TimeUnit.MILLISECONDS);
}
}
@@ -56,6 +56,7 @@ public class Config {
public static class Options {
public String host;
public int port;
public boolean useProxy;
public String serverName;
public String username;
public int reconnectDelay;
@@ -1,7 +1,6 @@
package land.chipmunk.parker2991.nitoribot;
import land.chipmunk.parker2991.nitoribot.util.ErrorToString;
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
import land.chipmunk.parker2991.nitoribot.modules.ConsoleModule;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.LoaderOptions;
@@ -31,7 +30,7 @@ public class Main {
public static Config config;
public final List<Bot> Bots = new ArrayList<>();
public static final List<Bot> Bots = new ArrayList<>();
public Config loadConfig() throws IOException {
final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
@@ -51,21 +50,24 @@ public class Main {
return config;
}
public static ConsoleModule console;
public void main(String[] args) {
try {
config = loadConfig();
Config.Options[] bots = config.bots;
console = new ConsoleModule(config);
for (Config.Options options : bots) {
final Bot bot = new Bot(options, Bots, config);
Bots.add(bot);
}
synchronized(obj) {
obj.wait();
};
} catch (Exception e) {
String Error = ErrorToString.errorToString(e);
// LoggerManager.ERROR(null, Error);
}
};
}
@@ -13,7 +13,7 @@ public abstract class CommandInfo {
this.description = description;
}
public abstract CommandContext execute (CommandContext context);
public abstract void execute (CommandContext context);
}
@@ -24,7 +24,7 @@ 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(),
@@ -33,8 +33,7 @@ public class CommandSource {
"NitoriBot",
convertToJson
);
// bot.core.run(formatCommand);
String selector = String.format(
"@p[nbt={UUID:%s}]",
sender.entityUUID
@@ -16,18 +16,13 @@ public class EchoCommand extends CommandInfo {
}
@Override
public CommandContext execute(CommandContext context) {
public void execute(CommandContext context) {
Bot bot = context.bot;
String args = String.join(" ", context.args);//context.args.join(' ');
String args = String.join(" ", context.args);
if (args.startsWith("/")) {
bot.chat.command(args.substring("/".length()));
// return;
} else {
bot.chat.message(args);
}
//CommandSource source = context.source;
return null;
}
}
@@ -1,15 +1,21 @@
package land.chipmunk.parker2991.nitoribot.commands.Public;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.Config;
import land.chipmunk.parker2991.nitoribot.command.*;
import land.chipmunk.parker2991.nitoribot.util.TranslationsUtil;
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
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.Arrays;
import java.util.List;
public class HelpCommand extends CommandInfo {
@@ -47,34 +53,101 @@ public class HelpCommand extends CommandInfo {
Component component = Component.empty()
.append(Public)
.append(Component.text("\n"));
.append(Component.text("\n"))
.append(Trusted);
// .append(Component.text("\n"));
return component;
}
private Component getCommand (Bot bot, String[] command) {
List<Component> list = new ArrayList<>();
Component component = null;
for (CommandInfo commands : bot.commandManager.commands) {
if (commands.name.equals(command[0])) component = Component.empty()
.append(
TranslationsUtil.customTranslations(
"command.help.info.layout",
List.of(
TranslationsUtil.customTranslations("command.help.info.command", null).color(NamedTextColor.BLUE),
Component.text(commands.name).color(NamedTextColor.AQUA)
)
)
)
.append(
TranslationsUtil.customTranslations(
"command.help.info.layout",
List.of(
TranslationsUtil.customTranslations("command.help.info.aliases", null).color(NamedTextColor.BLUE),
Component.text(Arrays.toString(commands.aliases)).color(NamedTextColor.AQUA)
)
)
)
.append(
TranslationsUtil.customTranslations(
"command.help.info.layout",
List.of(
TranslationsUtil.customTranslations("command.help.info.description", null).color(NamedTextColor.BLUE),
Component.text(commands.description).color(NamedTextColor.AQUA)
)
)
)
.append(
TranslationsUtil.customTranslations(
"command.help.info.layout",
List.of(
TranslationsUtil.customTranslations("command.help.info.trust_level", null).color(NamedTextColor.BLUE),
Component.text(commands.trustlevel + "").color(NamedTextColor.AQUA)
)
)
)
.append(
TranslationsUtil.customTranslations(
"command.help.info.layout",
List.of(
TranslationsUtil.customTranslations("command.help.info.usages", null).color(NamedTextColor.BLUE),
Component.text("DUMMY String").color(NamedTextColor.AQUA)
)
)
);
}
return component;
}
@Override
public CommandContext execute (CommandContext context) {
public void execute (CommandContext context) {
Bot bot = context.bot;
String[] args = context.args;
CommandSource source = context.source;
Config config = bot.config;
Config.Colors colors = config.colors;
List<Component> list = new ArrayList<>();
Component HelpLayout = Component.translatable(
"%s: (%s) (%s | %s | %s | %s) \u203a\n",
Component.text("Commands").color(NamedTextColor.BLUE),
Component.text(bot.commandManager.commands.size()).color(NamedTextColor.GOLD),
Component.text("Public").color(NamedTextColor.BLUE),
Component.text("Trusted").color(NamedTextColor.DARK_AQUA),
Component.text("Admin").color(NamedTextColor.AQUA),
Component.text("Owner").color(NamedTextColor.LIGHT_PURPLE)
).color(NamedTextColor.GRAY);
if (args.length != 0) {
source.sendFeedback(getCommand(bot, args));
//return null;
}
list = List.of(
Component.text("Commands").color(NamedTextColor.NAMES.value(colors.commands.primary)),
Component.text(bot.commandManager.commands.size()).color(NamedTextColor.NAMES.value(colors.integer)),
TranslationsUtil.customTranslations("command.help.trust_level.public", null).color(NamedTextColor.NAMES.value(colors.help.Public)),
TranslationsUtil.customTranslations("command.help.trust_level.trusted", null).color(NamedTextColor.NAMES.value(colors.help.trusted)),
TranslationsUtil.customTranslations("command.help.trust_level.admin", null).color(NamedTextColor.NAMES.value(colors.help.admin)),
TranslationsUtil.customTranslations("command.help.trust_level.owner", null).color(NamedTextColor.NAMES.value(colors.help.owner))
);
Component helpLayout = TranslationsUtil.customTranslations(
"command.help.layout",
list
);
Component component = Component.empty()
.append(HelpLayout)
.append(helpLayout)
.append(Component.join(JoinConfiguration.separator(Component.space()), getCommands(bot)));
// System.out.println(ComponentUtil.componentToAnsi(component));
source.sendFeedback(component);
return null;
}
}
@@ -0,0 +1,58 @@
package land.chipmunk.parker2991.nitoribot.commands.Public;
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class MCServerCommand extends CommandInfo {
public MCServerCommand () {
super(
"mcserver",
CommandTrustLevels.PUBLIC,
new String[] { "minecraftserver" },
"ping a minecraft server"
);
}
@Override
public void execute (CommandContext context) {
var bot = context.bot;
var source = context.source;
String args = String.join(" ", context.args);
var ip = args.split(":");
var info = bot.mcServer.pingServer(ip);
System.out.println(info);
/*source.sendFeedback(
Component.translatable(
"%s: (%s / %s)",
Component.text("Players").color(NamedTextColor.BLUE),
Component.text(info.playersOnline()).color(NamedTextColor.GOLD),
Component.text(info.maxPlayers()).color(NamedTextColor.GOLD)
)
);*/
/*source.sendFeedback(
Component.translatable(
"Server Version %s %s %s",
Component.text(":").color(NamedTextColor.GRAY),
Component.text(info.versionName()),
Component.text(info.protocolVersion())
)
);*/
//source.sendFeedback(info.description());
}
}
/*
[logs] [System Chat] Ip: kaboom.pw:25565
Players: 8/0
Server Version: Paper 26.2
Welcome to Kaboom!
> Free OP - Anarchy - Creative
*/
@@ -0,0 +1,30 @@
package land.chipmunk.parker2991.nitoribot.commands.Public;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class RCCommand extends CommandInfo {
public RCCommand () {
super(
"rc",
CommandTrustLevels.PUBLIC,
new String[] { "refill", "refillcore" },
"refill the bot's core"
);
}
@Override
public void execute (CommandContext context) {
Bot bot = context.bot;
CommandSource source = context.source;
bot.core.move();
source.sendFeedback(Component.text("Refilling core").color(NamedTextColor.BLUE));
}
}
@@ -0,0 +1,21 @@
package land.chipmunk.parker2991.nitoribot.commands.trusted;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.command.*;
public class ReconnectCommand extends CommandInfo {
public ReconnectCommand () {
super(
"reconnect",
CommandTrustLevels.TRUSTED,
new String[] { },
"reconnect the bot"
);
}
@Override
public void execute (CommandContext context) {
Bot bot = context.bot;
bot.session.disconnect("Reconnect Command");
}
}
@@ -0,0 +1,16 @@
package land.chipmunk.parker2991.nitoribot.data;
import net.kyori.adventure.text.Component;
public record PingServerData (
//String ip,
//int port,
String versionName,
long protocolVersion,
int playersOnline,
int maxPlayers,
Component description
//long latency
) {
public void latency (long pingTime) { System.out.println(versionName); }
}
@@ -1,16 +1,24 @@
package land.chipmunk.parker2991.nitoribot.listeners;
import io.netty.buffer.ByteBuf;
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.packet.Packet;
import land.chipmunk.parker2991.nitoribot.data.chat.PlayerMessageData;
import net.kyori.adventure.text.Component;
import java.util.UUID;
public class Listener {
public void packetSent (Session session, Packet packet) {}
public void packetReceived (Session session, Packet packet) {}
public void extrasMessagingReceived (MCProtocolLibMessenger messenger) {}
public void chatAttestationMessageReceived () {}
public void playerChatReceived (Component message) {}
public void disguisedChatReceived (Component message) {}
@@ -28,7 +28,7 @@ public class ChatCommandHandlerModule extends Listener {
String command = plainMessage.substring(prefix.length());
CommandSource source = new CommandSource(bot, data.sender);
bot.commandManager.executeString(source, command);
}
@@ -74,8 +74,7 @@ public class ChatModule extends Listener {
public void playerChat (ClientboundPlayerChatPacket packet) {
final Component unsignedContent = packet.getUnsignedContent();
final Component content = Component.text(packet.getContent());
//final PlayerProfileData sender = bot.players.getPlayerUUID(packet.getSender());
//System.out.println(packet.getSender());
for (Listener listener : bot.listenerManager.listeners) {
listener.playerChatReceived(unsignedContent);
@@ -3,6 +3,7 @@ package land.chipmunk.parker2991.nitoribot.modules;
import java.util.HashMap;
import java.util.Map;
import land.chipmunk.parker2991.nitoribot.logger.Logger;
import org.cloudburstmc.math.vector.Vector3d;
import org.cloudburstmc.math.vector.Vector3i;
@@ -63,7 +64,7 @@ public class CommandCoreModule extends Listener {
botPos.getZ()
);
chatRefill();
itemRefill();
};
public void chatRefill () {
@@ -78,7 +79,7 @@ public class CommandCoreModule extends Listener {
int endPosZ = pos.getZ() - coreArea.end.getZ();
String command = String.format(
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s} destroy",
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s}",
startPosX,
startPosY,
startPosZ,
@@ -94,7 +95,28 @@ public class CommandCoreModule extends Listener {
public void itemRefill () {
final NbtMapBuilder blockEntityTagBuilder = NbtMap.builder();
blockEntityTagBuilder.putString("Command", "say meow")
Vector3i pos = position;
CommandCoreAreaData coreArea = area;
int startPosX = pos.getX() - coreArea.start.getX();
int startPosY = pos.getY() - coreArea.start.getY();
int startPosZ = pos.getZ() - coreArea.start.getZ();
int endPosX = pos.getX() - coreArea.end.getX();
int endPosY = pos.getY() - coreArea.end.getY();
int endPosZ = pos.getZ() - coreArea.end.getZ();
String command = String.format(
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s} replace",
startPosX,
startPosY,
startPosZ,
endPosX,
endPosY,
endPosZ,
bot.config.core.coreName
);
blockEntityTagBuilder.putString("Command", command)
.putByte("auto", (byte) 1)
.putByte("TrackOutput", (byte) 1);
@@ -141,7 +163,7 @@ public class CommandCoreModule extends Listener {
new ServerboundSetCreativeModeSlotPacket(
(short) 36,
new ItemStack(
454,
482,
64,
dataComponents
)
@@ -171,35 +193,7 @@ public class CommandCoreModule extends Listener {
)
);
}
/*
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 () {
@@ -241,6 +235,7 @@ public class CommandCoreModule extends Listener {
}
public void commandBlock (String command, boolean doesTrackOutput, boolean conditional, boolean automatic) {
if (command.length() > 32767) return;
bot.session.send(
new ServerboundSetCommandBlockPacket(
position,
@@ -6,7 +6,8 @@ import land.chipmunk.parker2991.nitoribot.command.CommandContext;
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
import land.chipmunk.parker2991.nitoribot.commands.Public.*;
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
import land.chipmunk.parker2991.nitoribot.commands.trusted.ReconnectCommand;
import land.chipmunk.parker2991.nitoribot.logger.Logger;
import land.chipmunk.parker2991.nitoribot.util.ErrorToString;
import net.kyori.adventure.text.Component;
@@ -15,6 +16,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
public class CommandManagerModule {
private Bot bot;
@@ -27,6 +29,9 @@ public class CommandManagerModule {
public CommandInfo getCommand (String getCommand) {
for (CommandInfo command : commands) {
for (String aliases : command.aliases) {
if (getCommand.equals(aliases)) return command;
}
if (getCommand.equals(command.name)) return command;
}
return null;
@@ -34,7 +39,7 @@ public class CommandManagerModule {
public void execute (CommandSource source, String commandName, String[] args) {
try {
CommandInfo command = getCommand(commandName);
CommandInfo command = getCommand(commandName.toLowerCase());
if (command == null) throw new CommandError(
Component.translatable(
@@ -57,7 +62,7 @@ public class CommandManagerModule {
Component.translatable("command.failed").color(NamedTextColor.DARK_RED)
);
String Error = ErrorToString.errorToString(error);
LoggerManager.ERROR(bot, Error);
Logger.ERROR(bot, Error);
}
}
@@ -74,5 +79,8 @@ public class CommandManagerModule {
registerCommand(new EchoCommand());
registerCommand(new HelpCommand());
registerCommand(new ReconnectCommand());
registerCommand(new RCCommand());
registerCommand(new MCServerCommand());
}
}
@@ -3,51 +3,49 @@ package land.chipmunk.parker2991.nitoribot.modules;
import land.chipmunk.parker2991.nitoribot.Bot;
//import org.jline
import land.chipmunk.parker2991.nitoribot.Config;
import land.chipmunk.parker2991.nitoribot.Main;
import org.jline.reader.*;
import org.jline.terminal.*;
import javax.sound.sampled.Line;
import java.io.IOException;
import java.util.List;
public class ConsoleModule implements Completer {
private Bot bot;
private List<Bot> servers;
private static final List<Bot> servers = Main.Bots;
public LineReader reader;
public Terminal terminal;
public String server = "all";
public String readLine (String message) {
return "";
}
@Override
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
}
public void handleLine (String line) {
private void handleLine (String line) {
for (Bot bot : servers) {
if (line.equals("c.kill")) System.exit(0);
bot.chat.send(line);
}
}
public ConsoleModule (Bot bot) {
try {
this.bot = bot;
this.servers = bot.bots;
public ConsoleModule (Config config) {
this.reader = LineReaderBuilder.builder()
.completer(this)
.build();
terminal = TerminalBuilder.builder().build();
Main.executorService.submit(() -> {
while (true) {
try {
String line = null;
reader = LineReaderBuilder.builder().terminal(terminal).build();
line = reader.readLine(String.format("[%s] > ", this.server));
Main.executorService.submit(() -> {
while (true) {
reader.readLine("> ");
}
});
} catch (Exception e) {}
handleLine(line);
} catch (Exception e) {}
}
}, "Console Thread");
}
}
@@ -0,0 +1,79 @@
package land.chipmunk.parker2991.nitoribot.modules;
/*
i will work on this module some other time,
i have been messing with it and trying to get it to work for 3 days straight
so this is currently stubbed
*/
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.listeners.*;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.packet.Packet;
import java.util.ArrayList;
import java.util.List;
public class ExtrasMessagingModule extends Listener {
private Bot bot;
public final List<String> channels = new ArrayList<>();
public static final String TEST_CHANNEL = "test";
public void register (String channel) {
}
public void unregister (String channel) {
}
public void sendMessage (MCProtocolLibMessenger messenger, String channel, String message) {
}
@Override
public void extrasMessagingReceived (MCProtocolLibMessenger message) {
/*var findPlayer = bot.players.getPlayerUUID(player).profile.getName();
bot.chat.tellraw("@a[tag=nitoribot_debug]",
Component.text(
"Recieved: " + message + "\n" +
"From: " + findPlayer + "\n" +
"Channel: " + channel
)
);*/
}
@Override
public void packetSent(Session session, Packet packet) {
}
/*
messenger.receivePayloads(
TEST_CHANNEL,
(_, _, payload) -> {
Logger.info(
"Received {}",
payload.toString(StandardCharsets.UTF_8)
);
messenger.sendMessage(TEST_CHANNEL, payload);
}
);
messenger.sendMessage(
TEST_CHANNEL,
wrappedBuffer("echo".getBytes(StandardCharsets.UTF_8))
);
*/
public ExtrasMessagingModule (Bot bot) {
this.bot = bot;
bot.listenerManager.addListener(this);
}
}
@@ -1,7 +1,7 @@
package land.chipmunk.parker2991.nitoribot.modules;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
import land.chipmunk.parker2991.nitoribot.logger.Logger;
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
import land.chipmunk.parker2991.nitoribot.listeners.*;
@@ -31,7 +31,8 @@ public class LoggingModule extends Listener {
final int port = bot.options.port;
String message = ComponentUtil.componentToAnsi(_message);
LoggerManager.LOG(bot, message);
//if (host.equals("kaboom.pw")) return;
// Logger.LOG(bot, message);
}
public LoggingModule (Bot bot) {
@@ -0,0 +1,98 @@
package land.chipmunk.parker2991.nitoribot.modules;
import land.chipmunk.parker2991.nitoribot.Bot;
import land.chipmunk.parker2991.nitoribot.data.PingServerData;
import org.geysermc.mcprotocollib.auth.SessionService;
import org.geysermc.mcprotocollib.network.ClientSession;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.HandPreference;
import org.geysermc.mcprotocollib.protocol.data.game.setting.ChatVisibility;
import org.geysermc.mcprotocollib.protocol.data.game.setting.ParticleStatus;
import org.geysermc.mcprotocollib.protocol.data.game.setting.SkinPart;
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundClientInformationPacket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class MCServerModule {
private Bot bot;
public ClientSession client;
public final SessionService sessionService = new SessionService();
public final MinecraftProtocol protocol = new MinecraftProtocol();
private final List<SkinPart> skinParts = new ArrayList<>();
public PingServerData pingServer (String[] host) {
AtomicReference<PingServerData> serverData = new AtomicReference<>();
client = ClientNetworkSessionFactory.factory()
.setAddress("kaboom.pw", 25565)
//.setAddress(host[0], Integer.parseInt(host[1]))
.setProtocol(protocol)
.create();
client.send(
new ServerboundClientInformationPacket(
"en_us",
1,
ChatVisibility.FULL,
true,
skinParts,
HandPreference.RIGHT_HAND,
false,
true,
ParticleStatus.ALL
)
);
client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
client.setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (Session session, ServerStatusInfo info) -> {
//System.out.println(info.getVersionInfo().getVersionName());
//System.out.println(info.getPlayerInfo().getOnlinePlayers());
//assert info.getVersionInfo() != null;
//assert info.getPlayerInfo() != null;
/*
String versionName,
long protocolVersion,
int playersOnline,
int maxPlayers,
Component description
*/
assert info.getVersionInfo() != null;
assert info.getPlayerInfo() != null;
serverData.set(new PingServerData(
info.getVersionInfo().getVersionName(),
info.getVersionInfo().getProtocolVersion(),
info.getPlayerInfo().getOnlinePlayers(),
info.getPlayerInfo().getMaxPlayers(),
info.getDescription()
));
});
System.out.println(serverData);
client.setFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY, (session, pingTime) ->
serverData.get().latency(pingTime)
);
bot.executor.submit(() -> {
client.connect();
});
return serverData.get();
}
public MCServerModule (Bot bot) {
this.bot = bot;
}
}
@@ -26,6 +26,8 @@ public class RegistryModule extends Listener {
}
}
public RegistryModule (Bot bot) {
bot.listenerManager.addListener(this);
}
@@ -32,7 +32,7 @@ public final class ComponentUtil {
private static final int MAX_DEPTH = 512; //translate depth limit
private static Map<String, String> loadJsonStringMap(String name) {
public static Map<String, String> loadJsonStringMap(String name) {
Map<String, String> map = new HashMap<>();
var is = ClassLoader.getSystemClassLoader().getResourceAsStream(name);
@@ -0,0 +1,39 @@
package land.chipmunk.parker2991.nitoribot.util;
import net.kyori.adventure.text.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class TranslationsUtil {
private static final String TAG = "nitoribot";
private static final Map<String, String> TRANSLATIONS = ComponentUtil.loadJsonStringMap("translations.json");
/*public static void customTranslations (String translation, Component component) {
List<Component> list = new ArrayList<>();
if (component != null) list = List.of(
component
);
customTranslations(translation, list);
}*/
public static Component customTranslations (String translation, List<Component> component) {
Component fallback;
if (component == null) fallback = Component.translatable(TAG + "." + translation).fallback(getTranslation(translation));
else fallback = Component.translatable(TAG + "." + translation, component).fallback(getTranslation(translation));
return fallback;
}
private static String getTranslation (String translation) {
for (Map.Entry<String, String> translations : TRANSLATIONS.entrySet()) {
if (translation.equals(translations.getKey())) return translations.getValue();
}
return null;
}
}
+37 -2
View File
@@ -1,6 +1,41 @@
prefixes:
- "!"
core:
area:
start:
x: 0
y: 0
z: 0
end:
x: 15
y: 0
z: 15
coreName: "[{text:\"Nitori\",color:\"blue\"},{text:\"Bot \",color:\"green\"},{text:\"Core\"}]"
colors:
integer: "gold"
commands:
primary: "blue"
secondary: "aqua"
tertiary: "dark_aqua"
help:
Public: "blue"
trusted: "dark_aqua"
admin: "aqua"
owner: "light_purple"
console: "dark_purple"
console:
prefix: "c."
chatAttestation:
url: "https://optmstc.dev/key-manifest-v1.json"
bots:
- host: "localhost"
port: 25565
username: "meow"
serverName: "localhost"
username: "NitoriBotJava"
reconnectDelay: 6000
selfcareInterval: 1000
selfcareInterval: 1000
+1 -1
View File
@@ -3,7 +3,7 @@
"bot": {
"version": "v9.0.0-alpha",
"codename": "Night of Nights",
"build": "5220"
"build": "5250"
}
},
"owner": "Parker2991",
+12
View File
@@ -1,3 +1,15 @@
{
"command.help.info.aliases":"Aliases",
"command.help.info.command": "Command",
"command.help.info.description": "Description",
"command.help.info.layout": "%s: %s\n",
"command.help.info.trust_level": "Trust Level",
"command.help.info.usages": "Usages",
"command.help.layout": "%s: (%s) (%s | %s | %s | %s) \u203a\n",
"command.help.trust_level.admin": "Admin",
"command.help.trust_level.owner": "Owner",
"command.help.trust_level.public": "Public",
"command.help.trust_level.trusted": "Trusted",
"command.string.placeholder": "DUMMY STRING"
}