mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 06:28:57 +00:00
Add support for EssentialsDiscord (#33)
* Add initial support for EssentialsDiscord * Fixup some stuff * Exclude JDA * Restore ChannelsHolder.java * Fix canceled logic * Fix bool logic * Make sure direct channel always gets handled * Remove isHooked check * Add javadoc to EssentialsDiscordHookListener, remove unneeded diff. Co-authored-by: Llm Dl <[email protected]>
This commit is contained in:
1 parent
ce03d1dd5c
commit
5bee9611aa
5 files changed
+80
-2
No files matched your search
@@ -107,6 +107,18 @@
|
|||||||
<version>2.10.4</version>
|
<version>2.10.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.EssentialsX.Essentials</groupId>
|
||||||
|
<artifactId>EssentialsXDiscord</artifactId>
|
||||||
|
<version>57600f333c</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.dv8tion</groupId>
|
||||||
|
<artifactId>JDA</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ website: http://towny.palmergames.com/towny/townychat/
|
|||||||
description: >
|
description: >
|
||||||
TownyChat plugin which hooks into Towny.
|
TownyChat plugin which hooks into Towny.
|
||||||
depend: [Towny]
|
depend: [Towny]
|
||||||
softdepend: [CraftIRC, PlaceholderAPI, dynmap]
|
softdepend: [CraftIRC, PlaceholderAPI, dynmap, EssentialsDiscord]
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# +------------------------------------------------------+ #
|
# +------------------------------------------------------+ #
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.palmergames.bukkit.TownyChat.channels.Channel;
|
|||||||
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
||||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||||
import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
|
import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
|
||||||
|
import com.palmergames.bukkit.TownyChat.listener.EssentialsDiscordHookListener;
|
||||||
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
||||||
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
||||||
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
||||||
@@ -47,6 +48,7 @@ public class Chat extends JavaPlugin {
|
|||||||
|
|
||||||
private static Version requiredTownyVersion = Version.fromString("0.97.0.0");
|
private static Version requiredTownyVersion = Version.fromString("0.97.0.0");
|
||||||
public static boolean usingPlaceholderAPI = false;
|
public static boolean usingPlaceholderAPI = false;
|
||||||
|
public static boolean usingEssentialsDiscord = false;
|
||||||
boolean chatConfigError = false;
|
boolean chatConfigError = false;
|
||||||
boolean channelsConfigError = false;
|
boolean channelsConfigError = false;
|
||||||
|
|
||||||
@@ -144,6 +146,11 @@ public class Chat extends JavaPlugin {
|
|||||||
usingPlaceholderAPI = true;
|
usingPlaceholderAPI = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test = pm.getPlugin("EssentialsDiscord");
|
||||||
|
if (test != null) {
|
||||||
|
usingEssentialsDiscord = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
@@ -155,6 +162,9 @@ public class Chat extends JavaPlugin {
|
|||||||
pm.registerEvents(TownyPlayerListener, this);
|
pm.registerEvents(TownyPlayerListener, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usingEssentialsDiscord) {
|
||||||
|
pm.registerEvents(new EssentialsDiscordHookListener(this), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPermissions() {
|
public void registerPermissions() {
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.palmergames.bukkit.TownyChat.listener;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.TownyChat.Chat;
|
||||||
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
|
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||||
|
import net.essentialsx.api.v2.events.discord.DiscordChatMessageEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener which stops non-global or limited-range
|
||||||
|
* chats from passing on to EssentialsDiscord.
|
||||||
|
*
|
||||||
|
* @author JRoy
|
||||||
|
* @since 0.90
|
||||||
|
*/
|
||||||
|
public class EssentialsDiscordHookListener implements Listener {
|
||||||
|
private final Chat plugin;
|
||||||
|
|
||||||
|
public EssentialsDiscordHookListener(Chat plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler()
|
||||||
|
public void onDiscordChat(DiscordChatMessageEvent event) {
|
||||||
|
String directChat = plugin.getTownyPlayerListener().directedChat.get(event.getPlayer());
|
||||||
|
if (directChat != null) {
|
||||||
|
plugin.getTownyPlayerListener().directedChat.remove(event.getPlayer());
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Channel channel = plugin.getChannelsHandler().getChannel(event.getPlayer(), directChat);
|
||||||
|
if (channel != null) {
|
||||||
|
event.setCancelled(channel.getType() != channelTypes.GLOBAL || channel.getRange() != -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Channel curChannel : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||||
|
if (plugin.getTowny().hasPlayerMode(event.getPlayer(), curChannel.getName())) {
|
||||||
|
event.setCancelled( curChannel.getType() != channelTypes.GLOBAL || curChannel.getRange() != -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel channel = plugin.getChannelsHandler().getActiveChannel(event.getPlayer(), channelTypes.GLOBAL);
|
||||||
|
if (channel != null) {
|
||||||
|
event.setCancelled(channel.getType() != channelTypes.GLOBAL || channel.getRange() != -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,22 +116,27 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
if (directedChat.containsKey(player)) {
|
if (directedChat.containsKey(player)) {
|
||||||
Channel channel = plugin.getChannelsHandler().getChannel(player, directedChat.get(player));
|
Channel channel = plugin.getChannelsHandler().getChannel(player, directedChat.get(player));
|
||||||
directedChat.remove(player);
|
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
// Notify player he is muted
|
// Notify player he is muted
|
||||||
if (channel.isMuted(player.getName())) {
|
if (channel.isMuted(player.getName())) {
|
||||||
TownyMessaging.sendErrorMsg(player, String.format(Translation.of("tc_err_you_are_currently_muted_in_channel"), channel.getName()));
|
TownyMessaging.sendErrorMsg(player, String.format(Translation.of("tc_err_you_are_currently_muted_in_channel"), channel.getName()));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
directedChat.remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (channel.isSpam(player)) {
|
if (channel.isSpam(player)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
directedChat.remove(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
channel.chatProcess(event);
|
channel.chatProcess(event);
|
||||||
|
if (!Chat.usingEssentialsDiscord || event.isCancelled()) {
|
||||||
|
directedChat.remove(player);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
directedChat.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in new issue
Block a user