forked from ChomeNS/chomens-bot-java
Add stuff - first commit
This commit is contained in:
commit
d0f5d29092
41 changed files with 7176 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Project exclude paths
|
||||
/target/
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
|
@ -0,0 +1 @@
|
|||
chomens_bot
|
12
.idea/chomens_bot.iml
Normal file
12
.idea/chomens_bot.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>
|
14
.idea/compiler.xml
Normal file
14
.idea/compiler.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="chomens_bot" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
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>
|
7
.idea/encodings.xml
Normal file
7
.idea/encodings.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
30
.idea/jarRepositories.xml
Normal file
30
.idea/jarRepositories.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="minecraft-libraries" />
|
||||
<option name="name" value="Minecraft Libraries" />
|
||||
<option name="url" value="https://libraries.minecraft.net" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="opencollab" />
|
||||
<option name="name" value="opencollab" />
|
||||
<option name="url" value="https://repo.opencollab.dev/maven-releases/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
Normal file
14
.idea/misc.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
55
dependency-reduced-pom.xml
Normal file
55
dependency-reduced-pom.xml
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.chayapak1</groupId>
|
||||
<artifactId>chomens_bot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>me.chayapak1.chomensbot_mabe.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>opencollab</id>
|
||||
<url>https://repo.opencollab.dev/maven-releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>minecraft-libraries</id>
|
||||
<name>Minecraft Libraries</name>
|
||||
<url>https://libraries.minecraft.net</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
2
lombok.config
Normal file
2
lombok.config
Normal file
|
@ -0,0 +1,2 @@
|
|||
config.stopBubbling = true
|
||||
lombok.accessors.fluent = true
|
120
pom.xml
Normal file
120
pom.xml
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.chayapak1</groupId>
|
||||
<artifactId>chomens_bot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>opencollab</id>
|
||||
<url>https://repo.opencollab.dev/maven-releases/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>minecraft-libraries</id>
|
||||
<name>Minecraft Libraries</name>
|
||||
<url>https://libraries.minecraft.net</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.steveice10</groupId>
|
||||
<artifactId>mcprotocollib</artifactId>
|
||||
<version>1.19.2-1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.13.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
<version>3.23.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<classifier>lib</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowjar-extra</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- Build an executable JAR -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>me.chayapak1.chomensbot_mabe.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
98
src/main/java/me/chayapak1/chomensbot_mabe/Bot.java
Normal file
98
src/main/java/me/chayapak1/chomensbot_mabe/Bot.java
Normal file
|
@ -0,0 +1,98 @@
|
|||
package me.chayapak1.chomensbot_mabe;
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.*;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.plugins.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class Bot {
|
||||
private final ArrayList<SessionListener>listeners = new ArrayList<>();
|
||||
|
||||
@Getter private final String host;
|
||||
@Getter private final int port;
|
||||
@Getter private final String username;
|
||||
|
||||
@Getter private final Session session;
|
||||
|
||||
@Getter private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
@Getter private final ChatPlugin chat = new ChatPlugin(this);
|
||||
@Getter private final LoggerPlugin logger = new LoggerPlugin(this);
|
||||
@Getter private final SelfCarePlugin selfCare = new SelfCarePlugin(this);
|
||||
@Getter private final ConsolePlugin console = new ConsolePlugin(this);
|
||||
@Getter private final PositionPlugin position = new PositionPlugin(this);
|
||||
@Getter private final CorePlugin core = new CorePlugin(this);
|
||||
@Getter private final CommandHandlerPlugin commandHandler = new CommandHandlerPlugin();
|
||||
@Getter private final ChatCommandHandlerPlugin chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
|
||||
public Bot (String host, int port, String username) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null);
|
||||
this.session = session;
|
||||
|
||||
session.addListener(new SessionAdapter() {
|
||||
// same stuff over and over yup
|
||||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
for (SessionListener listener : listeners) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
listener.connected(new ConnectedEvent(session));
|
||||
}
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSending(PacketSendingEvent packetSendingEvent) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.packetSending(packetSendingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent(Session session, Packet packet) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.packetSent(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetError(PacketErrorEvent packetErrorEvent) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.packetError(packetErrorEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnecting(DisconnectingEvent disconnectingEvent) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.disconnecting(disconnectingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(DisconnectedEvent disconnectedEvent) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.disconnected(disconnectedEvent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
session.connect();
|
||||
}
|
||||
|
||||
public void addListener (SessionListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
11
src/main/java/me/chayapak1/chomensbot_mabe/Main.java
Normal file
11
src/main/java/me/chayapak1/chomensbot_mabe/Main.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package me.chayapak1.chomensbot_mabe;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
final String host = args[0];
|
||||
final int port = Integer.parseInt(args[1]);
|
||||
final String username = args[2];
|
||||
|
||||
new Bot(host, port, username);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package me.chayapak1.chomensbot_mabe.chatParsers;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.ChatParser;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.PlayerMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class KaboomChatParser implements ChatParser {
|
||||
|
||||
public KaboomChatParser () {
|
||||
}
|
||||
|
||||
private static final Style empty = Style.empty();
|
||||
private static final Component SEPERATOR_COLON = Component.text(":");
|
||||
private static final Component SEPERATOR_SPACE = Component.space();
|
||||
|
||||
@Override
|
||||
public PlayerMessage parse (Component message) {
|
||||
if (message instanceof TextComponent) return parse((TextComponent) message);
|
||||
if (message instanceof TranslatableComponent) return parse((TranslatableComponent) message);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMessage parse (TranslatableComponent message) {
|
||||
if (message.key().equals("%s")) {
|
||||
message.args();
|
||||
if (message.args().size() == 1 && message.style().equals(empty)) return parse(message.args().get(0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMessage parse (TextComponent message) {
|
||||
List<Component> children = message.children();
|
||||
|
||||
if (!message.content().equals("") || !message.style().equals(empty) || children.size() < 3) return null;
|
||||
|
||||
final Map<String, Component> parameters = new HashMap<>();
|
||||
|
||||
final Component prefix = children.get(0);
|
||||
Component displayName = Component.empty();
|
||||
Component contents = Component.empty();
|
||||
|
||||
if (isSeperatorAt(children, 1)) { // Missing/blank display name
|
||||
if (children.size() > 3) contents = children.get(3);
|
||||
} else if (isSeperatorAt(children, 2)) {
|
||||
displayName = children.get(1);
|
||||
if (children.size() > 4) contents = children.get(4);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
parameters.put("sender", displayName);
|
||||
parameters.put("prefix", prefix);
|
||||
parameters.put("contents", contents);
|
||||
|
||||
return new PlayerMessage(parameters);
|
||||
}
|
||||
|
||||
private boolean isSeperatorAt (List<Component> children, int start) {
|
||||
return children.get(start).equals(SEPERATOR_COLON) && children.get(start + 1).equals(SEPERATOR_SPACE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package me.chayapak1.chomensbot_mabe.chatParsers;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.ChatParser;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.PlayerMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MinecraftChatParser implements ChatParser {
|
||||
// ? Is such a mapping necessary?
|
||||
private static final Map<String, String> typeMap = new HashMap<>();
|
||||
static {
|
||||
typeMap.put("chat.type.text", "minecraft:chat");
|
||||
typeMap.put("chat.type.announcement", "minecraft:say_command");
|
||||
typeMap.put("chat.type.command", "minecraft:msg_command");
|
||||
typeMap.put("chat.type.team.text", "minecraft:team_msg_command");
|
||||
typeMap.put("chat.type.emote", "minecraft:emote_command");
|
||||
}
|
||||
|
||||
public MinecraftChatParser () {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerMessage parse (Component message) {
|
||||
if (message instanceof TranslatableComponent) return parse((TranslatableComponent) message);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMessage parse (TranslatableComponent message) {
|
||||
final List<Component> args = message.args();
|
||||
final String key = message.key();
|
||||
if (args.size() < 2 || !typeMap.containsKey(key)) return null;
|
||||
|
||||
final Map<String, Component> parameters = new HashMap<>();
|
||||
|
||||
final Component senderComponent = args.get(0);
|
||||
final Component contents = args.get(1);
|
||||
|
||||
// Find the sender and attempt to map it to a player
|
||||
final HoverEvent<?> hoverEvent = senderComponent.hoverEvent();
|
||||
if (hoverEvent == null || !hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) return null;
|
||||
|
||||
parameters.put("sender", senderComponent);
|
||||
parameters.put("contents", contents);
|
||||
|
||||
return new PlayerMessage(parameters);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package me.chayapak1.chomensbot_mabe.chatParsers.data;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public interface ChatParser {
|
||||
PlayerMessage parse (Component message);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package me.chayapak1.chomensbot_mabe.chatParsers.data;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerMessage {
|
||||
private Map<String, Component> parameters;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package me.chayapak1.chomensbot_mabe.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Command {
|
||||
String description();
|
||||
List<String> usage();
|
||||
Component execute(CommandContext context, String[] args) throws Exception;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package me.chayapak1.chomensbot_mabe.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandContext {
|
||||
@Getter public final Bot bot;
|
||||
|
||||
public CommandContext(Bot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
public Component displayName () { return Component.empty(); }
|
||||
public void sendOutput (Component component) {}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package me.chayapak1.chomensbot_mabe.command;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class ConsoleCommandContext extends CommandContext {
|
||||
private final Bot bot;
|
||||
|
||||
public ConsoleCommandContext (Bot bot) {
|
||||
super(bot);
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOutput (Component component) {
|
||||
final String message = ComponentUtilities.stringify(component);
|
||||
bot.logger().log(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component displayName () {
|
||||
return Component.text(bot.username()).color(NamedTextColor.YELLOW);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package me.chayapak1.chomensbot_mabe.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class PlayerCommandContext extends CommandContext {
|
||||
@Getter private final String playerName;
|
||||
|
||||
private final Bot bot;
|
||||
|
||||
public PlayerCommandContext (Bot bot, String playerName) {
|
||||
super(bot);
|
||||
this.bot = bot;
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOutput (Component message) {
|
||||
bot.chat().tellraw(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component displayName () {
|
||||
return Component.text(playerName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBlockCommand implements Command {
|
||||
public String description() {
|
||||
return "Executes a command in the command core";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<command>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
bot.core().run(String.join(" ", args));
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import com.github.ricksbrown.cowsay.plugin.CowExecutor;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CowsayCommand implements Command {
|
||||
public String description() {
|
||||
return "Moo";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<cow> <message>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args) {
|
||||
final String cow = args[0];
|
||||
final String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
|
||||
final CowExecutor cowExecutor = new CowExecutor();
|
||||
cowExecutor.setCowfile(cow);
|
||||
cowExecutor.setMessage(message);
|
||||
|
||||
final String result = cowExecutor.execute();
|
||||
|
||||
context.sendOutput(Component.text(result));
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EchoCommand implements Command {
|
||||
public String description() {
|
||||
return "Says a message";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<message>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context, String[] args) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
bot.chat().send(String.join(" ", args));
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import me.chayapak1.chomensbot_mabe.plugins.CommandHandlerPlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HelpCommand implements Command {
|
||||
public String description() {
|
||||
return "Shows the help";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("[command]");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendCommandList(context);
|
||||
return Component.text("success");
|
||||
} else {
|
||||
return sendUsages(context, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendCommandList(CommandContext context) {
|
||||
final List<Component> list = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Command> entry : CommandHandlerPlugin.commands().entrySet()) {
|
||||
final String name = entry.getKey();
|
||||
|
||||
list.add(Component.text(name));
|
||||
}
|
||||
|
||||
final Component component = Component.empty()
|
||||
.append(Component.text("Commands ").color(NamedTextColor.GRAY))
|
||||
.append(Component.text("(").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.text("Length: ").color(NamedTextColor.GRAY))
|
||||
.append(Component.text(list.size()).color(NamedTextColor.GREEN))
|
||||
.append(Component.text(") - ").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.join(JoinConfiguration.separator(Component.space()), list).color(NamedTextColor.GREEN));
|
||||
|
||||
context.sendOutput(component);
|
||||
}
|
||||
|
||||
public Component sendUsages (CommandContext context, String[] args) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
final String prefix = bot.chatCommandHandler().prefix();
|
||||
|
||||
final String commandName = args[0];
|
||||
|
||||
for (Map.Entry<String, Command> entry : CommandHandlerPlugin.commands().entrySet()) {
|
||||
if (!entry.getKey().equals(commandName)) continue;
|
||||
|
||||
final List<Component> usages = new ArrayList<>();
|
||||
|
||||
final Command command = entry.getValue();
|
||||
|
||||
usages.add(
|
||||
Component.empty()
|
||||
.append(Component.text(prefix + commandName).color(NamedTextColor.GOLD))
|
||||
.append(Component.text(" - " + command.description()).color(NamedTextColor.GRAY))
|
||||
);
|
||||
|
||||
usages.add(
|
||||
Component.empty()
|
||||
.append(Component.text("Trust level: ").color(NamedTextColor.GREEN))
|
||||
.append(Component.text("TODO").color(NamedTextColor.YELLOW))
|
||||
);
|
||||
|
||||
for (String usage : command.usage()) {
|
||||
usages.add(
|
||||
Component.empty()
|
||||
.append(Component.text(prefix + commandName).color(NamedTextColor.GOLD))
|
||||
.append(Component.text(" "))
|
||||
.append(Component.text(usage).color(NamedTextColor.AQUA))
|
||||
);
|
||||
}
|
||||
|
||||
context.sendOutput(Component.join(JoinConfiguration.separator(Component.newline()), usages));
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
|
||||
return Component.text("Unknown command").color(NamedTextColor.RED);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestCommand implements Command {
|
||||
public String description() {
|
||||
return "Tests if the bot is working";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args) {
|
||||
context.sendOutput(
|
||||
Component.empty()
|
||||
.append(Component.text("Hello, World! Username: "))
|
||||
.append(context.displayName())
|
||||
.color(NamedTextColor.GREEN)
|
||||
);
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package me.chayapak1.chomensbot_mabe.commands;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ThrowCommand implements Command {
|
||||
public String description() {
|
||||
return "A command to throw an error, kinda useless";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("[message]");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args) throws Exception {
|
||||
final String message = String.join(" ", args);
|
||||
|
||||
throw new Exception(message.equals("") ? "among us" : message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.PlayerMessage;
|
||||
import me.chayapak1.chomensbot_mabe.command.PlayerCommandContext;
|
||||
import me.chayapak1.chomensbot_mabe.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener {
|
||||
@Getter private final String prefix = "j*";
|
||||
|
||||
public final Bot bot;
|
||||
|
||||
public ChatCommandHandlerPlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.chat().addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerMessageReceived (PlayerMessage message) {
|
||||
final Component displayNameComponent = message.parameters().get("sender");
|
||||
final Component messageComponent = message.parameters().get("contents");
|
||||
if (displayNameComponent == null || messageComponent == null) return;
|
||||
|
||||
final String displayName = ComponentUtilities.stringify(displayNameComponent);
|
||||
final String contents = ComponentUtilities.stringify(messageComponent);
|
||||
|
||||
if (!contents.startsWith(prefix)) return;
|
||||
final String commandString = contents.substring(prefix.length());
|
||||
|
||||
final PlayerCommandContext context = new PlayerCommandContext(bot, displayName);
|
||||
|
||||
final Component output = CommandHandlerPlugin.executeCommand(commandString, context);
|
||||
final String textOutput = ((TextComponent) output).content();
|
||||
|
||||
if (!textOutput.equals("success")) {
|
||||
context.sendOutput(output);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
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 me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.KaboomChatParser;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.MinecraftChatParser;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.ChatParser;
|
||||
import me.chayapak1.chomensbot_mabe.chatParsers.data.PlayerMessage;
|
||||
import me.chayapak1.chomensbot_mabe.util.ComponentUtilities;
|
||||
import me.chayapak1.chomensbot_mabe.util.UUIDUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatPlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
|
||||
private final List<ChatParser> chatParsers;
|
||||
|
||||
private final List<ChatListener> listeners = new ArrayList<>();
|
||||
|
||||
public ChatPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.addListener(this);
|
||||
|
||||
chatParsers = new ArrayList<>();
|
||||
chatParsers.add(new MinecraftChatParser());
|
||||
chatParsers.add(new KaboomChatParser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundSystemChatPacket) {
|
||||
packetReceived((ClientboundSystemChatPacket) packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundSystemChatPacket packet) {
|
||||
final Component component = packet.getContent();
|
||||
|
||||
try {
|
||||
final String key = ((TranslatableComponent) component).key();
|
||||
|
||||
if (
|
||||
key.equals("advMode.setCommand.success") ||
|
||||
key.equals("advMode.notAllowed")
|
||||
) return;
|
||||
} catch (ClassCastException ignored) {}
|
||||
|
||||
PlayerMessage playerMessage = null;
|
||||
|
||||
for (ChatParser parser : chatParsers) {
|
||||
playerMessage = parser.parse(component);
|
||||
if (playerMessage != null) break;
|
||||
}
|
||||
|
||||
final String message = ComponentUtilities.stringify(component);
|
||||
for (ChatListener listener : listeners) {
|
||||
listener.systemMessageReceived(message, component);
|
||||
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public void send (String message) {
|
||||
if (message.startsWith("/")) {
|
||||
bot.session().send(new ServerboundChatCommandPacket(
|
||||
message.substring(1),
|
||||
Instant.now().toEpochMilli(),
|
||||
0L,
|
||||
new ArrayList<>(),
|
||||
false,
|
||||
new ArrayList<>(),
|
||||
null
|
||||
));
|
||||
} else {
|
||||
bot.session().send(new ServerboundChatPacket(
|
||||
message,
|
||||
Instant.now().toEpochMilli(),
|
||||
0L,
|
||||
new byte[0],
|
||||
false,
|
||||
new ArrayList<>(),
|
||||
null
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public void tellraw (Component component, String targets) {
|
||||
bot.core().run("minecraft:tellraw " + targets + " " + GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
|
||||
public void tellraw (Component component, UUID uuid) { tellraw(component, UUIDUtilities.selector(uuid)); }
|
||||
|
||||
public void tellraw (Component component) { tellraw(component, "@a"); }
|
||||
|
||||
public void addListener (ChatListener listener) { listeners.add(listener); }
|
||||
|
||||
public static class ChatListener {
|
||||
public void playerMessageReceived (PlayerMessage message) {}
|
||||
public void systemMessageReceived (String message, Component component) {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.command.Command;
|
||||
import me.chayapak1.chomensbot_mabe.command.CommandContext;
|
||||
import me.chayapak1.chomensbot_mabe.commands.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandHandlerPlugin {
|
||||
@Getter private static final Map<String, Command> commands = new HashMap<>();
|
||||
|
||||
public CommandHandlerPlugin () {
|
||||
registerCommand("cb", new CommandBlockCommand());
|
||||
registerCommand("cowsay", new CowsayCommand());
|
||||
registerCommand("echo", new EchoCommand());
|
||||
registerCommand("help", new HelpCommand());
|
||||
registerCommand("test", new TestCommand());
|
||||
registerCommand("throw", new ThrowCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (String commandName, Command command) {
|
||||
commands.put(commandName, command);
|
||||
}
|
||||
|
||||
public static Component executeCommand (String input, CommandContext context) {
|
||||
final String[] splitInput = input.split(" ");
|
||||
|
||||
final String commandName = splitInput[0];
|
||||
final String[] args = Arrays.copyOfRange(splitInput, 1, splitInput.length);
|
||||
|
||||
final Command command = commands.get(commandName);
|
||||
|
||||
if (command != null) {
|
||||
try {
|
||||
return command.execute(context, args);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
final String stackTrace = ExceptionUtils.getStackTrace(exception);
|
||||
return Component
|
||||
.text("An error occurred while trying to execute the command, hover here for more details", NamedTextColor.RED)
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component
|
||||
.text(stackTrace)
|
||||
.color(NamedTextColor.RED)
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return Component.text("Unknown command: " + commandName).color(NamedTextColor.RED);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.command.ConsoleCommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.jline.reader.EndOfFileException;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.UserInterruptException;
|
||||
|
||||
public class ConsolePlugin {
|
||||
private final Bot bot;
|
||||
|
||||
@Getter public final LineReader reader;
|
||||
|
||||
@Getter private final String prefix = ".";
|
||||
|
||||
public ConsolePlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.reader = LineReaderBuilder.builder().build();
|
||||
String prompt = "> ";
|
||||
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
String line = null;
|
||||
try {
|
||||
line = reader.readLine(prompt);
|
||||
} catch (UserInterruptException e) {
|
||||
System.exit(1); // yup
|
||||
} catch (EndOfFileException e) {
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
handleLine(line);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void handleLine (String line) {
|
||||
if (line == null) return;
|
||||
|
||||
if (line.startsWith(prefix)) {
|
||||
final ConsoleCommandContext context = new ConsoleCommandContext(bot);
|
||||
|
||||
final Component output = CommandHandlerPlugin.executeCommand(line.substring(prefix.length()), context);
|
||||
final String textOutput = ((TextComponent) output).content();
|
||||
|
||||
if (!textOutput.equals("success")) {
|
||||
context.sendOutput(output);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bot.chat().tellraw(
|
||||
Component.translatable(
|
||||
"[%s] %s › %s",
|
||||
Component.text(bot.username() + " Console").color(NamedTextColor.GRAY),
|
||||
Component.text("chayapak").color(NamedTextColor.GREEN),
|
||||
Component.text(line).color(NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
|
||||
public class CorePlugin extends PositionPlugin.PositionListener {
|
||||
private final Bot bot;
|
||||
|
||||
public final Vector3i coreStart = Vector3i.from(0, 0, 0);
|
||||
public final Vector3i coreEnd = Vector3i.from(15, 2, 15);
|
||||
|
||||
public Vector3i origin;
|
||||
|
||||
public Vector3i relativeCorePosition = Vector3i.from(coreStart);
|
||||
|
||||
public CorePlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.position().addListener(this);
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
bot.session().send(new ServerboundSetCommandBlockPacket(
|
||||
absoluteCorePosition(),
|
||||
"",
|
||||
CommandBlockMode.REDSTONE,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
));
|
||||
bot.session().send(new ServerboundSetCommandBlockPacket(
|
||||
absoluteCorePosition(),
|
||||
command,
|
||||
CommandBlockMode.REDSTONE,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
));
|
||||
|
||||
incrementBlock();
|
||||
}
|
||||
|
||||
public Vector3i absoluteCorePosition () {
|
||||
return relativeCorePosition.add(origin);
|
||||
}
|
||||
|
||||
private void incrementBlock () {
|
||||
int x = relativeCorePosition.getX();
|
||||
int y = relativeCorePosition.getY();
|
||||
int z = relativeCorePosition.getZ();
|
||||
|
||||
x++;
|
||||
|
||||
if (x >= coreEnd.getX()) {
|
||||
x = coreStart.getX();
|
||||
z++;
|
||||
}
|
||||
|
||||
if (z >= coreEnd.getZ()) {
|
||||
z = coreStart.getZ();
|
||||
y++;
|
||||
}
|
||||
|
||||
if (y >= coreEnd.getY()) {
|
||||
x = coreStart.getX();
|
||||
y = coreStart.getY();
|
||||
z = coreStart.getZ();
|
||||
}
|
||||
|
||||
relativeCorePosition = Vector3i.from(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void positionChange (Vector3i position) {
|
||||
origin = Vector3i.from(
|
||||
bot.position().position().getX(),
|
||||
0,
|
||||
bot.position().position().getZ()
|
||||
);
|
||||
refill();
|
||||
}
|
||||
|
||||
public void refill () {
|
||||
final String command = String.format(
|
||||
"/minecraft:fill %s %s %s %s %s %s minecraft:command_block",
|
||||
|
||||
coreStart.getX() + origin.getX(),
|
||||
coreStart.getY(),
|
||||
coreStart.getZ() + origin.getZ(),
|
||||
|
||||
coreEnd.getX() + origin.getX(),
|
||||
coreEnd.getY(),
|
||||
coreEnd.getZ() + origin.getZ()
|
||||
);
|
||||
bot.chat().send(command);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LoggerPlugin extends ChatPlugin.ChatListener {
|
||||
private final Bot bot;
|
||||
|
||||
public LoggerPlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.chat().addListener(this);
|
||||
}
|
||||
|
||||
public void log (String message) {
|
||||
bot.console().reader().printAbove(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(String message, Component component) {
|
||||
log(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PositionPlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
|
||||
private final List<PositionListener> listeners = new ArrayList<>();
|
||||
|
||||
@Getter private Vector3i position = Vector3i.from(0, 0, 0);
|
||||
|
||||
public PositionPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerPositionPacket) {
|
||||
packetReceived((ClientboundPlayerPositionPacket) packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundPlayerPositionPacket packet) {
|
||||
position = Vector3i.from(packet.getX(), packet.getY(), packet.getZ());
|
||||
for (PositionListener listener : listeners) { listener.positionChange(position); }
|
||||
bot.session().send(new ServerboundAcceptTeleportationPacket(packet.getTeleportId()));
|
||||
}
|
||||
|
||||
public void addListener (PositionListener listener) { listeners.add(listener); }
|
||||
|
||||
public static class PositionListener {
|
||||
public void positionChange (Vector3i position) {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEventValue;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundGameEventPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfCarePlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> futureTask;
|
||||
|
||||
private int entityId;
|
||||
private GameMode gamemode;
|
||||
private int permissionLevel;
|
||||
private boolean cspy = false;
|
||||
private boolean vanish = false;
|
||||
private boolean socialspy = false;
|
||||
private boolean muted = false;
|
||||
private boolean prefix = false;
|
||||
|
||||
public SelfCarePlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.addListener(this);
|
||||
|
||||
bot.chat().addListener(new ChatPlugin.ChatListener() {
|
||||
@Override
|
||||
public void systemMessageReceived(String message, Component component) {
|
||||
if (message.equals("Successfully enabled CommandSpy")) cspy = true;
|
||||
else if (message.equals("Successfully disabled CommandSpy")) cspy = false;
|
||||
|
||||
else if (message.equals("Vanish for " + bot.username() + ": enabled")) vanish = true;
|
||||
else if (message.equals("Vanish for " + bot.username() + ": disabled")) vanish = false;
|
||||
|
||||
else if (message.equals("SocialSpy for " + bot.username() + ": enabled")) socialspy = true;
|
||||
else if (message.equals("SocialSpy for " + bot.username() + ": disabled")) socialspy = false;
|
||||
|
||||
else if (message.startsWith("You have been muted")) muted = true;
|
||||
else if (message.equals("You have been unmuted.")) muted = false;
|
||||
|
||||
else if (message.equals("You now have the tag: [ChomeNS Bot]") || // for 1.19.2 (or 1.19?) and older clones
|
||||
message.equals("You now have the tag: &8[&eChomeNS Bot&8]")
|
||||
) {
|
||||
prefix = true;
|
||||
return;
|
||||
}
|
||||
if (message.startsWith("You no longer have a tag")) prefix = false;
|
||||
if (message.startsWith("You now have the tag: ")) prefix = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void check () {
|
||||
if (gamemode != GameMode.CREATIVE) bot.chat().send("/minecraft:gamemode creative @s[type=player]");
|
||||
else if (permissionLevel < 2) bot.chat().send("/minecraft:op @s[type=player]");
|
||||
else if (!cspy) bot.chat().send("/commandspy:commandspy on");
|
||||
else if (!vanish) bot.chat().send("/essentials:vanish enable");
|
||||
else if (!socialspy) bot.chat().send("/essentials:socialspy enable");
|
||||
else if (muted) bot.chat().send("/essentials:mute " + bot.username());
|
||||
else if (!prefix) bot.chat().send("/extras:prefix &8[&eChomeNS Bot&8]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginPacket) packetReceived((ClientboundLoginPacket) packet);
|
||||
else if (packet instanceof ClientboundGameEventPacket) packetReceived((ClientboundGameEventPacket) packet);
|
||||
else if (packet instanceof ClientboundEntityEventPacket) packetReceived((ClientboundEntityEventPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundLoginPacket packet) {
|
||||
this.entityId = packet.getEntityId();
|
||||
this.gamemode = packet.getGameMode();
|
||||
|
||||
final Runnable task = () -> {
|
||||
final Session session = bot.session();
|
||||
final PacketProtocol protocol = session.getPacketProtocol();
|
||||
if (
|
||||
!session.isConnected() ||
|
||||
(
|
||||
protocol instanceof MinecraftProtocol &&
|
||||
((MinecraftProtocol) protocol).getState() != ProtocolState.GAME
|
||||
)
|
||||
) return;
|
||||
|
||||
check();
|
||||
};
|
||||
|
||||
futureTask = bot.executor().scheduleAtFixedRate(task, 50, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundGameEventPacket packet) {
|
||||
final GameEvent notification = packet.getNotification();
|
||||
final GameEventValue value = packet.getValue();
|
||||
|
||||
if (notification == GameEvent.CHANGE_GAMEMODE) gamemode = (GameMode) value;
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundEntityEventPacket packet) {
|
||||
final EntityEvent event = packet.getEvent();
|
||||
final int id = packet.getEntityId();
|
||||
|
||||
if (id != entityId) return;
|
||||
|
||||
if (event == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_0) permissionLevel = 0;
|
||||
else if (event == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_1) permissionLevel = 1;
|
||||
else if (event == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_2) permissionLevel = 2;
|
||||
else if (event == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_3) permissionLevel = 3;
|
||||
else if (event == EntityEvent.PLAYER_OP_PERMISSION_LEVEL_4) permissionLevel = 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
futureTask.cancel(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package me.chayapak1.chomensbot_mabe.util;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.SelectorComponent;
|
||||
import net.kyori.adventure.text.KeybindComponent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// totallynotskidded™ from chipmunkbot
|
||||
public class ComponentUtilities {
|
||||
private static final Map<String, String> language = loadJsonStringMap("language.json");
|
||||
private static final Map<String, String> keybinds = loadJsonStringMap("keybinds.json");
|
||||
|
||||
public static final Pattern ARG_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?([s%])");
|
||||
|
||||
private ComponentUtilities () {
|
||||
}
|
||||
|
||||
private static Map<String, String> loadJsonStringMap (String name) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(name);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
|
||||
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
|
||||
map.put(entry.getKey(), json.get(entry.getKey()).getAsString());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String getOrReturnKey (String key) {
|
||||
return ComponentUtilities.language.getOrDefault(key, key);
|
||||
}
|
||||
|
||||
public static String stringify (Component message) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(stringifyPartially(message));
|
||||
|
||||
for (Component child : message.children()) builder.append(stringify(child));
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (Component message) {
|
||||
if (message instanceof TextComponent) return stringifyPartially((TextComponent) message);
|
||||
if (message instanceof TranslatableComponent) return stringifyPartially((TranslatableComponent) message);
|
||||
if (message instanceof SelectorComponent) return stringifyPartially((SelectorComponent) message);
|
||||
if (message instanceof KeybindComponent) return stringifyPartially((KeybindComponent) message);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String stringifyPartially (TextComponent message) {
|
||||
return message.content();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (TranslatableComponent message) {
|
||||
String format = getOrReturnKey(message.key());
|
||||
|
||||
// totallynotskidded™️ from HBot (and changed a bit)
|
||||
Matcher matcher = ARG_PATTERN.matcher(format);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int i = 0;
|
||||
while (matcher.find()) {
|
||||
if (matcher.group().equals("%%")) {
|
||||
matcher.appendReplacement(sb, "%");
|
||||
} else {
|
||||
String idxStr = matcher.group(1);
|
||||
int idx = idxStr == null ? i++ : (Integer.parseInt(idxStr) - 1);
|
||||
if (idx >= 0 && idx < message.args().size()) {
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement( stringify(message.args().get(idx)) ));
|
||||
} else {
|
||||
matcher.appendReplacement(sb, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String stringifyPartially (SelectorComponent message) {
|
||||
return message.pattern(); // * Client-side selector components are equivalent to text ones, and do NOT list entities.
|
||||
}
|
||||
|
||||
public static String stringifyPartially (KeybindComponent message) {
|
||||
String keybind = message.keybind();
|
||||
Component component = keybinds.containsKey(keybind) ? Component.translatable(keybind) : Component.text(keybind); // TODO: Fix some keys like `key.keyboard.a`
|
||||
return stringifyPartially(component);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package me.chayapak1.chomensbot_mabe.util;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import java.util.UUID;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class UUIDUtilities {
|
||||
private UUIDUtilities () {}
|
||||
|
||||
public static int[] intArray (UUID uuid) {
|
||||
final ByteBuffer buffer = ByteBuffer.wrap(new byte[16]);
|
||||
buffer.putLong(0, uuid.getMostSignificantBits());
|
||||
buffer.putLong(8, uuid.getLeastSignificantBits());
|
||||
|
||||
final int[] intArray = new int[4];
|
||||
for (int i = 0; i < intArray.length; i++) intArray[i] = buffer.getInt();
|
||||
|
||||
return intArray;
|
||||
}
|
||||
|
||||
public static UUID byString (String string, int version) {
|
||||
UUID uuid = UUID.nameUUIDFromBytes(string.getBytes());
|
||||
uuid = new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() & ~(0xfL << 12));
|
||||
uuid = new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() | ((long) version << 12));
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static IntArrayTag tag (UUID uuid) {
|
||||
return new IntArrayTag("", intArray(uuid));
|
||||
}
|
||||
|
||||
public static String snbt (UUID uuid) {
|
||||
int[] array = intArray(uuid);
|
||||
return "[I;" + array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "]"; // TODO: improve lol
|
||||
}
|
||||
|
||||
public static String selector (UUID uuid) { return "@a[limit=1,nbt={UUID:" + snbt(uuid) + "}]"; }
|
||||
public static String exclusiveSelector (UUID uuid) { return "@a[nbt=!{UUID:" + snbt(uuid) + "}]"; }
|
||||
}
|
36
src/main/resources/keybinds.json
Normal file
36
src/main/resources/keybinds.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"key.attack": "key.mouse.left",
|
||||
"key.use": "key.mouse.right",
|
||||
"key.forward": "key.keyboard.w",
|
||||
"key.left": "key.keyboard.a",
|
||||
"key.back": "key.keyboard.s",
|
||||
"key.right": "key.keyboard.d",
|
||||
"key.jump": "key.keyboard.space",
|
||||
"key.sneak": "key.keyboard.left.shift",
|
||||
"key.sprint": "key.keyboard.left.control",
|
||||
"key.drop": "key.keyboard.q",
|
||||
"key.inventory": "key.keyboard.e",
|
||||
"key.chat": "key.keyboard.t",
|
||||
"key.playerlist": "key.keyboard.tab",
|
||||
"key.pickItem": "key.mouse.middle",
|
||||
"key.command": "key.keyboard.slash",
|
||||
"key.socialInteractions": "key.keyboard.p",
|
||||
"key.screenshot": "key.keyboard.f2",
|
||||
"key.togglePerspective": "key.keyboard.f5",
|
||||
"key.smoothCamera": "key.keyboard.unknown",
|
||||
"key.fullscreen": "key.keyboard.f11",
|
||||
"key.spectatorOutlines": "key.keyboard.unknown",
|
||||
"key.swapOffhand": "key.keyboard.f",
|
||||
"key.saveToolbarActivator": "key.keyboard.c",
|
||||
"key.loadToolbarActivator": "key.keyboard.x",
|
||||
"key.advancements": "key.keyboard.l",
|
||||
"key.hotbar.1": "key.keyboard.1",
|
||||
"key.hotbar.2": "key.keyboard.2",
|
||||
"key.hotbar.3": "key.keyboard.3",
|
||||
"key.hotbar.4": "key.keyboard.4",
|
||||
"key.hotbar.5": "key.keyboard.5",
|
||||
"key.hotbar.6": "key.keyboard.6",
|
||||
"key.hotbar.7": "key.keyboard.7",
|
||||
"key.hotbar.8": "key.keyboard.8",
|
||||
"key.hotbar.9": "key.keyboard.9"
|
||||
}
|
5435
src/main/resources/language.json
Normal file
5435
src/main/resources/language.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue