mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
- Fix channel sounds being played at the sender's location, fix muting
channel sounds. - Remove built-in HexFormatter. - Refactor some StandardChannel.
This commit is contained in:
1 parent
e256df5020
commit
93f8bd846e
7 files changed
+98
-177
No files matched your search
@@ -411,4 +411,6 @@ v0.97:
|
|||||||
- Closes https://github.com/TownyAdvanced/Towny/issues/6125
|
- Closes https://github.com/TownyAdvanced/Towny/issues/6125
|
||||||
- Update min. Towny version to 0.98.3.0.
|
- Update min. Towny version to 0.98.3.0.
|
||||||
- Make the alone message respect people's vanished status.
|
- Make the alone message respect people's vanished status.
|
||||||
- Closes https://github.com/TownyAdvanced/Towny/issues/6194
|
- Closes https://github.com/TownyAdvanced/Towny/issues/6194
|
||||||
|
- Fix channel sounds being played at the sender's location, fix muting channel sounds.
|
||||||
|
- Remove built-in HexFormatter.
|
||||||
@@ -10,6 +10,7 @@ import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
|
|||||||
import com.palmergames.bukkit.TownyChat.listener.EssentialsDiscordHookListener;
|
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.EssentialsIntegration;
|
||||||
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
||||||
import com.palmergames.bukkit.towny.Towny;
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
import com.palmergames.bukkit.util.Version;
|
import com.palmergames.bukkit.util.Version;
|
||||||
@@ -223,6 +224,12 @@ public class Chat extends JavaPlugin {
|
|||||||
return dynMap;
|
return dynMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIgnoredByEssentials(Player sender, Player player) {
|
||||||
|
if (!getTowny().isEssentials())
|
||||||
|
return false;
|
||||||
|
return EssentialsIntegration.ignoredByEssentials(sender, player);
|
||||||
|
}
|
||||||
|
|
||||||
private void registerObjectCommands() {
|
private void registerObjectCommands() {
|
||||||
List<Command> commands = new ArrayList<Command>();
|
List<Command> commands = new ArrayList<Command>();
|
||||||
for (Channel channel : channels.getAllChannels().values()) { // All channels
|
for (Channel channel : channels.getAllChannels().values()) { // All channels
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.palmergames.bukkit.TownyChat;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class HexFormatter {
|
|
||||||
|
|
||||||
public static final Pattern hexPattern = Pattern.compile("(?<!\\\\)(#[a-fA-F0-9]{6})");
|
|
||||||
public static final Pattern ampersandPattern = Pattern.compile("(?<!\\\\)(&#[a-fA-F0-9]{6})");
|
|
||||||
public static final Pattern bracketPattern = Pattern.compile("(?<!\\\\)\\{(#[a-fA-F0-9]{6})}");
|
|
||||||
|
|
||||||
public static String translateHexColors(String str) {
|
|
||||||
final Matcher hexMatcher = hexPattern.matcher(str);
|
|
||||||
final Matcher ampMatcher = ampersandPattern.matcher(str);
|
|
||||||
final Matcher bracketMatcher = bracketPattern.matcher(str);
|
|
||||||
|
|
||||||
while (hexMatcher.find()) {
|
|
||||||
String hex = hexMatcher.group();
|
|
||||||
str = str.replace(hex, ChatColor.of(hex).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
while (ampMatcher.find()) {
|
|
||||||
String hex = ampMatcher.group().replace("&", "");
|
|
||||||
str = str.replace(hex, ChatColor.of(hex).toString());
|
|
||||||
str = str.replace("&", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
while (bracketMatcher.find()) {
|
|
||||||
String hex = bracketMatcher.group().replace("{", "").replace("}", "");
|
|
||||||
str = str.replace(hex, ChatColor.of(hex).toString());
|
|
||||||
str = str.replace("{", "").replace("}", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ import com.palmergames.bukkit.towny.object.Government;
|
|||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.util.Colors;
|
||||||
import com.palmergames.util.StringMgmt;
|
import com.palmergames.util.StringMgmt;
|
||||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||||
|
|
||||||
@@ -203,12 +204,12 @@ public class TownyChatFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String hex(String str) {
|
public static String hex(String str) {
|
||||||
return HexFormatter.translateHexColors(str);
|
return Colors.translateColorCodes(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getChatFormat(LocalTownyChatEvent event) {
|
public static String getChatFormat(LocalTownyChatEvent event) {
|
||||||
// Replace the {msg} here so it's not regex parsed.
|
// Replace the {msg} here so it's not regex parsed.
|
||||||
return hex(replacer.replaceAll(event.getFormat(), event).replace("%", "").replace("{modplayername}", "%1$s").replace("{msg}", "%2$s"));
|
return replacer.replaceAll(event.getFormat(), event).replace("%", "").replace("{modplayername}", "%1$s").replace("{msg}", "%2$s");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.channels;
|
package com.palmergames.bukkit.TownyChat.channels;
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
|
||||||
import com.palmergames.bukkit.TownyChat.Chat;
|
import com.palmergames.bukkit.TownyChat.Chat;
|
||||||
import com.palmergames.bukkit.TownyChat.HexFormatter;
|
|
||||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||||
import com.palmergames.bukkit.TownyChat.events.AsyncChatHookEvent;
|
import com.palmergames.bukkit.TownyChat.events.AsyncChatHookEvent;
|
||||||
@@ -10,7 +8,6 @@ import com.palmergames.bukkit.TownyChat.events.PlayerJoinChatChannelEvent;
|
|||||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||||
import com.palmergames.bukkit.towny.TownyAPI;
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
@@ -31,6 +28,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StandardChannel extends Channel {
|
public class StandardChannel extends Channel {
|
||||||
|
|
||||||
@@ -113,28 +111,30 @@ public class StandardChannel extends Channel {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trySendingAloneMessage(player, recipients);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform all replace functions on this format
|
* Perform all replace functions on this format
|
||||||
*/
|
*/
|
||||||
if (Chat.usingPlaceholderAPI) {
|
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.
|
* Only modify GLOBAL channelType chat (general and local chat channels) if isModifyChat() is true.
|
||||||
*/
|
*/
|
||||||
if (!(channelType.equals(channelTypes.GLOBAL) && !ChatSettings.isModify_chat())) {
|
if (!(channelType.equals(channelTypes.GLOBAL) && !ChatSettings.isModify_chat())) {
|
||||||
event.setFormat(getFormat(format));
|
event.setFormat(getFormat(format));
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set all the listeners for Bukkit to send this message to.
|
* Set recipients for Bukkit to send this message to.
|
||||||
*/
|
*/
|
||||||
event.getRecipients().clear();
|
event.getRecipients().clear();
|
||||||
event.getRecipients().addAll(recipients);
|
event.getRecipients().addAll(recipients);
|
||||||
|
|
||||||
|
// If the server has marked this Channel as hooked, fire the AsyncChatHookEvent.
|
||||||
if (isHooked()) {
|
if (isHooked()) {
|
||||||
AsyncChatHookEvent hookEvent = new AsyncChatHookEvent(event, this, !Bukkit.getServer().isPrimaryThread());
|
AsyncChatHookEvent hookEvent = new AsyncChatHookEvent(event, this, !Bukkit.getServer().isPrimaryThread());
|
||||||
Bukkit.getServer().getPluginManager().callEvent(hookEvent);
|
Bukkit.getServer().getPluginManager().callEvent(hookEvent);
|
||||||
@@ -161,24 +161,10 @@ public class StandardChannel extends Channel {
|
|||||||
sendSpyMessage(event, channelType);
|
sendSpyMessage(event, channelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getChannelSound() != null) {
|
tryPlayChannelSound(event.getRecipients());
|
||||||
for (Player recipient : event.getRecipients()) {
|
|
||||||
if (!isSoundMuted(player)) {
|
|
||||||
try {
|
|
||||||
recipient.playSound(player.getLocation(), Sound.valueOf(getChannelSound()), 1.0f, 1.0f);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
plugin.getLogger().warning("Channel " + this.getName() + " has an invalid sound configured.");
|
|
||||||
setChannelSound(null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (notifyjoin)
|
||||||
if (notifyjoin) {
|
|
||||||
TownyMessaging.sendMessage(player, "You join " + Colors.White + getName());
|
TownyMessaging.sendMessage(player, "You join " + Colors.White + getName());
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform any last channel specific functions
|
* Perform any last channel specific functions
|
||||||
@@ -187,33 +173,43 @@ public class StandardChannel extends Channel {
|
|||||||
switch (channelType) {
|
switch (channelType) {
|
||||||
|
|
||||||
case TOWN:
|
case TOWN:
|
||||||
break;
|
|
||||||
|
|
||||||
case NATION:
|
case NATION:
|
||||||
break;
|
|
||||||
|
|
||||||
case ALLIANCE:
|
case ALLIANCE:
|
||||||
break;
|
|
||||||
|
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRIVATE:
|
case PRIVATE:
|
||||||
case GLOBAL:
|
case GLOBAL:
|
||||||
|
tryPostToDynmap(player, event.getMessage());
|
||||||
// Don't broadcast local/ranged chat into dynmap.
|
|
||||||
if (super.getRange() > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynmapAPI dynMap = plugin.getDynmap();
|
|
||||||
|
|
||||||
if (dynMap != null)
|
|
||||||
dynMap.postPlayerMessageToWeb(player, event.getMessage());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tryPlayChannelSound(Set<Player> recipients) {
|
||||||
|
if (getChannelSound() != null) {
|
||||||
|
for (Player recipient : recipients) {
|
||||||
|
if (!isSoundMuted(recipient)) {
|
||||||
|
try {
|
||||||
|
recipient.playSound(recipient.getLocation(), Sound.valueOf(getChannelSound()), 1.0f, 1.0f);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
plugin.getLogger().warning("Channel " + this.getName() + " has an invalid sound configured.");
|
||||||
|
setChannelSound(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryPostToDynmap(Player player, String message) {
|
||||||
|
if (super.getRange() > 0)
|
||||||
|
return;
|
||||||
|
DynmapAPI dynMap = plugin.getDynmap();
|
||||||
|
if (dynMap != null)
|
||||||
|
dynMap.postPlayerMessageToWeb(player, message);
|
||||||
|
}
|
||||||
|
|
||||||
private String getFormat(String format) {
|
private String getFormat(String format) {
|
||||||
return format
|
return format
|
||||||
.replace("{channelTag}", Colors.translateColorCodes(getChannelTag() != null ? getChannelTag() : ""))
|
.replace("{channelTag}", Colors.translateColorCodes(getChannelTag() != null ? getChannelTag() : ""))
|
||||||
@@ -242,10 +238,8 @@ public class StandardChannel extends Channel {
|
|||||||
return player1.getWorld().equals(player2.getWorld());
|
return player1.getWorld().equals(player2.getWorld());
|
||||||
|
|
||||||
// Range check (same world)
|
// Range check (same world)
|
||||||
if (player1.getWorld().equals(player2.getWorld()))
|
return player1.getWorld().equals(player2.getWorld()) &&
|
||||||
return (player1.getLocation().distance(player2.getLocation()) < range);
|
player1.getLocation().distance(player2.getLocation()) < range;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -256,72 +250,25 @@ public class StandardChannel extends Channel {
|
|||||||
* @return Set containing a list of players for this message.
|
* @return Set containing a list of players for this message.
|
||||||
*/
|
*/
|
||||||
private Set<Player> findRecipients(Player sender, List<Player> playerList) {
|
private Set<Player> findRecipients(Player sender, List<Player> playerList) {
|
||||||
|
// Refresh the potential channels a player can see, if they are not currently in the channel.
|
||||||
Set<Player> recipients = new HashSet<>();
|
playerList.stream().forEach(p -> refreshPlayer(this, p));
|
||||||
boolean bEssentials = plugin.getTowny().isEssentials();
|
return playerList.stream()
|
||||||
Channel channel = plugin.getChannelsHandler().getChannel(getName());
|
.filter(p -> TownyUniverse.getInstance().getPermissionSource().has(p, getPermission())) // Check permission.
|
||||||
// Compile the list of recipients
|
.filter(p -> testDistance(sender, p, getRange())) // Within range.
|
||||||
for (Player player : playerList) {
|
.filter(p -> !plugin.isIgnoredByEssentials(sender, p)) // Check essentials ignore.
|
||||||
|
.filter(p -> !isAbsent(p.getName())) // Check if player is purposefully absent.
|
||||||
/*
|
.collect(Collectors.toSet());
|
||||||
* Refresh the potential channels a player can see, if they are not currently in the channel.
|
}
|
||||||
*/
|
|
||||||
if (!channel.isPresent(player.getName()))
|
|
||||||
channel.forgetPlayer(player);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the player has the correct permission node.
|
|
||||||
*/
|
|
||||||
if (TownyUniverse.getInstance().getPermissionSource().has(player, getPermission())) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the player is within range for this 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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spy's can leave channels and we'll respect that
|
private void refreshPlayer(Channel channel, Player player) {
|
||||||
if (absentPlayers != null) {
|
if (!channel.isPresent(player.getName()))
|
||||||
// Ignore players who have left this channel
|
channel.forgetPlayer(player);
|
||||||
if (absentPlayers.containsKey(player.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
recipients.add(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trySendingAloneMessage(sender, recipients);
|
|
||||||
|
|
||||||
return recipients;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void trySendingAloneMessage(Player sender, Set<Player> recipients) {
|
private void trySendingAloneMessage(Player sender, Set<Player> recipients) {
|
||||||
if (ChatSettings.isUsingAloneMessage() &&
|
if (ChatSettings.isUsingAloneMessage() &&
|
||||||
recipients.stream().filter(p -> sender.canSee(p)).count() < 2) // sender will usually be a recipient of their own message.
|
recipients.stream().filter(p -> sender.canSee(p)).count() < 2) // sender will usually be a recipient of their own message.
|
||||||
sender.sendMessage(color(ChatSettings.getUsingAloneMessageString()));
|
sender.sendMessage(Colors.translateColorCodes(ChatSettings.getUsingAloneMessageString()));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return a coloured string.
|
|
||||||
*/
|
|
||||||
private String color(String str) {
|
|
||||||
// TODO: Replace this with Towny's colouring system post 0.98.4.0.
|
|
||||||
return HexFormatter.translateHexColors(ChatColor.translateAlternateColorCodes('&', str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,21 +277,16 @@ public class StandardChannel extends Channel {
|
|||||||
* @param event - Chat Event.
|
* @param event - Chat Event.
|
||||||
* @param type - Channel Type
|
* @param type - Channel Type
|
||||||
*/
|
*/
|
||||||
private void sendSpyMessage(AsyncPlayerChatEvent event, channelTypes type) {
|
private void sendSpyMessage(AsyncPlayerChatEvent event, channelTypes type) {
|
||||||
Set<Player> recipients = new HashSet<>();
|
Set<Player> recipients = event.getRecipients();
|
||||||
Set<Player> spies = new HashSet<>();
|
Set<Player> spies = getSpies();
|
||||||
|
|
||||||
recipients.addAll(event.getRecipients());
|
|
||||||
spies = checkSpying(spies);
|
|
||||||
String format = formatSpyMessage(type, event.getPlayer());
|
String format = formatSpyMessage(type, event.getPlayer());
|
||||||
if (format == null) return;
|
if (format == null) return;
|
||||||
|
|
||||||
// Remove spies who've already seen the message naturally.
|
// Remove spies who've already seen the message naturally.
|
||||||
for (Player spy : spies)
|
spies.stream()
|
||||||
if (recipients.contains(spy))
|
.filter(spy -> !recipients.contains(spy))
|
||||||
continue;
|
.forEach(spy -> spy.sendMessage(ChatColor.GOLD + "[SPY] " + ChatColor.WHITE + format + ": " + event.getMessage()));
|
||||||
else
|
|
||||||
spy.sendMessage(ChatColor.GOLD + "[SPY] " + ChatColor.WHITE + format + ": " + event.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,7 +304,7 @@ public class StandardChannel extends Channel {
|
|||||||
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
|
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
|
||||||
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
|
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
|
||||||
|
|
||||||
String format = color(getChannelTag() != null ? getChannelTag() : getName());
|
String format = Colors.translateColorCodes(getChannelTag() != null ? getChannelTag() : getName());
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TOWN:
|
case TOWN:
|
||||||
@@ -382,24 +324,13 @@ public class StandardChannel extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all spying players to the recipients list.
|
* @return A Set of players online who are spying.
|
||||||
*
|
|
||||||
* @param recipients
|
|
||||||
* @return new recipients including spying.
|
|
||||||
*/
|
*/
|
||||||
private Set<Player> checkSpying(Set<Player> recipients) {
|
private Set<Player> getSpies() {
|
||||||
|
|
||||||
|
|
||||||
// Compile the list of recipients with spy perms
|
// Compile the list of recipients with spy perms
|
||||||
for (Player test : plugin.getServer().getOnlinePlayers()) {
|
return plugin.getServer().getOnlinePlayers().stream()
|
||||||
|
.filter(p -> plugin.getTowny().hasPlayerMode(p, "spy"))
|
||||||
if (plugin.getTowny().hasPlayerMode(test, "spy") && !(recipients.contains(test))) {
|
.collect(Collectors.toSet());
|
||||||
recipients.add(test);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return recipients;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.palmergames.bukkit.TownyChat.listener;
|
package com.palmergames.bukkit.TownyChat.listener;
|
||||||
|
|
||||||
import com.palmergames.bukkit.TownyChat.Chat;
|
import com.palmergames.bukkit.TownyChat.Chat;
|
||||||
import com.palmergames.bukkit.TownyChat.HexFormatter;
|
|
||||||
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||||
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||||
@@ -13,10 +12,10 @@ import com.palmergames.bukkit.towny.object.Resident;
|
|||||||
import com.palmergames.bukkit.towny.object.Translatable;
|
import com.palmergames.bukkit.towny.object.Translatable;
|
||||||
import com.palmergames.bukkit.towny.object.metadata.StringDataField;
|
import com.palmergames.bukkit.towny.object.metadata.StringDataField;
|
||||||
import com.palmergames.bukkit.towny.utils.MetaDataUtil;
|
import com.palmergames.bukkit.towny.utils.MetaDataUtil;
|
||||||
|
import com.palmergames.bukkit.util.Colors;
|
||||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -104,7 +103,7 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(player.hasPermission("townychat.chat.color"))
|
if(player.hasPermission("townychat.chat.color"))
|
||||||
event.setMessage(HexFormatter.translateHexColors(ChatColor.translateAlternateColorCodes('&', event.getMessage())));
|
event.setMessage(Colors.translateColorCodes(event.getMessage()));
|
||||||
|
|
||||||
// Check if essentials has this player muted.
|
// Check if essentials has this player muted.
|
||||||
if (!isMuted(player)) {
|
if (!isMuted(player)) {
|
||||||
@@ -188,7 +187,7 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
|
|
||||||
event.setFormat(HexFormatter.translateHexColors(TownyChatFormatter.getChatFormat(chatEvent)));
|
event.setFormat(Colors.translateColorCodes(TownyChatFormatter.getChatFormat(chatEvent)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.palmergames.bukkit.TownyChat.util;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||||
|
|
||||||
|
public class EssentialsIntegration {
|
||||||
|
|
||||||
|
public static boolean ignoredByEssentials(Player sender, Player player) {
|
||||||
|
try {
|
||||||
|
com.earth2me.essentials.User targetUser = Towny.getPlugin().getEssentials().getUser(player);
|
||||||
|
com.earth2me.essentials.User senderUser = Towny.getPlugin().getEssentials().getUser(sender);
|
||||||
|
return targetUser.isIgnoredPlayer(senderUser);
|
||||||
|
} catch (TownyException ignored) {
|
||||||
|
// Failed to fetch user so ignore.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user