Compare commits

..

7 Commits

Author SHA1 Message Date
Etzelia 8d0b1f5acf
Updates
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-06-23 22:47:47 -05:00
Etzelia f3a8438904
Hype
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-06-22 23:27:10 -05:00
Etzelia e5a6d7ecc6
Fix erroneous cancellation
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-06-21 22:37:52 -05:00
Etzelia 127aeb53b2
Remove unused util
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-06-21 22:36:18 -05:00
Etzelia 9345ad73d3
Add DiscordSRV integration
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-06-21 22:34:32 -05:00
Etz Elia ab702eccf2 Add 'LICENSE' (#7)
Add 'LICENSE'

Reviewed-by: ZeroHD <joey@ahines.net>
2020-06-11 22:09:26 +02:00
Etzelia 232f51663f Update to 1.14.3 (#5) 2019-07-05 16:42:46 +02:00
13 changed files with 276 additions and 31 deletions

7
LICENSE 100644
View File

@ -0,0 +1,7 @@
Copyright 2020 Etzelia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

15
pom.xml
View File

@ -3,7 +3,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>DeluxeGroups</artifactId> <artifactId>DeluxeGroups</artifactId>
<!-- Version is used in plugin.yml --> <!-- Version is used in plugin.yml -->
<version>2.0</version> <version>2.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Plugin Information --> <!-- Plugin Information -->
@ -31,7 +31,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -39,6 +39,11 @@
<artifactId>dynmap-api</artifactId> <artifactId>dynmap-api</artifactId>
<version>1.9.4</version> <version>1.9.4</version>
</dependency> </dependency>
<dependency>
<groupId>com.discordsrv</groupId>
<artifactId>discordsrv</artifactId>
<version>1.19.0</version>
</dependency>
<dependency> <dependency>
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId> <artifactId>EtzCore</artifactId>
@ -62,6 +67,10 @@
<id>dynmap-repo</id> <id>dynmap-repo</id>
<url>http://repo.mikeprimm.com</url> <url>http://repo.mikeprimm.com</url>
</repository> </repository>
<repository>
<id>discordsrv-repo</id>
<url>https://nexus.scarsz.me/content/groups/public/</url>
</repository>
<repository> <repository>
<id>etztech-repo</id> <id>etztech-repo</id>
<url>http://repo.etztech.xyz</url> <url>http://repo.etztech.xyz</url>
@ -72,7 +81,7 @@
</repository> </repository>
<repository> <!-- This repo fixes issues with transitive dependencies --> <repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id> <id>jcenter</id>
<url>http://jcenter.bintray.com</url> <url>https://jcenter.bintray.com</url>
</repository> </repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>

View File

@ -130,12 +130,11 @@ public class DeluxeGroup {
} }
public void sendMessage(String message) { public void sendMessage(String message) {
//DeluxeUtil.log(this.log, message);
Player on; Player on;
for (OfflinePlayer player : this.groupList) { for (OfflinePlayer player : this.groupList) {
if (player.isOnline()) { if (player.isOnline()) {
on = Bukkit.getPlayer(player.getName()); on = Bukkit.getPlayer(player.getName());
on.sendMessage(ChatColor.AQUA + message); on.sendMessage(message);
} }
} }
} }

View File

@ -1,23 +1,22 @@
package xyz.etztech.deluxegroups; package xyz.etztech.deluxegroups;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.util.DiscordUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI; import org.dynmap.DynmapAPI;
import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.deluxegroups.command.CommandGroup; import xyz.etztech.deluxegroups.command.CommandGroup;
import xyz.etztech.deluxegroups.command.CommandMain; import xyz.etztech.deluxegroups.command.CommandMain;
import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener; import xyz.etztech.deluxegroups.listeners.AsyncPlayerChatListener;
import xyz.etztech.deluxegroups.listeners.DGListener;
import xyz.etztech.deluxegroups.listeners.DiscordSRVListener;
import xyz.etztech.deluxegroups.listeners.SessionListener; import xyz.etztech.deluxegroups.listeners.SessionListener;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -32,13 +31,13 @@ public class DeluxeGroups extends JavaPlugin {
// Objects that can be reloaded // Objects that can be reloaded
private AsyncPlayerChatListener chatListener; private AsyncPlayerChatListener chatListener;
// Dynmap API // Dynmap APIDynmapAPI
private static DynmapAPI dynmap = null; private static DynmapAPI dynmap = null;
// MinecraftManager API // MinecraftManager API
private static IMinecraftManager minecraftManager = null; private static IMinecraftManager minecraftManager = null;
private static boolean discord = false;
public void onEnable() { public void onEnable() {
@ -69,17 +68,23 @@ public class DeluxeGroups extends JavaPlugin {
minecraftManager.logOverride(true); minecraftManager.logOverride(true);
} }
// DiscordSRV integration
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
discord = true;
DiscordSRV.api.subscribe(new DiscordSRVListener(this));
}
// Add Commands // Add Commands
CommandMain cmdMain = new CommandMain(this); CommandMain cmdMain = new CommandMain(this);
this.getCommand("deluxegroups").setExecutor(cmdMain); this.getCommand("deluxegroups").setExecutor(cmdMain);
CommandGroup cmdGroup = new CommandGroup(this); CommandGroup cmdGroup = new CommandGroup(this);
this.getCommand("group").setExecutor(cmdGroup); this.getCommand("group").setExecutor(cmdGroup);
// Add Listeners // Add Listeners
chatListener = new AsyncPlayerChatListener(this); chatListener = new AsyncPlayerChatListener(this);
getServer().getPluginManager().registerEvents(chatListener, this); getServer().getPluginManager().registerEvents(chatListener, this);
DGListener dgListener = new DGListener(this);
getServer().getPluginManager().registerEvents(dgListener, this);
} }
} }
@ -154,5 +159,8 @@ public class DeluxeGroups extends JavaPlugin {
return minecraftManager; return minecraftManager;
} }
public static boolean getDiscord() {
return discord;
}
} }

View File

@ -51,4 +51,11 @@ public class DeluxeUtil {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling Dynmap Game->Web Chat. All web chat will be handled by DeluxeGroups."); Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "IMPORTANT: Disabling Dynmap Game->Web Chat. All web chat will be handled by DeluxeGroups.");
((DynmapAPI) dynmap).setDisableChatToWebProcessing(true); ((DynmapAPI) dynmap).setDisableChatToWebProcessing(true);
} }
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;
}
} }

View File

@ -119,7 +119,7 @@ public class CommandGroup
DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]); DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(args[1]);
if (args.length == 2) { if (args.length == 2) {
if (!group.hasPassword()) { 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() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else { } else {
@ -127,11 +127,11 @@ public class CommandGroup
} }
} else if ( args.length == 3) { } else if ( args.length == 3) {
if (group.hasPassword() && args[2].equals(group.getPassword())) { 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() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else if (!group.hasPassword()) { } 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() + "!"); DeluxeUtil.sms(player, ChatColor.AQUA + "You have joined " + group.getName() + "!");
DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId()); DeluxeGroups.getDatabase().addPlayer(player.getUniqueId().toString(), group.getId());
} else { } else {

View File

@ -0,0 +1,47 @@
package xyz.etztech.deluxegroups.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GlobalChatEvent extends Event implements Cancellable {
private Player author;
private String message;
public GlobalChatEvent(Player author, String message) {
this.author = author;
this.message = message;
}
public Player getAuthor() {
return author;
}
public String getMessage() {
return message;
}
//
// - - - HandlerList boilerplate - - -
//
public static final HandlerList HANDLERS = new HandlerList();
@Override
public HandlerList getHandlers() { return HANDLERS; }
public static HandlerList getHandlerList() { return HANDLERS; }
//
// - - - Cancellable boilerplate - - -
//
private boolean isCancelled = false;
@Override
public boolean isCancelled() { return isCancelled; }
@Override
public void setCancelled(boolean cancelled) { isCancelled = cancelled; }
}

View File

@ -0,0 +1,55 @@
package xyz.etztech.deluxegroups.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import xyz.etztech.deluxegroups.DeluxeGroup;
import xyz.etztech.deluxegroups.DeluxeUtil;
public class GroupChatEvent extends Event implements Cancellable {
private Player author;
private DeluxeGroup group;
private String message;
public GroupChatEvent(Player author, DeluxeGroup group, String message) {
this.author = author;
this.group = group;
this.message = message;
}
public Player getAuthor() {
return author;
}
public DeluxeGroup getGroup() {
return group;
}
public String getMessage() {
return message;
}
//
// - - - HandlerList boilerplate - - -
//
public static final HandlerList HANDLERS = new HandlerList();
@Override
public HandlerList getHandlers() { return HANDLERS; }
public static HandlerList getHandlerList() { return HANDLERS; }
//
// - - - Cancellable boilerplate - - -
//
private boolean isCancelled = false;
@Override
public boolean isCancelled() { return isCancelled; }
@Override
public void setCancelled(boolean cancelled) { isCancelled = cancelled; }
}

View File

@ -1,6 +1,9 @@
package xyz.etztech.deluxegroups.listeners; 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.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,6 +15,9 @@ import org.dynmap.DynmapCommonAPI;
import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.core.api.IMinecraftManager;
import xyz.etztech.deluxegroups.DeluxeGroup; import xyz.etztech.deluxegroups.DeluxeGroup;
import xyz.etztech.deluxegroups.DeluxeGroups; import xyz.etztech.deluxegroups.DeluxeGroups;
import xyz.etztech.deluxegroups.DeluxeUtil;
import xyz.etztech.deluxegroups.events.GlobalChatEvent;
import xyz.etztech.deluxegroups.events.GroupChatEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -29,7 +35,7 @@ public class AsyncPlayerChatListener implements Listener {
public void reload() { public void reload() {
this.groupPrefixes = new ArrayList<>(); 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) @EventHandler(priority=EventPriority.HIGH)
@ -90,6 +96,14 @@ public class AsyncPlayerChatListener implements Listener {
} }
} }
event.setMessage(chat); event.setMessage(chat);
// DiscordSRV
if (DeluxeGroups.getDiscord()) {
String finalChat = chat;
plugin.getServer().getScheduler().runTask(plugin, () ->
Bukkit.getPluginManager().callEvent(new GroupChatEvent(sender, group, finalChat))
);
}
return; return;
} }
} }
@ -106,17 +120,10 @@ public class AsyncPlayerChatListener implements Listener {
if (minecraftManager != null) { if (minecraftManager != null) {
minecraftManager.globalLog(sender, chat); minecraftManager.globalLog(sender, chat);
} }
plugin.getServer().getScheduler().runTask(plugin, () ->
Bukkit.getPluginManager().callEvent(new GlobalChatEvent(sender, chat))
);
} }
} }
private List<String> trimmed(List<String> list) {
for (int i = 0; i < list.size(); i++) {
list.set(i, list.get(i).trim());
}
return list;
}
} }

View File

@ -0,0 +1,43 @@
package xyz.etztech.deluxegroups.listeners;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import xyz.etztech.deluxegroups.DeluxeGroups;
import xyz.etztech.deluxegroups.events.GlobalChatEvent;
import xyz.etztech.deluxegroups.events.GroupChatEvent;
public class DGListener implements Listener {
private DeluxeGroups plugin;
public DGListener(DeluxeGroups deluxeGroups) {
this.plugin = deluxeGroups;
}
@EventHandler
public void onGlobalChat(GlobalChatEvent event) {
TextChannel mainChannel = DiscordSRV.getPlugin().getMainTextChannel();
if (mainChannel != null) {
String message = DiscordSRV.config().getString("MinecraftChatToDiscordMessageFormatNoPrimaryGroup").
replace("%displayname%", event.getAuthor().getName()).
replace("%message%", event.getMessage());
mainChannel.sendMessage(message).queue();
}
}
@EventHandler
public void onGroupChat(GroupChatEvent event) {
TextChannel groupChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(event.getGroup().getName());
if (groupChannel != null) {
String discordFormat = plugin.getConfig().getString("discord.mtd", "<author> > <message>");
String message = discordFormat.
replace("<group>", event.getGroup().getName()).
replace("<message>", ChatColor.stripColor(event.getMessage())).
replace("<author>", event.getAuthor().getName());
groupChannel.sendMessage(message).queue();
}
}
}

View File

@ -0,0 +1,54 @@
package xyz.etztech.deluxegroups.listeners;
import github.scarsz.discordsrv.DiscordSRV;
import github.scarsz.discordsrv.api.Subscribe;
import github.scarsz.discordsrv.api.events.DiscordGuildMessagePreProcessEvent;
import github.scarsz.discordsrv.api.events.GameChatMessagePreProcessEvent;
import org.bukkit.Bukkit;
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) {
if (DeluxeGroups.getDatabase().groupExists(event.getChannel().getName())) {
DeluxeGroup group = DeluxeGroups.getDatabase().getGroup(event.getChannel().getName());
String format = plugin.getConfig().getString("discord.dtm", "[DISCORD | <group>] <author> > <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);
event.setCancelled(true);
}
if (!event.getChannel().getId().equals(DiscordSRV.getPlugin().getMainTextChannel().getId())) {
event.setCancelled(true);
}
}
@Subscribe
public void onMinecraftMessage(GameChatMessagePreProcessEvent event) {
// Handled with custom events
event.setCancelled(true);
}
}

View File

@ -7,7 +7,15 @@ prefix:
# So, we have a few options to make players aware of group chat vs global chat # So, we have a few options to make players aware of group chat vs global chat
# If you don't want anything, leave these as-is # If you don't want anything, leave these as-is
format: format:
color: '' color: '&b'
# Custom format. The variables <group> and <message> are available and will be # Custom format. The variables <group> and <message> are available and will be
# replaced by the group name and chat message respectively # 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: '[&bDiscord &f| &b<group>&f] <author> > &b<message>'
# Minecraft to Discord
mtd: '<author> > <message>'

View File

@ -4,7 +4,8 @@ description: ${description}
author: ${author} author: ${author}
website: ${url} website: ${url}
main: ${mainClass} main: ${mainClass}
softdepend: [dynmap, MinecraftManager] softdepend: [dynmap, MinecraftManager, DiscordSRV]
api-version: 1.15
commands: commands:
deluxegroups: deluxegroups:
description: Base DeluxeGroups command description: Base DeluxeGroups command