forked from afspiegeling/NitoriBot
threads! totally not taken from chomens ™️ (i credited chayapak in src/main/resources/info.json)
This commit is contained in:
@@ -40,6 +40,7 @@ kotlin {
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.26.1")
|
||||
implementation("net.lenni0451:Reflect:1.6.2")
|
||||
implementation("org.ow2.asm:asm:9.9.1")
|
||||
implementation("com.google.guava:guava:33.2.1-jre")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,40 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.modules.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.PacketErrorEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
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.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
|
||||
|
||||
// credits to chayapak for the listeners from chomens
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
private final List<SessionAdapter> listeners = new ArrayList<>();
|
||||
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
|
||||
public ClientNetworkSession session;
|
||||
|
||||
public GameProfile profile;
|
||||
|
||||
public Config config;
|
||||
|
||||
public Config.Options options;
|
||||
@@ -31,17 +45,21 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
public ConsoleModule console;
|
||||
|
||||
public SelfcareModule selfcare;
|
||||
|
||||
public void loadModules () {
|
||||
this.chat = new ChatModule(this);
|
||||
this.console = new ConsoleModule(this);
|
||||
this.selfcare = new SelfcareModule(this);
|
||||
}
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, Config config) {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
// loadModules();
|
||||
connect();
|
||||
|
||||
loadModules();
|
||||
};
|
||||
|
||||
public void connect () {
|
||||
@@ -55,20 +73,57 @@ public class Bot extends SessionAdapter {
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
session.addListener(this);
|
||||
loadModules();
|
||||
session.connect(false);
|
||||
//loadModules();
|
||||
session.connect(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnecting (DisconnectingEvent event) {}
|
||||
public void disconnecting (DisconnectingEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
// session.send(packet);
|
||||
public void packetError (PacketErrorEvent error) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginFinishedPacket) packetReceived((ClientboundLoginFinishedPacket) packet);
|
||||
}
|
||||
|
||||
|
||||
public void packetReceived (ClientboundLoginFinishedPacket packet) {
|
||||
profile = packet.getProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
Component component = event.getReason();
|
||||
String reason = ComponentUtil.componentToAnsi(component);
|
||||
Component host = Component.text(options.host + ":" + options.port);
|
||||
LoggerManager.RECONNECT(host, reason);
|
||||
long reconnectDelay = options.reconnectDelay;
|
||||
|
||||
executor.schedule(() -> connect(), reconnectDelay, TimeUnit.MILLISECONDS);
|
||||
/*Timer timer = new Timer();
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
connect();
|
||||
}
|
||||
};
|
||||
timer.schedule(task, reconnectDelay);*/
|
||||
}
|
||||
|
||||
public void addListener (SessionAdapter event) {
|
||||
listeners.add(event);
|
||||
}
|
||||
|
||||
public static class Listener {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package land.chipmunk.parker2991.nitoribot;
|
||||
public class Config {
|
||||
|
||||
public Options[] bots = new Options[]{};
|
||||
|
||||
//public ArrayList Bots = new ArrayList<>();
|
||||
|
||||
public static class Options {
|
||||
public String host;
|
||||
public int port;
|
||||
public String username;
|
||||
public int reconnectDelay;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Thanks Blackilykat and OptmisticDev and PthePro777 helping me with the client creation
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
@@ -17,10 +16,21 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class Main {
|
||||
public final Object obj = new Object();
|
||||
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
|
||||
public final Component host = Component.text("Nitori Jar");
|
||||
|
||||
public static Config config;
|
||||
@@ -28,7 +38,6 @@ public class Main {
|
||||
public final List<Bot> Bots = new ArrayList<>();
|
||||
|
||||
public Config loadConfig() throws IOException {
|
||||
// Blackilykat helped me with the file coping and PthePro777 helped me with reading the file
|
||||
final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
@@ -51,6 +60,7 @@ public class Main {
|
||||
config = loadConfig();
|
||||
Config.Options[] bots = config.bots;
|
||||
|
||||
System.out.println(Thread.currentThread().getName());
|
||||
for (Config.Options options : bots) {
|
||||
final Bot bot = new Bot(options, Bots, config);
|
||||
Bots.add(bot);
|
||||
@@ -59,7 +69,7 @@ public class Main {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (Exception e) {
|
||||
String Error = ErrorToString.ErrorToString(e);
|
||||
String Error = ErrorToString.errorToString(e);
|
||||
LoggerManager.ERROR(host, Error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ package land.chipmunk.parker2991.nitoribot.logger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@@ -15,7 +15,7 @@ import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class LoggerManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoggerManager.class);
|
||||
//private static final Logger logger = LoggerFactory.getLogger(LoggerManager.class);
|
||||
|
||||
private static final DateTimeFormatter formatTime = DateTimeFormatter.ofPattern("hh:mm:ss");
|
||||
|
||||
@@ -27,18 +27,19 @@ public class LoggerManager {
|
||||
ZoneId timezone = ZoneId.of("America/Chicago");
|
||||
|
||||
ZonedDateTime ZoneDate = ZonedDateTime.now(timezone);
|
||||
|
||||
LocalDate date = ZoneDate.toLocalDate();
|
||||
LocalTime time = ZoneDate.toLocalTime();
|
||||
|
||||
System.out.println(Thread.currentThread().getName());
|
||||
component = Component.translatable(
|
||||
"[%s %s %s] [%s] %s",
|
||||
Component.translatable(formatTime.format(time)).color(NamedTextColor.DARK_BLUE),
|
||||
Component.translatable(formatDate.format(date)).color(NamedTextColor.AQUA),
|
||||
"[%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_GRAY);
|
||||
).color(NamedTextColor.DARK_BLUE);
|
||||
|
||||
return ComponentUtil.componentToAnsi(component);
|
||||
};
|
||||
@@ -71,4 +72,10 @@ public class LoggerManager {
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +13,32 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.Clientbound
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ChatModule extends SessionAdapter {
|
||||
private Bot bot;
|
||||
|
||||
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
// totally didnt take this from chomens java
|
||||
if (packet instanceof ClientboundSystemChatPacket) systemChat((ClientboundSystemChatPacket) packet);
|
||||
else if (packet instanceof ClientboundPlayerChatPacket) playerChat((ClientboundPlayerChatPacket) packet);
|
||||
else if (packet instanceof ClientboundDisguisedChatPacket) diguisedChat((ClientboundDisguisedChatPacket) packet);
|
||||
}
|
||||
|
||||
|
||||
public void systemChat (ClientboundSystemChatPacket packet) {
|
||||
final Component message = packet.getContent();
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
final boolean received = listener.systemChatReceived(message);
|
||||
listener.systemChatReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +46,7 @@ public class ChatModule extends SessionAdapter {
|
||||
Component message = packet.getMessage();
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
final boolean received = listener.disguisedChatReceived(message);
|
||||
listener.disguisedChatReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +54,40 @@ public class ChatModule extends SessionAdapter {
|
||||
final Component unsignedContent = packet.getUnsignedContent();
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
final boolean received = listener.playerChatReceived(unsignedContent);
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
}
|
||||
}// session.sendPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0, null, 0, new BitSet(), 0));
|
||||
|
||||
|
||||
public void message (String message) {
|
||||
bot.session.send(
|
||||
new ServerboundChatPacket(
|
||||
message,
|
||||
Instant.now().toEpochMilli(),
|
||||
0,
|
||||
null,
|
||||
0,
|
||||
new BitSet(),
|
||||
0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void command (String command) {
|
||||
bot.session.send(
|
||||
new ServerboundChatCommandPacket(
|
||||
command
|
||||
)
|
||||
);
|
||||
}
|
||||
/*
|
||||
command,
|
||||
Instant.now().toEpochMilli(),
|
||||
0L,
|
||||
Collections.emptyList(),
|
||||
0,
|
||||
new BitSet()
|
||||
*/
|
||||
public ChatModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.session.addListener(this);
|
||||
@@ -66,6 +101,12 @@ public class ChatModule extends SessionAdapter {
|
||||
public boolean disguisedChatReceived (Component message) { return true; };
|
||||
}
|
||||
|
||||
|
||||
//@Override
|
||||
//public void packetReceived (Session session, Packet packet) {
|
||||
|
||||
//}
|
||||
|
||||
public void addListener (Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import land.chipmunk.parker2991.nitoribot.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class ConsoleModule extends ChatModule.Listener {
|
||||
private Bot bot;
|
||||
@@ -33,7 +32,7 @@ public class ConsoleModule extends ChatModule.Listener {
|
||||
final String host = bot.options.host;
|
||||
final int port = bot.options.port;
|
||||
String parsed = ComponentUtil.componentToAnsi(message);
|
||||
Component component = Component.text(host + ":" + port);
|
||||
Component component = Component.text(host + ":" + port).color(NamedTextColor.BLUE);
|
||||
LoggerManager.LOG(component, parsed);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
|
||||
public class SelfcareModule extends SessionAdapter {
|
||||
private Bot bot;
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
// this.bot = bot;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package land.chipmunk.parker2991.nitoribot.selfcare.entity;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
|
||||
|
||||
public class PermissionSelfcare extends SessionAdapter {
|
||||
|
||||
// @Override
|
||||
// public void packetReceived (Session session, Packet packet) {
|
||||
|
||||
//}
|
||||
|
||||
public PermissionSelfcare () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,8 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
// credits to Werkku and OptimisticDev for this
|
||||
public class ErrorToString {
|
||||
public static String ErrorToString (Throwable error) {
|
||||
public static String errorToString (Throwable error) {
|
||||
final var byteArrayOut = new ByteArrayOutputStream();
|
||||
final var outWriter = new OutputStreamWriter(byteArrayOut);
|
||||
final var printWriter = new PrintWriter(outWriter);
|
||||
|
||||
@@ -5,6 +5,19 @@
|
||||
"codename": "Night of Nights",
|
||||
"build": "5200"
|
||||
}
|
||||
}
|
||||
},
|
||||
"owner": "Parker2991",
|
||||
"credits": [
|
||||
{ "name": "_ChipMC_", "reason": "v4.0.0 rewrite" },
|
||||
{ "name": "chayapak", "reason": "v4.0.0-rewrite / listeners for v9.0.0" },
|
||||
{ "name": "_yfd", "reason": "rewriting the discord logging for v4.x and giving tht version a username gen" },
|
||||
{ "name": "aaa/ImFloriz", "reason": "v6.0.3 vanish support" },
|
||||
{ "name": "Ploat/ImGloriz/NamespaceDev", "reason": "v7.0.3 command core runTracked function" },
|
||||
{ "name": "TurtleKid", "reason": "v5.0.7b file logger rewrite" },
|
||||
{ "name": "Blackilykat", "reason": "v9.0.0 client creation / v9.0.0 config creation" },
|
||||
{ "name": "OptimisticDev", "reason": "v9.0.0 client creation / v9.0.0 ErrorToString function / v9.0.0 multi-server connecting / v9.0.0 jar creation" },
|
||||
{ "name": "PthePro777", "reason": "v9.0.0 client creation / v9.0.0 config yaml parsing" },
|
||||
{ "name": "Werkku", "reason": "v9.0.0 ComponentUtil functions / v9.0.0 command sending" }
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
writer.level = info
|
||||
writer.level = error
|
||||
|
||||
Reference in New Issue
Block a user