Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
Etzelia | 8d0b1f5acf | |
Etzelia | f3a8438904 | |
Etzelia | e5a6d7ecc6 | |
Etzelia | 127aeb53b2 | |
Etzelia | 9345ad73d3 | |
Etz Elia | ab702eccf2 | |
Etzelia | 232f51663f |
|
@ -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
15
pom.xml
|
@ -3,7 +3,7 @@
|
|||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>DeluxeGroups</artifactId>
|
||||
<!-- Version is used in plugin.yml -->
|
||||
<version>2.0</version>
|
||||
<version>2.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- Plugin Information -->
|
||||
|
@ -31,7 +31,7 @@
|
|||
<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>
|
||||
|
@ -39,6 +39,11 @@
|
|||
<artifactId>dynmap-api</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discordsrv</groupId>
|
||||
<artifactId>discordsrv</artifactId>
|
||||
<version>1.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>EtzCore</artifactId>
|
||||
|
@ -62,6 +67,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 +81,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,22 @@
|
|||
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.DGListener;
|
||||
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 +31,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,17 +68,23 @@ 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);
|
||||
CommandGroup cmdGroup = new CommandGroup(this);
|
||||
this.getCommand("group").setExecutor(cmdGroup);
|
||||
|
||||
|
||||
|
||||
// Add Listeners
|
||||
chatListener = new AsyncPlayerChatListener(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;
|
||||
}
|
||||
|
||||
public static boolean getDiscord() {
|
||||
return discord;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.");
|
||||
((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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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; }
|
||||
}
|
|
@ -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; }
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
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.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -12,6 +15,9 @@ 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 xyz.etztech.deluxegroups.events.GlobalChatEvent;
|
||||
import xyz.etztech.deluxegroups.events.GroupChatEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -29,7 +35,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 +96,14 @@ public class AsyncPlayerChatListener implements Listener {
|
|||
}
|
||||
}
|
||||
event.setMessage(chat);
|
||||
|
||||
// DiscordSRV
|
||||
if (DeluxeGroups.getDiscord()) {
|
||||
String finalChat = chat;
|
||||
plugin.getServer().getScheduler().runTask(plugin, () ->
|
||||
Bukkit.getPluginManager().callEvent(new GroupChatEvent(sender, group, finalChat))
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -106,17 +120,10 @@ public class AsyncPlayerChatListener implements Listener {
|
|||
if (minecraftManager != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,15 @@ prefix:
|
|||
# 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
|
||||
format:
|
||||
color: ''
|
||||
color: '&b'
|
||||
# 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: '[&bDiscord &f| &b<group>&f] <author> > &b<message>'
|
||||
# Minecraft to Discord
|
||||
mtd: '<author> > <message>'
|
|
@ -4,7 +4,8 @@ description: ${description}
|
|||
author: ${author}
|
||||
website: ${url}
|
||||
main: ${mainClass}
|
||||
softdepend: [dynmap, MinecraftManager]
|
||||
softdepend: [dynmap, MinecraftManager, DiscordSRV]
|
||||
api-version: 1.15
|
||||
commands:
|
||||
deluxegroups:
|
||||
description: Base DeluxeGroups command
|
||||
|
|
Loading…
Reference in New Issue