diff --git a/pom.xml b/pom.xml
index e524bc9..3aa63b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,13 +31,20 @@
org.spigotmc
spigot-api
- 1.14.3-R0.1-SNAPSHOT
+ 1.15.2-R0.1-SNAPSHOT
provided
us.dynmap
dynmap-api
1.9.4
+ provided
+
+
+ com.discordsrv
+ discordsrv
+ 1.19.0
+ provided
xyz.etztech
@@ -62,6 +69,10 @@
dynmap-repo
http://repo.mikeprimm.com
+
+ discordsrv-repo
+ https://nexus.scarsz.me/content/groups/public/
+
etztech-repo
http://repo.etztech.xyz
@@ -72,7 +83,7 @@
jcenter
- http://jcenter.bintray.com
+ https://jcenter.bintray.com
jitpack.io
diff --git a/src/main/java/xyz/etztech/deluxegroups/DeluxeGroup.java b/src/main/java/xyz/etztech/deluxegroups/DeluxeGroup.java
index a2bc070..8e097b7 100644
--- a/src/main/java/xyz/etztech/deluxegroups/DeluxeGroup.java
+++ b/src/main/java/xyz/etztech/deluxegroups/DeluxeGroup.java
@@ -130,12 +130,11 @@ public class DeluxeGroup {
}
public void sendMessage(String message) {
- //DeluxeUtil.log(this.log, message);
Player on;
for (OfflinePlayer player : this.groupList) {
if (player.isOnline()) {
on = Bukkit.getPlayer(player.getName());
- on.sendMessage(ChatColor.AQUA + message);
+ on.sendMessage(message);
}
}
}
diff --git a/src/main/java/xyz/etztech/deluxegroups/DeluxeGroups.java b/src/main/java/xyz/etztech/deluxegroups/DeluxeGroups.java
index 9ce1d5f..81d209b 100644
--- a/src/main/java/xyz/etztech/deluxegroups/DeluxeGroups.java
+++ b/src/main/java/xyz/etztech/deluxegroups/DeluxeGroups.java
@@ -1,23 +1,21 @@
package xyz.etztech.deluxegroups;
+import github.scarsz.discordsrv.DiscordSRV;
+import github.scarsz.discordsrv.util.DiscordUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.deluxegroups.command.CommandGroup;
import xyz.etztech.deluxegroups.command.CommandMain;
import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener;
+import xyz.etztech.deluxegroups.listeners.DiscordSRVListener;
import xyz.etztech.deluxegroups.listeners.SessionListener;
import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.*;
import java.util.logging.Logger;
@@ -32,13 +30,13 @@ public class DeluxeGroups extends JavaPlugin {
// Objects that can be reloaded
private AsyncPlayerChatListener chatListener;
- // Dynmap API
+ // Dynmap APIDynmapAPI
private static DynmapAPI dynmap = null;
// MinecraftManager API
private static IMinecraftManager minecraftManager = null;
-
+ private static boolean discord = false;
public void onEnable() {
@@ -69,6 +67,12 @@ public class DeluxeGroups extends JavaPlugin {
minecraftManager.logOverride(true);
}
+ // DiscordSRV integration
+ if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
+ discord = true;
+ DiscordSRV.api.subscribe(new DiscordSRVListener(this));
+ }
+
// Add Commands
CommandMain cmdMain = new CommandMain(this);
this.getCommand("deluxegroups").setExecutor(cmdMain);
@@ -154,5 +158,8 @@ public class DeluxeGroups extends JavaPlugin {
return minecraftManager;
}
+ public static boolean getDiscord() {
+ return discord;
+ }
}
diff --git a/src/main/java/xyz/etztech/deluxegroups/DeluxeUtil.java b/src/main/java/xyz/etztech/deluxegroups/DeluxeUtil.java
index 2c9e6b4..14eba42 100644
--- a/src/main/java/xyz/etztech/deluxegroups/DeluxeUtil.java
+++ b/src/main/java/xyz/etztech/deluxegroups/DeluxeUtil.java
@@ -51,4 +51,28 @@ public class DeluxeUtil {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling Dynmap Game->Web Chat. All web chat will be handled by DeluxeGroups.");
((DynmapAPI) dynmap).setDisableChatToWebProcessing(true);
}
+
+ public static boolean isGroupChat(List prefixes, String message) {
+ boolean groupChat = false;
+ for (String prefix : prefixes) {
+ // If chat starts with 1 prefix, it is group chat.
+ if (message.startsWith(prefix)) {
+ groupChat = true;
+ message = message.substring(1);
+ // If chat still starts with the prefix, it means there were two and we are delegating to normal chat
+ if (message.startsWith(prefix)) {
+ return false;
+ }
+ break;
+ }
+ }
+ return groupChat;
+ }
+
+ public static List trimmed(List list) {
+ for (int i = 0; i < list.size(); i++) {
+ list.set(i, list.get(i).trim());
+ }
+ return list;
+ }
}
diff --git a/src/main/java/xyz/etztech/deluxegroups/command/CommandGroup.java b/src/main/java/xyz/etztech/deluxegroups/command/CommandGroup.java
index 5d1935c..8da60bf 100644
--- a/src/main/java/xyz/etztech/deluxegroups/command/CommandGroup.java
+++ b/src/main/java/xyz/etztech/deluxegroups/command/CommandGroup.java
@@ -119,7 +119,7 @@ public class CommandGroup
DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]);
if (args.length == 2) {
if (!group.hasPassword()) {
- group.sendMessage(player.getName() + " has joined the group!");
+ group.sendMessage(ChatColor.AQUA + player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else {
@@ -127,11 +127,11 @@ public class CommandGroup
}
} else if ( args.length == 3) {
if (group.hasPassword() && args[2].equals(group.getPassword())) {
- group.sendMessage(player.getName() + " has joined the group!");
+ group.sendMessage(ChatColor.AQUA + player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else if (!group.hasPassword()) {
- group.sendMessage(player.getName() + " has joined the group!");
+ group.sendMessage(ChatColor.AQUA + player.getName() + " has joined the group!");
DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else {
diff --git a/src/main/java/xyz/etztech/deluxegroups/listeners/AsyncPlayerChatListener.java b/src/main/java/xyz/etztech/deluxegroups/listeners/AsyncPlayerChatListener.java
index 697a791..536e7d5 100644
--- a/src/main/java/xyz/etztech/deluxegroups/listeners/AsyncPlayerChatListener.java
+++ b/src/main/java/xyz/etztech/deluxegroups/listeners/AsyncPlayerChatListener.java
@@ -1,5 +1,7 @@
package xyz.etztech.deluxegroups.listeners;
+import github.scarsz.discordsrv.DiscordSRV;
+import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -12,6 +14,7 @@ import org.dynmap.DynmapCommonAPI;
import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.deluxegroups.DeluxeGroup;
import xyz.etztech.deluxegroups.DeluxeGroups;
+import xyz.etztech.deluxegroups.DeluxeUtil;
import java.util.ArrayList;
import java.util.Iterator;
@@ -29,7 +32,7 @@ public class AsyncPlayerChatListener implements Listener {
public void reload() {
this.groupPrefixes = new ArrayList<>();
- this.groupPrefixes.addAll(trimmed(this.plugin.getConfig().getStringList("prefix")));
+ this.groupPrefixes.addAll(DeluxeUtil.trimmed(this.plugin.getConfig().getStringList("prefix")));
}
@EventHandler(priority=EventPriority.HIGH)
@@ -90,6 +93,19 @@ public class AsyncPlayerChatListener implements Listener {
}
}
event.setMessage(chat);
+
+ // DiscordSRV
+ if (DeluxeGroups.getDiscord()) {
+ TextChannel groupChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(group.getName());
+ if (groupChannel != null) {
+ String discordFormat = plugin.getConfig().getString("mtd", " > ");
+ String message = discordFormat.
+ replace("", group.getName()).
+ replace("", event.getMessage()).
+ replace("", event.getPlayer().getName());
+ groupChannel.sendMessage(message);
+ }
+ }
return;
}
}
@@ -109,14 +125,4 @@ public class AsyncPlayerChatListener implements Listener {
}
}
- private List trimmed(List list) {
- for (int i = 0; i < list.size(); i++) {
- list.set(i, list.get(i).trim());
- }
- return list;
- }
-
-
-
-
}
diff --git a/src/main/java/xyz/etztech/deluxegroups/listeners/DiscordSRVListener.java b/src/main/java/xyz/etztech/deluxegroups/listeners/DiscordSRVListener.java
new file mode 100644
index 0000000..efeb1a0
--- /dev/null
+++ b/src/main/java/xyz/etztech/deluxegroups/listeners/DiscordSRVListener.java
@@ -0,0 +1,65 @@
+package xyz.etztech.deluxegroups.listeners;
+
+import github.scarsz.discordsrv.api.Subscribe;
+import github.scarsz.discordsrv.api.events.DiscordGuildMessagePreProcessEvent;
+import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
+import org.bukkit.ChatColor;
+import xyz.etztech.deluxegroups.DeluxeGroup;
+import xyz.etztech.deluxegroups.DeluxeGroups;
+import xyz.etztech.deluxegroups.DeluxeUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DiscordSRVListener {
+
+ private DeluxeGroups plugin;
+ private List groupPrefixes;
+
+ public DiscordSRVListener(DeluxeGroups deluxeGroups) {
+ this.plugin = deluxeGroups;
+ reload();
+ }
+
+ public void reload() {
+ this.groupPrefixes = new ArrayList<>();
+ this.groupPrefixes.addAll(DeluxeUtil.trimmed(this.plugin.getConfig().getStringList("prefix")));
+ }
+
+ @Subscribe
+ public void onDiscordMessage(DiscordGuildMessagePreProcessEvent event) {
+ event.setCancelled(true);
+ if (DeluxeGroups.getDatabase().groupExists(event.getChannel().getName())) {
+ DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(event.getChannel().getName());
+ String format = plugin.getConfig().getString("dtm", "[DISCORD | ] > ");
+ String chat = format.
+ replace("", group.getName()).
+ replace("", event.getMessage().getContentStripped()).
+ replace("", event.getAuthor().getName());
+ chat = ChatColor.translateAlternateColorCodes('&', chat);
+ group.sendMessage(chat);
+ }
+ }
+
+ @Subscribe
+ public void onMinecraftMessage(GameChatMessagePreProcessEvent event) {
+ String chat = event.getMessage();
+ boolean groupChat = false;
+ for (String prefix : this.groupPrefixes) {
+ // If chat starts with 1 prefix, it is group chat.
+ if (chat.startsWith(prefix)) {
+ groupChat = true;
+ chat = chat.substring(1);
+ // If chat still starts with the prefix, it means there were two and we are delegating to normal chat
+ if (chat.startsWith(prefix)) {
+ event.setMessage(chat);
+ return;
+ }
+ break;
+ }
+ }
+ if (groupChat) {
+ event.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 7a6118f..907b3dd 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -10,4 +10,12 @@ format:
color: ''
# Custom format. The variables and are available and will be
# replaced by the group name and chat message respectively
- custom: ''
\ No newline at end of file
+ custom: ''
+
+# Optional formatting for DiscordSRV integration
+discord:
+ # These have the same variables available as custom, but also for the name of the speaker
+ # Discord to Minecraft. Can include color codes
+ dtm: '[DISCORD | ] > '
+ # Minecraft to Discord
+ mtd: ' > '
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index f03f47a..d6326fb 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -4,7 +4,7 @@ description: ${description}
author: ${author}
website: ${url}
main: ${mainClass}
-softdepend: [dynmap, MinecraftManager]
+softdepend: [dynmap, MinecraftManager, DiscordSRV]
commands:
deluxegroups:
description: Base DeluxeGroups command