forked from afspiegeling/NitoriBot
refactored the command system
made the bot store the config in <home directory root>/.config fuck you custom translations semi-parsed the world
This commit is contained in:
+1
-1
@@ -11,4 +11,4 @@ build
|
||||
bin
|
||||
|
||||
# Ignore the config
|
||||
config.yaml
|
||||
config.yml
|
||||
|
||||
Generated
+7
@@ -1,5 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="PrintToLogpointModuleInspectionState">
|
||||
<option name="disabledModuleNames">
|
||||
<set>
|
||||
<option value="NitoriBot.main" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25 (4)" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
@@ -30,15 +30,11 @@ import java.util.concurrent.*;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
public final ConcurrentMap<String, Future<?>> services = Main.services;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
public ClientNetworkSession session;
|
||||
public GameProfile profile;
|
||||
public final @NotNull Config config;
|
||||
public final Config.Options options;
|
||||
public final List<Bot> bots;
|
||||
@@ -47,8 +43,13 @@ public class Bot extends SessionAdapter {
|
||||
public final CommandCoreModule core;
|
||||
public final PlayerListModule players;
|
||||
public final RegistryModule registry;
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public ClientNetworkSession session;
|
||||
public GameProfile profile;
|
||||
public CommandManagerModule commandManager;
|
||||
public MCServerModule mcServer;
|
||||
public WorldModule world;
|
||||
public List<?> modules;
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, @NotNull Config config) throws IOException {
|
||||
@@ -56,20 +57,7 @@ public class Bot extends SessionAdapter {
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
|
||||
this.modules = List.of(
|
||||
this.chat = new ChatModule(this),
|
||||
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),
|
||||
this.mcServer = new MCServerModule(this),
|
||||
new CommandSpyModule(this)
|
||||
);
|
||||
this.modules = List.of(this.chat = new ChatModule(this), 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), this.mcServer = new MCServerModule(this), new CommandSpyModule(this), this.world = new WorldModule(this));
|
||||
|
||||
try {
|
||||
connect();
|
||||
@@ -81,22 +69,11 @@ public class Bot extends SessionAdapter {
|
||||
public void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProxy(new GetProxiesList().randomProxyIp())
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
if (options.useProxy)
|
||||
session = ClientNetworkSessionFactory.factory().setAddress(options.host, options.port).setProxy(new GetProxiesList().randomProxyIp()).setProtocol(protocol).create();
|
||||
|
||||
else session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
else
|
||||
session = ClientNetworkSessionFactory.factory().setAddress(options.host, options.port).setProtocol(protocol).create();
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
@@ -122,9 +99,7 @@ public class Bot extends SessionAdapter {
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
try {
|
||||
if (packet instanceof ClientboundLoginPacket) this.session.send(
|
||||
ServerboundPlayerLoadedPacket.INSTANCE
|
||||
);
|
||||
if (packet instanceof ClientboundLoginPacket) this.session.send(ServerboundPlayerLoadedPacket.INSTANCE);
|
||||
|
||||
if (packet instanceof ServerboundPlayerLoadedPacket) {
|
||||
System.out.println(packet);
|
||||
@@ -161,15 +136,12 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
if (services.get("reconnect") != null) services.get("reconnect").cancel(true);
|
||||
|
||||
services.put(
|
||||
"reconnect",
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, options.reconnectDelay, TimeUnit.MILLISECONDS)
|
||||
);
|
||||
services.put("reconnect", executor.schedule(() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, options.reconnectDelay, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package land.chipmunk.parker2991.nitoribot;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public final Colors colors = new Colors();
|
||||
public final Core core = new Core();
|
||||
public final Console console = new Console();
|
||||
public final Options[] bots = new Options[]{};
|
||||
public List<String> prefixes;
|
||||
|
||||
public static class Core {
|
||||
@@ -40,19 +44,11 @@ public class Config {
|
||||
}
|
||||
|
||||
public static class Colors {
|
||||
public String integer;
|
||||
public final CommandColors commands = new CommandColors();
|
||||
public final HelpCommandColors help = new HelpCommandColors();
|
||||
public String integer;
|
||||
}
|
||||
|
||||
public final Colors colors = new Colors();
|
||||
|
||||
public final Core core = new Core();
|
||||
|
||||
public final Console console = new Console();
|
||||
|
||||
public final Options[] bots = new Options[]{ };
|
||||
|
||||
public static class Options {
|
||||
public String host;
|
||||
public int port;
|
||||
@@ -63,5 +59,4 @@ public class Config {
|
||||
public int selfcareInterval;
|
||||
public String mode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,26 +12,21 @@ import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class Main {
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ExecutorService virtualThreads = Executors.newVirtualThreadPerTaskExecutor();
|
||||
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ConcurrentMap<String, Future<?>> services = new ConcurrentHashMap<>();
|
||||
public static final List<Bot> Bots = new ArrayList<>();
|
||||
public static RepoCommitInfo repoCommitInfo = null;
|
||||
public static BotBuildInfo botBuildInfo = null;
|
||||
public Config config;
|
||||
public static final List<Bot> Bots = new ArrayList<>();
|
||||
public static ConsoleModule console;
|
||||
public Config config;
|
||||
|
||||
void main (String[] args) {
|
||||
void main () {
|
||||
try {
|
||||
config = new LoadConfig().loadConfig();
|
||||
Config.Options[] bots = config.bots;
|
||||
|
||||
console = new ConsoleModule();
|
||||
repoCommitInfo = new GetRepoInfo().getRepoInfo();
|
||||
botBuildInfo = new GetBotBuildInfo().getBuildInfo();
|
||||
@@ -44,5 +39,4 @@ public class Main {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,10 +12,7 @@ public class GetBotBuildInfo {
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public BotBuildInfo getBuildInfo () {
|
||||
Reader reader = new InputStreamReader(
|
||||
Objects.requireNonNull(Main.class
|
||||
.getResourceAsStream("/info.json"))
|
||||
);
|
||||
Reader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/info.json")));
|
||||
|
||||
return GSON.fromJson(reader, BotBuildInfo.class);
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ public class GetProxiesList {
|
||||
public ProxyInfo randomProxyIp () throws IOException {
|
||||
Path proxiesPath = Paths.get("proxies.txt");
|
||||
|
||||
int countLines = Math.round(
|
||||
Files.lines(proxiesPath).count()
|
||||
);
|
||||
int countLines = Math.round(Files.lines(proxiesPath).count());
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
@@ -24,20 +22,10 @@ public class GetProxiesList {
|
||||
|
||||
List<String> lines = Files.lines(proxiesPath).toList();
|
||||
|
||||
String[] ip = lines.stream()
|
||||
.skip(randomIndex)
|
||||
.findAny()
|
||||
.get()
|
||||
.split(":");
|
||||
String[] ip = lines.stream().skip(randomIndex).findAny().get().split(":");
|
||||
|
||||
InetSocketAddress address = new InetSocketAddress(
|
||||
ip[0],
|
||||
Integer.parseInt(ip[1])
|
||||
);
|
||||
InetSocketAddress address = new InetSocketAddress(ip[0], Integer.parseInt(ip[1]));
|
||||
|
||||
return new ProxyInfo(
|
||||
ProxyInfo.Type.SOCKS5,
|
||||
address
|
||||
);
|
||||
return new ProxyInfo(ProxyInfo.Type.SOCKS5, address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,9 @@ public class GetRepoInfo {
|
||||
|
||||
public RepoCommitInfo getRepoInfo () {
|
||||
final String repo = "https://code.chipmunk.land/api/v1/repos/Parker2991/NitoriBot/commits?sha=main";
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build();
|
||||
HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).connectTimeout(Duration.ofSeconds(10)).build();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(repo))
|
||||
.timeout(Duration.ofSeconds(20))
|
||||
.header("accept", "application/json")
|
||||
.build();
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(repo)).timeout(Duration.ofSeconds(20)).header("accept", "application/json").build();
|
||||
|
||||
RepoCommitInfo info = null;
|
||||
try {
|
||||
|
||||
@@ -13,15 +13,24 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LoadConfig {
|
||||
private static final String XDG_CONFIG_HOME = System.getenv("XDG_CONFIG_HOME");
|
||||
private final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
private final Yaml yaml = new Yaml(yamlConfig);
|
||||
private final String homeDirectory = System.getProperty("user.home");
|
||||
|
||||
public Config loadConfig () throws IOException {
|
||||
final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
if (! Files.exists(configPath)) {
|
||||
Path configDirectory;
|
||||
|
||||
Logger.INFO(null, "config not found making config now");
|
||||
if (XDG_CONFIG_HOME == null) configDirectory = Path.of(homeDirectory, ".config/NitoriBot");
|
||||
else configDirectory = Path.of(XDG_CONFIG_HOME, "NitoriBot");
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");
|
||||
final Path configPath = Path.of(String.valueOf(configDirectory), "config.yml");
|
||||
if (!Files.exists(configPath)) {
|
||||
Logger.INFO(null, "config not found, creating config in " + configPath);
|
||||
|
||||
if (!Files.exists(configDirectory)) Files.createDirectory(configDirectory);
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yml");
|
||||
if (defaultConfig != null) {
|
||||
Files.copy(defaultConfig, configPath);
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import java.util.List;
|
||||
|
||||
public class KaboomChatParser implements ParseChatData {
|
||||
private final Bot bot;
|
||||
private static final Component SEPERATOR_COLON = Component.text(":");
|
||||
private static final Component SEPERATOR_COLON_RACCOON = Component.text("§f:"); // https://github.com/raccoonserver/extras/commit/315f704075db2f00e3e1bfbf55f858469c22880f
|
||||
private static final Component SEPERATOR_SPACE = Component.space();
|
||||
private final Bot bot;
|
||||
|
||||
public KaboomChatParser (Bot bot) {
|
||||
this.bot = bot;
|
||||
@@ -28,8 +28,7 @@ public class KaboomChatParser implements ParseChatData {
|
||||
public PlayerMessageData parse (TextComponent message) {
|
||||
List<Component> children = message.children();
|
||||
|
||||
if (!message.content().isEmpty() || !message.style().isEmpty() || children.size() < 3)
|
||||
return null;
|
||||
if (!message.content().isEmpty() || !message.style().isEmpty() || children.size() < 3) return null;
|
||||
|
||||
final Component prefix = children.getFirst();
|
||||
Component displayName = Component.empty();
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public abstract class CommandInfo {
|
||||
// probably could make this a record or interface
|
||||
public final String name;
|
||||
public final CommandTrustLevels trustlevel;
|
||||
public final String[] aliases;
|
||||
public final String description;
|
||||
import java.util.List;
|
||||
|
||||
public CommandInfo (
|
||||
String name,
|
||||
CommandTrustLevels trustlevel,
|
||||
String[] aliases,
|
||||
String description
|
||||
) {
|
||||
this.name = name;
|
||||
this.trustlevel = trustlevel;
|
||||
this.aliases = aliases;
|
||||
this.description = description;
|
||||
}
|
||||
public interface CommandInfo {
|
||||
//String getCommandName ();
|
||||
|
||||
public abstract void execute (CommandContext context);
|
||||
CommandTrustLevels getTrustLevel ();
|
||||
|
||||
List<String> getAliases ();
|
||||
|
||||
String getDescription ();
|
||||
|
||||
void execute (CommandContext context);
|
||||
}
|
||||
@@ -1,48 +1,16 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandSource {
|
||||
private final Bot bot;
|
||||
public record CommandSource(PlayerProfileData sender, boolean inGame, ParsedChatType chatType) {
|
||||
public void sendFeedback (Bot bot, Component message) {
|
||||
final String selector = String.format("@p[nbt={UUID:%s}]", sender().entityUUID());
|
||||
|
||||
public final PlayerProfileData sender;
|
||||
|
||||
public boolean inGame;
|
||||
|
||||
public final ParsedChatType parsedChatType;
|
||||
|
||||
public CommandSource (Bot bot, ParsedChatType parsedChatType, PlayerProfileData sender) {
|
||||
this.bot = bot;
|
||||
this.parsedChatType = parsedChatType;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void sendFeedback (Component message) {
|
||||
String convertToJson = ComponentUtil.componentToJSON(message);
|
||||
//Vector3d playerPos = sender.position.position();
|
||||
|
||||
/* String formatCommand = String.format(
|
||||
"minecraft:summon text_display %s %s %s {tag:[%s], text:%s}",
|
||||
playerPos.getX(),
|
||||
playerPos.getY(),
|
||||
playerPos.getZ(),
|
||||
"NitoriBot",
|
||||
convertToJson
|
||||
);*/
|
||||
|
||||
String selector = String.format(
|
||||
"@p[nbt={UUID:%s}]",
|
||||
sender.entityUUID()
|
||||
);
|
||||
|
||||
//System.out.println(sender.profile.getName());
|
||||
|
||||
if (this.parsedChatType == ParsedChatType.NORMAL) bot.chat.tellraw("@a", message);
|
||||
if (chatType() == ParsedChatType.NORMAL) bot.chat.tellraw("@a", message);
|
||||
else bot.chat.tellraw(selector, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public enum CommandTrustLevels {
|
||||
PUBLIC,
|
||||
TRUSTED,
|
||||
ADMIN,
|
||||
OWNER,
|
||||
CONSOLE,
|
||||
DISABLED
|
||||
}
|
||||
PUBLIC, TRUSTED, ADMIN, OWNER, CONSOLE, DISABLED
|
||||
}
|
||||
|
||||
@@ -5,14 +5,26 @@ import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
|
||||
public class EchoCommand extends CommandInfo {
|
||||
import java.util.List;
|
||||
|
||||
public class EchoCommand implements CommandInfo {
|
||||
public EchoCommand () {
|
||||
super(
|
||||
"echo",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "say" },
|
||||
"make the bot say a message"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("echo", "say");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "make the bot say something";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,110 +1,65 @@
|
||||
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.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.util.TranslationsUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class HelpCommand extends CommandInfo {
|
||||
import static land.chipmunk.parker2991.nitoribot.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class HelpCommand implements CommandInfo {
|
||||
public HelpCommand () {
|
||||
super(
|
||||
"help",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "heko", "hell", "?", "cmds" },
|
||||
"see the list of commands"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("help", "hell", "?", "heko", "cmds", "commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "see the list of commands the bot has";
|
||||
}
|
||||
|
||||
public Component getCommands (Bot bot) {
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
switch (commands.trustlevel) {
|
||||
case CommandTrustLevels.PUBLIC:
|
||||
Public.add(
|
||||
Component.text(commands.name + " ").color(NamedTextColor.BLUE)
|
||||
);
|
||||
break;
|
||||
case CommandTrustLevels.TRUSTED:
|
||||
Trusted.add(
|
||||
Component.text(commands.name + " ").color(NamedTextColor.DARK_AQUA)
|
||||
);
|
||||
break;
|
||||
switch (commands.getTrustLevel()) {
|
||||
case CommandTrustLevels.PUBLIC -> {
|
||||
Public.add(Component.text(commands.getAliases().getFirst() + " ").color(convertColorString(bot.config.colors.help.Public)));
|
||||
}
|
||||
case CommandTrustLevels.TRUSTED -> {
|
||||
Trusted.add(Component.text(commands.getAliases().getFirst() + " ").color(convertColorString(bot.config.colors.help.trusted)));
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// .append(Component.text("\n"));
|
||||
|
||||
return Component.empty()
|
||||
.append(Public)
|
||||
.append(Component.text("\n"))
|
||||
.append(Trusted);
|
||||
return Component.empty().append(Public).append(Component.text("\n")).append(Trusted);
|
||||
}
|
||||
|
||||
private Component getCommand (Bot bot, String[] command) {
|
||||
|
||||
Component component = null;
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
for (String aliases : commands.aliases) {
|
||||
if (commands.name.equals(command[0]) || aliases.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)
|
||||
)
|
||||
)
|
||||
);
|
||||
for (String aliases : commands.getAliases()) {
|
||||
if (aliases.equals(command[0]))
|
||||
component = Component.translatable("%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", Component.text("Command").color(convertColorString(bot.config.colors.commands.primary)), Component.text(commands.getAliases().getFirst()).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Aliases").color(convertColorString(bot.config.colors.commands.primary)), Component.text(commands.getAliases().toString()).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Description").color(convertColorString(bot.config.colors.commands.primary)), Component.text(commands.getDescription()).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Trust Level").color(convertColorString(bot.config.colors.commands.primary)), Component.text(commands.getTrustLevel().toString()).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Usages").color(convertColorString(bot.config.colors.commands.primary)), Component.text("DUMMY STRING").color(convertColorString(bot.config.colors.commands.secondary))).color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
}
|
||||
return component;
|
||||
@@ -115,34 +70,16 @@ public class HelpCommand extends CommandInfo {
|
||||
Bot bot = context.bot();
|
||||
String[] args = context.args();
|
||||
CommandSource source = context.source();
|
||||
Config config = bot.config;
|
||||
Config.Colors colors;
|
||||
colors = config.colors;
|
||||
List<Component> list;
|
||||
|
||||
if (args.length != 0) {
|
||||
source.sendFeedback(getCommand(bot, args));
|
||||
source.sendFeedback(bot, getCommand(bot, args));
|
||||
return;
|
||||
}
|
||||
|
||||
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 = Component.translatable("%s: (%s) (%s | %s | %s | %s) ›\n", Component.text("Commands").color(convertColorString(bot.config.colors.commands.primary)), Component.text(String.valueOf(bot.commandManager.commands.size())).color(convertColorString(bot.config.colors.integer)), Component.text("Public").color(convertColorString(bot.config.colors.help.Public)), Component.text("Trusted").color(convertColorString(bot.config.colors.help.trusted)), Component.text("Admin").color(convertColorString(bot.config.colors.help.admin)), Component.text("Owner").color(convertColorString(bot.config.colors.help.owner)));
|
||||
|
||||
Component helpLayout = TranslationsUtil.customTranslations(
|
||||
"command.help.layout",
|
||||
list
|
||||
);
|
||||
Component component = Component.empty().append(helpLayout).append(Component.join(JoinConfiguration.separator(Component.space()), getCommands(bot))).color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
Component component = Component.empty()
|
||||
.append(helpLayout)
|
||||
.append(Component.join(JoinConfiguration.separator(Component.space()), getCommands(bot)));
|
||||
|
||||
source.sendFeedback(component);
|
||||
source.sendFeedback(bot, component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.data.buildstring.RepoCommitInfo;
|
||||
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;
|
||||
@@ -14,26 +13,36 @@ import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class InfoCommand extends CommandInfo {
|
||||
import static land.chipmunk.parker2991.nitoribot.util.ComponentUtil.convertColorString;
|
||||
|
||||
public 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");
|
||||
|
||||
public InfoCommand () throws IOException {
|
||||
super(
|
||||
"info",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "information" },
|
||||
"information about the bot"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private final Enumeration<URL> resources = InfoCommand.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
private final Manifest manifest = new Manifest(resources.nextElement().openStream());
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("information", "info");
|
||||
}
|
||||
|
||||
private final Attributes attributes = manifest.getMainAttributes();
|
||||
|
||||
private final String buildTime = attributes.getValue("Build-Time");
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "see the bots info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
@@ -44,25 +53,12 @@ public class InfoCommand extends CommandInfo {
|
||||
var args = context.args();
|
||||
|
||||
Component component = null;
|
||||
/*
|
||||
Build: 3355
|
||||
Repo Build: 242
|
||||
Version Release Date: 10/22/2025, 11:24:04 AM
|
||||
Commit: fcbd9f983c
|
||||
11/22/22-9/10/2026
|
||||
*/
|
||||
|
||||
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 "loaded" ->
|
||||
component = Component.translatable("%s: %s\n%s: %s\n%s: %s", Component.text("Modules").color(convertColorString(bot.config.colors.commands.primary)), Component.text(bot.modules.size()).color(convertColorString(bot.config.colors.integer)), Component.text("Commands").color(convertColorString(bot.config.colors.commands.primary)), Component.text(bot.commandManager.commands.size()).color(convertColorString(bot.config.colors.integer)), Component.text("Chat Parsers").color(convertColorString(bot.config.colors.commands.primary)), Component.text(bot.chat.chatParsers.size()).color(convertColorString(bot.config.colors.integer)));
|
||||
|
||||
case "version" -> {
|
||||
BotBuildInfo info = bot.botBuildInfo;
|
||||
@@ -73,25 +69,10 @@ Commit: fcbd9f983c
|
||||
|
||||
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\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("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);
|
||||
component = Component.translatable("%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(convertColorString(bot.config.colors.commands.secondary)), gson.deserialize(info.buildstring.codename.toString()), Component.text("Build").color(convertColorString(bot.config.colors.commands.primary)), Component.text(info.buildstring.build).color(convertColorString(bot.config.colors.integer)), Component.text("Commit").color(convertColorString(bot.config.colors.commands.primary)), Component.text(repoCommitInfo.sha.substring(0, 8)).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Version release Date").color(convertColorString(bot.config.colors.commands.primary)), Component.text(dateTime.format(dateTimeFormatter)).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Initial Bot Release").color(convertColorString(bot.config.colors.commands.primary)), Component.text(info.buildstring.initialBotRelease).color(convertColorString(bot.config.colors.commands.secondary)), Component.text("Jar Compile Date").color(convertColorString(bot.config.colors.commands.primary)), Component.text(buildTime).color(convertColorString(bot.config.colors.commands.secondary))).color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
}
|
||||
|
||||
source.sendFeedback(component);
|
||||
source.sendFeedback(bot, component);
|
||||
}
|
||||
}
|
||||
+19
-26
@@ -4,14 +4,26 @@ import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
|
||||
public class MCServerCommand extends CommandInfo {
|
||||
import java.util.List;
|
||||
|
||||
public class MCServerCommand implements CommandInfo {
|
||||
public MCServerCommand () {
|
||||
super(
|
||||
"mcserver",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "minecraftserver" },
|
||||
"ping a minecraft server"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("mcserver");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "ping minecraft servers";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,25 +38,6 @@ public class MCServerCommand extends CommandInfo {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -6,16 +6,28 @@ 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 {
|
||||
import java.util.List;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class RCCommand implements CommandInfo {
|
||||
public RCCommand () {
|
||||
super(
|
||||
"rc",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "refill", "refillcore" },
|
||||
"refill the bot's core"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("rc", "refillcore");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "refill the bots core";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,6 +37,6 @@ public class RCCommand extends CommandInfo {
|
||||
|
||||
bot.core.move();
|
||||
|
||||
source.sendFeedback(Component.text("Refilling core").color(NamedTextColor.BLUE));
|
||||
source.sendFeedback(bot, Component.text("Refilling core").color(convertColorString(bot.config.colors.commands.primary)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/*
|
||||
Adventure Minimessage is very fucking weird.....
|
||||
@@ -13,40 +15,39 @@ the fact it uses an HTML style with strings instead of components is very weird
|
||||
it also makes the JSON so fucking big especially with gradients
|
||||
this does remind me of how i did component.push shit in the JS build of my bot aka v8.0.0-Reignite
|
||||
*/
|
||||
public class TestCommand extends CommandInfo {
|
||||
public class TestCommand implements CommandInfo {
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
|
||||
public TestCommand () {
|
||||
super(
|
||||
"test",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[]{ "t" },
|
||||
"testing shit"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "test cmd";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
|
||||
var bot = context.bot();
|
||||
var args = String.join(" ", context.args());
|
||||
|
||||
var source = context.source();
|
||||
|
||||
var component = MINI_MESSAGE.deserialize(
|
||||
String.format(
|
||||
"%s%s %s %s %s %s %s%s%s",
|
||||
"<gradient:dark_aqua:aqua:blue:dark_blue:light_purple:dark_purple>", // gradient shenanigans
|
||||
"Hello World! User:",
|
||||
source.sender.profile().getName(),
|
||||
"UUID:",
|
||||
source.sender.uuid(),
|
||||
"Args:",
|
||||
"<rainbow>", // we gotta turn the arguments gay!
|
||||
args,
|
||||
"</gradient>"
|
||||
)
|
||||
);
|
||||
var component = MINI_MESSAGE.deserialize(String.format("%s%s %s %s %s %s %s%s%s", "<gradient:dark_aqua:aqua:blue:dark_blue:light_purple:dark_purple>", // gradient shenanigans
|
||||
"Hello World! User:", source.sender().profile().getName(), "UUID:", source.sender().uuid(), "Args:", "<rainbow>", // we gotta turn the arguments gay!
|
||||
args, "</gradient>"));
|
||||
|
||||
source.sendFeedback(component);
|
||||
source.sendFeedback(bot, component);
|
||||
}
|
||||
}
|
||||
+19
-7
@@ -5,14 +5,26 @@ import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
|
||||
public class ReconnectCommand extends CommandInfo {
|
||||
import java.util.List;
|
||||
|
||||
public class ReconnectCommand implements CommandInfo {
|
||||
public ReconnectCommand () {
|
||||
super(
|
||||
"reconnect",
|
||||
CommandTrustLevels.TRUSTED,
|
||||
new String[]{ },
|
||||
"reconnect the bot"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.TRUSTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("end");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "reconnect the bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
public enum ChatType {
|
||||
PLAYER,
|
||||
SYSTEM,
|
||||
DISGUISED
|
||||
PLAYER, SYSTEM, DISGUISED
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
public record DimensionData(String dimension, int maxHeight, int minHeight) {
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
public enum ParsedChatType {
|
||||
COMMANDSPY,
|
||||
NORMAL
|
||||
COMMANDSPY, NORMAL
|
||||
}
|
||||
|
||||
@@ -5,12 +5,10 @@ import net.kyori.adventure.text.Component;
|
||||
public record PingServerData(
|
||||
//String ip,
|
||||
//int port,
|
||||
String versionName,
|
||||
long protocolVersion,
|
||||
int playersOnline,
|
||||
int maxPlayers,
|
||||
Component description
|
||||
String versionName, long protocolVersion, int playersOnline, int maxPlayers, Component description
|
||||
//long latency
|
||||
) {
|
||||
public void latency (long pingTime) {System.out.println(versionName);}
|
||||
public void latency (long pingTime) {
|
||||
System.out.println(versionName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record PlayerProfileData(
|
||||
UUID uuid,
|
||||
String entityUUID,
|
||||
GameProfile profile,
|
||||
boolean listed,
|
||||
int latency,
|
||||
GameMode gameMode,
|
||||
Component displayName,
|
||||
boolean showHat,
|
||||
int listOrder,
|
||||
PositionData position,
|
||||
String dimension,
|
||||
Integer entityId
|
||||
) {
|
||||
public record PlayerProfileData(UUID uuid, String entityUUID, GameProfile profile, boolean listed, int latency,
|
||||
GameMode gameMode, Component displayName, boolean showHat, int listOrder,
|
||||
PositionData position, String dimension, Integer entityId) {
|
||||
public void listed (boolean listed) {
|
||||
}
|
||||
|
||||
@@ -29,9 +18,9 @@ public record PlayerProfileData(
|
||||
|
||||
public void latency (int latency) {
|
||||
}
|
||||
|
||||
|
||||
public void position (PositionData position) {
|
||||
}
|
||||
}
|
||||
|
||||
public void displayName (@Nullable Component displayName) {
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import com.google.gson.JsonObject;
|
||||
import java.util.List;
|
||||
|
||||
public class BotBuildInfo {
|
||||
public final BuildInfo buildstring = new BuildInfo();
|
||||
public String owner;
|
||||
public Contributors[] contributors = new Contributors[]{};
|
||||
|
||||
public static class BuildInfo {
|
||||
public List<JsonObject> botName;
|
||||
public String version;
|
||||
@@ -14,14 +18,8 @@ public class BotBuildInfo {
|
||||
public String initialBotRelease;
|
||||
}
|
||||
|
||||
public final BuildInfo buildstring = new BuildInfo();
|
||||
|
||||
public String owner;
|
||||
|
||||
public static class Contributors {
|
||||
public String name;
|
||||
public String reason;
|
||||
}
|
||||
|
||||
public Contributors[] contributors = new Contributors[]{ };
|
||||
}
|
||||
@@ -3,10 +3,5 @@ package land.chipmunk.parker2991.nitoribot.data.chat;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public record PlayerMessageData(
|
||||
PlayerProfileData sender,
|
||||
Component contents,
|
||||
String chatType,
|
||||
Component senderName
|
||||
) {
|
||||
public record PlayerMessageData(PlayerProfileData sender, Component contents, String chatType, Component senderName) {
|
||||
}
|
||||
@@ -5,20 +5,28 @@ import land.chipmunk.parker2991.nitoribot.data.chat.PlayerMessageData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
|
||||
public class Listener {
|
||||
public void packetSent () {}
|
||||
public interface Listener {
|
||||
default void packetSent () {
|
||||
}
|
||||
|
||||
public void packetReceived (Packet packet) {}
|
||||
default void packetReceived (Packet packet) {
|
||||
}
|
||||
|
||||
public void playerChatReceived (Component message) {}
|
||||
default void playerChatReceived (Component message) {
|
||||
}
|
||||
|
||||
public void disguisedChatReceived (Component message) {}
|
||||
default void disguisedChatReceived (Component message) {
|
||||
}
|
||||
|
||||
public void systemChatReceived (Component message) {}
|
||||
default void systemChatReceived (Component message) {
|
||||
}
|
||||
|
||||
public void parsedMessage (PlayerMessageData data) {}
|
||||
default void parsedMessage (PlayerMessageData data) {
|
||||
}
|
||||
|
||||
public void botMoved () {}
|
||||
default void botMoved () {
|
||||
}
|
||||
|
||||
public void commandSpyReceived (PlayerProfileData player, String command) {}
|
||||
default void commandSpyReceived (PlayerProfileData player, String command) {
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,38 @@ public class Logger {
|
||||
|
||||
private final DateTimeFormatter formatDate = DateTimeFormatter.ofPattern("MM/dd/yyyy");
|
||||
|
||||
public Logger () {
|
||||
|
||||
}
|
||||
|
||||
public static void LOG (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.LOG, bot, message);
|
||||
}
|
||||
|
||||
public static void DEBUG (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.DEBUG, bot, message);
|
||||
}
|
||||
|
||||
public static void ERROR (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.ERROR, bot, message);
|
||||
}
|
||||
|
||||
public static void WARN (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.WARN, bot, message);
|
||||
}
|
||||
|
||||
public static void COMMAND (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.COMMAND, bot, message);
|
||||
}
|
||||
|
||||
public static void RECONNECT (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.RECONNECT, bot, message);
|
||||
}
|
||||
|
||||
public static void INFO (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.INFO, bot, message);
|
||||
}
|
||||
|
||||
public Component getLoggerType (LoggerType type) {
|
||||
Component logType = null;
|
||||
switch (type) {
|
||||
@@ -46,78 +78,11 @@ public class Logger {
|
||||
if (bot == null) host = Component.text("NitoriBot Jar").color(NamedTextColor.BLUE);
|
||||
else host = Component.text(bot.options.host + ":" + bot.options.port).color(NamedTextColor.BLUE);
|
||||
|
||||
component = Component.translatable(
|
||||
"[%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_BLUE);
|
||||
component = Component.translatable("[%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_BLUE);
|
||||
|
||||
String log = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
Main.console.reader.printAbove(log);
|
||||
}
|
||||
|
||||
public static void LOG (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.LOG,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void DEBUG (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.DEBUG,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void ERROR (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.ERROR,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void WARN (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.WARN,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void COMMAND (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.COMMAND,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void RECONNECT (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.RECONNECT,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void INFO (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.INFO,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public Logger () {
|
||||
|
||||
if (bot == null) System.out.println(log);
|
||||
else Main.console.reader.printAbove(log);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.logger;
|
||||
|
||||
public enum LoggerType {
|
||||
LOG,
|
||||
DEBUG,
|
||||
INFO,
|
||||
COMMAND,
|
||||
WARN,
|
||||
ERROR,
|
||||
RECONNECT,
|
||||
LOG, DEBUG, INFO, COMMAND, WARN, ERROR, RECONNECT,
|
||||
}
|
||||
+11
-11
@@ -12,12 +12,19 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChatCommandHandlerModule extends Listener {
|
||||
public class ChatCommandHandlerModule implements Listener {
|
||||
private @NotNull final Bot bot;
|
||||
private @NotNull final Config config;
|
||||
|
||||
public ChatCommandHandlerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
this.config = bot.config;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsedMessage ( PlayerMessageData data) {
|
||||
public void parsedMessage (PlayerMessageData data) {
|
||||
if (!data.chatType().equals("minecraft:chat")) return;
|
||||
|
||||
List<String> prefixes = config.prefixes;
|
||||
@@ -29,7 +36,7 @@ public class ChatCommandHandlerModule extends Listener {
|
||||
|
||||
String command = plainMessage.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(bot, ParsedChatType.NORMAL, data.sender());
|
||||
CommandSource source = new CommandSource(data.sender(), true, ParsedChatType.NORMAL);
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
|
||||
@@ -45,16 +52,9 @@ public class ChatCommandHandlerModule extends Listener {
|
||||
|
||||
String command = message.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(bot, ParsedChatType.COMMANDSPY, player);
|
||||
CommandSource source = new CommandSource(player, true, ParsedChatType.COMMANDSPY);
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
}
|
||||
}
|
||||
|
||||
public ChatCommandHandlerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
this.config = bot.config;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -20,17 +20,27 @@ import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatModule extends Listener {
|
||||
public class ChatModule implements Listener {
|
||||
public final List<ParseChatData> chatParsers;
|
||||
private final Bot bot;
|
||||
|
||||
public final List<ParseChatData> chatParsers;
|
||||
public ChatModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.chatParsers = List.of(new KaboomChatParser(bot));
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof ClientboundSystemChatPacket) systemChat((ClientboundSystemChatPacket) packet);
|
||||
else if (packet instanceof ClientboundPlayerChatPacket) playerChat((ClientboundPlayerChatPacket) packet);
|
||||
else if (packet instanceof ClientboundDisguisedChatPacket)
|
||||
diguisedChat((ClientboundDisguisedChatPacket) packet);
|
||||
switch (packet) {
|
||||
case ClientboundSystemChatPacket p -> systemChat(p);
|
||||
case ClientboundPlayerChatPacket p -> playerChat(p);
|
||||
case ClientboundDisguisedChatPacket p -> disguisedChat(p);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String parseChatTypes (int chatType) {
|
||||
@@ -46,7 +56,7 @@ public class ChatModule extends Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void diguisedChat (ClientboundDisguisedChatPacket packet) {
|
||||
public void disguisedChat (ClientboundDisguisedChatPacket packet) {
|
||||
Component getMessage = packet.getMessage();
|
||||
Component targetUsername = packet.getName();
|
||||
|
||||
@@ -57,11 +67,7 @@ public class ChatModule extends Listener {
|
||||
if (packet.getChatType().id() == 4) {
|
||||
message = getMessage;
|
||||
} else {
|
||||
message = Component.translatable(
|
||||
parseChatTypes,
|
||||
targetUsername,
|
||||
getMessage
|
||||
);
|
||||
message = Component.translatable(parseChatTypes, targetUsername, getMessage);
|
||||
}
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
@@ -70,15 +76,7 @@ public class ChatModule extends Listener {
|
||||
|
||||
TextComponent textComponent = (TextComponent) targetUsername;
|
||||
|
||||
parseMessage(
|
||||
message,
|
||||
new PlayerMessageData(
|
||||
bot.players.getPlayerByUsername(textComponent.content()),
|
||||
packet.getMessage(),
|
||||
"minecraft:chat",
|
||||
Objects.requireNonNull(bot.players.getPlayerByUsername(textComponent.content())).displayName()
|
||||
)
|
||||
);
|
||||
parseMessage(message, new PlayerMessageData(bot.players.getPlayerByUsername(textComponent.content()), packet.getMessage(), "minecraft:chat", Objects.requireNonNull(bot.players.getPlayerByUsername(textComponent.content())).displayName()));
|
||||
}
|
||||
|
||||
public void playerChat (ClientboundPlayerChatPacket packet) {
|
||||
@@ -89,15 +87,7 @@ public class ChatModule extends Listener {
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
}
|
||||
|
||||
parseMessage(
|
||||
unsignedContent,
|
||||
new PlayerMessageData(
|
||||
bot.players.getPlayerUUID(packet.getSender()),
|
||||
content,
|
||||
"minecraft:chat",
|
||||
Objects.requireNonNull(bot.players.getPlayerUUID(packet.getSender())).displayName()
|
||||
)
|
||||
);
|
||||
parseMessage(unsignedContent, new PlayerMessageData(bot.players.getPlayerUUID(packet.getSender()), content, "minecraft:chat", Objects.requireNonNull(bot.players.getPlayerUUID(packet.getSender())).displayName()));
|
||||
}
|
||||
|
||||
public void parseMessage (Component message, PlayerMessageData data) {
|
||||
@@ -120,25 +110,11 @@ public class ChatModule extends Listener {
|
||||
}
|
||||
|
||||
public void message (String message) {
|
||||
bot.session.send(
|
||||
new ServerboundChatPacket(
|
||||
message,
|
||||
Instant.now().toEpochMilli(),
|
||||
0,
|
||||
null,
|
||||
0,
|
||||
new BitSet(),
|
||||
0
|
||||
)
|
||||
);
|
||||
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
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundChatCommandPacket(command));
|
||||
}
|
||||
|
||||
public void send (String message) {
|
||||
@@ -148,24 +124,7 @@ public class ChatModule extends Listener {
|
||||
}
|
||||
|
||||
public void tellraw (String selector, Component message) {
|
||||
bot.core.run(
|
||||
String.format(
|
||||
"%s %s %s",
|
||||
"minecraft:tellraw",
|
||||
selector,
|
||||
GsonComponentSerializer.gson().serialize(message).trim()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public ChatModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.chatParsers = List.of(
|
||||
new KaboomChatParser(bot)
|
||||
);
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
bot.core.run(String.format("%s %s %s", "minecraft:tellraw", selector, GsonComponentSerializer.gson().serialize(message).trim()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,33 +25,30 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandCoreModule extends Listener {
|
||||
private @NotNull final Bot bot;
|
||||
|
||||
public class CommandCoreModule implements Listener {
|
||||
public final CommandCoreAreaData area;
|
||||
private @NotNull final Bot bot;
|
||||
public Vector3i position;
|
||||
public Vector3i itemPosition;
|
||||
public Vector3d currentBlockRelative = Vector3d.from(0, 0, 0);
|
||||
|
||||
public CommandCoreModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.area = new CommandCoreAreaData(Vector3d.from(bot.config.core.area.start.x, bot.config.core.area.start.y, bot.config.core.area.start.z), Vector3d.from(bot.config.core.area.end.x, bot.config.core.area.end.y, bot.config.core.area.end.z));
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void botMoved () {
|
||||
move();
|
||||
}
|
||||
|
||||
public Vector3i position;
|
||||
|
||||
public Vector3i itemPosition;
|
||||
|
||||
public void move () {
|
||||
Vector3d botPos = bot.position.positionData.position();
|
||||
position = Vector3i.from(
|
||||
Math.floor(botPos.getX() / 16) * 16,
|
||||
0,
|
||||
Math.floor(botPos.getZ() / 16) * 16
|
||||
);
|
||||
position = Vector3i.from(Math.floor(botPos.getX() / 16) * 16, 0, Math.floor(botPos.getZ() / 16) * 16);
|
||||
|
||||
itemPosition = Vector3i.from(
|
||||
botPos.getX(),
|
||||
botPos.getY() - 1,
|
||||
botPos.getZ()
|
||||
);
|
||||
itemPosition = Vector3i.from(botPos.getX(), botPos.getY() - 1, botPos.getZ());
|
||||
|
||||
chatRefill();
|
||||
}
|
||||
@@ -67,16 +64,7 @@ public class CommandCoreModule extends Listener {
|
||||
int endPosY = (int) Math.floor(pos.getY() - coreArea.end().getY());
|
||||
int endPosZ = (int) Math.floor(pos.getZ() - coreArea.end().getZ());
|
||||
|
||||
String command = String.format(
|
||||
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s} destroy",
|
||||
startPosX,
|
||||
startPosY,
|
||||
startPosZ,
|
||||
endPosX,
|
||||
endPosY,
|
||||
endPosZ,
|
||||
bot.config.core.coreName
|
||||
);
|
||||
String command = String.format("minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s} destroy", startPosX, startPosY, startPosZ, endPosX, endPosY, endPosZ, bot.config.core.coreName);
|
||||
|
||||
bot.chat.command(command);
|
||||
}
|
||||
@@ -86,82 +74,25 @@ public class CommandCoreModule extends Listener {
|
||||
|
||||
String command = getCommand();
|
||||
|
||||
blockEntityTagBuilder.putString("Command", command)
|
||||
.putByte("auto", (byte) 1)
|
||||
.putByte("TrackOutput", (byte) 1);
|
||||
blockEntityTagBuilder.putString("Command", command).putByte("auto", (byte) 1).putByte("TrackOutput", (byte) 1);
|
||||
|
||||
final NbtMap blockEntityTag = blockEntityTagBuilder.build();
|
||||
|
||||
final Map<DataComponentType<?>, DataComponent<?, ?>> map = new HashMap<>();
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
TypedEntityData.<BlockEntityType>builder()
|
||||
.type(BlockEntityType.COMMAND_BLOCK)
|
||||
.tag(blockEntityTag)
|
||||
.build()
|
||||
)
|
||||
);
|
||||
map.put(DataComponentTypes.BLOCK_ENTITY_DATA, DataComponentTypes.BLOCK_ENTITY_DATA.getDataComponentFactory().create(DataComponentTypes.BLOCK_ENTITY_DATA, TypedEntityData.<BlockEntityType>builder().type(BlockEntityType.COMMAND_BLOCK).tag(blockEntityTag).build()));
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
DataComponentTypes.ITEM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
map.put(DataComponentTypes.ITEM_NAME, DataComponentTypes.ITEM_NAME.getDataComponentFactory().create(DataComponentTypes.ITEM_NAME, ComponentUtil.componentFromJSON(bot.config.core.coreName)));
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
DataComponentTypes.CUSTOM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
map.put(DataComponentTypes.CUSTOM_NAME, DataComponentTypes.CUSTOM_NAME.getDataComponentFactory().create(DataComponentTypes.CUSTOM_NAME, ComponentUtil.componentFromJSON(bot.config.core.coreName)));
|
||||
|
||||
final DataComponents dataComponents = new DataComponents(map);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundSetCreativeModeSlotPacket(
|
||||
(short) 36,
|
||||
new ItemStack(
|
||||
482,
|
||||
64,
|
||||
dataComponents
|
||||
)
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundSetCreativeModeSlotPacket((short) 36, new ItemStack(482, 64, dataComponents)));
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundPlayerActionPacket(
|
||||
PlayerAction.START_DIGGING,
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
0
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, itemPosition, Direction.NORTH, 0));
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundUseItemOnPacket(
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
Hand.MAIN_HAND,
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5f,
|
||||
false,
|
||||
false,
|
||||
1
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundUseItemOnPacket(itemPosition, Direction.NORTH, Hand.MAIN_HAND, 0.5f, 0.5f, 0.5f, false, false, 1));
|
||||
}
|
||||
|
||||
private String getCommand () {
|
||||
@@ -175,29 +106,14 @@ public class CommandCoreModule extends Listener {
|
||||
int endPosY = (int) Math.round(pos.getY() - coreArea.end().getY());
|
||||
int endPosZ = (int) Math.round(pos.getZ() - coreArea.end().getZ());
|
||||
|
||||
return 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
|
||||
);
|
||||
return 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);
|
||||
}
|
||||
|
||||
public Vector3d currentBlockRelative = Vector3d.from(0, 0, 0);
|
||||
|
||||
public PositionData currentBlock () {
|
||||
Vector3d relativePosition = currentBlockRelative;
|
||||
Vector3i corePosition = position;
|
||||
|
||||
return new PositionData(
|
||||
(float) (relativePosition.getX() + corePosition.getX()),
|
||||
(float) (relativePosition.getY() + corePosition.getY()),
|
||||
Vector3d.from(relativePosition.getZ(), relativePosition.getY(), relativePosition.getZ())
|
||||
);
|
||||
return new PositionData((float) (relativePosition.getX() + corePosition.getX()), (float) (relativePosition.getY() + corePosition.getY()), Vector3d.from(relativePosition.getZ(), relativePosition.getY(), relativePosition.getZ()));
|
||||
}
|
||||
|
||||
public void incrementCurrentBlock () {
|
||||
@@ -231,16 +147,7 @@ public class CommandCoreModule extends Listener {
|
||||
|
||||
public void commandBlock (String command, boolean doesTrackOutput, boolean conditional, boolean automatic) {
|
||||
if (command.length() > 32767 || position == null) return;
|
||||
bot.session.send(
|
||||
new ServerboundSetCommandBlockPacket(
|
||||
position,
|
||||
command,
|
||||
CommandBlockMode.AUTO,
|
||||
doesTrackOutput,
|
||||
conditional,
|
||||
automatic
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundSetCommandBlockPacket(position, command, CommandBlockMode.AUTO, doesTrackOutput, conditional, automatic));
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
@@ -249,22 +156,4 @@ public class CommandCoreModule extends Listener {
|
||||
|
||||
incrementCurrentBlock();
|
||||
}
|
||||
|
||||
public CommandCoreModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.area = new CommandCoreAreaData(
|
||||
Vector3d.from(
|
||||
bot.config.core.area.start.x,
|
||||
bot.config.core.area.start.y,
|
||||
bot.config.core.area.start.z
|
||||
),
|
||||
Vector3d.from(
|
||||
bot.config.core.area.end.x,
|
||||
bot.config.core.area.end.y,
|
||||
bot.config.core.area.end.z
|
||||
)
|
||||
);
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
+41
-52
@@ -18,59 +18,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManagerModule {
|
||||
private final Bot bot;
|
||||
|
||||
public final List<CommandInfo> commands = new ArrayList<>();
|
||||
|
||||
public void registerCommand (CommandInfo command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void execute (CommandSource source, String commandName, String[] args) {
|
||||
try {
|
||||
CommandInfo command = getCommand(commandName.toLowerCase());
|
||||
|
||||
if (command == null) throw new CommandError(
|
||||
Component.translatable(
|
||||
"%s%s%s %s",
|
||||
Component.translatable("command.unknown.command"),
|
||||
Component.text("\n"),
|
||||
Component.text(commandName).color(NamedTextColor.GRAY),
|
||||
Component.translatable("command.context.here")
|
||||
).color(NamedTextColor.RED)
|
||||
);
|
||||
|
||||
CommandContext context = new CommandContext(bot, args, source);
|
||||
|
||||
command.execute(context);
|
||||
} catch (CommandError error) {
|
||||
source.sendFeedback(error.message());
|
||||
} catch (Exception error) {
|
||||
source.sendFeedback(
|
||||
Component.translatable("command.failed").color(NamedTextColor.DARK_RED)
|
||||
);
|
||||
String Error = ErrorToString.errorToString(error);
|
||||
Logger.ERROR(bot, Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void executeString (CommandSource source, String command) {
|
||||
String[] splitArguments = command.split(" ");
|
||||
String commandName = splitArguments[0];
|
||||
final String[] args = Arrays.copyOfRange(splitArguments, 1, splitArguments.length);
|
||||
|
||||
this.execute(source, commandName, args);
|
||||
}
|
||||
private final Bot bot;
|
||||
|
||||
public CommandManagerModule (Bot bot) throws IOException {
|
||||
this.bot = bot;
|
||||
@@ -83,4 +32,44 @@ public class CommandManagerModule {
|
||||
registerCommand(new TestCommand());
|
||||
registerCommand(new InfoCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (CommandInfo command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
public CommandInfo getCommand (String getCommand) {
|
||||
for (CommandInfo command : commands) {
|
||||
for (String aliases : command.getAliases()) {
|
||||
if (getCommand.equals(aliases)) return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void execute (CommandSource source, String commandName, String[] args) {
|
||||
try {
|
||||
CommandInfo command = getCommand(commandName.toLowerCase());
|
||||
|
||||
if (command == null)
|
||||
throw new CommandError(Component.translatable("%s%s%s %s", Component.translatable("command.unknown.command"), Component.text("\n"), Component.text(commandName).color(NamedTextColor.GRAY), Component.translatable("command.context.here")).color(NamedTextColor.RED));
|
||||
|
||||
CommandContext context = new CommandContext(bot, args, source);
|
||||
|
||||
command.execute(context);
|
||||
} catch (CommandError error) {
|
||||
source.sendFeedback(bot, error.message());
|
||||
} catch (Exception error) {
|
||||
source.sendFeedback(bot, Component.translatable("command.failed").color(NamedTextColor.DARK_RED));
|
||||
String Error = ErrorToString.errorToString(error);
|
||||
Logger.ERROR(bot, Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void executeString (CommandSource source, String command) {
|
||||
String[] splitArguments = command.split(" ");
|
||||
String commandName = splitArguments[0];
|
||||
final String[] args = Arrays.copyOfRange(splitArguments, 1, splitArguments.length);
|
||||
|
||||
this.execute(source, commandName, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,15 @@ import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSpyModule extends Listener {
|
||||
public class CommandSpyModule implements Listener {
|
||||
private static final String SLASH = "/";
|
||||
private final Bot bot;
|
||||
|
||||
private static final String SLASH = "/";
|
||||
public CommandSpyModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemChatReceived (Component data) {
|
||||
@@ -32,22 +37,10 @@ public class CommandSpyModule extends Listener {
|
||||
|
||||
String command = commandComponent.content().substring(SLASH.length());
|
||||
|
||||
if (
|
||||
(
|
||||
commandComponent.content().contains(SLASH + command)
|
||||
&&
|
||||
sender != null
|
||||
)
|
||||
) {
|
||||
if ((commandComponent.content().contains(SLASH + command) && sender != null)) {
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.commandSpyReceived(sender, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CommandSpyModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,22 +13,8 @@ public class ConsoleModule implements Completer {
|
||||
|
||||
public final String server = "all";
|
||||
|
||||
@Override
|
||||
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
|
||||
}
|
||||
|
||||
private void handleLine (String line) {
|
||||
for (Bot bot : servers) {
|
||||
if (line.equals(bot.config.console.prefix + "kill")) System.exit(0);
|
||||
bot.chat.send(line);
|
||||
}
|
||||
}
|
||||
|
||||
public ConsoleModule () {
|
||||
this.reader = LineReaderBuilder.builder()
|
||||
.completer(this)
|
||||
.build();
|
||||
this.reader = LineReaderBuilder.builder().completer(this).build();
|
||||
|
||||
Main.executorService.submit(() -> {
|
||||
while (true) {
|
||||
@@ -43,4 +29,16 @@ public class ConsoleModule implements Completer {
|
||||
}
|
||||
}, "Console Thread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
|
||||
}
|
||||
|
||||
private void handleLine (String line) {
|
||||
for (Bot bot : servers) {
|
||||
if (line.equals(bot.config.console.prefix + "kill")) System.exit(0);
|
||||
bot.chat.send(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,15 @@ import land.chipmunk.parker2991.nitoribot.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LoggingModule extends Listener {
|
||||
public class LoggingModule implements Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public LoggingModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
@@ -30,10 +36,4 @@ public class LoggingModule extends Listener {
|
||||
//if (host.equals("kaboom.pw")) return;
|
||||
Logger.LOG(bot, message);
|
||||
}
|
||||
|
||||
public LoggingModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -20,38 +20,25 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class MCServerModule {
|
||||
public final SessionService sessionService = new SessionService();
|
||||
public final MinecraftProtocol protocol = new MinecraftProtocol();
|
||||
private final Bot bot;
|
||||
|
||||
private final List<SkinPart> skinParts = new ArrayList<>();
|
||||
public ClientSession client;
|
||||
|
||||
public final SessionService sessionService = new SessionService();
|
||||
public MCServerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
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)
|
||||
client = ClientNetworkSessionFactory.factory().setAddress("kaboom.pw", 25565)
|
||||
//.setAddress(host[0], Integer.parseInt(host[1]))
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
.setProtocol(protocol).create();
|
||||
|
||||
client.send(
|
||||
new ServerboundClientInformationPacket(
|
||||
"en_us",
|
||||
1,
|
||||
ChatVisibility.FULL,
|
||||
true,
|
||||
skinParts,
|
||||
HandPreference.RIGHT_HAND,
|
||||
false,
|
||||
true,
|
||||
ParticleStatus.ALL
|
||||
)
|
||||
);
|
||||
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);
|
||||
|
||||
@@ -59,27 +46,14 @@ public class MCServerModule {
|
||||
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()
|
||||
));
|
||||
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)
|
||||
);
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,22 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListModule extends Listener {
|
||||
public class PlayerListModule implements Listener {
|
||||
|
||||
public final List<PlayerProfileData> list = new ArrayList<>();
|
||||
|
||||
public PlayerListModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
switch (packet) {
|
||||
case ClientboundPlayerInfoUpdatePacket p -> playerInfo(p);
|
||||
case ClientboundPlayerInfoRemovePacket p -> playerRemove(p);
|
||||
case ClientboundAddEntityPacket p -> getPlayerPosition(p);
|
||||
default -> {}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +45,8 @@ public class PlayerListModule extends Listener {
|
||||
for (PlayerListEntryAction action : actions) {
|
||||
for (PlayerListEntry entry : packet.getEntries()) {
|
||||
switch (action) {
|
||||
case PlayerListEntryAction.UPDATE_LIST_ORDER,
|
||||
PlayerListEntryAction.UPDATE_HAT,
|
||||
PlayerListEntryAction.INITIALIZE_CHAT,
|
||||
PlayerListEntryAction.ADD_PLAYER -> addPlayer(entry);
|
||||
case PlayerListEntryAction.UPDATE_LIST_ORDER, PlayerListEntryAction.UPDATE_HAT,
|
||||
PlayerListEntryAction.INITIALIZE_CHAT, PlayerListEntryAction.ADD_PLAYER -> addPlayer(entry);
|
||||
case PlayerListEntryAction.UPDATE_LISTED -> updateListed(entry);
|
||||
case PlayerListEntryAction.UPDATE_GAME_MODE -> updateGamemode(entry);
|
||||
case PlayerListEntryAction.UPDATE_LATENCY -> updateLatency(entry);
|
||||
@@ -67,7 +70,6 @@ public class PlayerListModule extends Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public final PlayerProfileData getPlayerUUID (UUID uuid) {
|
||||
PlayerProfileData playerInfo = null;
|
||||
@@ -119,27 +121,21 @@ public class PlayerListModule extends Listener {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) {
|
||||
}
|
||||
|
||||
else getPlayer.gameMode(player.getGameMode());
|
||||
} else getPlayer.gameMode(player.getGameMode());
|
||||
}
|
||||
|
||||
public void updateLatency (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) {
|
||||
}
|
||||
|
||||
else getPlayer.latency(player.getLatency());
|
||||
} else getPlayer.latency(player.getLatency());
|
||||
}
|
||||
|
||||
public void updateDisplayName (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) {
|
||||
}
|
||||
|
||||
else getPlayer.displayName(player.getDisplayName());
|
||||
} else getPlayer.displayName(player.getDisplayName());
|
||||
}
|
||||
|
||||
public void addPlayer (PlayerListEntry player) {
|
||||
@@ -147,20 +143,7 @@ public class PlayerListModule extends Listener {
|
||||
|
||||
if (findDuplicatePlayer != null) list.remove(findDuplicatePlayer);
|
||||
|
||||
PlayerProfileData formatPlayerData = new PlayerProfileData(
|
||||
player.getProfileId(),
|
||||
null,
|
||||
player.getProfile(),
|
||||
player.isListed(),
|
||||
player.getLatency(),
|
||||
player.getGameMode(),
|
||||
player.getDisplayName(),
|
||||
player.isShowHat(),
|
||||
player.getListOrder(),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
PlayerProfileData formatPlayerData = new PlayerProfileData(player.getProfileId(), null, player.getProfile(), player.isListed(), player.getLatency(), player.getGameMode(), player.getDisplayName(), player.isShowHat(), player.getListOrder(), null, null, null);
|
||||
|
||||
list.add(formatPlayerData);
|
||||
}
|
||||
@@ -173,8 +156,4 @@ public class PlayerListModule extends Listener {
|
||||
list.remove(getPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerListModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,21 @@ import java.util.Objects;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PositionModule extends Listener {
|
||||
public class PositionModule implements Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public ScheduledFuture<?> timer;
|
||||
|
||||
private int i = 0;
|
||||
|
||||
public PositionData positionData;
|
||||
|
||||
private int i = 0;
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public PositionModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerPositionPacket) packetReceived((ClientboundPlayerPositionPacket) packet);
|
||||
@@ -37,11 +40,7 @@ public class PositionModule extends Listener {
|
||||
int y = (int) Math.round(getPosition.getY());
|
||||
z = (int) Math.round(getPosition.getZ());
|
||||
|
||||
positionData = new PositionData(
|
||||
packet.getXRot(),
|
||||
packet.getYRot(),
|
||||
packet.getPosition()
|
||||
);
|
||||
positionData = new PositionData(packet.getXRot(), packet.getYRot(), packet.getPosition());
|
||||
|
||||
if (bot.options.mode.equals("totalfreedom")) {
|
||||
if (i < 5) timer = bot.executor.scheduleAtFixedRate(() -> {
|
||||
@@ -49,15 +48,7 @@ public class PositionModule extends Listener {
|
||||
x += 1;
|
||||
z += 1;
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundMovePlayerPosPacket(
|
||||
false,
|
||||
false,
|
||||
x,
|
||||
y,
|
||||
z
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundMovePlayerPosPacket(false, false, x, y, z));
|
||||
System.out.println("moved");
|
||||
System.out.println(x);
|
||||
i++;
|
||||
@@ -65,21 +56,11 @@ public class PositionModule extends Listener {
|
||||
}, 5000, 5000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundAcceptTeleportationPacket(
|
||||
packet.getId()
|
||||
)
|
||||
);
|
||||
bot.session.send(new ServerboundAcceptTeleportationPacket(packet.getId()));
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
if (! Objects.equals(bot.options.mode, "kaboom")) return;
|
||||
if (!Objects.equals(bot.options.mode, "kaboom")) return;
|
||||
listener.botMoved();
|
||||
}
|
||||
}
|
||||
|
||||
public PositionModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.DimensionData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
||||
@@ -9,8 +10,16 @@ import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.Clie
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RegistryModule extends Listener {
|
||||
public class RegistryModule implements Listener {
|
||||
public final List<String> chatTypes = new ArrayList<>();
|
||||
public final List<DimensionData> dimensions = new ArrayList<>();
|
||||
private Bot bot;
|
||||
|
||||
|
||||
public RegistryModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
@@ -20,15 +29,21 @@ public class RegistryModule extends Listener {
|
||||
public void packetReceived (ClientboundRegistryDataPacket packet) {
|
||||
String getRegistry = packet.getRegistry().asString();
|
||||
for (RegistryEntry entry : packet.getEntries()) {
|
||||
if (getRegistry.equals("minecraft:chat_type"))
|
||||
if (getRegistry.equals("minecraft:chat_type")) if (entry.getData() != null) {
|
||||
chatTypes.add(entry.getData().getCompound("chat").getString("translation_key"));
|
||||
}
|
||||
if (getRegistry.equals("minecraft:worldgen/biome")) {
|
||||
System.out.println(entry);
|
||||
}
|
||||
if (getRegistry.equals("minecraft:dimension_type")) {
|
||||
if (entry.getData() != null) {
|
||||
chatTypes.add(entry.getData().getCompound("chat").getString("translation_key"));
|
||||
String dimension = null;
|
||||
if (entry.getId().toString().equals("minecraft:overworld_caves"))
|
||||
dimension = "minecraft:world_flatlands";
|
||||
else dimension = String.valueOf(entry.getId());
|
||||
this.dimensions.add(new DimensionData(dimension, Integer.parseInt(entry.getData().get("height").toString().replace("i", "")), Integer.parseInt(entry.getData().get("min_y").toString().replace("i", ""))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RegistryModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,21 @@ import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundL
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfcareModule extends Listener {
|
||||
public ScheduledFuture<?> timer;
|
||||
|
||||
public class SelfcareModule implements Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public ScheduledFuture<?> timer;
|
||||
public PermissionSelfcare permission;
|
||||
|
||||
public GamemodeSelfcare gamemode;
|
||||
|
||||
public int entityId;
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
loadSelfcare();
|
||||
}
|
||||
|
||||
public void loadSelfcare () {
|
||||
this.permission = new PermissionSelfcare(bot);
|
||||
this.gamemode = new GamemodeSelfcare(bot);
|
||||
@@ -34,7 +38,8 @@ public class SelfcareModule extends Listener {
|
||||
switch (packet) {
|
||||
case ClientboundLoginFinishedPacket p -> login(p);
|
||||
case ClientboundDisconnectPacket p -> disconnect(p);
|
||||
default -> {}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,22 +47,11 @@ public class SelfcareModule extends Listener {
|
||||
if (bot.options.mode.equals("totalfreedom")) return;
|
||||
timer = bot.executor.scheduleAtFixedRate(() -> {
|
||||
if (permission.level < 2 && bot.loggedIn) bot.chat.command("minecraft:op @s[type=player]");
|
||||
else if (gamemode.gamemode != 1) bot.session.send(
|
||||
new ServerboundChangeGameModePacket(
|
||||
GameMode.CREATIVE
|
||||
)
|
||||
);
|
||||
else if (gamemode.gamemode != 1) bot.session.send(new ServerboundChangeGameModePacket(GameMode.CREATIVE));
|
||||
}, 0, bot.options.selfcareInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
public void disconnect (ClientboundDisconnectPacket event) {
|
||||
timer.cancel(true);
|
||||
}
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
loadSelfcare();
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,13 @@ import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket;
|
||||
|
||||
public class TextDisplayModule extends Listener {
|
||||
|
||||
public class TextDisplayModule implements Listener {
|
||||
private static final int TEXT_DISPLAY_ENTITY_ID = 32;
|
||||
|
||||
public TextDisplayModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof ClientboundSetEntityDataPacket) getTextDisplay((ClientboundSetEntityDataPacket) packet);
|
||||
@@ -25,8 +28,4 @@ public class TextDisplayModule extends Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextDisplayModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldModule implements Listener {
|
||||
private @NotNull Bot bot;
|
||||
|
||||
public WorldModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
switch (packet) {
|
||||
case ClientboundLevelChunkWithLightPacket p -> chunks(p);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chunks (ClientboundLevelChunkWithLightPacket packet) {
|
||||
//System.out.println(Arrays.toString(packet.getChunkData()));
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,9 +8,13 @@ import org.geysermc.mcprotocollib.protocol.data.game.level.notify.GameEvent;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.notify.GameEventValue;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket;
|
||||
|
||||
public class GamemodeSelfcare extends Listener {
|
||||
public class GamemodeSelfcare implements Listener {
|
||||
public int gamemode = 1;
|
||||
|
||||
public GamemodeSelfcare (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
if (packet instanceof ClientboundGameEventPacket) checkGamemode((ClientboundGameEventPacket) packet);
|
||||
@@ -38,8 +42,4 @@ public class GamemodeSelfcare extends Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GamemodeSelfcare (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -7,10 +7,14 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
|
||||
|
||||
|
||||
public class PermissionSelfcare extends Listener {
|
||||
public class PermissionSelfcare implements Listener {
|
||||
private final Bot bot;
|
||||
public int level;
|
||||
|
||||
private final Bot bot;
|
||||
public PermissionSelfcare (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
@@ -32,9 +36,4 @@ public class PermissionSelfcare extends Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PermissionSelfcare (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,14 @@ public final class ComponentUtil {
|
||||
private static final ThreadLocal<Integer> TOTAL_DEPTH = ThreadLocal.withInitial(() -> 0); //used to track the depth of translate components
|
||||
|
||||
private static final int MAX_DEPTH = 512; //translate depth limit
|
||||
private static final GsonComponentSerializer GSON_COMPONENT_SERIALIZER = GsonComponentSerializer.builder() // 1.21.5+ gson serializer
|
||||
.build();
|
||||
private static final ANSIComponentSerializer ANSI_COMPONENT_SERIALIZER = ANSIComponentSerializer.builder().flattener(getFlattener(true)).colorLevel(ColorLevel.TRUE_COLOR).build();
|
||||
private static final PlainTextComponentSerializer PLAIN_TEXT_COMPONENT_SERIALIZER = PlainTextComponentSerializer.builder().flattener(getFlattener(false)).build();
|
||||
|
||||
public static NamedTextColor convertColorString (String color) {
|
||||
return NamedTextColor.NAMES.value(color);
|
||||
}
|
||||
|
||||
public static Map<String, String> loadJsonStringMap (String name) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
@@ -46,29 +54,8 @@ public final class ComponentUtil {
|
||||
return map;
|
||||
}
|
||||
|
||||
private static final GsonComponentSerializer GSON_COMPONENT_SERIALIZER = GsonComponentSerializer.builder() // 1.21.5+ gson serializer
|
||||
.build();
|
||||
|
||||
private static final ANSIComponentSerializer ANSI_COMPONENT_SERIALIZER = ANSIComponentSerializer.builder()
|
||||
.flattener(getFlattener(true))
|
||||
.colorLevel(ColorLevel.TRUE_COLOR)
|
||||
.build();
|
||||
|
||||
private static final PlainTextComponentSerializer PLAIN_TEXT_COMPONENT_SERIALIZER = PlainTextComponentSerializer.builder()
|
||||
.flattener(getFlattener(false))
|
||||
.build();
|
||||
|
||||
private static ComponentFlattener getFlattener (boolean parseSectionSigns) {
|
||||
return ComponentFlattener.builder()
|
||||
.mapper(TextComponent.class, component -> mapText(
|
||||
component, parseSectionSigns
|
||||
))
|
||||
.mapper(ObjectComponent.class, ComponentUtil::mapObject)
|
||||
.complexMapper(KeybindComponent.class, ComponentUtil::mapKeybind)
|
||||
.mapper(SelectorComponent.class, SelectorComponent::pattern)
|
||||
.complexMapper(TranslatableComponent.class, ComponentUtil::mapTranslatable)
|
||||
.unknownMapper(_ -> "")
|
||||
.nestingLimit(MAX_DEPTH) //max depth for nested mapper calls
|
||||
return ComponentFlattener.builder().mapper(TextComponent.class, component -> mapText(component, parseSectionSigns)).mapper(ObjectComponent.class, ComponentUtil::mapObject).complexMapper(KeybindComponent.class, ComponentUtil::mapKeybind).mapper(SelectorComponent.class, SelectorComponent::pattern).complexMapper(TranslatableComponent.class, ComponentUtil::mapTranslatable).unknownMapper(_ -> "").nestingLimit(MAX_DEPTH) //max depth for nested mapper calls
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -77,20 +64,14 @@ public final class ComponentUtil {
|
||||
var key = component.key();
|
||||
var fallback = component.fallback();
|
||||
|
||||
return LANGUAGE.getOrDefault(
|
||||
key,
|
||||
fallback == null ? key : fallback
|
||||
);
|
||||
return LANGUAGE.getOrDefault(key, fallback == null ? key : fallback);
|
||||
}
|
||||
|
||||
private static String guardedStringify (ComponentEncoder<Component, String> serializer, Component message) {
|
||||
try {
|
||||
return serializer.serialize(message);
|
||||
} catch (Exception e) {
|
||||
return serializer.serialize(Component.translatable(
|
||||
"<Failed to parse component: %s>",
|
||||
NamedTextColor.RED,
|
||||
Component.text(e.toString())));
|
||||
return serializer.serialize(Component.translatable("<Failed to parse component: %s>", NamedTextColor.RED, Component.text(e.toString())));
|
||||
} finally {
|
||||
TOTAL_DEPTH.set(0); //set translate depth to 0 after component is parsed
|
||||
}
|
||||
@@ -161,7 +142,7 @@ public final class ComponentUtil {
|
||||
if (start > lastIndex) {
|
||||
var formatSegment = format.substring(lastIndex, start);
|
||||
//ensure that theres no % in the formatSegment (if there is, we have a problem with escaping)
|
||||
if (formatSegment.indexOf('%') != - 1) throw new IllegalArgumentException();
|
||||
if (formatSegment.indexOf('%') != -1) throw new IllegalArgumentException();
|
||||
result.add(Component.text(formatSegment));
|
||||
}
|
||||
|
||||
@@ -198,7 +179,7 @@ public final class ComponentUtil {
|
||||
//handle any remaining part of the string after the last match
|
||||
if (lastIndex < format.length()) {
|
||||
var remaining = format.substring(lastIndex);
|
||||
if (remaining.indexOf('%') != - 1)
|
||||
if (remaining.indexOf('%') != -1)
|
||||
throw new IllegalArgumentException(); // Make sure no unescaped '%' remains
|
||||
result.add(Component.text(remaining));
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,11 @@ public class UUIDUtil {
|
||||
return "[I;" + array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "]";
|
||||
}
|
||||
|
||||
public static String selector (UUID uuid) {return "@p[nbt={UUID:" + snbt(uuid) + "}]";}
|
||||
public static String selector (UUID uuid) {
|
||||
return "@p[nbt={UUID:" + snbt(uuid) + "}]";
|
||||
}
|
||||
|
||||
public static String exclusiveSelector (UUID uuid) {return "@a[nbt=!{UUID:" + snbt(uuid) + "}]";}
|
||||
public static String exclusiveSelector (UUID uuid) {
|
||||
return "@a[nbt=!{UUID:" + snbt(uuid) + "}]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ colors:
|
||||
integer: "gold"
|
||||
commands:
|
||||
primary: "blue"
|
||||
secondary: "aqua"
|
||||
tertiary: "dark_aqua"
|
||||
secondary: "dark_aqua"
|
||||
tertiary: "aqua"
|
||||
help:
|
||||
Public: "blue"
|
||||
trusted: "dark_aqua"
|
||||
@@ -29,9 +29,6 @@ colors:
|
||||
console:
|
||||
prefix: "c."
|
||||
|
||||
chatAttestation:
|
||||
url: "https://optmstc.dev/key-manifest-v1.json"
|
||||
|
||||
bots:
|
||||
- host: "localhost"
|
||||
port: 25565
|
||||
@@ -25,7 +25,7 @@
|
||||
"color": "blue"
|
||||
}
|
||||
],
|
||||
"build": "5310",
|
||||
"build": "5311",
|
||||
"versionReleaseDate": "N\\A",
|
||||
"initialBotRelease": "11/22/22"
|
||||
},
|
||||
|
||||
+7765
-7765
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
writer.level = error
|
||||
writer.level=error
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
|
||||
public record CommandContext(Bot bot, String[] args, CommandSource source) {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandError extends Exception {
|
||||
public final Component message;
|
||||
|
||||
public CommandError (Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Component message () {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public abstract class CommandInfo {
|
||||
// probably could make this a record or interface
|
||||
public final String name;
|
||||
public final CommandTrustLevels trustlevel;
|
||||
public final String[] aliases;
|
||||
public final String description;
|
||||
|
||||
public CommandInfo (String name, CommandTrustLevels trustlevel, String[] aliases, String description) {
|
||||
this.name = name;
|
||||
this.trustlevel = trustlevel;
|
||||
this.aliases = aliases;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract void execute (CommandContext context);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandSource {
|
||||
public final PlayerProfileData sender;
|
||||
public final ParsedChatType parsedChatType;
|
||||
private final Bot bot;
|
||||
public boolean inGame;
|
||||
|
||||
public CommandSource (Bot bot, ParsedChatType parsedChatType, PlayerProfileData sender) {
|
||||
this.bot = bot;
|
||||
this.parsedChatType = parsedChatType;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void sendFeedback (Component message) {
|
||||
String convertToJson = ComponentUtil.componentToJSON(message);
|
||||
//Vector3d playerPos = sender.position.position();
|
||||
|
||||
/* String formatCommand = String.format(
|
||||
"minecraft:summon text_display %s %s %s {tag:[%s], text:%s}",
|
||||
playerPos.getX(),
|
||||
playerPos.getY(),
|
||||
playerPos.getZ(),
|
||||
"NitoriBot",
|
||||
convertToJson
|
||||
);*/
|
||||
|
||||
String selector = String.format("@p[nbt={UUID:%s}]", sender.entityUUID());
|
||||
|
||||
//System.out.println(sender.profile.getName());
|
||||
|
||||
if (this.parsedChatType == ParsedChatType.NORMAL) bot.chat.tellraw("@a", message);
|
||||
else bot.chat.tellraw(selector, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public enum CommandTrustLevels {
|
||||
PUBLIC, TRUSTED, ADMIN, OWNER, CONSOLE, DISABLED
|
||||
}
|
||||
Reference in New Issue
Block a user