fucking intellij formatting

This commit is contained in:
Parker2991
2026-10-08 10:28:41 -05:00
parent 4fb7099c0f
commit a331466d9e
18 changed files with 328 additions and 79 deletions
@@ -57,7 +57,21 @@ 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.world = new WorldModule(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();
@@ -69,11 +83,15 @@ 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);
}
@@ -136,12 +154,16 @@ 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
)
);
}
}
@@ -16,9 +16,13 @@ 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(10)).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 {
@@ -48,6 +48,7 @@ public class KaboomChatParser implements ParseChatData {
}
private boolean isSeperatorAt (List<Component> children, int start) {
return (children.get(start).equals(SEPERATOR_COLON) || children.get(start).equals(SEPERATOR_COLON_RACCOON)) && children.get(start + 1).equals(SEPERATOR_SPACE);
return (children.get(start).equals(SEPERATOR_COLON) || children.get(start).equals(SEPERATOR_COLON_RACCOON)) && children.get(
start + 1).equals(SEPERATOR_SPACE);
}
}
@@ -58,8 +58,19 @@ public class HelpCommand implements CommandInfo {
for (CommandInfo commands : bot.commandManager.commands) {
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));
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;
@@ -76,9 +87,20 @@ public class HelpCommand implements CommandInfo {
return;
}
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 = 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 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)
)).color(convertColorString(bot.config.colors.commands.tertiary));
source.sendFeedback(bot, component);
}
@@ -57,8 +57,15 @@ public class InfoCommand implements CommandInfo {
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(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 "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;
@@ -69,7 +76,25 @@ public class InfoCommand implements CommandInfo {
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(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));
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));
}
}
@@ -37,6 +37,9 @@ public class RCCommand implements CommandInfo {
bot.core.move();
source.sendFeedback(bot, Component.text("Refilling core").color(convertColorString(bot.config.colors.commands.primary)));
source.sendFeedback(
bot,
Component.text("Refilling core").color(convertColorString(bot.config.colors.commands.primary))
);
}
}
@@ -44,9 +44,18 @@ public class TestCommand implements CommandInfo {
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(bot, component);
}
@@ -78,7 +78,15 @@ 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);
@@ -76,7 +76,15 @@ public class ChatModule implements 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) {
@@ -87,7 +95,15 @@ public class ChatModule implements 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) {
@@ -124,7 +140,12 @@ public class ChatModule implements Listener {
}
public void tellraw (String selector, Component message) {
bot.core.run(String.format("%s %s %s", "minecraft:tellraw", selector, GsonComponentSerializer.gson().serialize(message).trim()));
bot.core.run(String.format(
"%s %s %s",
"minecraft:tellraw",
selector,
GsonComponentSerializer.gson().serialize(message).trim()
));
}
}
@@ -35,7 +35,13 @@ public class CommandCoreModule implements Listener {
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));
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);
}
@@ -64,7 +70,16 @@ public class CommandCoreModule implements 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);
}
@@ -80,19 +95,52 @@ public class CommandCoreModule implements Listener {
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 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 () {
@@ -106,14 +154,27 @@ public class CommandCoreModule implements 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 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 () {
@@ -147,7 +208,14 @@ public class CommandCoreModule implements 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) {
@@ -50,8 +50,13 @@ public class CommandManagerModule {
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));
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);
@@ -16,18 +16,20 @@ public class ConsoleModule implements Completer {
public ConsoleModule () {
this.reader = LineReaderBuilder.builder().completer(this).build();
Main.executorService.submit(() -> {
while (true) {
try {
String line;
Main.executorService.submit(
() -> {
while (true) {
try {
String line;
line = reader.readLine(String.format("[%s] > ", this.server));
line = reader.readLine(String.format("[%s] > ", this.server));
handleLine(line);
} catch (Exception _) {
handleLine(line);
} catch (Exception _) {
}
}
}
}, "Console Thread");
}, "Console Thread"
);
}
@Override
@@ -38,20 +38,41 @@ public class MCServerModule {
//.setAddress(host[0], Integer.parseInt(host[1]))
.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);
client.setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (Session session, ServerStatusInfo info) -> {
assert info.getVersionInfo() != null;
assert info.getPlayerInfo() != null;
client.setFlag(
MinecraftConstants.SERVER_INFO_HANDLER_KEY, (Session session, ServerStatusInfo info) -> {
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();
@@ -143,7 +143,20 @@ public class PlayerListModule implements 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);
}
@@ -43,17 +43,19 @@ public class PositionModule implements Listener {
positionData = new PositionData(packet.getXRot(), packet.getYRot(), packet.getPosition());
if (bot.options.mode.equals("totalfreedom")) {
if (i < 5) timer = bot.executor.scheduleAtFixedRate(() -> {
System.out.println(i);
x += 1;
z += 1;
if (i < 5) timer = bot.executor.scheduleAtFixedRate(
() -> {
System.out.println(i);
x += 1;
z += 1;
bot.session.send(new ServerboundMovePlayerPosPacket(false, false, x, y, z));
System.out.println("moved");
System.out.println(x);
i++;
if (i > 5) timer.cancel(true);
}, 5000, 5000, TimeUnit.MILLISECONDS);
bot.session.send(new ServerboundMovePlayerPosPacket(false, false, x, y, z));
System.out.println("moved");
System.out.println(x);
i++;
if (i > 5) timer.cancel(true);
}, 5000, 5000, TimeUnit.MILLISECONDS
);
}
bot.session.send(new ServerboundAcceptTeleportationPacket(packet.getId()));
@@ -41,7 +41,11 @@ public class RegistryModule implements Listener {
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", ""))));
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", ""))
));
}
}
}
@@ -45,10 +45,13 @@ public class SelfcareModule implements Listener {
public void login (ClientboundLoginFinishedPacket packet) {
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));
}, 0, bot.options.selfcareInterval, TimeUnit.MILLISECONDS);
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));
}, 0, bot.options.selfcareInterval, TimeUnit.MILLISECONDS
);
}
public void disconnect (ClientboundDisconnectPacket event) {
@@ -32,8 +32,10 @@ public final class ComponentUtil {
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();
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);
@@ -55,7 +57,16 @@ public final class ComponentUtil {
}
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();
}
@@ -71,7 +82,11 @@ public final class ComponentUtil {
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
}
@@ -110,7 +125,8 @@ public final class ComponentUtil {
return switch (content) {
case SpriteObjectContents c -> "<Sprite:" + c.sprite() + ">";
case PlayerHeadObjectContents c ->
"<PlayerHead:" + componentToString(Component.translatable("block.minecraft.player_head.named").arguments(Component.text((c.name() != null) ? Objects.requireNonNull(c.name()) : "Unknown"))) + ">";
"<PlayerHead:" + componentToString(Component.translatable("block.minecraft.player_head.named").arguments(
Component.text((c.name() != null) ? Objects.requireNonNull(c.name()) : "Unknown"))) + ">";
};
}