Merge remote-tracking branch 'origin/main'

This commit is contained in:
Chayapak 2023-06-22 18:26:40 +07:00
commit bcdbf5c2f3
32 changed files with 441 additions and 151 deletions

7
.idea/discord.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View file

@ -11,6 +11,11 @@
<option name="name" value="Central Repository" /> <option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" /> <option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="opencollab" />
<option name="name" value="opencollab" />
<option name="url" value="https://repo.opencollab.dev/maven-snapshots/" />
</remote-repository>
<remote-repository> <remote-repository>
<option name="id" value="central" /> <option name="id" value="central" />
<option name="name" value="Maven Central repository" /> <option name="name" value="Maven Central repository" />

View file

@ -8,5 +8,5 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="19" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="17" project-jdk-type="JavaSDK" />
</project> </project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/chipmunkbot.iml" filepath="$PROJECT_DIR$/chipmunkbot.iml" />
</modules>
</component>
</project>

View file

@ -1,2 +1,2 @@
# chipmunkbot # Chipmunk Sex Bot
A work-in-progress mcprotocollib utility bot, created for free-op servers with minimal restrictions Sexy version of [ChipmunkBot](https://code.chipmunk.land/ChipmunkMC/chipmunkbot)!!!!!!

12
chipmunkbot.iml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>

View file

@ -14,8 +14,8 @@
<repositories> <repositories>
<repository> <repository>
<id>opencollab</id> <id>opencollab</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url> <url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository> </repository>
<repository> <repository>
@ -48,7 +48,7 @@
<dependency> <dependency>
<groupId>com.mojang</groupId> <groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId> <artifactId>brigadier</artifactId>
<version>1.0.18</version> <version>1.1.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -1,18 +1,13 @@
package land.chipmunk.chipmunkbot; package land.chipmunk.chipmunkbot;
import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.packetlib.ProxyInfo;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.tcp.TcpClientSession;
import com.github.steveice10.packetlib.event.session.SessionListener;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Constructor;
import lombok.Getter; import lombok.Getter;
import land.chipmunk.chipmunkbot.plugins.*; import land.chipmunk.chipmunkbot.plugins.*;
import java.util.List; import java.util.List;
public class ChipmunkBot extends Client { public class ChipmunkBot extends Client {
@Getter private final Configuration config;
@Getter private final TickLoop tickLoop; @Getter private final TickLoop tickLoop;
@Getter private final ChatPlugin chat; @Getter private final ChatPlugin chat;
@Getter private final TabCompletePlugin tabComplete; @Getter private final TabCompletePlugin tabComplete;
@ -26,9 +21,11 @@ public class ChipmunkBot extends Client {
@Getter private final SelfCarePlugin selfCare; @Getter private final SelfCarePlugin selfCare;
@Getter private final SongPlayer songPlayer; @Getter private final SongPlayer songPlayer;
public ChipmunkBot (Options options, List<Client> allClients) { public ChipmunkBot (Configuration config, Configuration.Bot options, List<Client> allClients) {
super(options.host, options.port, new MinecraftProtocol(options.username), null, options.reconnectDelay, allClients); super(options.host, options.port, new MinecraftProtocol(options.username), null, options.reconnectDelay, allClients);
this.config = config;
this.tickLoop = new TickLoop(this); this.tickLoop = new TickLoop(this);
this.chat = new ChatPlugin(this); this.chat = new ChatPlugin(this);
this.tabComplete = new TabCompletePlugin(this); this.tabComplete = new TabCompletePlugin(this);
@ -39,7 +36,7 @@ public class ChipmunkBot extends Client {
this.playerCommandHandler = new PlayerCommandHandler(this, options); this.playerCommandHandler = new PlayerCommandHandler(this, options);
this.position = new PositionManager(this); this.position = new PositionManager(this);
this.core = new CommandCore(this, options); this.core = new CommandCore(this, options);
this.selfCare = new SelfCarePlugin(this); this.selfCare = new SelfCarePlugin(this, options);
this.songPlayer = new SongPlayer(this); this.songPlayer = new SongPlayer(this);
} }
} }

View file

@ -0,0 +1,47 @@
package land.chipmunk.chipmunkbot;
import lombok.Getter;
public class Configuration {
@Getter public Color color = new Color();
public Bot[] bots = new Bot[]{};
public static class Color {
@Getter public String primary = "#ffc0cb";
@Getter public String secondary = "#c95367";
}
public static class Bot {
public String host = "0.0.0.0";
public int port = 25565;
public String username = "Player";
// public ProxyInfo proxy;
public long reconnectDelay = 1000;
public Commands commands = new Commands();
public Core core = new Core();
public SelfCares selfCares = new SelfCares();
public static class SelfCares {
public boolean cspy = true;
public PrefixSelfCare prefix = new PrefixSelfCare();
public static class PrefixSelfCare {
public boolean enabled = true;
public String prefix = "&x&c&9&5&3&6&7[&x&f&f&c&0&c&bPrefix: s'&x&c&9&5&3&6&7]";
}
}
public static class Commands {
public String prefix = "default.";
public String cspyPrefix = "default.";
}
public static class Core {
public boolean enabled = true;
}
}
}

View file

@ -1,11 +1,5 @@
package land.chipmunk.chipmunkbot; package land.chipmunk.chipmunkbot;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.InputStream; import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -65,13 +59,9 @@ public class Main {
List<Client> allClients = new ArrayList<>(); List<Client> allClients = new ArrayList<>();
for (Options options : config.bots) { for (Configuration.Bot options : config.bots) {
final Client client = new ChipmunkBot(options, allClients); final Client client = new ChipmunkBot(config, options, allClients);
allClients.add(client); allClients.add(client);
} }
} }
private static class Configuration {
public Options[] bots;
}
} }

View file

@ -1,22 +0,0 @@
package land.chipmunk.chipmunkbot;
public class Options {
public String host = "0.0.0.0";
public int port = 25565;
public String username = "Player";
// public ProxyInfo proxy;
public long reconnectDelay = 1000;
public Commands commands = new Commands();
public Core core = new Core();
public class Commands {
public String prefix = "default.";
public String cspyPrefix = "default.";
}
public class Core {
public boolean enabled = true;
}
}

View file

@ -3,6 +3,7 @@ package land.chipmunk.chipmunkbot.command;
import land.chipmunk.chipmunkbot.ChipmunkBot; import land.chipmunk.chipmunkbot.ChipmunkBot;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
public class ConsoleCommandSource extends CommandSource { public class ConsoleCommandSource extends CommandSource {

View file

@ -6,6 +6,7 @@ import land.chipmunk.chipmunkbot.ChipmunkBot;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;

View file

@ -16,6 +16,7 @@ public class EchoCommand {
dispatcher.register( dispatcher.register(
literal("echo") literal("echo")
.describe(ComponentMessage.wrap(Component.text("Echoes a message")))
.then( .then(
argument("text", greedyString()) argument("text", greedyString())
.executes(instance::echo) .executes(instance::echo)

View file

@ -1,6 +1,8 @@
package land.chipmunk.chipmunkbot.commands; package land.chipmunk.chipmunkbot.commands;
import land.chipmunk.chipmunkbot.ChipmunkBot; import com.mojang.brigadier.Message;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.command.*; import land.chipmunk.chipmunkbot.command.*;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal; import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument; import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
@ -13,6 +15,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
@ -22,11 +27,12 @@ public class HelpCommand {
dispatcher.register( dispatcher.register(
literal("help") literal("help")
.executes(instance::sendCommandList) .describe(ComponentMessage.wrap(Component.text("Shows the help")))
.then( .executes(instance::sendCommandList)
argument("command", greedyString()) .then(
.executes(instance::sendUsage) argument("command", greedyString())
) .executes(instance::sendUsage)
)
); );
} }
@ -36,7 +42,7 @@ public class HelpCommand {
final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher(); final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher();
source.sendOutput(generateCommandList(dispatcher), false); source.sendOutput(generateCommandList(client, dispatcher), false);
return 1; return 1;
} }
@ -50,7 +56,7 @@ public class HelpCommand {
final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher(); final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher();
for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) { for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) {
if (!node.getName().equals(commandName)) continue; if (!node.getName().equals(commandName)) continue;
source.sendOutput(generateUsages(dispatcher, node), false); source.sendOutput(generateUsages(client.config(), dispatcher, node), false);
return 1; return 1;
} }
@ -58,29 +64,60 @@ public class HelpCommand {
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().create(); throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().create();
} }
public Component generateCommandList (CommandDispatcher<CommandSource> dispatcher) { public Component generateCommandList (ChipmunkBot client, CommandDispatcher<CommandSource> dispatcher) {
final List<Component> list = new ArrayList<>(); final List<Component> list = new ArrayList<>();
for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) { for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) {
final String name = node.getName(); final String name = node.getName();
final Component usages = generateUsages(dispatcher, node); final Component usages = generateUsages(client.config(), dispatcher, node);
final HoverEvent hoverEvent = HoverEvent.showText(usages); final HoverEvent hoverEvent = HoverEvent.showText(usages);
list.add(Component.text(name).hoverEvent(hoverEvent)); list.add(
Component
.text(name)
.color(TextColor.fromHexString(client.config().color().primary()))
.hoverEvent(hoverEvent)
);
} }
return Component.translatable("Commands - %s", Component.join(JoinConfiguration.separator(Component.space()), list)); return Component.translatable(
"%s - %s",
Component.text("Commands").color(NamedTextColor.GRAY),
Component.join(JoinConfiguration.separator(Component.space()), list)
).color(NamedTextColor.DARK_GRAY);
} }
public Component generateUsages (CommandDispatcher dispatcher, CommandNode<CommandSource> node) { public Component generateUsages (Configuration config, CommandDispatcher dispatcher, CommandNode<CommandSource> node) {
final List<Component> components = new ArrayList<>();
final List<Component> usages = new ArrayList<>(); final List<Component> usages = new ArrayList<>();
for (String usage : dispatcher.getAllUsage(node, null, true)) { for (String usage : dispatcher.getAllUsage(node, null, true)) {
final String text = (node.getName() + " " + usage).trim(); usages.add(
usages.add(Component.text(text)); Component
.text(node.getName())
.color(TextColor.fromHexString(config.color().secondary()))
.append(Component.space())
.append(
Component
.text(usage)
.color(TextColor.fromHexString(config.color().primary()))
)
);
} }
return Component.join(JoinConfiguration.separator(Component.newline()), usages); final Message description = node.getDescription();
components.add(
Component.translatable(
"%s - %s",
Component.text(node.getName()).color(TextColor.fromHexString(config.color().primary())),
Component.text(description == null ? "No description" : description.getString()).color(NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY)
);
components.add(Component.join(JoinConfiguration.separator(Component.newline()), usages));
return Component.join(JoinConfiguration.separator(Component.newline()), components);
} }
} }

View file

@ -1,30 +1,34 @@
package land.chipmunk.chipmunkbot.commands; package land.chipmunk.chipmunkbot.commands;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.util.CPUInfo; import land.chipmunk.chipmunkbot.util.CPUInfo;
import land.chipmunk.chipmunkbot.command.*; import land.chipmunk.chipmunkbot.command.*;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal; import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import java.util.List;
import java.util.ArrayList;
import java.net.InetAddress; import java.net.InetAddress;
import java.lang.management.*; import java.lang.management.*;
import java.io.IOException; import java.io.IOException;
public class InfoCommand { public class InfoCommand {
private static final String REPOSITORY_URL = "https://code.chipmunk.land/ChipmunkMC/chipmunkbot"; private static final String ORIGINAL_REPOSITORY_URL = "https://code.chipmunk.land/ChipmunkMC/chipmunkbot";
private static final String FORK_URL = "https://code.chipmunk.land/ChomeNS/chipmunkbot";
private static ChipmunkBot client;
public static void register (CommandDispatcher dispatcher) { public static void register (CommandDispatcher dispatcher) {
final InfoCommand instance = new InfoCommand(); final InfoCommand instance = new InfoCommand();
dispatcher.register( dispatcher.register(
literal("info") literal("info")
.describe(ComponentMessage.wrap(Component.text("Shows the info about the bot")))
.executes(instance::sendBotInfo) .executes(instance::sendBotInfo)
.then( .then(
literal("server") literal("server")
@ -35,17 +39,35 @@ public class InfoCommand {
public int sendBotInfo (CommandContext<CommandSource> context) { public int sendBotInfo (CommandContext<CommandSource> context) {
final CommandSource source = context.getSource(); final CommandSource source = context.getSource();
client = source.client();
final Component component = Component.empty() final Component component = Component.empty()
.append(Component.text("ChipmunkBot", NamedTextColor.GREEN)) .append(Component.text("Chipmunk(Sex)Bot", TextColor.fromHexString(client.config().color().primary())))
.append(Component.text(" - A utility bot for free-operator servers with minimal or no restrictions", NamedTextColor.GRAY)) .append(Component.text(" - A utility bot for free-operator servers with minimal or no restrictions", NamedTextColor.GRAY))
.append(Component.newline()) .append(Component.newline())
.append(Component.text("Made by ", NamedTextColor.GRAY)) .append(Component.text("Made by ", NamedTextColor.GRAY))
.append(Component.text("_ChipMC_", NamedTextColor.DARK_GREEN)) .append(Component.text("_ChipMC_", TextColor.fromHexString(client.config().color().secondary())))
.append(Component.text(", ", TextColor.fromHexString(client.config().color().primary())))
.append(Component.text("chayapak", TextColor.fromHexString(client.config().color().secondary())))
.append(Component.text(" (").color(NamedTextColor.DARK_GRAY))
.append(
Component
.text("<3")
.color(NamedTextColor.RED)
.hoverEvent(
HoverEvent.showText(
Component.text("y e s :)")
)
)
)
.append(Component.text(")").color(NamedTextColor.DARK_GRAY))
.append(Component.text(" and contributors", NamedTextColor.GRAY)) .append(Component.text(" and contributors", NamedTextColor.GRAY))
.append(Component.newline()) .append(Component.newline())
.append(Component.text("Repository: ", NamedTextColor.GRAY)) .append(Component.text("Original Repository: ", NamedTextColor.GRAY))
.append(Component.text(REPOSITORY_URL, NamedTextColor.GREEN).clickEvent(ClickEvent.openUrl(REPOSITORY_URL))); .append(Component.text(ORIGINAL_REPOSITORY_URL, TextColor.fromHexString(client.config().color().primary())).clickEvent(ClickEvent.openUrl(ORIGINAL_REPOSITORY_URL)))
.append(Component.newline())
.append(Component.text("My fork: ", NamedTextColor.GRAY))
.append(Component.text(FORK_URL, TextColor.fromHexString(client.config().color().primary())).clickEvent(ClickEvent.openUrl(FORK_URL)));
source.sendOutput(component, false); source.sendOutput(component, false);
@ -55,6 +77,8 @@ public class InfoCommand {
public int sendServerInfo (CommandContext<CommandSource> context) { public int sendServerInfo (CommandContext<CommandSource> context) {
final CommandSource source = context.getSource(); final CommandSource source = context.getSource();
client = source.client();
final Runtime runtime = Runtime.getRuntime(); final Runtime runtime = Runtime.getRuntime();
final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
@ -98,8 +122,8 @@ public class InfoCommand {
public Component formatEntry (Component key, Component value) { public Component formatEntry (Component key, Component value) {
return Component.translatable( return Component.translatable(
"%s: %s", "%s: %s",
key.color(NamedTextColor.GREEN), key.color(TextColor.fromHexString(client.config().color().primary())),
value.color(NamedTextColor.DARK_GREEN) value.color(TextColor.fromHexString(client.config().color().secondary()))
); );
} }

View file

@ -1,29 +1,32 @@
package land.chipmunk.chipmunkbot.commands; package land.chipmunk.chipmunkbot.commands;
import land.chipmunk.chipmunkbot.util.Logging;
import land.chipmunk.chipmunkbot.command.*;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.kyori.adventure.text.Component; import land.chipmunk.chipmunkbot.ChipmunkBot;
import net.kyori.adventure.text.format.NamedTextColor; import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage;
import land.chipmunk.chipmunkbot.util.Logging;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.Arrays; import java.util.Arrays;
import java.util.Scanner;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
public class LogQueryCommand { public class LogQueryCommand {
private LogQueryThread thread; private LogQueryThread thread;
@ -35,6 +38,7 @@ public class LogQueryCommand {
dispatcher.register( dispatcher.register(
literal("logquery") literal("logquery")
.describe(ComponentMessage.wrap(Component.text("Queries the bots log files")))
.then( .then(
literal("abort") literal("abort")
.executes(instance::abortCommand) .executes(instance::abortCommand)
@ -86,20 +90,24 @@ public class LogQueryCommand {
final CommandSource source = context.getSource(); final CommandSource source = context.getSource();
final ChipmunkBot client = source.client();
final String text = getString(context, "text"); final String text = getString(context, "text");
thread = new CountThread(line -> line.contains(text), Logging.LOGS_DIR, source); thread = new CountThread(line -> line.contains(text), Logging.LOGS_DIR, source);
thread.start(); thread.start();
source.sendOutput(Component.translatable("Searching for instances of %s in the logs", Component.text(text, NamedTextColor.GREEN))); source.sendOutput(Component.translatable("Searching for instances of %s in the logs", Component.text(text, TextColor.fromHexString(client.config().color().primary()))));
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public int progressCommand (CommandContext<CommandSource> context) { public int progressCommand (CommandContext<CommandSource> context) {
final ChipmunkBot client = context.getSource().client();
final Component progress = Component.translatable( final Component progress = Component.translatable(
"Currently reading %s (%s/%s)", "Currently reading %s (%s/%s)",
Component.text(thread.currentFilename, NamedTextColor.GREEN), Component.text(thread.currentFilename, TextColor.fromHexString(client.config().color().primary())),
Component.text(thread.currentIndex + 1), Component.text(thread.currentIndex + 1),
Component.text(thread.totalFiles) Component.text(thread.totalFiles)
); );
@ -185,8 +193,9 @@ public class LogQueryCommand {
} }
public void onFinish () { public void onFinish () {
final ChipmunkBot client = source.client();
double seconds = (double) (System.currentTimeMillis() - startTime) / 1000d; double seconds = (double) (System.currentTimeMillis() - startTime) / 1000d;
source.sendOutput(Component.translatable("Found %s instances of the specified query in %s seconds", Component.text(instances, NamedTextColor.GREEN), Component.text(seconds, NamedTextColor.GREEN))); source.sendOutput(Component.translatable("Found %s instances of the specified query in %s seconds", Component.text(instances, TextColor.fromHexString(client.config().color().primary())), Component.text(seconds, TextColor.fromHexString(client.config().color().primary()))));
} }
} }
} }

View file

@ -1,34 +1,34 @@
package land.chipmunk.chipmunkbot.commands; package land.chipmunk.chipmunkbot.commands;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.song.Song;
import land.chipmunk.chipmunkbot.plugins.SongPlayer;
import land.chipmunk.chipmunkbot.command.*;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.location;
import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.filepath;
import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.getPath;
import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.getUrl;
import static land.chipmunk.chipmunkbot.command.arguments.TimestampArgumentType.timestamp;
import static com.mojang.brigadier.arguments.LongArgumentType.getLong;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage;
import land.chipmunk.chipmunkbot.plugins.SongPlayer;
import land.chipmunk.chipmunkbot.song.Song;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.format.TextColor;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg;
import static com.mojang.brigadier.arguments.LongArgumentType.getLong;
import static land.chipmunk.chipmunkbot.command.arguments.LocationArgumentType.*;
import static land.chipmunk.chipmunkbot.command.arguments.TimestampArgumentType.timestamp;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
public class MusicCommand { public class MusicCommand {
private static SimpleCommandExceptionType NO_SONG_IS_CURRENTLY_PLAYING = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("No song is currently playing"))); private static SimpleCommandExceptionType NO_SONG_IS_CURRENTLY_PLAYING = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("No song is currently playing")));
@ -42,6 +42,7 @@ public class MusicCommand {
dispatcher.register( dispatcher.register(
literal("music") literal("music")
.describe(ComponentMessage.wrap(Component.text("Play musics")))
.then( .then(
literal("play") literal("play")
.then( .then(
@ -79,6 +80,14 @@ public class MusicCommand {
.executes(instance::gotoCommand) .executes(instance::gotoCommand)
) )
) )
.then(
literal("pitch")
.then(
argument("pitch", floatArg())
.executes(instance::pitch)
)
)
); );
} }
@ -95,25 +104,27 @@ public class MusicCommand {
public int stop (CommandContext<CommandSource> context) throws CommandSyntaxException { public int stop (CommandContext<CommandSource> context) throws CommandSyntaxException {
final CommandSource source = context.getSource(); final CommandSource source = context.getSource();
final SongPlayer songPlayer = source.client().songPlayer(); final ChipmunkBot client = source.client();
final SongPlayer songPlayer = client.songPlayer();
if (songPlayer.currentSong() == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create(); if (songPlayer.currentSong() == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create();
songPlayer.stopPlaying(); songPlayer.stopPlaying();
songPlayer.songQueue().clear(); songPlayer.songQueue().clear();
source.sendOutput(Component.translatable("Stopped music playback", NamedTextColor.GREEN)); source.sendOutput(Component.translatable("Stopped music playback", TextColor.fromHexString(client.config().color().primary())));
return 1; return 1;
} }
public int skip (CommandContext<CommandSource> context) throws CommandSyntaxException { public int skip (CommandContext<CommandSource> context) throws CommandSyntaxException {
final CommandSource source = context.getSource(); final CommandSource source = context.getSource();
final SongPlayer songPlayer = source.client().songPlayer(); final ChipmunkBot client = source.client();
final SongPlayer songPlayer = client.songPlayer();
if (songPlayer.currentSong() == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create(); if (songPlayer.currentSong() == null) throw NO_SONG_IS_CURRENTLY_PLAYING.create();
songPlayer.stopPlaying(); songPlayer.stopPlaying();
source.sendOutput(Component.translatable("Skipped the current song", NamedTextColor.GREEN)); source.sendOutput(Component.translatable("Skipped the current song", TextColor.fromHexString(client.config().color().primary())));
return 1; return 1;
} }
@ -158,7 +169,7 @@ public class MusicCommand {
final File file = new File(directory, filename); final File file = new File(directory, filename);
if (!file.isDirectory()) continue; if (!file.isDirectory()) continue;
final NamedTextColor color = (i++ & 1) == 0 ? NamedTextColor.DARK_GREEN : NamedTextColor.GREEN; final TextColor color = (i++ & 1) == 0 ? TextColor.fromHexString(client.config().color().secondary()) : TextColor.fromHexString(client.config().color().primary());
final Path relativeFilepath = Path.of(relativePath, filename); final Path relativeFilepath = Path.of(relativePath, filename);
final String escapedPath = escapePath(relativeFilepath.toString()); final String escapedPath = escapePath(relativeFilepath.toString());
@ -174,7 +185,7 @@ public class MusicCommand {
final File file = new File(directory, filename); final File file = new File(directory, filename);
if (file.isDirectory()) continue; if (file.isDirectory()) continue;
final NamedTextColor color = (i++ & 1) == 0 ? NamedTextColor.DARK_GREEN : NamedTextColor.GREEN; final TextColor color = (i++ & 1) == 0 ? TextColor.fromHexString(client.config().color().secondary()) : TextColor.fromHexString(client.config().color().primary());
final Path relativeFilepath = Path.of(relativePath, filename); final Path relativeFilepath = Path.of(relativePath, filename);
final String escapedPath = escapePath(relativeFilepath.toString()); final String escapedPath = escapePath(relativeFilepath.toString());
@ -189,7 +200,7 @@ public class MusicCommand {
final ArrayList<Component> mergedList = new ArrayList<>(); final ArrayList<Component> mergedList = new ArrayList<>();
for (Component component : directories) mergedList.add(component); for (Component component : directories) mergedList.add(component);
for (Component component : files) mergedList.add(component); for (Component component : files) mergedList.add(component);
final Component component = Component.translatable("Songs - %s", Component.join(JoinConfiguration.separator(Component.space()), mergedList)).color(NamedTextColor.GREEN); final Component component = Component.translatable("Songs - %s", Component.join(JoinConfiguration.separator(Component.space()), mergedList)).color(TextColor.fromHexString(client.config().color().primary()));
source.sendOutput(component, false); source.sendOutput(component, false);
return 1; return 1;
@ -255,4 +266,22 @@ public class MusicCommand {
return 1; return 1;
} }
public int pitch (CommandContext<CommandSource> context) {
final CommandSource source = context.getSource();
final SongPlayer songPlayer = source.client().songPlayer();
final float pitch = getFloat(context, "pitch");
songPlayer.pitch(pitch);
source.sendOutput(
Component.translatable(
"Set the pitch to: %s",
Component.text(String.valueOf(pitch))
).color(TextColor.fromHexString(source.client().config().color().primary()))
);
return 1;
}
} }

View file

@ -14,6 +14,7 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.data.ProtocolState; import com.github.steveice10.mc.protocol.data.ProtocolState;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
public class NetMsgCommand { public class NetMsgCommand {
public static void register (CommandDispatcher dispatcher) { public static void register (CommandDispatcher dispatcher) {
@ -21,10 +22,11 @@ public class NetMsgCommand {
dispatcher.register( dispatcher.register(
literal("netmsg") literal("netmsg")
.then( .describe(ComponentMessage.wrap(Component.text("Broadcasts a message to every server")))
argument("message", greedyString()) .then(
.executes(instance::netmsg) argument("message", greedyString())
) .executes(instance::netmsg)
)
); );
} }
@ -36,7 +38,7 @@ public class NetMsgCommand {
final Component message = Component.translatable( final Component message = Component.translatable(
"[%s] %s \u203a %s", "[%s] %s \u203a %s",
Component.text(client.session().getHost() + ":" + client.session().getPort(), NamedTextColor.GRAY), Component.text(client.session().getHost() + ":" + client.session().getPort(), NamedTextColor.GRAY),
Component.empty().color(NamedTextColor.DARK_GREEN).append(source.displayName()), Component.empty().color(TextColor.fromHexString(client.config().color().secondary())).append(source.displayName()),
Component.text(input, NamedTextColor.GRAY) Component.text(input, NamedTextColor.GRAY)
).color(NamedTextColor.DARK_GRAY); ).color(NamedTextColor.DARK_GRAY);

View file

@ -13,7 +13,8 @@ public class ReconnectCommand {
dispatcher.register( dispatcher.register(
literal("reconnect") literal("reconnect")
.executes(instance::reconnect) .describe(ComponentMessage.wrap(Component.text("Reconnects the bot")))
.executes(instance::reconnect)
); );
} }

View file

@ -20,10 +20,11 @@ public class RunCommand {
dispatcher.register( dispatcher.register(
literal("run") literal("run")
.then( .describe(ComponentMessage.wrap(Component.text("Runs a command in the command core and return its output")))
argument("command", greedyString()) .then(
.executes(instance::run) argument("command", greedyString())
) .executes(instance::run)
)
); );
} }

View file

@ -0,0 +1,40 @@
package land.chipmunk.chipmunkbot.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage;
import net.kyori.adventure.text.Component;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
public class SayCommand {
public static void register (CommandDispatcher dispatcher) {
final SayCommand instance = new SayCommand();
dispatcher.register(
literal("say")
.describe(ComponentMessage.wrap(Component.text("Makes the bot say a message")))
.then(
argument("message", greedyString())
.executes(instance::say)
)
);
}
public int say (CommandContext<CommandSource> context) {
final CommandSource source = context.getSource();
final String message = getString(context, "message");
final ChipmunkBot client = source.client();
if (message.startsWith("/")) client.chat().command(message.substring(1));
else client.chat().message(message);
return 1;
}
}

View file

@ -12,7 +12,8 @@ public class TestCommand {
dispatcher.register( dispatcher.register(
literal("test") literal("test")
.executes(instance::helloWorld) .describe(ComponentMessage.wrap(Component.text("Tests if the bot is online/working")))
.executes(instance::helloWorld)
); );
} }

View file

@ -47,6 +47,7 @@ public class ChatPlugin extends SessionAdapter {
systemChatParsers = new ArrayList<>(); systemChatParsers = new ArrayList<>();
systemChatParsers.add(new MinecraftChatParser(client)); systemChatParsers.add(new MinecraftChatParser(client));
systemChatParsers.add(new KaboomChatParser(client)); systemChatParsers.add(new KaboomChatParser(client));
systemChatParsers.add(new ChomeNSCustomChatParser(client));
} }
public void message (String message) { public void message (String message) {

View file

@ -1,8 +1,7 @@
package land.chipmunk.chipmunkbot.plugins; package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.ChipmunkBot; import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.Options; import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.plugins.PositionManager;
import land.chipmunk.chipmunkbot.data.BlockArea; import land.chipmunk.chipmunkbot.data.BlockArea;
import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.math.vector.Vector3i;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -15,7 +14,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.Server
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundBlockEntityTagQuery;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
@ -24,7 +22,6 @@ import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.google.gson.JsonObject;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
@ -45,7 +42,7 @@ public class CommandCore extends SessionAdapter {
@Getter private List<Listener> listeners = new ArrayList<>(); @Getter private List<Listener> listeners = new ArrayList<>();
public CommandCore (ChipmunkBot client, Options options) { public CommandCore (ChipmunkBot client, Configuration.Bot options) {
this.client = client; this.client = client;
this.enabled = options.core.enabled; this.enabled = options.core.enabled;
client.addListener((SessionListener) this); client.addListener((SessionListener) this);

View file

@ -1,12 +1,15 @@
package land.chipmunk.chipmunkbot.plugins; package land.chipmunk.chipmunkbot.plugins;
import com.mojang.brigadier.builder.ArgumentBuilder;
import land.chipmunk.chipmunkbot.ChipmunkBot; import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.command.CommandSource; import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage; import land.chipmunk.chipmunkbot.command.ComponentMessage;
import land.chipmunk.chipmunkbot.command.BuiltInExceptions; import land.chipmunk.chipmunkbot.command.BuiltInExceptions;
import land.chipmunk.chipmunkbot.commands.*; import land.chipmunk.chipmunkbot.commands.*;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
@ -40,6 +43,7 @@ public class CommandManager {
NetMsgCommand.register(dispatcher); NetMsgCommand.register(dispatcher);
MusicCommand.register(dispatcher); MusicCommand.register(dispatcher);
LogQueryCommand.register(dispatcher); LogQueryCommand.register(dispatcher);
SayCommand.register(dispatcher);
} }
public static void sendException (CommandSource source, CommandSyntaxException exception) { public static void sendException (CommandSource source, CommandSyntaxException exception) {

View file

@ -1,7 +1,7 @@
package land.chipmunk.chipmunkbot.plugins; package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.ChipmunkBot; import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.Options; import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.command.CommandSource; import land.chipmunk.chipmunkbot.command.CommandSource;
import land.chipmunk.chipmunkbot.command.PlayerCommandSource; import land.chipmunk.chipmunkbot.command.PlayerCommandSource;
import land.chipmunk.chipmunkbot.command.ComponentMessage; import land.chipmunk.chipmunkbot.command.ComponentMessage;
@ -23,7 +23,7 @@ public class PlayerCommandHandler {
@Getter @Setter private String prefix; @Getter @Setter private String prefix;
@Getter @Setter private String cspyPrefix; @Getter @Setter private String cspyPrefix;
public PlayerCommandHandler (ChipmunkBot client, Options options) { public PlayerCommandHandler (ChipmunkBot client, Configuration.Bot options) {
this.client = client; this.client = client;
this.prefix = options.commands.prefix; this.prefix = options.commands.prefix;
this.cspyPrefix = options.commands.cspyPrefix != null ? options.commands.cspyPrefix : this.prefix; this.cspyPrefix = options.commands.cspyPrefix != null ? options.commands.cspyPrefix : this.prefix;

View file

@ -18,23 +18,45 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLo
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
import land.chipmunk.chipmunkbot.Configuration;
import land.chipmunk.chipmunkbot.util.ComponentUtilities;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
public class SelfCarePlugin extends SessionAdapter { public class SelfCarePlugin extends SessionAdapter {
private final ChipmunkBot client; private final ChipmunkBot client;
private final Configuration.Bot options;
@Getter @Setter private GameMode gamemode; @Getter @Setter private GameMode gamemode;
@Getter @Setter private int permissionLevel; @Getter @Setter private int permissionLevel;
private boolean prefix = false;
private Timer timer; private Timer timer;
private int entityId; // TODO: Move entity id handling somewhere else private int entityId; // TODO: Move entity id handling somewhere else
public SelfCarePlugin (ChipmunkBot client) { public SelfCarePlugin (ChipmunkBot client, Configuration.Bot options) {
this.client = client; this.client = client;
this.options = options;
client.addListener((SessionListener) this); client.addListener((SessionListener) this);
client.chat().addListener(new ChatPlugin.Listener() {
@Override
public void systemMessageReceived(Component component, boolean overlay) {
// mabe parse using components? too lazy
final String stringifiedMessage = ComponentUtilities.stringify(component);
if (stringifiedMessage.equals("You now have the tag: " + options.selfCares.prefix.prefix)) prefix = true;
else if (stringifiedMessage.equals("You no longer have a tag")) prefix = false;
else if (stringifiedMessage.startsWith("You now have the tag: ")) prefix = false;
}
});
final TimerTask task = new TimerTask() { final TimerTask task = new TimerTask() {
@Override @Override
public void run () { public void run () {
@ -48,19 +70,19 @@ public class SelfCarePlugin extends SessionAdapter {
}; };
timer = new Timer(); timer = new Timer();
timer.schedule(task, 75, 75); timer.schedule(task, 125, 125);
} }
public void tick () { public void tick () {
if (permissionLevel < 2) client.chat().command("minecraft:op @s[type=player]"); if (permissionLevel < 2) client.chat().command("minecraft:op @s[type=player]");
else if (gamemode != GameMode.CREATIVE) client.chat().command("minecraft:gamemode creative"); else if (gamemode != GameMode.CREATIVE) client.chat().command("minecraft:gamemode creative");
else if (!client.commandSpy().enabled()) client.chat().command("c on"); else if (!client.commandSpy().enabled() && options.selfCares.cspy) client.chat().command("c on");
else if (!prefix && options.selfCares.prefix.enabled) client.chat().command("prefix " + options.selfCares.prefix.prefix);
} }
@Override @Override
public void packetReceived (Session session, Packet packet) { public void packetReceived (Session session, Packet packet) {
if (packet instanceof ClientboundGameEventPacket) packetReceived(session, (ClientboundGameEventPacket) packet); if (packet instanceof ClientboundGameEventPacket) packetReceived(session, (ClientboundGameEventPacket) packet);
else if (packet instanceof ClientboundGameEventPacket) packetReceived(session, (ClientboundGameEventPacket) packet);
else if (packet instanceof ClientboundEntityEventPacket) packetReceived(session, (ClientboundEntityEventPacket) packet); else if (packet instanceof ClientboundEntityEventPacket) packetReceived(session, (ClientboundEntityEventPacket) packet);
else if (packet instanceof ClientboundLoginPacket) packetReceived(session, (ClientboundLoginPacket) packet); else if (packet instanceof ClientboundLoginPacket) packetReceived(session, (ClientboundLoginPacket) packet);
} }

View file

@ -7,8 +7,10 @@ import land.chipmunk.chipmunkbot.song.*;
import com.github.steveice10.packetlib.event.session.SessionListener; import com.github.steveice10.packetlib.event.session.SessionListener;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import land.chipmunk.chipmunkbot.util.MathUtilities;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -33,6 +35,8 @@ public class SongPlayer extends SessionAdapter {
@Getter @Setter private SongLoaderThread loaderThread; @Getter @Setter private SongLoaderThread loaderThread;
private int ticksUntilPausedActionbar = 20; private int ticksUntilPausedActionbar = 20;
@Getter @Setter private float pitch = 0;
public SongPlayer (ChipmunkBot client) { public SongPlayer (ChipmunkBot client) {
this.client = client; this.client = client;
client.addListener((SessionListener) this); client.addListener((SessionListener) this);
@ -54,7 +58,7 @@ public class SongPlayer extends SessionAdapter {
try { try {
final SongLoaderThread _loaderThread = new SongLoaderThread(location); final SongLoaderThread _loaderThread = new SongLoaderThread(location);
client.chat().tellraw(Component.translatable("Loading %s", Component.text(location.getFileName().toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); client.chat().tellraw(Component.translatable("Loading %s", Component.text(location.getFileName().toString(), TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())));
_loaderThread.start(); _loaderThread.start();
loaderThread = _loaderThread; loaderThread = _loaderThread;
} catch (SongLoaderException e) { } catch (SongLoaderException e) {
@ -71,7 +75,7 @@ public class SongPlayer extends SessionAdapter {
try { try {
final SongLoaderThread _loaderThread = new SongLoaderThread(location); final SongLoaderThread _loaderThread = new SongLoaderThread(location);
client.chat().tellraw(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); client.chat().tellraw(Component.translatable("Loading %s", Component.text(location.toString(), TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())));
_loaderThread.start(); _loaderThread.start();
loaderThread = _loaderThread; loaderThread = _loaderThread;
} catch (SongLoaderException e) { } catch (SongLoaderException e) {
@ -92,7 +96,7 @@ public class SongPlayer extends SessionAdapter {
client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED)); client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
} else { } else {
songQueue.add(loaderThread.song); songQueue.add(loaderThread.song);
client.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); client.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())));
} }
loaderThread = null; loaderThread = null;
} }
@ -101,7 +105,7 @@ public class SongPlayer extends SessionAdapter {
if (songQueue.size() == 0) return; if (songQueue.size() == 0) return;
currentSong = songQueue.poll(); currentSong = songQueue.poll();
client.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); client.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())));
currentSong.play(); currentSong.play();
} }
@ -115,35 +119,35 @@ public class SongPlayer extends SessionAdapter {
handlePlaying(); handlePlaying();
if (currentSong.finished()) { if (currentSong.finished()) {
client.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); client.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())));
currentSong = null; currentSong = null;
} }
} }
public Component generateActionbar () { public Component generateActionbar () {
Component component = Component.empty() Component component = Component.empty()
.append(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)) .append(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(TextColor.fromHexString(client.config().color().secondary()))).color(TextColor.fromHexString(client.config().color().primary())))
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("%s / %s", formatTime(currentSong.time).color(NamedTextColor.GREEN), formatTime(currentSong.length).color(NamedTextColor.GREEN)).color(NamedTextColor.GRAY)) .append(Component.translatable("%s / %s", formatTime(currentSong.time).color(TextColor.fromHexString(client.config().color().primary())), formatTime(currentSong.length).color(TextColor.fromHexString(client.config().color().primary()))).color(NamedTextColor.GRAY))
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("%s / %s", Component.text(currentSong.position, NamedTextColor.GREEN), Component.text(currentSong.size(), NamedTextColor.GREEN)).color(NamedTextColor.GRAY)); .append(Component.translatable("%s / %s", Component.text(currentSong.position, TextColor.fromHexString(client.config().color().primary())), Component.text(currentSong.size(), TextColor.fromHexString(client.config().color().primary()))).color(NamedTextColor.GRAY));
if (currentSong.paused) { if (currentSong.paused) {
return component return component
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("Paused", NamedTextColor.DARK_GREEN)); .append(Component.translatable("Paused", TextColor.fromHexString(client.config().color().secondary())));
} }
if (currentSong.looping) { if (currentSong.looping) {
if (currentSong.loopCount > 0) { if (currentSong.loopCount > 0) {
return component return component
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("Looping (%s/%s)", Component.text(currentSong.currentLoop), Component.text(currentSong.loopCount)).color(NamedTextColor.DARK_GREEN)); .append(Component.translatable("Looping (%s/%s)", Component.text(currentSong.currentLoop), Component.text(currentSong.loopCount)).color(TextColor.fromHexString(client.config().color().secondary())));
} }
return component return component
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
.append(Component.translatable("Looping", NamedTextColor.DARK_GREEN)); .append(Component.translatable("Looping", TextColor.fromHexString(client.config().color().secondary())));
} }
return component; return component;
@ -176,7 +180,7 @@ public class SongPlayer extends SessionAdapter {
while (currentSong.reachedNextNote()) { while (currentSong.reachedNextNote()) {
final Note note = currentSong.getNextNote(); final Note note = currentSong.getNextNote();
final double floatingPitch = Math.pow(2, (note.pitch - 12) / 12.0); final double floatingPitch = MathUtilities.clamp(0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12))), 0, 2);
client.core().run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); client.core().run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch);
} }

View file

@ -0,0 +1,52 @@
package land.chipmunk.chipmunkbot.systemChat;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkbot.data.chat.PlayerMessage;
import land.chipmunk.chipmunkbot.data.chat.SystemChatParser;
import land.chipmunk.chipmunkbot.util.ComponentUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.event.HoverEvent;
import java.util.List;
import java.util.UUID;
// ported from chomens sex bot
public class ChomeNSCustomChatParser implements SystemChatParser {
private final ChipmunkBot client;
public ChomeNSCustomChatParser (ChipmunkBot client) {
this.client = client;
}
@Override
public PlayerMessage parse (Component message) {
if (message instanceof TranslatableComponent) return parse((TranslatableComponent) message);
return null;
}
// very similar to MinecraftChatParser
public PlayerMessage parse (TranslatableComponent message) {
final List<Component> args = message.args();
if (args.size() < 3 || (!message.key().equals("[%s] %s %s") && !message.key().equals("%s %s %s"))) return null;
final Component senderComponent = args.get(1);
final Component contents = args.get(2);
MutablePlayerListEntry sender;
final HoverEvent<?> hoverEvent = senderComponent.hoverEvent();
if (hoverEvent != null && hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) {
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
final UUID senderUUID = entityInfo.id();
sender = client.playerList().getEntry(senderUUID);
} else {
final String stringUsername = ComponentUtilities.stringify(senderComponent);
sender = client.playerList().getEntry(stringUsername);
}
if (sender == null) return null;
return new PlayerMessage(sender, contents, "minecraft:chat", senderComponent);
}
}

View file

@ -0,0 +1,7 @@
package land.chipmunk.chipmunkbot.util;
public class MathUtilities {
public static double clamp (double value, double min, double max) {
return Math.max(Math.min(value, max), min);
}
}

View file

@ -1,4 +1,8 @@
{ {
"color": {
"primary": "#ffc0cb",
"secondary": "#c95367"
},
"bots": [ "bots": [
{ {
"host": "localhost", "host": "localhost",
@ -11,6 +15,14 @@
"cspyPrefix": "default." "cspyPrefix": "default."
}, },
"selfCares": {
"cspy": true,
"prefix": {
"enabled": true,
"prefix": "&x&c&9&5&3&6&7[&x&f&f&c&0&c&bPrefix: s'&x&c&9&5&3&6&7]"
}
},
"core": { "core": {
"enabled": true "enabled": true
} }