#5: add DiscordSRV support
This commit is contained in:
parent
b5e3086577
commit
90e0084fca
15
pom.xml
15
pom.xml
|
@ -27,6 +27,15 @@
|
|||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dv8tion</id>
|
||||
<name>m2-dv8tion</name>
|
||||
<url>https://m2.dv8tion.net/releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Scarsz-Nexus</id>
|
||||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
@ -56,6 +65,12 @@
|
|||
<version>2.11.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.25.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -3,6 +3,8 @@ package me.oskar3123.staffchat.spigot.listener;
|
|||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import github.scarsz.discordsrv.util.DiscordUtil;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
@ -68,6 +70,9 @@ public class ChatListener implements Listener, PluginMessageListener {
|
|||
format = format.replaceAll("\\{MESSAGE}", StringUtils.sanitize(message));
|
||||
final String finalMessage = format;
|
||||
|
||||
if (plugin.getConfig().getBoolean("discordsrv.enable")) {
|
||||
sendDiscordMessage(event.getPlayer(), message);
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("settings.sendmessagestoallservers")) {
|
||||
sendForwardPluginMessage(event.getPlayer(), finalMessage);
|
||||
}
|
||||
|
@ -130,6 +135,21 @@ public class ChatListener implements Listener, PluginMessageListener {
|
|||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
|
||||
private void sendDiscordMessage(Player player, String message) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
|
||||
String format =
|
||||
plugin
|
||||
.replacePlaceholders(player, plugin.getConfig().getString("discordsrv.format", ""))
|
||||
.replaceAll("\\{NAME}", StringUtils.sanitize(player.getName()))
|
||||
.replaceAll("\\{MESSAGE}", StringUtils.sanitize(message));
|
||||
DiscordUtil.sendMessage(
|
||||
DiscordSRV.getPlugin()
|
||||
.getOptionalTextChannel(
|
||||
plugin.getConfig().getString("discordsrv.channel", "staffchat")),
|
||||
format);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean togglePlayer(@NotNull UUID player) {
|
||||
if (toggledPlayers.contains(player)) {
|
||||
toggledPlayers.remove(player);
|
||||
|
|
|
@ -11,3 +11,7 @@ messages:
|
|||
toggled: 'You toggled auto staffchat %s'
|
||||
onstring: 'on'
|
||||
offstring: 'off'
|
||||
discordsrv:
|
||||
enable: false
|
||||
channel: 'staffchat'
|
||||
format: '{NAME} » {MESSAGE}'
|
||||
|
|
|
@ -3,7 +3,7 @@ authors: [ oskar3123 ]
|
|||
main: me.oskar3123.staffchat.spigot.Main
|
||||
api-version: 1.13
|
||||
version: SNAPSHOT
|
||||
softdepend: [ PlaceholderAPI ]
|
||||
softdepend: [ PlaceholderAPI, DiscordSRV ]
|
||||
commands:
|
||||
staffchat:
|
||||
usage: /<command>
|
||||
|
|
Loading…
Reference in New Issue