using shading on the Jar

switched to Discord4j instead of JDA
getEventDispatcher() not working
NEW be04 version
This commit is contained in:
nzBryce101
2024-04-23 00:32:35 +12:00
parent dd21b58774
commit 7d30515539
13 changed files with 159 additions and 94 deletions

Binary file not shown.

View File

@@ -0,0 +1,93 @@
<?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>com.example</groupId>
<artifactId>MCdiscord_bot</artifactId>
<version>1.1be04</version>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>net.dv8tion:JDA</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>net.dv8tion</pattern>
<shadedPattern>com.example.MCdiscordbot.shaded.net.dv8tion</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<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>
<repository>
<id>discordJDA</id>
<name>JDA for Discord</name>
<url>https://github.com/DV8FromTheWorld/JDA</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.20.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.katsstuff</groupId>
<artifactId>ackcord-data_sjs1_2.13</artifactId>
<version>2.0.0.0-M1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
</properties>
</project>

98
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.example</groupId> <groupId>com.example</groupId>
<artifactId>MCdiscord_bot</artifactId> <artifactId>MCdiscord_bot</artifactId>
<version>1.1be02</version> <version>1.1be04</version>
<packaging>jar</packaging> <!-- Specify the correct packaging type here --> <packaging>jar</packaging> <!-- Specify the correct packaging type here -->
<properties> <properties>
@@ -33,12 +33,6 @@
<url>https://jcenter.bintray.com</url> <url>https://jcenter.bintray.com</url>
</repository> </repository>
<repository>
<id>discordJDA</id>
<name>JDA for Discord</name>
<url>https://github.com/DV8FromTheWorld/JDA</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@@ -55,29 +49,14 @@
<version>1.20.4</version> <version>1.20.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--(Java Discord API) with JFlac and Tritonus-dsp --> <!--(Java Discord API) -->
<dependency> <dependency>
<!-- https://mvnrepository.com/artifact/net.dv8tion/JDA --> <groupId>com.discord4j</groupId>
<groupId>net.dv8tion</groupId> <artifactId>discord4j-core</artifactId>
<artifactId>JDA</artifactId> <version>3.3.0-RC1</version>
<version>5.0.0-alpha.4</version><!-- Update version to the latest stable version -->
<exclusions>
<exclusion>
<groupId>jflac</groupId>
<artifactId>jflac</artifactId>
</exclusion>
<exclusion>
<groupId>tritonus</groupId>
<artifactId>tritonus-dsp</artifactId>
</exclusion>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency> </dependency>
<!-- Logging--> <!-- Logging-->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
@@ -104,46 +83,33 @@
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version> <!-- Adjust version as needed --> <version>3.5.2</version> <!-- Use the latest version -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration> <configuration>
<resources> <artifactSet>
<resource> <includes>
<directory>src/main/resources</directory> <include>club.minced.discord4j</include>
<includes> </includes>
<include>**/*.yml</include> </artifactSet>
</includes> <relocations>
</resource> <relocation>
</resources> <pattern>club.minced</pattern>
<descriptorRefs> <shadedPattern>com.example.MCdiscordbot.shaded.club.minced</shadedPattern>
<descriptorRef>jar-with-dependencies</descriptorRef> </relocation>
</descriptorRefs> </relocations>
<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> </configuration>
<executions> </execution>
<execution> </executions>
<id>make-assembly</id> </plugin>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -1,29 +1,39 @@
import discord4j.core.DiscordClient;
import net.dv8tion.jda.api.JDABuilder; import discord4j.core.DiscordClientBuilder;
import net.dv8tion.jda.api.entities.TextChannel; import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.event.domain.message.MessageCreateEvent;
import javax.security.auth.login.LoginException; import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import listeners.MinecraftEventListener;
public class disMCbot { public class disMCbot {
private static TextChannel updateChannel;
private static final Logger logger = LogManager.getLogger(disMCbot.class); private static final Logger logger = LogManager.getLogger(disMCbot.class);
public static void main(String[] args) throws LoginException { public static void main(String[] args) {
logger.info("Starting Discord Bot..."); logger.info("Starting Discord Bot...");
String token = "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80"; String token = "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80";
JDABuilder builder = JDABuilder.createDefault(token);
builder.addEventListeners(new MinecraftEventListener(updateChannel));
builder.build();
}
public void setUpdateChannel(TextChannel channel) { DiscordClient client = DiscordClientBuilder.create(token).build();
disMCbot.updateChannel = channel; client.login().block();
}
client.getEventDispatcher().on(ReadyEvent.class)
.subscribe(ready -> {
System.out.println("Logged in as: " + ready.getSelf().getUsername());
client.updatePresence(Presence.online(Activity.playing("Minecraft")));
});
client.getEventDispatcher().on(MessageCreateEvent.class)
.subscribe(event -> {
String messageContent = event.getMessage().getContent();
if (messageContent.equalsIgnoreCase("!ping")) {
event.getMessage().getChannel().block().createMessage("Pong!").block();
}
// Add more commands as needed
});
client.onDisconnect().block();
}
// Other methods and event listeners can be added as needed // Other methods and event listeners can be added as needed
} }

View File

@@ -4,12 +4,13 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import net.dv8tion.jda.api.entities.TextChannel; import discord4j.core.object.entity.channel.TextChannel;
public class MinecraftEventListener implements Listener { public class MinecraftEventListener implements Listener {
private final TextChannel updateChannel; // Discord channel to send updates private final discord4j.core.object.entity.channel.TextChannel updateChannel; // Discord channel to send updates
public MinecraftEventListener(TextChannel updateChannel) { public MinecraftEventListener(TextChannel updateChannel) {
this.updateChannel = updateChannel; this.updateChannel = updateChannel;
@@ -18,12 +19,12 @@ public class MinecraftEventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
String playerName = event.getPlayer().getName(); String playerName = event.getPlayer().getName();
updateChannel.sendMessage("Player " + playerName + " has joined the server.").queue(); updateChannel.createMessage("Player " + playerName + " has joined the server.");
} }
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
String playerName = event.getPlayer().getName(); String playerName = event.getPlayer().getName();
updateChannel.sendMessage("Player " + playerName + " has left the server.").queue(); updateChannel.createMessage("Player " + playerName + " has left the server.");
} }
} }

View File

@@ -1,5 +1,5 @@
name: MCdiscord_bot-1 name: MCdiscord_bot-1
version: 1.1be02 version: 1.1be04
main: MCdiscord_bot-1.src.main.java.disMCbot main: MCdiscord_bot-1.src.main.java.disMCbot
description: A Discord bot plugin for Minecraft. description: A Discord bot plugin for Minecraft.
author: Bryce author: Bryce

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,5 @@
name: MCdiscord_bot-1 name: MCdiscord_bot-1
version: 1.1be02 version: 1.1be04
main: MCdiscord_bot-1.src.main.java.disMCbot main: MCdiscord_bot-1.src.main.java.disMCbot
description: A Discord bot plugin for Minecraft. description: A Discord bot plugin for Minecraft.
author: Bryce author: Bryce

View File

@@ -1,3 +0,0 @@
artifactId=MCdiscord_bot
groupId=com.example
version=1.1be02

View File

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