mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 06:28:58 +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
+81
-3
No files matched your search
@@ -107,6 +107,18 @@
|
||||
<version>2.10.4</version>
|
||||
<scope>provided</scope>
|
||||
</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>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@ website: http://towny.palmergames.com/towny/townychat/
|
||||
description: >
|
||||
TownyChat plugin which hooks into 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.config.ChatSettings;
|
||||
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.tasks.onLoadedTask;
|
||||
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");
|
||||
public static boolean usingPlaceholderAPI = false;
|
||||
public static boolean usingEssentialsDiscord = false;
|
||||
boolean chatConfigError = false;
|
||||
boolean channelsConfigError = false;
|
||||
|
||||
@@ -144,6 +146,11 @@ public class Chat extends JavaPlugin {
|
||||
usingPlaceholderAPI = true;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("EssentialsDiscord");
|
||||
if (test != null) {
|
||||
usingEssentialsDiscord = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
@@ -154,7 +161,10 @@ public class Chat extends JavaPlugin {
|
||||
if (TownyPlayerListener != null)
|
||||
pm.registerEvents(TownyPlayerListener, this);
|
||||
}
|
||||
|
||||
|
||||
if (usingEssentialsDiscord) {
|
||||
pm.registerEvents(new EssentialsDiscordHookListener(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
Channel channel = plugin.getChannelsHandler().getChannel(player, directedChat.get(player));
|
||||
directedChat.remove(player);
|
||||
|
||||
if (channel != null) {
|
||||
// Notify player he is muted
|
||||
if (channel.isMuted(player.getName())) {
|
||||
TownyMessaging.sendErrorMsg(player, String.format(Translation.of("tc_err_you_are_currently_muted_in_channel"), channel.getName()));
|
||||
event.setCancelled(true);
|
||||
directedChat.remove(player);
|
||||
return;
|
||||
}
|
||||
if (channel.isSpam(player)) {
|
||||
event.setCancelled(true);
|
||||
directedChat.remove(player);
|
||||
return;
|
||||
}
|
||||
channel.chatProcess(event);
|
||||
if (!Chat.usingEssentialsDiscord || event.isCancelled()) {
|
||||
directedChat.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
directedChat.remove(player);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user