mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 22:21:52 +00:00
- People spying on chat will now see the chat formatted differently
from normal.
- De-clutters the chat.
- Closes: https://github.com/TownyAdvanced/Towny/issues/2665
This commit is contained in:
1 parent
5ef8fd21e9
commit
3f44221356
2 files changed
+68
-6
No files matched your search
@@ -302,3 +302,6 @@ v0.69:
|
|||||||
v0.70:
|
v0.70:
|
||||||
- Allow for $ and \ to be used in the chat line.
|
- Allow for $ and \ to be used in the chat line.
|
||||||
- Closes: https://github.com/TownyAdvanced/Towny/issues/3960
|
- Closes: https://github.com/TownyAdvanced/Towny/issues/3960
|
||||||
|
- People spying on chat will now see the chat formatted differently from normal.
|
||||||
|
- De-clutters the chat.
|
||||||
|
- Closes: https://github.com/TownyAdvanced/Towny/issues/2665
|
||||||
@@ -19,6 +19,7 @@ import com.palmergames.bukkit.util.Colors;
|
|||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
|
||||||
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.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.dynmap.DynmapAPI;
|
import org.dynmap.DynmapAPI;
|
||||||
@@ -78,7 +79,6 @@ public class StandardChannel extends Channel {
|
|||||||
}
|
}
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
Format = ChatSettings.getRelevantFormatGroup(player).getTOWN();
|
||||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(town)));
|
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(town)));
|
||||||
recipients = checkSpying(recipients);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NATION:
|
case NATION:
|
||||||
@@ -88,7 +88,6 @@ public class StandardChannel extends Channel {
|
|||||||
}
|
}
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
Format = ChatSettings.getRelevantFormatGroup(player).getNATION();
|
||||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(nation)));
|
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayers(nation)));
|
||||||
recipients = checkSpying(recipients);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALLIANCE:
|
case ALLIANCE:
|
||||||
@@ -98,7 +97,6 @@ public class StandardChannel extends Channel {
|
|||||||
}
|
}
|
||||||
Format = ChatSettings.getRelevantFormatGroup(player).getALLIANCE();
|
Format = ChatSettings.getRelevantFormatGroup(player).getALLIANCE();
|
||||||
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayersAlliance(nation)));
|
recipients = new HashSet<>(findRecipients(player, TownyAPI.getInstance().getOnlinePlayersAlliance(nation)));
|
||||||
recipients = checkSpying(recipients);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
@@ -186,8 +184,12 @@ public class StandardChannel extends Channel {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendSpyMessage(event, exec);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the distance between players and return a result based upon the range setting
|
* Check the distance between players and return a result based upon the range setting
|
||||||
* -1 = no limit
|
* -1 = no limit
|
||||||
@@ -239,10 +241,9 @@ public class StandardChannel extends Channel {
|
|||||||
if (TownyUniverse.getInstance().getPermissionSource().has(test, getPermission())) {
|
if (TownyUniverse.getInstance().getPermissionSource().has(test, getPermission())) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the player is within range for this channel
|
* If the player is within range for this channel.
|
||||||
* or the recipient has the spy mode.
|
|
||||||
*/
|
*/
|
||||||
if ((testDistance(sender, test, getRange())) || (plugin.getTowny().hasPlayerMode(test, "spy"))) {
|
if (testDistance(sender, test, getRange())){
|
||||||
|
|
||||||
if (bEssentials) {
|
if (bEssentials) {
|
||||||
try {
|
try {
|
||||||
@@ -275,6 +276,64 @@ public class StandardChannel extends Channel {
|
|||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends messages to spies who have not already seen the message naturally.
|
||||||
|
*
|
||||||
|
* @param event - Chat Event.
|
||||||
|
* @param type - Channel Type
|
||||||
|
*/
|
||||||
|
private void sendSpyMessage(AsyncPlayerChatEvent event, channelTypes type) {
|
||||||
|
Set<Player> recipients = new HashSet<>();
|
||||||
|
Set<Player> spies = new HashSet<>();
|
||||||
|
|
||||||
|
recipients.addAll(event.getRecipients());
|
||||||
|
spies = checkSpying(spies);
|
||||||
|
String format = formatSpyMessage(type, event.getPlayer());
|
||||||
|
|
||||||
|
// Remove spies who've already seen the message naturally.
|
||||||
|
for (Player spy : spies)
|
||||||
|
if (recipients.contains(spy))
|
||||||
|
spies.remove(spy);
|
||||||
|
else
|
||||||
|
spy.sendMessage(ChatColor.GOLD + "[SPY] " + ChatColor.WHITE + format + ": " + event.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats look of message for spies
|
||||||
|
*
|
||||||
|
* @param type - Channel Type.
|
||||||
|
* @param player - Player who chatted.
|
||||||
|
* @return format - Message format.
|
||||||
|
*/
|
||||||
|
private String formatSpyMessage(channelTypes type, Player player) {
|
||||||
|
Resident resident = null;
|
||||||
|
Town town = null;
|
||||||
|
Nation nation = null;
|
||||||
|
try {
|
||||||
|
resident = TownyUniverse.getInstance().getDataSource().getResident(player.getName());
|
||||||
|
town = resident.getTown();
|
||||||
|
nation = resident.getTown().getNation();
|
||||||
|
} catch (NotRegisteredException e1) {
|
||||||
|
// Not in a town/nation (doesn't matter which)
|
||||||
|
}
|
||||||
|
String format = ChatColor.translateAlternateColorCodes('&', getChannelTag());
|
||||||
|
switch (type) {
|
||||||
|
case TOWN:
|
||||||
|
format = format + " [" + town.getName() + "] " + resident.getName();
|
||||||
|
break;
|
||||||
|
case NATION:
|
||||||
|
case ALLIANCE:
|
||||||
|
format = format + " [" + nation.getName() + "] " + resident.getName();
|
||||||
|
break;
|
||||||
|
case GLOBAL:
|
||||||
|
case PRIVATE:
|
||||||
|
case DEFAULT:
|
||||||
|
format = format + " " + resident.getName();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all spying players to the recipients list.
|
* Add all spying players to the recipients list.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user