added a developer mode, find out how to enable it :3

This commit is contained in:
Parker
2026-12-05 03:02:35 +08:00
parent a1dafa1f25
commit f917edf9d9
9 changed files with 213 additions and 128 deletions
-1
View File
@@ -63,7 +63,6 @@ tasks.jar {
manifest {
attributes["Main-Class"] = "land.chipmunk.parker2991.nitoribot.nightofnights.Main"
attributes("Build-Time" to dateTimeFormatter.format(dateTimeInfo))
attributes("Enable-Native-Access" to "ALL-UNNAMED")
}
archiveClassifier.set("all")
@@ -7,6 +7,7 @@ import com.google.gson.JsonParser;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetBotBuildInfo;
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadConfig;
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadRegistries;
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
import land.chipmunk.parker2991.nitoribot.nightofnights.console.CreateConsole;
import land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks.BlockRegistries;
@@ -36,108 +37,27 @@ import org.slf4j.LoggerFactory;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;
import java.util.Map;
import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
public final class Main implements EventListener {
private static final Gson GSON = new Gson();
public static final ExecutorService executorService = Executors.newSingleThreadExecutor();
public static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
public static final List<NitoriBot> Bots = new ArrayList<>();
public static boolean devModeEnabled = false;
public static RepoCommitInfo repoCommitInfo = null;
public static BotBuildInfo botBuildInfo = null;
public static CreateConsole console;
public static Config config;
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static final List<BlockRegistries> blocks = new ArrayList<>();
public static final List<BlockRegistries> blocks = new LoadRegistries().load();
public static JDA discordClient;
static {
final List<BlockRegistries> registries = new ArrayList<>();
final List<BlockRegistries> blockRegistries = new ArrayList<>();
final Reader blockRegistryReader = new InputStreamReader(Main.class.getResourceAsStream("/blocks" + ".json"));
final Reader registriesReader = new InputStreamReader(Main.class.getResourceAsStream("/registries" + ".json"));
final Map<?, ?> map = GSON.fromJson(
blockRegistryReader,
Map.class
);
for (Map.Entry<?, ?> entry : map.entrySet()) {
String json = GSON.toJson(entry.getValue());
final BlockRegistries parsed = GSON.fromJson(
json,
BlockRegistries.class
);
parsed.block = entry
.getKey()
.toString();
registries.add(parsed);
}
final JsonElement parseRegistries = JsonParser.parseReader(registriesReader);
final JsonElement itemArray = parseRegistries
.getAsJsonObject()
.get("minecraft:item")
.getAsJsonObject()
.get("entries");
final JsonElement blockArray = parseRegistries
.getAsJsonObject()
.get("minecraft:block")
.getAsJsonObject()
.get("entries");
final Map<?, ?> blockEntrySet = GSON.fromJson(
blockArray,
Map.class
);
final Map<?, ?> itemEntrySet = GSON.fromJson(
itemArray,
Map.class
);
for (Map.Entry<?, ?> entry : blockEntrySet.entrySet()) {
String key = entry
.getKey()
.toString();
for (BlockRegistries block : registries) {
if (block.block.equals(key)) {
final JsonObject json = JsonParser
.parseString(entry
.getValue()
.toString())
.getAsJsonObject();
block.blockId = (int) Float.parseFloat(json
.get("protocol_id")
.getAsString());
blockRegistries.add(block);
}
}
}
for (Map.Entry<?, ?> entry : itemEntrySet.entrySet()) {
final String key = entry
.getKey()
.toString();
for (BlockRegistries block : blockRegistries) {
final JsonObject json = JsonParser
.parseString(entry
.getValue()
.toString())
.getAsJsonObject();
if (block.block.equals(key)) {
block.itemId = (int) Float.parseFloat(json
.get("protocol_id")
.getAsString());
blocks.add(block);
}
}
}
}
public static void stop () {
for (final NitoriBot eachBot : Bots) {
eachBot.stop();
@@ -154,6 +74,19 @@ public final class Main implements EventListener {
System.exit(1);
}
public static String getAttribute (String attribute) {
String attributeText = null;
try {
final Enumeration<URL> resources = Main.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
final Manifest manifest = new Manifest(resources.nextElement().openStream());
final Attributes attributes = manifest.getMainAttributes();
attributeText = attributes.getValue(attribute);
} catch (Exception e) {
LOGGER.error("{}", e.getClass(), e);
}
return attributeText;
}
void main () {
try {
System.setProperty(
@@ -161,13 +94,33 @@ public final class Main implements EventListener {
"4"
);
if (getAttribute("Dev-Mode") != null) devModeEnabled = true;
botBuildInfo = new GetBotBuildInfo().getBuildInfo();
config = new LoadConfig().loadConfig();
Config.Options[] bots = config.bots;
console = new CreateConsole();
System.out.println("Starting NitoriBot " + ComponentUtil.componentToAnsi(GsonComponentSerializer
final String codename = ComponentUtil.componentToAnsi(GsonComponentSerializer
.gson()
.deserialize(botBuildInfo.buildstring.codename.toString())));
.deserialize(botBuildInfo.buildstring.codename.toString()));
if (devModeEnabled) {
botBuildInfo.buildstring.version = botBuildInfo.buildstring.version + "-Dev";
final String devMessage = String.format(
"Starting NitoriBot %s-%s-%s",
botBuildInfo.buildstring.version,
codename,
botBuildInfo.buildstring.build
);
LOGGER.info(devMessage);
LOGGER.warn("Developer mode is enabled! there will be a LOT of verbose output in the console");
Thread.sleep(4000);
} else {
System.out.println("Starting NitoriBot");
}
if (config.discord.enabled) {
JDABuilder builder = JDABuilder.createDefault(config.discord.token);
@@ -180,6 +133,8 @@ public final class Main implements EventListener {
discordClient = builder.build();
discordClient.addEventListener(new MessageLogger(discordClient));
discordClient.awaitReady();
if (devModeEnabled) LOGGER.info("Logged into discord with the user " + discordClient.getSelfUser().getAsTag());
}
for (Config.Options options : bots) {
@@ -189,6 +144,13 @@ public final class Main implements EventListener {
config
);
Bots.add(bot);
if (devModeEnabled) LOGGER.info(
"added {}:{} to the list of bots",
bot.options.host,
bot.options.port
);
bot.connect();
}
@@ -0,0 +1,100 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks.BlockRegistries;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class LoadRegistries {
private static final Gson GSON = new Gson();
public List<BlockRegistries> load () {
final List<BlockRegistries> registries = new ArrayList<>();
final List<BlockRegistries> blockRegistries = new ArrayList<>();
final List<BlockRegistries> blocks = new ArrayList<>();
final Reader blockRegistryReader = new InputStreamReader(LoadRegistries.class.getResourceAsStream("/blocks" + ".json"));
final Reader registriesReader = new InputStreamReader(LoadRegistries.class.getResourceAsStream("/registries" + ".json"));
final Map<?, ?> map = GSON.fromJson(
blockRegistryReader,
Map.class
);
for (Map.Entry<?, ?> entry : map.entrySet()) {
String json = GSON.toJson(entry.getValue());
final BlockRegistries parsed = GSON.fromJson(
json,
BlockRegistries.class
);
parsed.block = entry
.getKey()
.toString();
registries.add(parsed);
}
final JsonElement parseRegistries = JsonParser.parseReader(registriesReader);
final JsonElement itemArray = parseRegistries
.getAsJsonObject()
.get("minecraft:item")
.getAsJsonObject()
.get("entries");
final JsonElement blockArray = parseRegistries
.getAsJsonObject()
.get("minecraft:block")
.getAsJsonObject()
.get("entries");
final Map<?, ?> blockEntrySet = GSON.fromJson(
blockArray,
Map.class
);
final Map<?, ?> itemEntrySet = GSON.fromJson(
itemArray,
Map.class
);
for (Map.Entry<?, ?> entry : blockEntrySet.entrySet()) {
String key = entry
.getKey()
.toString();
for (BlockRegistries block : registries) {
if (block.block.equals(key)) {
final JsonObject json = JsonParser
.parseString(entry
.getValue()
.toString())
.getAsJsonObject();
block.blockId = (int) Float.parseFloat(json
.get("protocol_id")
.getAsString());
blockRegistries.add(block);
}
}
}
for (Map.Entry<?, ?> entry : itemEntrySet.entrySet()) {
final String key = entry
.getKey()
.toString();
for (BlockRegistries block : blockRegistries) {
final JsonObject json = JsonParser
.parseString(entry
.getValue()
.toString())
.getAsJsonObject();
if (block.block.equals(key)) {
block.itemId = (int) Float.parseFloat(json
.get("protocol_id")
.getAsString());
blocks.add(block);
}
}
}
return blocks;
}
}
@@ -1,5 +1,6 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
@@ -32,15 +33,8 @@ import java.util.jar.Manifest;
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
public final class InfoCommand implements CommandInfo {
private final Enumeration<URL> resources = InfoCommand.class
.getClassLoader()
.getResources("META-INF/MANIFEST.MF");
private final Manifest manifest = new Manifest(resources
.nextElement()
.openStream());
private final Attributes attributes = manifest.getMainAttributes();
private final String buildTime = attributes.getValue("Build-Time");
private final String classPath = attributes.getValue("Main-Class");
private final String buildTime = Main.getAttribute("Build-Time");
private final String classPath = Main.getAttribute("Main-Class");
public InfoCommand () throws IOException {
@@ -1,5 +1,6 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.console;
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +33,7 @@ public final class FileLogging {
"latest.log"
);
try {
LOGGER.info("compressing log file");
if (Main.devModeEnabled) LOGGER.debug("compressing log file");
if (!Files.exists(newFilePath)) Files.move(
path,
newFilePath
@@ -83,7 +84,7 @@ public final class FileLogging {
);
}
LOGGER.info("Finished compressing log");
if (Main.devModeEnabled) LOGGER.debug("Finished compressing log");
}
public static void writeLog (String message) {
@@ -1,5 +1,6 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
import land.chipmunk.parker2991.nitoribot.nightofnights.chatparsers.kaboom.ChipmunkModChatParser;
import land.chipmunk.parker2991.nitoribot.nightofnights.chatparsers.kaboom.KaboomChatParser;
@@ -88,24 +89,13 @@ public final class ChatModule implements Listener {
for (Listener listener : bot.listenerManager.listeners()) {
listener.systemChatReceived(message);
if (Main.devModeEnabled && Main.getAttribute("Debug-Chat") != null) listener.chatMessageReceived(ChatType.SYSTEM, Component.text(message.toString()));
listener.chatMessageReceived(
ChatType.SYSTEM,
message
);
}
/*
parseMessage(
ChatType.PLAYER,
unsignedContent,
new PlayerMessageData(
bot.players.getPlayerUUID(packet.getSender()),
content,
ChatType.PLAYER,
Objects.requireNonNull(bot.players.getPlayerUUID(packet.getSender())).displayName
)
);
*/
}
public void disguisedChat (ClientboundDisguisedChatPacket packet) {
@@ -137,6 +127,9 @@ public final class ChatModule implements Listener {
);*/
for (Listener listener : bot.listenerManager.listeners()) {
if (Main.devModeEnabled && Main.getAttribute("Debug-Chat") != null) listener.chatMessageReceived(ChatType.DISGUISED,
Component.text(message.toString()));
listener.chatMessageReceived(
ChatType.DISGUISED,
message
@@ -163,6 +156,8 @@ public final class ChatModule implements Listener {
final Component content = Component.text(packet.getContent());
for (Listener listener : bot.listenerManager.listeners()) {
if (Main.devModeEnabled && Main.getAttribute("Debug-Chat") != null) listener.chatMessageReceived(ChatType.PLAYER, Component.text(unsignedContent.toString()));
listener.chatMessageReceived(
ChatType.PLAYER,
unsignedContent
@@ -264,17 +259,5 @@ public final class ChatModule implements Listener {
.trim()
));
}
// final String minimessage = MiniMessage.miniMessage().serialize(message);
//bot.core.run("bcmm " + minimessage);
/*bot.core.run(String.format(
"%s %s %s",
"minecraft:tellraw",
selector,
GsonComponentSerializer
.gson()
.serialize(message)
.trim()
));*/
}
}
@@ -1,5 +1,6 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public.*;
@@ -14,8 +15,11 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.Validat
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.SlashCommandEvent;
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -130,6 +134,43 @@ public final class CommandManagerModule {
source
);
if (Main.devModeEnabled) {
String user = null;
if (source.source().equals(CommandMessageSource.CONSOLE)) user = "CONSOLE";
else if (source.discordEvent() != null) {
final GenericEvent discordEvent = source.discordEvent();
if (discordEvent instanceof MessageReceivedEvent event) {
user = event
.getMember()
.getUser()
.getAsTag();
} else if (discordEvent instanceof SlashCommandInteractionEvent event) {
user = event
.getUser()
.getAsTag();
}
} else {
user = source.sender().profile.getName();
}
final Component component = Component
.empty()
.append(Component.translatable(
"Username: %s | Server %s | Source: %s | Command: %s | Arguments: %s",
Component.text(user),
Component.text(bot.options.host + ":" + bot.options.port),
Component.text(source.source().toString()),
Component.text(commandName),
Component.text(String.join(" ", args))
));
String message = ComponentUtil.componentToAnsi(component);
LOGGER.info(message);
}
final int cmdTrustLevel = command
.getTrustLevel()
.level();
@@ -1,5 +1,6 @@
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
import org.cloudburstmc.math.vector.Vector3d;
@@ -7,12 +8,15 @@ import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public final class PositionModule implements Listener {
private static final Logger LOGGER = LoggerFactory.getLogger(PositionModule.class);
private final NitoriBot bot;
public ScheduledFuture<?> timer;
@@ -41,7 +45,8 @@ public final class PositionModule implements Listener {
z = (int) Math.round(getPosition.getZ());
positionData = Vector3d.from(packet.getPosition());
// positionData = new PositionData( packet.getPosition());
if (Main.devModeEnabled) LOGGER.info(positionData.toString());
if (bot.options.mode.equals("totalfreedom")) {
if (i < 5)
+1 -1
View File
@@ -26,7 +26,7 @@
"color": "blue"
}
],
"build": "5322",
"build": "5323",
"versionReleaseDate": "N\\A",
"initialBotRelease": "November 22, 2022"
},