minor tweaks

Working on JDA dependency incompatibility
This commit is contained in:
nzBryce101
2024-04-17 13:51:29 +12:00
parent 79517ca036
commit 44970fbab7
14 changed files with 173 additions and 81 deletions

Binary file not shown.

94
pom.xml
View File

@@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>minecraft-chatbot</artifactId>
<version>1.0</version>
<artifactId>MCdiscord_bot</artifactId>
<version>1.1be01</version>
<packaging>jar</packaging> <!-- Specify the correct packaging type here -->
<properties>
@@ -21,9 +21,28 @@
<name>spigot-1.20.4</name>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
<repository>
<id>buk-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version> <!-- Update to the appropriate version -->
<scope>provided</scope>
</dependency>
<!-- Spigot API dependency -->
<dependency>
<groupId>org.spigotmc</groupId>
@@ -46,7 +65,12 @@
<groupId>tritonus</groupId>
<artifactId>tritonus-dsp</artifactId>
</exclusion>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<!-- Logging-->
@@ -78,31 +102,49 @@
</dependencies>
<build>
<plugins>
<!-- Maven Compiler Plugin configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version> <!-- Use the appropriate version -->
<executions>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version> <!-- Adjust version as needed -->
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>disMCbot</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${project.artifactId}-${project.version}</finalName>
<includes>
<include>plugin.yml</include>
</includes>
</configuration>
<executions>
<execution>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0</version>
</requireMavenVersion>
</rules>
<source>21</source> <!-- Update to the Java version you're using -->
<target>21</target> <!-- Update to the Java version you're using -->
<compilerArgs>
<arg>--enable-preview</arg> <!-- Enable preview features -->
</compilerArgs>
</configuration>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Add other plugins as needed -->
</plugins>
</build>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,68 +1,29 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.annotation.Nonnull;
import javax.security.auth.login.LoginException;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import listeners.MinecraftEventListener;
public class disMCbot extends ListenerAdapter {
private TextChannel updateChannel; // Define the channel where updates will be posted
public class disMCbot {
private static TextChannel updateChannel;
private static final Logger logger = LogManager.getLogger(disMCbot.class);
public static void main(String[] args) throws LoginException {
logger.info("Starting Discord Comms...");
JDABuilder builder = JDABuilder
.createDefault("MTIyNjY1NTgxODU0NDMxNjQxNw.GALTlL.vPRJyKTEJNqN1Snfj5G-_2306lBKFdOYB1eDXE");
builder.addEventListeners(new disMCbot());
logger.info("Starting Discord Bot...");
String token = "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80";
JDABuilder builder = JDABuilder.createDefault(token);
builder.addEventListeners(new MinecraftEventListener(updateChannel));
builder.build();
}
@Override
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
if (event.getAuthor().isBot()) return; // Ignore messages from bots
String message = event.getMessage().getContentRaw();
// Check for conditions or events triggering updates
if (message.contains("Player1 died")) {
// Log It
logger.info("Player1 died - detected");
// Post update to the specified channel
if (updateChannel != null) {
updateChannel.sendMessage("Player1 has died in Minecraft!").queue();
// Log It
logger.info("Message Posted in Discord.");
}
} else if (message.contains("Player1 Exp")) {
// Log It
logger.info("Player1 Exp Gained");
// Post another type of update
if (updateChannel != null) {
updateChannel.sendMessage("Player1 gained experience in Minecraft!").queue();
// Log It
logger.info("Message sent to Discord.");
}
} else if (message.contains("drowned")) {
// Log It
logger.info("Player1 has drowned");
// Post another type of update
if (updateChannel != null) {
updateChannel.sendMessage("Player1 has drowned - they got thirsty!").queue();
// Log It
logger.info("Message sent to Discord.");
}
}
public void setUpdateChannel(TextChannel channel) {
disMCbot.updateChannel = channel;
}
public void setUpdateChannel(TextChannel channel) {
this.updateChannel = channel;
}
}
// Other methods and event listeners can be added as needed
}

View File

@@ -0,0 +1,29 @@
package listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import net.dv8tion.jda.api.entities.TextChannel;
public class MinecraftEventListener implements Listener {
private final TextChannel updateChannel; // Discord channel to send updates
public MinecraftEventListener(TextChannel updateChannel) {
this.updateChannel = updateChannel;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
String playerName = event.getPlayer().getName();
updateChannel.sendMessage("Player " + playerName + " has joined the server.").queue();
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
String playerName = event.getPlayer().getName();
updateChannel.sendMessage("Player " + playerName + " has left the server.").queue();
}
}

View File

@@ -0,0 +1,29 @@
name: MCdiscord_bot-1
version: 1.1be01
main: MCdiscord_bot-1.src.main.java.disMCbot
description: A Discord bot plugin for Minecraft.
author: Bryce
api-version: 1.20.4
depend: [JDA]
# Listener Configuration
listeners:
- MCdiscordbot-1.src.main.java.listeners.MinecraftEventListener
# Discord Bot Configuration
discord:
token: "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80"
server:
id: "710784165460836402"
name: "Bryce & Evee's Community Server"
channel: "1226860741592743977"
logChannel: "1226860741592743977"
# Minecraft Event Settings
minecraft:
events:
- type: playerJoin
discordChannel: "mc_bot-spam"
- type: playerQuit
discordChannel: "mc_bot-spam"
# Add more event types and their corresponding Discord channels as needed

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

29
target/classes/plugin.yml Normal file
View File

@@ -0,0 +1,29 @@
name: MCdiscord_bot-1
version: 1.1be01
main: MCdiscord_bot-1.src.main.java.disMCbot
description: A Discord bot plugin for Minecraft.
author: Bryce
api-version: 1.20.4
depend: [JDA]
# Listener Configuration
listeners:
- MCdiscordbot-1.src.main.java.listeners.MinecraftEventListener
# Discord Bot Configuration
discord:
token: "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80"
server:
id: "710784165460836402"
name: "Bryce & Evee's Community Server"
channel: "1226860741592743977"
logChannel: "1226860741592743977"
# Minecraft Event Settings
minecraft:
events:
- type: playerJoin
discordChannel: "mc_bot-spam"
- type: playerQuit
discordChannel: "mc_bot-spam"
# Add more event types and their corresponding Discord channels as needed

View File

@@ -1,3 +1,3 @@
artifactId=minecraft-chatbot
artifactId=MCdiscord_bot
groupId=com.example
version=1.0
version=1.1be01

View File

@@ -1 +1,2 @@
disMCbot.class
listeners\MinecraftEventListener.class

View File

@@ -1 +1,2 @@
C:\Users\hbmann\Documents\Projects\_MCdiscord-bot\MCdiscord_bot-1\src\main\java\disMCbot.java
C:\Users\hbmann\Documents\Projects\_MCdiscord-bot\MCdiscord_bot-1\src\main\java\listeners\MinecraftEventListener.java

Binary file not shown.