-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 09d3383
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Eclipse specific files | ||
.settings/ | ||
.classpath | ||
.project | ||
|
||
# Generated files | ||
target/ | ||
dependency-reduced-pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.wetterquarz</groupId> | ||
<artifactId>minecraftdiscordsync</artifactId> | ||
<version>0.1.5</version> | ||
|
||
<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>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>sonatype</id> | ||
<url>https://oss.sonatype.org/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.20.4-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Mojang dependencies --> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-buffer</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-codec</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-common</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-handler</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-resolver</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-transport</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-transport-classes-epoll</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-transport-native-epoll</artifactId> | ||
<version>4.1.97.Final</version> | ||
<classifier>linux-x86_64</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-transport-native-epoll</artifactId> | ||
<version>4.1.97.Final</version> | ||
<classifier>linux-aarch_64</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-transport-native-unix-common</artifactId> | ||
<version>4.1.97.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- End of Mojang dependencies--> | ||
<dependency> | ||
<groupId>com.discord4j</groupId> | ||
<artifactId>discord4j-core</artifactId> | ||
<version>3.2.6</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.5.2</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/wetterquarz/minecraftdiscordsync/DiscordSyncPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.wetterquarz.minecraftdiscordsync; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import discord4j.common.util.Snowflake; | ||
import discord4j.core.DiscordClient; | ||
import discord4j.core.GatewayDiscordClient; | ||
import discord4j.core.object.entity.channel.GuildMessageChannel; | ||
import net.md_5.bungee.api.ChatColor; | ||
import reactor.core.Disposable; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class DiscordSyncPlugin extends JavaPlugin { | ||
|
||
private Disposable discordAccess = null; | ||
|
||
@Override | ||
public void onEnable() { | ||
saveDefaultConfig(); | ||
Flux<String> events = Flux.create(new MinecraftEventListener(this)) | ||
.map(ChatColor::stripColor); | ||
final String token = getConfig().getString("bot_token"); | ||
DiscordClient client = DiscordClient.create(token); | ||
discordAccess = client.login() | ||
.flatMap(gateway -> this.printMessages(gateway, events)) | ||
.subscribe(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
discordAccess.dispose(); | ||
discordAccess = null; | ||
} | ||
|
||
private Mono<Void> printMessages(GatewayDiscordClient gateway, Flux<String> messages) { | ||
final String channelId = getConfig().getString("channel_id"); | ||
GuildMessageChannel channel = (GuildMessageChannel) gateway.getChannelById(Snowflake.of(channelId)).block(); | ||
getLogger().info("Showing join and leave activity in channel " + channel.getName()); | ||
return Flux.create(new MinecraftEventListener(this)) | ||
.map(ChatColor::stripColor) | ||
.flatMap(channel::createMessage) | ||
.onErrorContinue((t, msg) -> getLogger().severe(t.toString())) | ||
.then(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/wetterquarz/minecraftdiscordsync/MinecraftEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.wetterquarz.minecraftdiscordsync; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.bukkit.event.*; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import reactor.core.publisher.FluxSink; | ||
|
||
public class MinecraftEventListener implements Listener, Consumer<FluxSink<String>> { | ||
|
||
private FluxSink<String> eventSink; | ||
private final JavaPlugin plugin; | ||
|
||
public MinecraftEventListener(JavaPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
eventSink.next(event.getJoinMessage()); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerLeave(PlayerQuitEvent event) { | ||
eventSink.next(event.getQuitMessage()); | ||
} | ||
|
||
@Override | ||
public void accept(FluxSink<String> sink) { | ||
eventSink = sink; | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
eventSink.onDispose(() -> HandlerList.unregisterAll(this)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bot_token: PUT_YOUR_DISCORD_BOT_TOKEN_HERE | ||
channel_id: PUT_THE_CHANNEL_ID_WHERE_MESSAGES_SHOULD_BE_SENT_HERE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: 'DiscordSyncPlugin' | ||
main: 'com.wetterquarz.minecraftdiscordsync.DiscordSyncPlugin' | ||
version: '0.1.5' | ||
api: '1.20.4' | ||
api-version: '1.20' |