forked from chipmunkmc/chipmunkbot
make it more sexy!111!!!!%!@#$!43!%
mabe
This commit is contained in:
parent
f5db2e02a3
commit
18fb46c008
24 changed files with 280 additions and 128 deletions
7
.idea/discord.xml
Normal file
7
.idea/discord.xml
Normal 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>
|
|
@ -11,6 +11,11 @@
|
|||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</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>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
|
|
|
@ -8,5 +8,5 @@
|
|||
</list>
|
||||
</option>
|
||||
</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>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal 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>
|
12
chipmunkbot.iml
Normal file
12
chipmunkbot.iml
Normal 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>
|
|
@ -1,18 +1,13 @@
|
|||
package land.chipmunk.chipmunkbot;
|
||||
|
||||
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 land.chipmunk.chipmunkbot.plugins.*;
|
||||
import java.util.List;
|
||||
|
||||
public class ChipmunkBot extends Client {
|
||||
@Getter private final Configuration config;
|
||||
|
||||
@Getter private final TickLoop tickLoop;
|
||||
@Getter private final ChatPlugin chat;
|
||||
@Getter private final TabCompletePlugin tabComplete;
|
||||
|
@ -25,9 +20,11 @@ public class ChipmunkBot extends Client {
|
|||
@Getter private final SelfCarePlugin selfCare;
|
||||
@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);
|
||||
|
||||
this.config = config;
|
||||
|
||||
this.tickLoop = new TickLoop(this);
|
||||
this.chat = new ChatPlugin(this);
|
||||
this.tabComplete = new TabCompletePlugin(this);
|
||||
|
|
34
src/main/java/land/chipmunk/chipmunkbot/Configuration.java
Normal file
34
src/main/java/land/chipmunk/chipmunkbot/Configuration.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
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 static class Commands {
|
||||
public String prefix = "default.";
|
||||
}
|
||||
|
||||
public static class Core {
|
||||
public boolean enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,5 @@
|
|||
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.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -65,13 +59,9 @@ public class Main {
|
|||
|
||||
List<Client> allClients = new ArrayList<>();
|
||||
|
||||
for (Options options : config.bots) {
|
||||
final Client client = new ChipmunkBot(options, allClients);
|
||||
for (Configuration.Bot options : config.bots) {
|
||||
final Client client = new ChipmunkBot(config, options, allClients);
|
||||
allClients.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Configuration {
|
||||
public Options[] bots;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +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 class Core {
|
||||
public boolean enabled = true;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chipmunkbot.command;
|
|||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
public class ConsoleCommandSource extends CommandSource {
|
||||
|
|
|
@ -6,6 +6,7 @@ import land.chipmunk.chipmunkbot.ChipmunkBot;
|
|||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.Style;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chipmunkbot.commands;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.Configuration;
|
||||
import land.chipmunk.chipmunkbot.command.*;
|
||||
import static land.chipmunk.chipmunkbot.plugins.CommandManager.literal;
|
||||
import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument;
|
||||
|
@ -13,6 +14,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
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.ArrayList;
|
||||
|
||||
|
@ -36,7 +40,7 @@ public class HelpCommand {
|
|||
|
||||
final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher();
|
||||
|
||||
source.sendOutput(generateCommandList(dispatcher), false);
|
||||
source.sendOutput(generateCommandList(client, dispatcher), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -50,7 +54,7 @@ public class HelpCommand {
|
|||
final CommandDispatcher<CommandSource> dispatcher = client.commandManager().dispatcher();
|
||||
for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) {
|
||||
if (!node.getName().equals(commandName)) continue;
|
||||
source.sendOutput(generateUsages(dispatcher, node), false);
|
||||
source.sendOutput(generateUsages(client.config(), dispatcher, node), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -58,27 +62,45 @@ public class HelpCommand {
|
|||
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<>();
|
||||
|
||||
for (CommandNode<CommandSource> node : dispatcher.getRoot().getChildren()) {
|
||||
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);
|
||||
|
||||
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> usages = new ArrayList<>();
|
||||
|
||||
for (String usage : dispatcher.getAllUsage(node, null, true)) {
|
||||
final String text = (node.getName() + " " + usage).trim();
|
||||
usages.add(Component.text(text));
|
||||
usages.add(
|
||||
Component
|
||||
.text(node.getName())
|
||||
.color(TextColor.fromHexString("#c95367"))
|
||||
.append(Component.space())
|
||||
.append(
|
||||
Component
|
||||
.text(usage)
|
||||
.color(TextColor.fromHexString(config.color().primary()))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Component.join(JoinConfiguration.separator(Component.newline()), usages);
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
package land.chipmunk.chipmunkbot.commands;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.util.CPUInfo;
|
||||
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.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.lang.management.*;
|
||||
import java.io.IOException;
|
||||
|
||||
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) {
|
||||
final InfoCommand instance = new InfoCommand();
|
||||
|
@ -35,17 +37,21 @@ public class InfoCommand {
|
|||
|
||||
public int sendBotInfo (CommandContext<CommandSource> context) {
|
||||
final CommandSource source = context.getSource();
|
||||
client = source.client();
|
||||
|
||||
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.newline())
|
||||
.append(Component.text("Made by ", NamedTextColor.GRAY))
|
||||
.append(Component.text("_ChipMC_", NamedTextColor.DARK_GREEN))
|
||||
.append(Component.text("_ChipMC_", TextColor.fromHexString("#c95367")))
|
||||
.append(Component.text(" and contributors", NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Repository: ", NamedTextColor.GRAY))
|
||||
.append(Component.text(REPOSITORY_URL, NamedTextColor.GREEN).clickEvent(ClickEvent.openUrl(REPOSITORY_URL)));
|
||||
.append(Component.text("Original Repository: ", NamedTextColor.GRAY))
|
||||
.append(Component.text(ORIGINAL_REPOSITORY_URL, TextColor.fromHexString(client.config().color().primary())).clickEvent(ClickEvent.openUrl(ORIGINAL_REPOSITORY_URL)))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("chayapak's fork: ", NamedTextColor.GRAY))
|
||||
.append(Component.text(FORK_URL, TextColor.fromHexString(client.config().color().primary())).clickEvent(ClickEvent.openUrl(FORK_URL)));
|
||||
|
||||
source.sendOutput(component, false);
|
||||
|
||||
|
@ -55,6 +61,8 @@ public class InfoCommand {
|
|||
public int sendServerInfo (CommandContext<CommandSource> context) {
|
||||
final CommandSource source = context.getSource();
|
||||
|
||||
client = source.client();
|
||||
|
||||
final Runtime runtime = Runtime.getRuntime();
|
||||
final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
|
||||
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
|
||||
|
@ -98,8 +106,8 @@ public class InfoCommand {
|
|||
public Component formatEntry (Component key, Component value) {
|
||||
return Component.translatable(
|
||||
"%s: %s",
|
||||
key.color(NamedTextColor.GREEN),
|
||||
value.color(NamedTextColor.DARK_GREEN)
|
||||
key.color(TextColor.fromHexString(client.config().color().primary())),
|
||||
value.color(TextColor.fromHexString("#c95367"))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
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.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.command.CommandSource;
|
||||
import land.chipmunk.chipmunkbot.command.ComponentMessage;
|
||||
import land.chipmunk.chipmunkbot.util.Logging;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Scanner;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Predicate;
|
||||
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 {
|
||||
private LogQueryThread thread;
|
||||
|
||||
|
@ -86,20 +89,24 @@ public class LogQueryCommand {
|
|||
|
||||
final CommandSource source = context.getSource();
|
||||
|
||||
final ChipmunkBot client = source.client();
|
||||
|
||||
final String text = getString(context, "text");
|
||||
|
||||
thread = new CountThread(line -> line.contains(text), Logging.LOGS_DIR, source);
|
||||
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;
|
||||
}
|
||||
|
||||
public int progressCommand (CommandContext<CommandSource> context) {
|
||||
final ChipmunkBot client = context.getSource().client();
|
||||
|
||||
final Component progress = Component.translatable(
|
||||
"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.totalFiles)
|
||||
);
|
||||
|
@ -185,8 +192,9 @@ public class LogQueryCommand {
|
|||
}
|
||||
|
||||
public void onFinish () {
|
||||
final ChipmunkBot client = source.client();
|
||||
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()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
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.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
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.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
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.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
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 {
|
||||
private static SimpleCommandExceptionType NO_SONG_IS_CURRENTLY_PLAYING = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("No song is currently playing")));
|
||||
|
@ -95,25 +93,27 @@ public class MusicCommand {
|
|||
|
||||
public int stop (CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||
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();
|
||||
|
||||
songPlayer.stopPlaying();
|
||||
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;
|
||||
}
|
||||
|
||||
public int skip (CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class MusicCommand {
|
|||
final File file = new File(directory, filename);
|
||||
if (!file.isDirectory()) continue;
|
||||
|
||||
final NamedTextColor color = (i++ & 1) == 0 ? NamedTextColor.DARK_GREEN : NamedTextColor.GREEN;
|
||||
final TextColor color = (i++ & 1) == 0 ? TextColor.fromHexString("#c95367") : TextColor.fromHexString(client.config().color().primary());
|
||||
|
||||
final Path relativeFilepath = Path.of(relativePath, filename);
|
||||
final String escapedPath = escapePath(relativeFilepath.toString());
|
||||
|
@ -174,7 +174,7 @@ public class MusicCommand {
|
|||
final File file = new File(directory, filename);
|
||||
if (file.isDirectory()) continue;
|
||||
|
||||
final NamedTextColor color = (i++ & 1) == 0 ? NamedTextColor.DARK_GREEN : NamedTextColor.GREEN;
|
||||
final TextColor color = (i++ & 1) == 0 ? TextColor.fromHexString("#c95367") : TextColor.fromHexString(client.config().color().primary());
|
||||
|
||||
final Path relativeFilepath = Path.of(relativePath, filename);
|
||||
final String escapedPath = escapePath(relativeFilepath.toString());
|
||||
|
@ -189,7 +189,7 @@ public class MusicCommand {
|
|||
final ArrayList<Component> mergedList = new ArrayList<>();
|
||||
for (Component component : directories) 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);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
|||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public class NetMsgCommand {
|
||||
public static void register (CommandDispatcher dispatcher) {
|
||||
|
@ -36,7 +37,7 @@ public class NetMsgCommand {
|
|||
final Component message = Component.translatable(
|
||||
"[%s] %s \u203a %s",
|
||||
Component.text(client.session().getHost() + ":" + client.session().getPort(), NamedTextColor.GRAY),
|
||||
Component.empty().color(NamedTextColor.DARK_GREEN).append(source.displayName()),
|
||||
Component.empty().color(TextColor.fromHexString("#c95367")).append(source.displayName()),
|
||||
Component.text(input, NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY);
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
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 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")
|
||||
.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;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,14 @@
|
|||
package land.chipmunk.chipmunkbot.plugins;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.Options;
|
||||
import land.chipmunk.chipmunkbot.command.CommandSource;
|
||||
import land.chipmunk.chipmunkbot.Configuration;
|
||||
import land.chipmunk.chipmunkbot.command.PlayerCommandSource;
|
||||
import land.chipmunk.chipmunkbot.command.ComponentMessage;
|
||||
import land.chipmunk.chipmunkbot.plugins.ChatPlugin;
|
||||
import land.chipmunk.chipmunkbot.data.chat.PlayerMessage;
|
||||
import land.chipmunk.chipmunkbot.util.ComponentUtilities;
|
||||
import land.chipmunk.chipmunkbot.plugins.CommandManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.Message;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
@ -21,7 +16,7 @@ public class ChatCommandHandler extends ChatPlugin.Listener {
|
|||
private ChipmunkBot client;
|
||||
@Getter @Setter private String prefix;
|
||||
|
||||
public ChatCommandHandler (ChipmunkBot client, Options options) {
|
||||
public ChatCommandHandler (ChipmunkBot client, Configuration.Bot options) {
|
||||
this.client = client;
|
||||
this.prefix = options.commands.prefix;
|
||||
client.chat().addListener((ChatPlugin.Listener) this);
|
||||
|
|
|
@ -47,6 +47,7 @@ public class ChatPlugin extends SessionAdapter {
|
|||
systemChatParsers = new ArrayList<>();
|
||||
systemChatParsers.add(new MinecraftChatParser(client));
|
||||
systemChatParsers.add(new KaboomChatParser(client));
|
||||
systemChatParsers.add(new ChomeNSCustomChatParser(client));
|
||||
}
|
||||
|
||||
public void message (String message) {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package land.chipmunk.chipmunkbot.plugins;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.Options;
|
||||
import land.chipmunk.chipmunkbot.plugins.PositionManager;
|
||||
import land.chipmunk.chipmunkbot.Configuration;
|
||||
import land.chipmunk.chipmunkbot.data.BlockArea;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
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.player.ServerboundPlayerActionPacket;
|
||||
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.player.Hand;
|
||||
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.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
|
@ -45,7 +42,7 @@ public class CommandCore extends SessionAdapter {
|
|||
|
||||
@Getter private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public CommandCore (ChipmunkBot client, Options options) {
|
||||
public CommandCore (ChipmunkBot client, Configuration.Bot options) {
|
||||
this.client = client;
|
||||
this.enabled = options.core.enabled;
|
||||
client.addListener((SessionListener) this);
|
||||
|
|
|
@ -7,6 +7,7 @@ import land.chipmunk.chipmunkbot.command.BuiltInExceptions;
|
|||
import land.chipmunk.chipmunkbot.commands.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.event.ClickEvent;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
@ -40,6 +41,7 @@ public class CommandManager {
|
|||
NetMsgCommand.register(dispatcher);
|
||||
MusicCommand.register(dispatcher);
|
||||
LogQueryCommand.register(dispatcher);
|
||||
SayCommand.register(dispatcher);
|
||||
}
|
||||
|
||||
public static void sendException (CommandSource source, CommandSyntaxException exception) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
|||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -54,7 +55,7 @@ public class SongPlayer extends SessionAdapter {
|
|||
|
||||
try {
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())));
|
||||
_loaderThread.start();
|
||||
loaderThread = _loaderThread;
|
||||
} catch (SongLoaderException e) {
|
||||
|
@ -71,7 +72,7 @@ public class SongPlayer extends SessionAdapter {
|
|||
|
||||
try {
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())));
|
||||
_loaderThread.start();
|
||||
loaderThread = _loaderThread;
|
||||
} catch (SongLoaderException e) {
|
||||
|
@ -92,7 +93,7 @@ public class SongPlayer extends SessionAdapter {
|
|||
client.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||
} else {
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())));
|
||||
}
|
||||
loaderThread = null;
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ public class SongPlayer extends SessionAdapter {
|
|||
if (songQueue.size() == 0) return;
|
||||
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())));
|
||||
currentSong.play();
|
||||
}
|
||||
|
||||
|
@ -115,35 +116,35 @@ public class SongPlayer extends SessionAdapter {
|
|||
handlePlaying();
|
||||
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())));
|
||||
currentSong = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Component generateActionbar () {
|
||||
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("#c95367"))).color(TextColor.fromHexString(client.config().color().primary())))
|
||||
.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("%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) {
|
||||
return component
|
||||
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
|
||||
.append(Component.translatable("Paused", NamedTextColor.DARK_GREEN));
|
||||
.append(Component.translatable("Paused", TextColor.fromHexString("#c95367")));
|
||||
}
|
||||
|
||||
if (currentSong.looping) {
|
||||
if (currentSong.loopCount > 0) {
|
||||
return component
|
||||
.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("#c95367")));
|
||||
}
|
||||
|
||||
return component
|
||||
.append(Component.translatable(" | ", NamedTextColor.DARK_GRAY))
|
||||
.append(Component.translatable("Looping", NamedTextColor.DARK_GREEN));
|
||||
.append(Component.translatable("Looping", TextColor.fromHexString("#c95367")));
|
||||
}
|
||||
|
||||
return component;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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 java.util.List;
|
||||
|
||||
// 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 username = args.get(1);
|
||||
final Component contents = args.get(2);
|
||||
|
||||
final String stringUsername = ComponentUtilities.stringify(username);
|
||||
MutablePlayerListEntry sender = client.playerList().getEntry(stringUsername);
|
||||
|
||||
if (sender == null) return null;
|
||||
|
||||
return new PlayerMessage(sender, contents, "minecraft:chat", username);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"color": {
|
||||
"primary": "#ffc0cb",
|
||||
"secondary": "#c9536"
|
||||
},
|
||||
"bots": [
|
||||
{
|
||||
"host": "localhost",
|
||||
|
|
Loading…
Reference in a new issue