mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 06:28:58 +00:00
- Update min. Towny version to 0.98.3.0.
- Make the alone message respect people's vanished status.
- Closes https://github.com/TownyAdvanced/Towny/issues/6194
This commit is contained in:
1 parent
60d2af7361
commit
e256df5020
7 files changed
+40
-49
No files matched your search
@@ -74,7 +74,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.TownyAdvanced</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>0.97.5.0</version>
|
||||
<version>0.98.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -408,4 +408,7 @@ v0.96:
|
||||
- Closes https://github.com/TownyAdvanced/Towny/issues/5802
|
||||
v0.97:
|
||||
- Replace % when it is found in the channel formats.
|
||||
- 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.
|
||||
- Make the alone message respect people's vanished status.
|
||||
- Closes https://github.com/TownyAdvanced/Towny/issues/6194
|
||||
@@ -50,7 +50,7 @@ public class Chat extends JavaPlugin {
|
||||
private Towny towny = null;
|
||||
private DynmapAPI dynMap = null;
|
||||
|
||||
private static Version requiredTownyVersion = Version.fromString("0.97.5.0");
|
||||
private static Version requiredTownyVersion = Version.fromString("0.98.3.0");
|
||||
public static boolean usingPlaceholderAPI = false;
|
||||
public static boolean usingEssentialsDiscord = false;
|
||||
boolean chatConfigError = false;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.palmergames.bukkit.TownyChat;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||
import com.palmergames.bukkit.TownyChat.util.StringReplaceManager;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownySettings;
|
||||
import com.palmergames.bukkit.towny.object.Government;
|
||||
@@ -203,17 +202,13 @@ public class TownyChatFormatter {
|
||||
|
||||
}
|
||||
|
||||
public static String hexIfCompatible(String str) {
|
||||
if (Towny.is116Plus()) {
|
||||
return HexFormatter.translateHexColors(str);
|
||||
}
|
||||
|
||||
return str;
|
||||
public static String hex(String str) {
|
||||
return HexFormatter.translateHexColors(str);
|
||||
}
|
||||
|
||||
public static String getChatFormat(LocalTownyChatEvent event) {
|
||||
// Replace the {msg} here so it's not regex parsed.
|
||||
return hexIfCompatible(replacer.replaceAll(event.getFormat(), event).replace("%", "").replace("{modplayername}", "%1$s").replace("{msg}", "%2$s"));
|
||||
return hex(replacer.replaceAll(event.getFormat(), event).replace("%", "").replace("{modplayername}", "%1$s").replace("{msg}", "%2$s"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,11 +275,11 @@ public class TownyChatFormatter {
|
||||
if (resident.hasTown()) {
|
||||
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
|
||||
if (full)
|
||||
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(town)));
|
||||
return hex(String.format(ChatSettings.getTownTag(), getName(town)));
|
||||
else if (town.hasTag())
|
||||
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getTag(town)));
|
||||
return hex(String.format(ChatSettings.getTownTag(), getTag(town)));
|
||||
else if (override)
|
||||
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(town)));
|
||||
return hex(String.format(ChatSettings.getTownTag(), getName(town)));
|
||||
|
||||
}
|
||||
return "";
|
||||
@@ -294,11 +289,11 @@ public class TownyChatFormatter {
|
||||
if (resident.hasNation()) {
|
||||
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
|
||||
if (full)
|
||||
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(nation)));
|
||||
return hex(String.format(ChatSettings.getNationTag(), getName(nation)));
|
||||
else if (nation.hasTag())
|
||||
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getTag(nation)));
|
||||
return hex(String.format(ChatSettings.getNationTag(), getTag(nation)));
|
||||
else if (override)
|
||||
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(nation)));
|
||||
return hex(String.format(ChatSettings.getNationTag(), getName(nation)));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ 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.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
@@ -256,12 +255,10 @@ public class StandardChannel extends Channel {
|
||||
* @param playerList
|
||||
* @return Set containing a list of players for this message.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private Set<Player> findRecipients(Player sender, List<Player> playerList) {
|
||||
|
||||
Set<Player> recipients = new HashSet<>();
|
||||
boolean bEssentials = plugin.getTowny().isEssentials();
|
||||
String sendersName = sender.getName();
|
||||
Channel channel = plugin.getChannelsHandler().getChannel(getName());
|
||||
// Compile the list of recipients
|
||||
for (Player player : playerList) {
|
||||
@@ -285,10 +282,11 @@ public class StandardChannel extends Channel {
|
||||
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(sendersName))
|
||||
if (targetUser.isIgnoredPlayer(senderUser))
|
||||
continue;
|
||||
} catch (TownyException e) {
|
||||
// Failed to fetch user so ignore.
|
||||
@@ -306,19 +304,26 @@ public class StandardChannel extends Channel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recipients.size() <= 1 && ChatSettings.isUsingAloneMessage()) {
|
||||
|
||||
String aloneMsg = ChatSettings.getUsingAloneMessageString();
|
||||
if (Towny.is116Plus())
|
||||
aloneMsg = HexFormatter.translateHexColors(aloneMsg);
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', aloneMsg));
|
||||
}
|
||||
|
||||
trySendingAloneMessage(sender, recipients);
|
||||
|
||||
return recipients;
|
||||
}
|
||||
|
||||
|
||||
private void trySendingAloneMessage(Player sender, Set<Player> recipients) {
|
||||
if (ChatSettings.isUsingAloneMessage() &&
|
||||
recipients.stream().filter(p -> sender.canSee(p)).count() < 2) // sender will usually be a recipient of their own message.
|
||||
sender.sendMessage(color(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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages to spies who have not already seen the message naturally.
|
||||
*
|
||||
@@ -357,9 +362,7 @@ public class StandardChannel extends Channel {
|
||||
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
|
||||
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
|
||||
|
||||
String format = ChatColor.translateAlternateColorCodes('&', getChannelTag() != null ? getChannelTag() : getName());
|
||||
if (Towny.is116Plus())
|
||||
format = HexFormatter.translateHexColors(format);
|
||||
String format = color(getChannelTag() != null ? getChannelTag() : getName());
|
||||
|
||||
switch (type) {
|
||||
case TOWN:
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ChatSettings extends tag_formats {
|
||||
|
||||
private static void setWorldDefaults() {
|
||||
if (perWorld()) {
|
||||
for (TownyWorld world : TownyUniverse.getInstance().getDataSource().getWorlds()) {
|
||||
for (TownyWorld world : TownyUniverse.getInstance().getTownyWorlds()) {
|
||||
if (!chatConfig.contains("worlds." + world )
|
||||
|| !chatConfig.contains("worlds." + world + ".global")
|
||||
|| !chatConfig.contains("worlds." + world + ".town")
|
||||
@@ -284,7 +284,7 @@ public class ChatSettings extends tag_formats {
|
||||
|
||||
boolean updated = false;
|
||||
|
||||
for (TownyWorld world : TownyUniverse.getInstance().getDataSource().getWorlds()) {
|
||||
for (TownyWorld world : TownyUniverse.getInstance().getTownyWorlds()) {
|
||||
if (!hasFormatGroup(world.getName())) {
|
||||
addFormatGroup(getFormatGroup("channel_formats").clone(world.getName()));
|
||||
updated = true;
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.palmergames.bukkit.TownyChat.TownyChatFormatter;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.channelTypes;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownyMessaging;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
@@ -104,14 +103,9 @@ public class TownyChatPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if(player.hasPermission("townychat.chat.color")) {
|
||||
event.setMessage(ChatColor.translateAlternateColorCodes('&', event.getMessage()));
|
||||
if(player.hasPermission("townychat.chat.color"))
|
||||
event.setMessage(HexFormatter.translateHexColors(ChatColor.translateAlternateColorCodes('&', event.getMessage())));
|
||||
|
||||
if (Towny.is116Plus()) {
|
||||
event.setMessage(HexFormatter.translateHexColors(event.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if essentials has this player muted.
|
||||
if (!isMuted(player)) {
|
||||
|
||||
@@ -194,11 +188,7 @@ public class TownyChatPlayerListener implements Listener {
|
||||
|
||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||
|
||||
if (Towny.is116Plus()) {
|
||||
event.setFormat(HexFormatter.translateHexColors(TownyChatFormatter.getChatFormat(chatEvent)));
|
||||
} else {
|
||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||
}
|
||||
event.setFormat(HexFormatter.translateHexColors(TownyChatFormatter.getChatFormat(chatEvent)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user