EMERGENCY THREAD FIX!?!!11!!

This commit is contained in:
Parker2991
2026-09-17 12:07:23 -05:00
parent 6a26617c83
commit 16c92b075d
5 changed files with 80 additions and 48 deletions
+15 -1
View File
@@ -1,3 +1,12 @@
/*
ZoneId timezone = ZoneId.of("America/Chicago");
ZonedDateTime zoneDate = ZonedDateTime.now(timezone);
LocalDate date = zoneDate.toLocalDate();
LocalTime time = zoneDate.toLocalTime();
*/
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
version = "v9.0.0-alpha"
group = "nitoribot"
description = "NitoriBot"
@@ -47,11 +56,16 @@ dependencies {
}
tasks.jar {
val dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy hh:mm:ss a")
val dateTimeInfo = LocalDateTime.now();
manifest {
attributes["Main-Class"] = "land.chipmunk.parker2991.nitoribot.Main"
attributes("Build-Time" to dateTimeFormatter.format(dateTimeInfo))
//attributes["Build-Time"] = dateTimeFormatter.format(dateTimeInfo);
attributes("Enable-Native-Access" to "ALL-UNNAMED")
}
//"Custom-Attribute-Name" to "YourCustomValue"
archiveClassifier.set("all")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
@@ -34,6 +34,10 @@ import java.nio.file.Paths;
public class Bot extends SessionAdapter {
public final ListenerManager listenerManager = new ListenerManager();
//public static final List modulesList = new ArrayList<>();
public List<?> modules;
public boolean loggedIn = false;
public int entityId;
@@ -46,7 +50,7 @@ public class Bot extends SessionAdapter {
public BotBuildInfo botBuildInfo = Main.botBuildInfo;
public RepoCommitInfo repoCommitInfo;
public RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
public ClientNetworkSession session;
@@ -110,19 +114,21 @@ public class Bot extends SessionAdapter {
public void loadModules () {
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);
new CommandSpyModule(this);
modules = List.of(
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),
new CommandSpyModule(this)
);
} catch (Exception e) {
}
}
@@ -132,41 +138,20 @@ public class Bot extends SessionAdapter {
this.bots = bots;
this.config = config;
Main.services.put(
/*Main.services.put(
"bot build information",
executorService.submit(() -> {
this.botBuildInfo = Main.getBuildInfo();
this.repoCommitInfo = Main.getRepoInfo();
})
);
);*/
try {
connect();
} catch (Exception e) {
e.printStackTrace(System.err);
}
Future<?> botBuildThread = services.get("bot build information");
if (botBuildThread != null) {
try {
executorService.submit(() -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
botBuildThread.cancel(true);
}).cancel(true);
/*
i counted how long it takes to get the repo info via https
which is approximately 2 - 3 seconds
so clear the thread after 3 seconds
*/
} catch (Exception e) {
}
}
};
}
public void connect () throws IOException {
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
@@ -71,7 +71,7 @@ public class Main {
String body = response.body();
JsonElement e = JsonParser.parseString(response.body());
info = GSON.fromJson(e.getAsJsonArray().get(1), RepoCommitInfo.class);
info = GSON.fromJson(e.getAsJsonArray().get(0), RepoCommitInfo.class);
} catch (Exception e) {
e.printStackTrace(System.err);
@@ -84,7 +84,7 @@ public class Main {
public static BotBuildInfo botBuildInfo = null;// = getBuildInfo();
public static Config config;
public Config config;
public static final List<Bot> Bots = new ArrayList<>();
@@ -115,6 +115,9 @@ public class Main {
console = new ConsoleModule(config);
repoCommitInfo = getRepoInfo();
botBuildInfo = getBuildInfo();
for (Config.Options options : bots) {
final Bot bot = new Bot(options, Bots, config);
Bots.add(bot);
@@ -9,11 +9,16 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.io.IOException;
import java.net.URL;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
public class InfoCommand extends CommandInfo {
public InfoCommand () {
public InfoCommand () throws IOException {
super(
"info",
CommandTrustLevels.PUBLIC,
@@ -22,6 +27,14 @@ public class InfoCommand extends 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");
@Override
public void execute (CommandContext context) {
var bot = context.bot;
@@ -41,6 +54,18 @@ Commit: fcbd9f983c
GsonComponentSerializer gson = GsonComponentSerializer.gson();
switch (args[0].toLowerCase()) {
case "loaded" -> {
component = Component.translatable(
"%s: %s\n%s: %s\n%s: %s",
Component.text("Modules").color(NamedTextColor.BLUE),
Component.text(bot.modules.size()).color(NamedTextColor.GOLD),
Component.text("Commands").color(NamedTextColor.BLUE),
Component.text(bot.commandManager.commands.size()).color(NamedTextColor.GOLD),
Component.text("Chat Parsers").color(NamedTextColor.BLUE),
Component.text(bot.chat.chatParsers.size()).color(NamedTextColor.GOLD)
);
}
case "version" -> {
BotBuildInfo info = bot.botBuildInfo;
@@ -48,23 +73,27 @@ Commit: fcbd9f983c
ZonedDateTime dateTime = ZonedDateTime.parse(repoCommitInfo.created);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy hh:mm:ss");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy hh:mm:ss a");
component = Component.translatable(
"%s-%s-%s\n%s: %s\n%s: %s\n%s: %s",
"%s-%s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
gson.deserialize(info.buildstring.botName.toString()),
Component.text(info.buildstring.version).color(NamedTextColor.AQUA),
gson.deserialize(info.buildstring.codename.toString()),
Component.text("Build").color(NamedTextColor.BLUE),
Component.text(info.buildstring.build).color(NamedTextColor.YELLOW),
Component.text("Commit").color(NamedTextColor.BLUE),
Component.text(repoCommitInfo.sha.substring(0, 8)).color(NamedTextColor.DARK_BLUE),
Component.text("Version release Date").color(NamedTextColor.BLUE),
Component.text(dateTime.format(dateTimeFormatter)).color(NamedTextColor.DARK_BLUE),
Component.text("Commit").color(NamedTextColor.BLUE),
Component.text(repoCommitInfo.sha.substring(0, 8)).color(NamedTextColor.DARK_BLUE)
Component.text("Initial Bot Release").color(NamedTextColor.BLUE),
Component.text(info.buildstring.initialBotRelease).color(NamedTextColor.DARK_BLUE),
Component.text("Jar Compile Date").color(NamedTextColor.BLUE),
Component.text(buildTime).color(NamedTextColor.DARK_BLUE)
).color(NamedTextColor.GRAY);
}
}
source.sendFeedback(component);
}
}
}
@@ -13,6 +13,7 @@ import land.chipmunk.parker2991.nitoribot.util.ErrorToString;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -74,7 +75,7 @@ public class CommandManagerModule {
this.execute(source, commandName, args);
}
public CommandManagerModule (Bot bot) {
public CommandManagerModule (Bot bot) throws IOException {
this.bot = bot;
registerCommand(new EchoCommand());