#5: add DiscordSRV support
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user