mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 06:28:58 +00:00
Make it so that non-Essentials servers can still load TC, bump
Essentials version to 2.18.2.
This commit is contained in:
1 parent
af02f6571a
commit
5a1c9b6ced
5 files changed
+52
-31
No files matched your search
@@ -92,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.17.1</version>
|
||||
<version>2.18.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -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, Essentials]
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
|
||||
@@ -11,6 +12,7 @@ import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
||||
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
||||
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.util.Version;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -44,11 +46,13 @@ public class Chat extends JavaPlugin {
|
||||
protected PluginManager pm;
|
||||
private Towny towny = null;
|
||||
private DynmapAPI dynMap = null;
|
||||
private Essentials essentials = null;
|
||||
|
||||
private static Version requiredTownyVersion = Version.fromString("0.96.5.5");
|
||||
public static boolean usingPlaceholderAPI = false;
|
||||
boolean chatConfigError = false;
|
||||
boolean channelsConfigError = false;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@@ -84,6 +88,11 @@ public class Chat extends JavaPlugin {
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (towny.isEssentials())
|
||||
try {
|
||||
essentials = towny.getEssentials();
|
||||
} catch (TownyException ignored) {}
|
||||
|
||||
getCommand("townychat").setExecutor(new TownyChatCommand(this));
|
||||
getCommand("channel").setExecutor(new ChannelCommand(this));
|
||||
@@ -201,12 +210,15 @@ public class Chat extends JavaPlugin {
|
||||
public Towny getTowny() {
|
||||
return towny;
|
||||
}
|
||||
|
||||
|
||||
public DynmapAPI getDynmap() {
|
||||
return dynMap;
|
||||
}
|
||||
|
||||
public Essentials getEssentials() {
|
||||
return essentials;
|
||||
}
|
||||
|
||||
private void registerObjectCommands() {
|
||||
List<Command> commands = new ArrayList<Command>();
|
||||
for (Channel channel : channels.getAllChannels().values()) { // All channels
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.palmergames.bukkit.TownyChat.channels;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
import com.palmergames.bukkit.TownyChat.HexFormatter;
|
||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||
@@ -8,11 +7,11 @@ import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.events.AsyncChatHookEvent;
|
||||
import com.palmergames.bukkit.TownyChat.events.PlayerJoinChatChannelEvent;
|
||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||
import com.palmergames.bukkit.TownyChat.util.EssentialsUtil;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
@@ -45,10 +44,10 @@ public class StandardChannel extends Channel {
|
||||
@Override
|
||||
public void chatProcess(AsyncPlayerChatEvent event) {
|
||||
|
||||
channelTypes channelType = this.getType();
|
||||
channelTypes channelType = channelTypes.valueOf(getType().name());
|
||||
Player player = event.getPlayer();
|
||||
Set<Player> recipients = null;
|
||||
String Format = "";
|
||||
String format = "";
|
||||
boolean notifyjoin = false;
|
||||
|
||||
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
|
||||
@@ -86,7 +85,7 @@ public class StandardChannel extends Channel {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(town)));
|
||||
break;
|
||||
|
||||
@@ -95,7 +94,7 @@ public class StandardChannel extends Channel {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(nation)));
|
||||
break;
|
||||
|
||||
@@ -104,22 +103,22 @@ public class StandardChannel extends Channel {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getALLIANCE();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getALLIANCE();
|
||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayersAlliance(nation)));
|
||||
break;
|
||||
|
||||
case DEFAULT:
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getDEFAULT();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getDEFAULT();
|
||||
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||
break;
|
||||
|
||||
case GLOBAL:
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||
break;
|
||||
|
||||
case PRIVATE:
|
||||
Format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||
format = ChatSettings.getRelevantFormatGroup(player).getGLOBAL();
|
||||
recipients = new HashSet<>(findRecipients(player, new ArrayList<>(event.getRecipients())));
|
||||
break;
|
||||
}
|
||||
@@ -128,14 +127,14 @@ public class StandardChannel extends Channel {
|
||||
* Perform all replace functions on this format
|
||||
*/
|
||||
if (Chat.usingPlaceholderAPI) {
|
||||
Format = PlaceholderAPI.setPlaceholders(player, Format);
|
||||
format = PlaceholderAPI.setPlaceholders(player, format);
|
||||
}
|
||||
|
||||
/*
|
||||
* Only modify GLOBAL channelType chat (general and local chat channels) if isModifyChat() is true.
|
||||
*/
|
||||
if (!(channelType.equals(channelTypes.GLOBAL) && !ChatSettings.isModify_chat())) {
|
||||
event.setFormat(Format.replace("{channelTag}", getChannelTag()).replace("{msgcolour}", TownyChatFormatter.hexIfCompatible(getMessageColour())));
|
||||
event.setFormat(format.replace("{channelTag}", getChannelTag()).replace("{msgcolour}", TownyChatFormatter.hexIfCompatible(getMessageColour())));
|
||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||
}
|
||||
@@ -249,9 +248,8 @@ public class StandardChannel extends Channel {
|
||||
*/
|
||||
private Set<Player> findRecipients(Player sender, List<Player> playerList) {
|
||||
|
||||
Set<Player> recipients = new HashSet<>();
|
||||
boolean bEssentials = plugin.getTowny().isEssentials();
|
||||
Channel channel = this;
|
||||
Set<Player> recipients = new HashSet<>();
|
||||
Channel channel = plugin.getChannelsHandler().getChannel(getName());
|
||||
// Compile the list of recipients
|
||||
for (Player player : playerList) {
|
||||
|
||||
@@ -271,19 +269,11 @@ public class StandardChannel extends Channel {
|
||||
*/
|
||||
if (testDistance(sender, player, getRange())){
|
||||
|
||||
if (bEssentials) {
|
||||
try {
|
||||
User targetUser = plugin.getTowny().getEssentials().getUser(player);
|
||||
User senderUser = plugin.getTowny().getEssentials().getUser(sender);
|
||||
/*
|
||||
* Don't send this message if the user is ignored
|
||||
*/
|
||||
if (targetUser.isIgnoredPlayer(senderUser))
|
||||
continue;
|
||||
} catch (TownyException e) {
|
||||
// Failed to fetch user so ignore.
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Don't send anything if the player is ignoring the sender.
|
||||
*/
|
||||
if (plugin.getEssentials() != null && EssentialsUtil.isUserIgnoringUser(sender, player))
|
||||
continue;
|
||||
|
||||
// Spy's can leave channels and we'll respect that
|
||||
if (absentPlayers != null) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.palmergames.bukkit.TownyChat.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.Chat;
|
||||
|
||||
public class EssentialsUtil {
|
||||
|
||||
static Chat plugin;
|
||||
public EssentialsUtil(Chat chat) {
|
||||
plugin = chat;
|
||||
}
|
||||
public static boolean isUserIgnoringUser(Player sender, Player receiver) {
|
||||
if (plugin.getEssentials().getUser(receiver).isIgnoredPlayer(plugin.getEssentials().getUser(sender)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user