parent
ab702eccf2
commit
9345ad73d3
15
pom.xml
15
pom.xml
|
@ -31,13 +31,20 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.3-R0.1-SNAPSHOT</version>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>1.9.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
|
@ -62,6 +69,10 @@
|
|||
<id>dynmap-repo</id>
|
||||
<url>http://repo.mikeprimm.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>discordsrv-repo</id>
|
||||
<url>https://nexus.scarsz.me/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>etztech-repo</id>
|
||||
<url>http://repo.etztech.xyz</url>
|
||||
|
@ -72,7 +83,7 @@
|
|||
</repository>
|
||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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<String> trimmed(List<String> list) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
list.set(i, list.get(i).trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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", "<author> > <message>");
|
||||
String message = discordFormat.
|
||||
replace("<group>", group.getName()).
|
||||
replace("<message>", event.getMessage()).
|
||||
replace("<author>", event.getPlayer().getName());
|
||||
groupChannel.sendMessage(message);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -109,14 +125,4 @@ public class AsyncPlayerChatListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
private List<String> trimmed(List<String> list) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
list.set(i, list.get(i).trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String> 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 | <group>] <player> > <message>");
|
||||
String chat = format.
|
||||
replace("<group>", group.getName()).
|
||||
replace("<message>", event.getMessage().getContentStripped()).
|
||||
replace("<author>", 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,4 +10,12 @@ format:
|
|||
color: ''
|
||||
# Custom format. The variables <group> and <message> are available and will be
|
||||
# replaced by the group name and chat message respectively
|
||||
custom: ''
|
||||
custom: ''
|
||||
|
||||
# Optional formatting for DiscordSRV integration
|
||||
discord:
|
||||
# These have the same variables available as custom, but also <author> for the name of the speaker
|
||||
# Discord to Minecraft. Can include color codes
|
||||
dtm: '[DISCORD | <group>] <author> > <message>'
|
||||
# Minecraft to Discord
|
||||
mtd: '<author> > <message>'
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue