mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-11-29 13:45:38 -05:00
Night of Nights build: 5316
This commit is contained in:
+1
-4
@@ -10,14 +10,11 @@ build
|
||||
# Ignore the bin folder vscode keeps creating
|
||||
bin
|
||||
|
||||
# get a nbt parser somewhere else lmao
|
||||
src/main/kotlin
|
||||
|
||||
# proxies
|
||||
proxies.txt
|
||||
|
||||
# ignore the config
|
||||
config.yaml
|
||||
config.yml
|
||||
|
||||
# ignore chat attestation
|
||||
chatattestation
|
||||
|
||||
Generated
-1
@@ -5,7 +5,6 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="25 (2)" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
Generated
+3
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25 (3)" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
Generated
-13
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
Generated
-13
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
@@ -24,11 +24,13 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public @NullMarked class Client extends NitoriBot {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NitoriBot.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);
|
||||
|
||||
public Client (
|
||||
Config.Options options,
|
||||
@@ -63,8 +65,6 @@ public @NullMarked class Client extends NitoriBot {
|
||||
public void disconnecting (
|
||||
DisconnectingEvent event
|
||||
) {
|
||||
Component component = event.getReason();
|
||||
session.disconnect(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,6 +126,7 @@ public @NullMarked class Client extends NitoriBot {
|
||||
public void disconnected (
|
||||
DisconnectedEvent event
|
||||
) {
|
||||
listenerManager.clearListener();
|
||||
loggedIn = false;
|
||||
|
||||
Component host = Component
|
||||
@@ -140,30 +141,22 @@ public @NullMarked class Client extends NitoriBot {
|
||||
.append(host)
|
||||
.append(event.getReason());
|
||||
|
||||
if (services.get("reconnect") != null)
|
||||
services
|
||||
.get("reconnect")
|
||||
.cancel(true);
|
||||
|
||||
logger.reconnect(ComponentUtil.componentToAnsi(reason));
|
||||
|
||||
services.put(
|
||||
"reconnect",
|
||||
executor.schedule(
|
||||
() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
NitoriBot.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
},
|
||||
options.reconnectDelay,
|
||||
TimeUnit.MILLISECONDS
|
||||
)
|
||||
scheduler.schedule(
|
||||
() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
NitoriBot.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
},
|
||||
options.reconnectDelay,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Config {
|
||||
|
||||
public static class Discord {
|
||||
public String token;
|
||||
public boolean enabled;
|
||||
public String prefix;
|
||||
public String invite;
|
||||
public final DiscordRoles roles = new DiscordRoles();
|
||||
|
||||
@@ -27,18 +27,10 @@ import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Main {
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime
|
||||
.getRuntime()
|
||||
.availableProcessors());
|
||||
private static final Gson GSON = new Gson();
|
||||
// public static final ExecutorService virtualThreads = Executors.newVirtualThreadPerTaskExecutor();
|
||||
|
||||
public static final ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(Runtime
|
||||
.getRuntime()
|
||||
.availableProcessors());
|
||||
public static final ConcurrentMap<String, Future<?>> services = new ConcurrentHashMap<>();
|
||||
public static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
public static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
public static final List<NitoriBot> Bots = new ArrayList<>();
|
||||
public static RepoCommitInfo repoCommitInfo = null;
|
||||
public static BotBuildInfo botBuildInfo = null;
|
||||
@@ -49,7 +41,7 @@ public class Main {
|
||||
|
||||
public static JDA discordClient;
|
||||
|
||||
private void parseBlockRegistries () {
|
||||
static {
|
||||
final List<BlockRegistries> registries = new ArrayList<>();
|
||||
final List<BlockRegistries> blockRegistries = new ArrayList<>();
|
||||
final Reader blockRegistryReader = new InputStreamReader(Main.class.getResourceAsStream("/blocks" + ".json"));
|
||||
@@ -90,7 +82,6 @@ public class Main {
|
||||
Map.class
|
||||
);
|
||||
|
||||
|
||||
for (Map.Entry<?, ?> entry : blockEntrySet.entrySet()) {
|
||||
String key = entry
|
||||
.getKey()
|
||||
@@ -128,6 +119,7 @@ public class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main () {
|
||||
try {
|
||||
botBuildInfo = new GetBotBuildInfo().getBuildInfo();
|
||||
@@ -139,22 +131,18 @@ public class Main {
|
||||
console = new CreateConsole();
|
||||
repoCommitInfo = new GetRepoInfo().getRepoInfo();
|
||||
|
||||
executor.setKeepAliveTime(
|
||||
500,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
if (config.discord.enabled) {
|
||||
JDABuilder builder = JDABuilder.createDefault(config.discord.token);
|
||||
builder.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.DIRECT_MESSAGES,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
);
|
||||
|
||||
JDABuilder builder = JDABuilder.createDefault(config.discord.token);
|
||||
builder.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.DIRECT_MESSAGES,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
);
|
||||
|
||||
discordClient = builder.build();
|
||||
discordClient.addEventListener(new MessageLogger(discordClient));
|
||||
discordClient.awaitReady();
|
||||
discordClient = builder.build();
|
||||
discordClient.addEventListener(new MessageLogger(discordClient));
|
||||
discordClient.awaitReady();
|
||||
}
|
||||
|
||||
for (Config.Options options : bots) {
|
||||
final NitoriBot bot = new Client(
|
||||
@@ -163,8 +151,6 @@ public class Main {
|
||||
config
|
||||
);
|
||||
Bots.add(bot);
|
||||
}
|
||||
for (NitoriBot bot : Bots) {
|
||||
bot.connect();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import jdk.jshell.JShell;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.Injector;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessagingEntrypoint;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
@@ -20,12 +21,15 @@ import net.lenni0451.lambdaevents.generator.ReflectionGenerator;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.netty.DefaultPacketHandlerExecutor;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -34,9 +38,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingEntrypoint {
|
||||
public final LoggerManager logger = new LoggerManager();
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
//public final ExecutorService executorService = Main.executorService;
|
||||
public final ConcurrentMap<String, Future<?>> services = Main.services;
|
||||
public final ScheduledExecutorService scheduler = Main.scheduler;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
public Config config;
|
||||
@@ -59,7 +61,34 @@ public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingE
|
||||
public ExtrasMessagingModule extrasMessaging;
|
||||
public List<?> modules;
|
||||
public DiscordModule discord;
|
||||
public final Map<Object, JShell> evalStorage = new HashMap<>();
|
||||
|
||||
public void addServer (String host, int port, String discordChannelId, String username, boolean useProxy) {
|
||||
// this function is here for shits and giggles
|
||||
Config.Options botOptions = new Config.Options();
|
||||
botOptions.host = host;
|
||||
botOptions.port = port;
|
||||
botOptions.username = username;
|
||||
botOptions.discordChannelId = discordChannelId;
|
||||
botOptions.isPrivate = false;
|
||||
botOptions.reconnectDelay = 6000;
|
||||
botOptions.serverName = "test";
|
||||
botOptions.useProxy = useProxy;
|
||||
botOptions.useMiniMessage = false;
|
||||
|
||||
try {
|
||||
NitoriBot client = new Client(
|
||||
botOptions,
|
||||
bots,
|
||||
config
|
||||
);
|
||||
|
||||
// Main.Bots.add(client);
|
||||
|
||||
client.connect();
|
||||
} catch (Exception ignore) {}
|
||||
|
||||
}
|
||||
//public final ChatAttestation chatAttestation = new ChatAttestation();
|
||||
|
||||
public void connect () throws IOException {
|
||||
|
||||
@@ -22,13 +22,13 @@ public class LoadConfig {
|
||||
new LoaderOptions()
|
||||
);
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
final Path configPath = Path.of("config.yml");
|
||||
if (!Files.exists(configPath)) {
|
||||
LOGGER.info("config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("default_config.yaml");
|
||||
.getResourceAsStream("default_config.yml");
|
||||
Files.copy(
|
||||
defaultConfig,
|
||||
configPath
|
||||
|
||||
+4
@@ -48,6 +48,7 @@ public class HelpCommand implements CommandInfo {
|
||||
public Component getCommands (NitoriBot bot) {
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
List<Component> Admin = new ArrayList<>();
|
||||
List<Component> Owner = new ArrayList<>();
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
@@ -62,6 +63,9 @@ public class HelpCommand implements CommandInfo {
|
||||
.getAliases()
|
||||
.getFirst() + " ")
|
||||
.color(convertColorString(bot.config.colors.help.trusted)));
|
||||
case CommandTrustLevels.ADMIN -> Admin.add(Component.text(commands
|
||||
.getAliases()
|
||||
.getFirst() + " ").color(convertColorString(bot.config.colors.help.admin)));
|
||||
case CommandTrustLevels.OWNER -> Owner.add(Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
|
||||
+9
-1
@@ -51,7 +51,15 @@ public class TestCommand implements CommandInfo {
|
||||
|
||||
var source = context.source();
|
||||
|
||||
return null;
|
||||
Component component = Component.text(
|
||||
bot.registry.getBlockRegistry(
|
||||
String.join(
|
||||
" ",
|
||||
args
|
||||
)
|
||||
).toString()
|
||||
);
|
||||
return component;
|
||||
|
||||
// bot.world.getBlock(Vector3i.from(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])));
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.admin;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetcmdCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.ADMIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("netcmd");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "run a command within the bot on another server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner;
|
||||
|
||||
import jdk.jshell.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ServerEvalCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.OWNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"servereval",
|
||||
"se"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "eval code unisolated";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<code>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
final NitoriBot bot = context.bot();
|
||||
final CommandSource source = context.source();
|
||||
Component component = null;
|
||||
final String args = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
|
||||
final JShell jShell = JShell
|
||||
.builder()
|
||||
.executionEngine("local")
|
||||
.build();
|
||||
|
||||
var ee = new ArrayList<>();
|
||||
|
||||
final int idx = ee.indexOf(bot);
|
||||
|
||||
if (bot.evalStorage.isEmpty()) {
|
||||
bot.evalStorage.put(
|
||||
"servereval",
|
||||
jShell
|
||||
);
|
||||
var shell = bot.evalStorage.get("servereval");
|
||||
|
||||
shell.eval("import land.chipmunk.parker2991.nitoribot.nightofnights.Main; ");
|
||||
shell.eval("import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot; ");
|
||||
shell.eval("import net.kyori.adventure.text.Component; ");
|
||||
|
||||
shell.eval("final NitoriBot bot = Main.Bots.get(" + idx + "); ");
|
||||
}
|
||||
|
||||
var shell = bot.evalStorage.get("servereval");
|
||||
|
||||
if (args.equalsIgnoreCase("reset")) {
|
||||
bot.evalStorage.clear();
|
||||
component =
|
||||
Component.text("Resetting the eval").color(convertColorString(bot.config.colors.commands.primary));
|
||||
} else {
|
||||
|
||||
List<SnippetEvent> events = shell.eval(args);
|
||||
|
||||
for (SnippetEvent event : events) {
|
||||
final Snippet.Status status = event.status();
|
||||
|
||||
switch (event.status()) {
|
||||
case VALID -> {
|
||||
String value = event.value();
|
||||
JShellException exception = event.exception();
|
||||
|
||||
if (exception != null) {
|
||||
if (exception instanceof EvalException eval) {
|
||||
|
||||
try {
|
||||
if (eval.getCause() != null) {
|
||||
component = Component.text(
|
||||
exception.getCause().getLocalizedMessage()
|
||||
).color(NamedTextColor.RED);
|
||||
} else {
|
||||
component = Component.text(
|
||||
exception.getMessage()
|
||||
).color(NamedTextColor.RED);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
component =
|
||||
Component.text(eval.toString()).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
}
|
||||
} else if (value == null) {
|
||||
component =
|
||||
Component.text("Ran successfully").color(convertColorString(bot.config.colors.commands.primary));
|
||||
} else {
|
||||
component =
|
||||
Component.text(value).color(convertColorString(bot.config.colors.commands.primary));
|
||||
|
||||
}
|
||||
bot.evalStorage.put(
|
||||
args,
|
||||
shell
|
||||
);
|
||||
}
|
||||
case REJECTED -> {
|
||||
shell
|
||||
.diagnostics(event.snippet())
|
||||
.forEach(diagnostic -> {
|
||||
String msg = diagnostic.getMessage(Locale.US);
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
Component
|
||||
.text(msg.split("\n")[0])
|
||||
.color(NamedTextColor.RED)
|
||||
.hoverEvent(Component
|
||||
.text(msg)
|
||||
.color(NamedTextColor.RED))
|
||||
);
|
||||
});
|
||||
}
|
||||
case OVERWRITTEN -> {
|
||||
component = Component.translatable(
|
||||
"Value %s overridden",
|
||||
Component.text(event.snippet().source())
|
||||
).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
case DROPPED -> {
|
||||
component =
|
||||
Component.text("Explicitly dropped").color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
default -> {
|
||||
component =
|
||||
Component.translatable("Status %s", Component.text(event.status().toString())).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
-4
@@ -11,7 +11,6 @@ public class CreateConsole implements Completer {
|
||||
public LineReader reader;
|
||||
public final String server = "all";
|
||||
|
||||
|
||||
@Override
|
||||
public void complete (
|
||||
LineReader reader,
|
||||
@@ -34,9 +33,6 @@ public class CreateConsole implements Completer {
|
||||
.builder()
|
||||
.completer(this)
|
||||
.build();
|
||||
//this.terminal = TerminalBuilder.builder().build();
|
||||
|
||||
//this.jLineAppender = new JlineAppender();
|
||||
|
||||
JlineAppender.setLineReader(reader);
|
||||
|
||||
|
||||
+12
-12
@@ -26,18 +26,18 @@ public class PlayerProfileData {
|
||||
public boolean alreadyValidated = false;
|
||||
|
||||
public PlayerProfileData (
|
||||
UUID uuid,
|
||||
String entityUUID,
|
||||
GameProfile profile,
|
||||
boolean listed,
|
||||
int latency,
|
||||
GameMode gameMode,
|
||||
Component displayName,
|
||||
boolean showHat,
|
||||
int listOrder,
|
||||
Vector3d position,
|
||||
String dimension,
|
||||
int entityId
|
||||
final UUID uuid,
|
||||
final String entityUUID,
|
||||
final GameProfile profile,
|
||||
final boolean listed,
|
||||
final int latency,
|
||||
final GameMode gameMode,
|
||||
final Component displayName,
|
||||
final boolean showHat,
|
||||
final int listOrder,
|
||||
final Vector3d position,
|
||||
final String dimension,
|
||||
final int entityId
|
||||
) {
|
||||
this.uuid = uuid;
|
||||
this.entityUUID = entityUUID;
|
||||
|
||||
+1
-23
@@ -38,26 +38,4 @@ public class MessageLogger extends ListenerAdapter {
|
||||
public MessageLogger (JDA client) {
|
||||
this.client = client;
|
||||
}
|
||||
}
|
||||
/*for (NitoriBot bot : Main.Bots) {
|
||||
if (!event.getChannel().getId().equals(bot.options.discordChannelId)) return;
|
||||
|
||||
if (event.getAuthor().getId().equals(client.getSelfUser().getId())) return;
|
||||
|
||||
Component component = Component.translatable(
|
||||
"[%s] %s \u203a %s",
|
||||
Component.translatable(
|
||||
"%s%s %s",
|
||||
Component.text("Nitori").color(NamedTextColor.BLUE),
|
||||
Component.text("Bot").color(NamedTextColor.GREEN),
|
||||
Component.text("Discord").color(NamedTextColor.DARK_BLUE)
|
||||
),
|
||||
Component.text(event.getAuthor().getName()).color(NamedTextColor.GRAY),
|
||||
Component.text(event.getMessage().getContentRaw()).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.AQUA);
|
||||
|
||||
bot.chat.tellraw(
|
||||
"@a",
|
||||
component
|
||||
);
|
||||
}*/
|
||||
}
|
||||
+9
-2
@@ -10,6 +10,7 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.PlayerMessageData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -46,10 +47,13 @@ public class ChatCommandHandlerModule implements Listener {
|
||||
);
|
||||
|
||||
|
||||
bot.commandManager.executeString(
|
||||
final Component cmdOutput = bot.commandManager.executeString(
|
||||
source,
|
||||
command
|
||||
);
|
||||
|
||||
if (cmdOutput == null) return;
|
||||
else source.sendFeedback(bot, cmdOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +78,13 @@ public class ChatCommandHandlerModule implements Listener {
|
||||
ParsedChatType.COMMANDSPY
|
||||
);
|
||||
|
||||
bot.commandManager.executeString(
|
||||
final Component cmdOutput = bot.commandManager.executeString(
|
||||
source,
|
||||
command
|
||||
);
|
||||
|
||||
if (cmdOutput == null) return;
|
||||
else source.sendFeedback(bot, cmdOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -3,7 +3,9 @@ package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.admin.NetcmdCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner.KillCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner.ServerEvalCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.ReconnectCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.ValidateCommand;
|
||||
|
||||
@@ -42,6 +44,8 @@ public class CommandManagerModule {
|
||||
registerCommand(new KillCommand());
|
||||
registerCommand(new NetmsgCommand());
|
||||
registerCommand(new RTPCommand());
|
||||
registerCommand(new ServerEvalCommand());
|
||||
registerCommand(new NetcmdCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (CommandInfo command) {
|
||||
@@ -95,11 +99,12 @@ public class CommandManagerModule {
|
||||
return trustLevel;
|
||||
}
|
||||
|
||||
public void execute (
|
||||
public Component execute (
|
||||
CommandSource source,
|
||||
String commandName,
|
||||
String[] args
|
||||
) {
|
||||
Component commandOutput = null;
|
||||
try {
|
||||
CommandInfo command = getCommand(commandName.toLowerCase());
|
||||
|
||||
@@ -186,14 +191,7 @@ public class CommandManagerModule {
|
||||
)
|
||||
.color(NamedTextColor.RED));
|
||||
|
||||
final Component execute = command.execute(context);
|
||||
if (execute == null)
|
||||
return;
|
||||
else
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
execute
|
||||
);
|
||||
commandOutput = command.execute(context);
|
||||
} catch (CommandError error) {
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
@@ -212,9 +210,11 @@ public class CommandManagerModule {
|
||||
error
|
||||
);
|
||||
}
|
||||
|
||||
return commandOutput;
|
||||
}
|
||||
|
||||
public void executeString (
|
||||
public Component executeString (
|
||||
CommandSource source,
|
||||
String command
|
||||
) {
|
||||
@@ -226,7 +226,7 @@ public class CommandManagerModule {
|
||||
splitArguments.length
|
||||
);
|
||||
|
||||
this.execute(
|
||||
return this.execute(
|
||||
source,
|
||||
commandName,
|
||||
args
|
||||
|
||||
+30
-38
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
|
||||
@@ -96,13 +97,6 @@ public class DiscordModule extends ListenerAdapter implements Listener {
|
||||
);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
PlayerProfileData sender,
|
||||
MessageReceivedEvent discordEvent,
|
||||
CommandMessageSource source,
|
||||
ChatType chatType,
|
||||
ParsedChatType parsedChatType
|
||||
*/
|
||||
|
||||
Component component = Component
|
||||
.translatable(
|
||||
@@ -141,42 +135,40 @@ public class DiscordModule extends ListenerAdapter implements Listener {
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof final ClientboundLoginFinishedPacket p) {
|
||||
Timer timer = new Timer();
|
||||
if (!bot.config.discord.enabled) return;
|
||||
bot.scheduler.scheduleAtFixedRate(
|
||||
() -> {
|
||||
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
if (discordQueue.isEmpty())
|
||||
return;
|
||||
try {
|
||||
final String message = String.join(
|
||||
"\n",
|
||||
discordQueue
|
||||
);
|
||||
if (discordQueue.isEmpty())
|
||||
return;
|
||||
try {
|
||||
final String message = String.join(
|
||||
"\n",
|
||||
discordQueue
|
||||
);
|
||||
|
||||
client
|
||||
.getTextChannelById(bot.options.discordChannelId)
|
||||
.sendMessage("```ansi\n" + message.substring(
|
||||
0,
|
||||
Math.min(
|
||||
message.length(),
|
||||
1984
|
||||
)
|
||||
) + "\n```")
|
||||
.queue();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
DiscordModule.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
discordQueue.clear();
|
||||
client
|
||||
.getTextChannelById(bot.options.discordChannelId)
|
||||
.sendMessage("```ansi\n" + message.substring(
|
||||
0,
|
||||
Math.min(
|
||||
message.length(),
|
||||
1984
|
||||
)
|
||||
) + "\n```")
|
||||
.queue();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
DiscordModule.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
discordQueue.clear();
|
||||
},
|
||||
0,
|
||||
2000,
|
||||
2000
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class PositionModule implements Listener {
|
||||
|
||||
if (bot.options.mode.equals("totalfreedom")) {
|
||||
if (i < 5)
|
||||
timer = bot.executor.scheduleAtFixedRate(
|
||||
timer = bot.scheduler.scheduleAtFixedRate(
|
||||
() -> {
|
||||
System.out.println(i);
|
||||
x += 1;
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class RegistryModule implements Listener {
|
||||
public final List<ChatTranslationsData> chatTypes = new ArrayList<>();
|
||||
public final Map<String, DimensionData> dimensions = new HashMap<>();
|
||||
private static final Gson GSON = new Gson();
|
||||
public final List<BlockRegistries> blocks = Main.blocks;
|
||||
public final List<BlockRegistries> blocks = new ArrayList<>();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryModule.class);
|
||||
|
||||
public RegistryModule (NitoriBot bot) {
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class SelfcareModule implements Listener {
|
||||
public void login (ClientboundLoginFinishedPacket packet) {
|
||||
if (bot.options.mode.equals("totalfreedom"))
|
||||
return;
|
||||
timer = bot.executor.scheduleWithFixedDelay(
|
||||
timer = bot.scheduler.scheduleAtFixedRate(
|
||||
() -> {
|
||||
if (permission.permLevel < 2 && bot.loggedIn)
|
||||
bot.chat.command("minecraft:op @s[type=player]");
|
||||
|
||||
+6
-14
@@ -8,6 +8,7 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.Serv
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ValidationModule {
|
||||
@@ -40,19 +41,10 @@ public class ValidationModule {
|
||||
public ValidationModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
trustedHash = generateHash(bot.config.keys.trusted);
|
||||
adminHash = generateHash(bot.config.keys.admin);
|
||||
ownerHash = generateHash(bot.config.keys.owner);
|
||||
}
|
||||
},
|
||||
0,
|
||||
100
|
||||
);
|
||||
bot.scheduler.scheduleAtFixedRate(() -> {
|
||||
trustedHash = generateHash(bot.config.keys.trusted);
|
||||
adminHash = generateHash(bot.config.keys.admin);
|
||||
ownerHash = generateHash(bot.config.keys.owner);
|
||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.util
|
||||
|
||||
import org.cloudburstmc.nbt.NbtList
|
||||
import org.cloudburstmc.nbt.NbtMap
|
||||
import com.google.gson.*
|
||||
|
||||
object NbtMapToJson {
|
||||
|
||||
fun convert(map: NbtMap): JsonObject {
|
||||
val json = JsonObject()
|
||||
|
||||
for ((key, value) in map.entries) {
|
||||
// ifEmpty to fix cloudburstmc NbtMap having empty key for literal strings in text components (e.g. "text" -> {"":"text"})
|
||||
json.add(key.ifEmpty { "text" }, convertValue(value))
|
||||
}
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
private fun convertValue(value: Any?): JsonElement {
|
||||
return when (value) {
|
||||
null -> JsonNull.INSTANCE
|
||||
|
||||
is Byte -> JsonPrimitive(value)
|
||||
is Short -> JsonPrimitive(value)
|
||||
is Int -> JsonPrimitive(value)
|
||||
is Long -> JsonPrimitive(value)
|
||||
is Float -> JsonPrimitive(value)
|
||||
is Double -> JsonPrimitive(value)
|
||||
|
||||
is String -> JsonPrimitive(value)
|
||||
|
||||
is ByteArray -> {
|
||||
val arr = JsonArray()
|
||||
for (b in value) arr.add(b.toInt())
|
||||
arr
|
||||
}
|
||||
|
||||
is IntArray -> {
|
||||
val arr = JsonArray()
|
||||
for (i in value) arr.add(i)
|
||||
arr
|
||||
}
|
||||
|
||||
is LongArray -> {
|
||||
val arr = JsonArray()
|
||||
for (l in value) arr.add(l)
|
||||
arr
|
||||
}
|
||||
|
||||
is NbtMap -> convert(value)
|
||||
|
||||
is NbtList<*> -> {
|
||||
val arr = JsonArray()
|
||||
for (element in value) {
|
||||
arr.add(convertValue(element))
|
||||
}
|
||||
arr
|
||||
}
|
||||
|
||||
is Boolean -> JsonPrimitive(value)
|
||||
|
||||
else -> JsonPrimitive(value.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,18 @@
|
||||
prefixes:
|
||||
- "!"
|
||||
|
||||
discord:
|
||||
token: "<discord token>"
|
||||
enabled: false
|
||||
prefix: "!"
|
||||
invite: "https://discord.gg/GCKtG4erux"
|
||||
roles:
|
||||
trusted: "trusted"
|
||||
admin: "admin"
|
||||
owner: "NitoriBot Owner"
|
||||
|
||||
core:
|
||||
itemRefill: true
|
||||
area:
|
||||
start:
|
||||
x: 0
|
||||
@@ -13,6 +24,12 @@ core:
|
||||
z: 15
|
||||
coreName: "[{text:\"Nitori\",color:\"blue\"},{text:\"Bot \",color:\"green\"},{text:\"Core\"}]"
|
||||
|
||||
keys:
|
||||
trusted: "<key>"
|
||||
admin: "<key>"
|
||||
owner: "<key>"
|
||||
|
||||
|
||||
colors:
|
||||
integer: "gold"
|
||||
commands:
|
||||
@@ -32,7 +49,11 @@ console:
|
||||
bots:
|
||||
- host: "localhost"
|
||||
port: 25565
|
||||
serverName: "localhost"
|
||||
useProxy: false
|
||||
isPrivate: false
|
||||
serverName: "kaboom"
|
||||
username: "NitoriBotJava"
|
||||
discordChannelId: "<discord channel id>"
|
||||
reconnectDelay: 6000
|
||||
selfcareInterval: 1000
|
||||
selfcareInterval: 1000
|
||||
mode: "kaboom"
|
||||
@@ -26,7 +26,7 @@
|
||||
"color": "blue"
|
||||
}
|
||||
],
|
||||
"build": "5315",
|
||||
"build": "5316",
|
||||
"versionReleaseDate": "N\\A",
|
||||
"initialBotRelease": "November 22, 2022"
|
||||
},
|
||||
|
||||
+8561
-7767
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user