- Add persistant leaving for channels.
    - Uses Towny resident metadata, you will be able to see ignored
channels on your /res status screen.
    - Normal joining/leaving commands are used just like before.
    - Closes https://github.com/TownyAdvanced/Towny/issues/3133.
  - Bump minimum Towny version to 0.96.3.0.
This commit is contained in:
Llm Dl committed 2020-12-19 10:08:14 -06:00
1 parent fecf3035a3
commit 44978325e5
7 files changed
+99 -27

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId> <groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId> <artifactId>TownyChat</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.84</version> <version>0.85</version>
<licenses> <licenses>
<license> <license>
@@ -74,7 +74,7 @@
<dependency> <dependency>
<groupId>com.github.TownyAdvanced</groupId> <groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId> <artifactId>Towny</artifactId>
<version>0.96.3.0</version> <version>0.96.5.6</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
+6
View File
@@ -356,3 +356,9 @@ v0.84:
- Closes https://github.com/TownyAdvanced/Towny/issues/4087. - Closes https://github.com/TownyAdvanced/Towny/issues/4087.
- Implemented PlayerJoinChatChannelEvent, courtesy of Glare with PR #32. - Implemented PlayerJoinChatChannelEvent, courtesy of Glare with PR #32.
- Closes https://github.com/TownyAdvanced/Towny/issues/4575. - Closes https://github.com/TownyAdvanced/Towny/issues/4575.
v0.85:
- Add persistant leaving for channels.
- Uses Towny resident metadata, you will be able to see ignored channels on your /res status screen.
- Normal joining/leaving commands are used just like before.
- Closes https://github.com/TownyAdvanced/Towny/issues/3133.
- Bump minimum Towny version to 0.96.3.0.
@@ -45,7 +45,7 @@ public class Chat extends JavaPlugin {
private Towny towny = null; private Towny towny = null;
private DynmapAPI dynMap = null; private DynmapAPI dynMap = null;
private static Version requiredTownyVersion = Version.fromString("0.96.2.17"); private static Version requiredTownyVersion = Version.fromString("0.96.3.0");
public static boolean usingPlaceholderAPI = false; public static boolean usingPlaceholderAPI = false;
boolean chatConfigError = false; boolean chatConfigError = false;
boolean channelsConfigError = false; boolean channelsConfigError = false;
@@ -62,7 +62,7 @@ public class Chat extends JavaPlugin {
loadConfigs(); loadConfigs();
if (!townyVersionCheck(towny.getDescription().getVersion())) { if (!townyVersionCheck(towny.getDescription().getVersion())) {
getLogger().severe("Towny version does not meet required version: " + requiredTownyVersion.toString()); getLogger().severe("Towny version does not meet required minimum version: " + requiredTownyVersion.toString());
this.getServer().getPluginManager().disablePlugin(this); this.getServer().getPluginManager().disablePlugin(this);
return; return;
} else { } else {
@@ -118,16 +118,10 @@ public class ChannelCommand extends BaseCommand implements CommandExecutor {
TownyMessaging.sendMessage(player, Colors.Gold + "Channel" + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_status")); TownyMessaging.sendMessage(player, Colors.Gold + "Channel" + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_status"));
for (Map.Entry<String, Channel> channel : chanList.entrySet()) { for (Map.Entry<String, Channel> channel : chanList.entrySet()) {
if (player.hasPermission(channel.getValue().getPermission())) if (player.hasPermission(channel.getValue().getPermission()))
if (channel.getValue().isPresent(player.getName())) { if (channel.getValue().isPresent(player.getName()))
TownyMessaging.sendMessage(player, Colors.Gold + channel.getKey() + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_in")); TownyMessaging.sendMessage(player, Colors.Gold + channel.getKey() + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_in"));
} else { else
/*if (!plugin.getTowny().isPermissions()
|| ( (plugin.getTowny().isPermissions())
&& (TownyUniverse.getPermissionSource().has(player, channel.getValue().getPermission()))
|| (channel.getValue().getPermission().isEmpty()))) {*/
TownyMessaging.sendMessage(player, Colors.Gold + channel.getKey() + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_out")); TownyMessaging.sendMessage(player, Colors.Gold + channel.getKey() + Colors.Gray + " - " + Colors.LightBlue + Translation.of("tc_channel_list_out"));
//}
}
} }
} }
@@ -319,7 +313,7 @@ public class ChannelCommand extends BaseCommand implements CommandExecutor {
} }
// If we fail you weren't in there to start with // If we fail you weren't in there to start with
if (!chan.leave(player.getName())) { if (!chan.leave(player)) {
TownyMessaging.sendMessage(player, Translation.of("tc_you_already_left_channel", chan.getName())); TownyMessaging.sendMessage(player, Translation.of("tc_you_already_left_channel", chan.getName()));
return; return;
} }
@@ -385,7 +379,7 @@ public class ChannelCommand extends BaseCommand implements CommandExecutor {
return; return;
} }
if (!chan.join(player.getName())) { if (!chan.join(player)) {
TownyMessaging.sendMessage(player, Translation.of("tc_you_are_already_in_channel", chan.getName())); TownyMessaging.sendMessage(player, Translation.of("tc_you_are_already_in_channel", chan.getName()));
return; return;
} }
@@ -10,7 +10,11 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Translation; import com.palmergames.bukkit.towny.object.Translation;
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
import com.palmergames.bukkit.towny.object.metadata.StringDataField;
public abstract class Channel { public abstract class Channel {
@@ -120,33 +124,38 @@ public abstract class Channel {
/* /*
* Used to reset channel settings for a given player * Used to reset channel settings for a given player
*/ */
public void forgetPlayer(String name) { public void forgetPlayer(Player player) {
// If the channel is auto join, they will be added // If the channel is auto join, they will be added
// If the channel is not auto join, they will marked as absent // If the channel is not auto join, they will marked as absent
if (playerIgnoringThisChannel(player))
return;
if (autojoin) { if (autojoin) {
join(name); join(player);
} else { } else {
leave(name); leave(player);
} }
} }
/* /*
* Mark a player as having left chat * Mark a player as having left chat
*/ */
public boolean leave(String name) { public boolean leave(Player player) {
if (absentPlayers == null) { if (absentPlayers == null) {
absentPlayers = new ConcurrentHashMap<String, Integer> (); absentPlayers = new ConcurrentHashMap<String, Integer> ();
} }
Integer res = absentPlayers.put(name, 1); Integer res = absentPlayers.put(player.getName(), 1);
playerAddIgnoreMeta(player);
return (res == null || res == 0); return (res == null || res == 0);
} }
/* /*
* Mark a player has having joined the chat * Mark a player has having joined the chat
*/ */
public boolean join(String name) { public boolean join(Player player) {
if (absentPlayers == null) return false; if (absentPlayers == null) return false;
Integer res = absentPlayers.remove(name); Integer res = absentPlayers.remove(player.getName());
playerRemoveIgnoreMeta(player);
return (res != null && res == 1); return (res != null && res == 1);
} }
@@ -275,4 +284,66 @@ public abstract class Channel {
return false; return false;
} }
private void playerAddIgnoreMeta(Player player) {
StringDataField icdf = new StringDataField("townychat_ignoredChannels", "", "Ignored TownyChat Channels");
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident == null)
return;
if (resident.hasMeta(icdf.getKey())) {
CustomDataField<?> cdf = resident.getMetadata(icdf.getKey());
if (cdf instanceof StringDataField) {
StringDataField sdf = (StringDataField) cdf;
sdf.setValue(sdf.getValue().concat("\uFF0C " + this.getName()));
TownyUniverse.getInstance().getDataSource().saveResident(resident);
}
} else {
resident.addMetaData(new StringDataField("townychat_ignoredChannels", this.getName(), "Ignored TownyChat Channels"));
}
}
private void playerRemoveIgnoreMeta(Player player) {
StringDataField icdf = new StringDataField("townychat_ignoredChannels", "", "Ignored TownyChat Channels");
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident == null || !resident.hasMeta(icdf.getKey()))
return;
CustomDataField<?> cdf = resident.getMetadata(icdf.getKey());
if (cdf instanceof StringDataField) {
StringDataField sdf = (StringDataField) cdf;
String newValues = "";
String[] values = sdf.getValue().split("\uFF0C ");
for (String chanName : values)
if (!chanName.equalsIgnoreCase(this.getName()))
if (newValues.isEmpty())
newValues = chanName;
else
newValues += "\uFF0C " + chanName;
if (!newValues.isEmpty()) {
sdf.setValue(newValues);
TownyUniverse.getInstance().getDataSource().saveResident(resident);
} else {
resident.removeMetaData(icdf);
}
}
}
private boolean playerIgnoringThisChannel(Player player) {
StringDataField idf = new StringDataField("townychat_ignoredChannels", "", "Ignored TownyChat Channels");
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident != null && resident.hasMeta(idf.getKey())) {
CustomDataField<?> cdf = resident.getMetadata(idf.getKey());
if (cdf instanceof StringDataField) {
StringDataField sdf = (StringDataField) cdf;
String[] split = sdf.getValue().split("\uFF0C ");
for (String string : split)
if (string.equalsIgnoreCase(this.getName()))
return true;
}
}
return false;
}
} }
@@ -65,7 +65,7 @@ public class StandardChannel extends Channel {
// If player sends a message to a channel it had left // If player sends a message to a channel it had left
// tell the channel to add the player back // tell the channel to add the player back
if (isAbsent(player.getName())) { if (isAbsent(player.getName())) {
join(player.getName()); join(player);
notifyjoin = true; notifyjoin = true;
Bukkit.getPluginManager().callEvent(new PlayerJoinChatChannelEvent(player, this)); Bukkit.getPluginManager().callEvent(new PlayerJoinChatChannelEvent(player, this));
} }
@@ -37,12 +37,14 @@ public class TownyChatPlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event) { public void onPlayerJoin(final PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName();
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) { for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, channel.getPermission()))
continue;
// If the channel is auto join, they will be added // If the channel is auto join, they will be added
// If the channel is not auto join, they will marked as absent // If the channel is not auto join, they will marked as absent
// TODO: Only do this for channels the user has permissions for channel.forgetPlayer(player);
channel.forgetPlayer(name);
} }
Channel channel = plugin.getChannelsHandler().getDefaultChannel(); Channel channel = plugin.getChannelsHandler().getDefaultChannel();
if (channel != null) { if (channel != null) {
@@ -58,11 +60,10 @@ public class TownyChatPlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerQuit(final PlayerQuitEvent event) { public void onPlayerQuit(final PlayerQuitEvent event) {
String name = event.getPlayer().getName();
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) { for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
// If the channel is auto join, they will be added // If the channel is auto join, they will be added
// If the channel is not auto join, they will marked as absent // If the channel is not auto join, they will marked as absent
channel.forgetPlayer(name); channel.forgetPlayer(event.getPlayer());
} }
} }