mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 14:38:57 +00:00
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.
This commit is contained in:
1 parent
fecf3035a3
commit
44978325e5
7 files changed
+101
-29
No files matched your search
@@ -7,7 +7,7 @@
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>TownyChat</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.84</version>
|
||||
<version>0.85</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
@@ -74,7 +74,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.TownyAdvanced</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>0.96.3.0</version>
|
||||
<version>0.96.5.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -355,4 +355,10 @@ v0.84:
|
||||
- Allow hex colour codes to be used in the messagecolour options channels.yml.
|
||||
- Closes https://github.com/TownyAdvanced/Towny/issues/4087.
|
||||
- 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 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;
|
||||
boolean chatConfigError = false;
|
||||
boolean channelsConfigError = false;
|
||||
@@ -62,7 +62,7 @@ public class Chat extends JavaPlugin {
|
||||
loadConfigs();
|
||||
|
||||
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);
|
||||
return;
|
||||
} 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"));
|
||||
for (Map.Entry<String, Channel> channel : chanList.entrySet()) {
|
||||
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"));
|
||||
} else {
|
||||
/*if (!plugin.getTowny().isPermissions()
|
||||
|| ( (plugin.getTowny().isPermissions())
|
||||
&& (TownyUniverse.getPermissionSource().has(player, channel.getValue().getPermission()))
|
||||
|| (channel.getValue().getPermission().isEmpty()))) {*/
|
||||
else
|
||||
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 (!chan.leave(player.getName())) {
|
||||
if (!chan.leave(player)) {
|
||||
TownyMessaging.sendMessage(player, Translation.of("tc_you_already_left_channel", chan.getName()));
|
||||
return;
|
||||
}
|
||||
@@ -385,7 +379,7 @@ public class ChannelCommand extends BaseCommand implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!chan.join(player.getName())) {
|
||||
if (!chan.join(player)) {
|
||||
TownyMessaging.sendMessage(player, Translation.of("tc_you_are_already_in_channel", chan.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
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.metadata.CustomDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.StringDataField;
|
||||
|
||||
public abstract class Channel {
|
||||
|
||||
@@ -120,33 +124,38 @@ public abstract class Channel {
|
||||
/*
|
||||
* 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 not auto join, they will marked as absent
|
||||
if (playerIgnoringThisChannel(player))
|
||||
return;
|
||||
|
||||
if (autojoin) {
|
||||
join(name);
|
||||
join(player);
|
||||
} else {
|
||||
leave(name);
|
||||
leave(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Mark a player as having left chat
|
||||
*/
|
||||
public boolean leave(String name) {
|
||||
public boolean leave(Player player) {
|
||||
if (absentPlayers == null) {
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark a player has having joined the chat
|
||||
*/
|
||||
public boolean join(String name) {
|
||||
public boolean join(Player player) {
|
||||
if (absentPlayers == null) return false;
|
||||
Integer res = absentPlayers.remove(name);
|
||||
Integer res = absentPlayers.remove(player.getName());
|
||||
playerRemoveIgnoreMeta(player);
|
||||
return (res != null && res == 1);
|
||||
}
|
||||
|
||||
@@ -274,5 +283,67 @@ public abstract class Channel {
|
||||
}
|
||||
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
|
||||
// tell the channel to add the player back
|
||||
if (isAbsent(player.getName())) {
|
||||
join(player.getName());
|
||||
join(player);
|
||||
notifyjoin = true;
|
||||
Bukkit.getPluginManager().callEvent(new PlayerJoinChatChannelEvent(player, this));
|
||||
}
|
||||
|
||||
@@ -37,12 +37,14 @@ public class TownyChatPlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String name = player.getName();
|
||||
|
||||
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 not auto join, they will marked as absent
|
||||
// TODO: Only do this for channels the user has permissions for
|
||||
channel.forgetPlayer(name);
|
||||
channel.forgetPlayer(player);
|
||||
}
|
||||
Channel channel = plugin.getChannelsHandler().getDefaultChannel();
|
||||
if (channel != null) {
|
||||
@@ -58,11 +60,10 @@ public class TownyChatPlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
String name = event.getPlayer().getName();
|
||||
for (Channel channel : plugin.getChannelsHandler().getAllChannels().values()) {
|
||||
// If the channel is auto join, they will be added
|
||||
// If the channel is not auto join, they will marked as absent
|
||||
channel.forgetPlayer(name);
|
||||
channel.forgetPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user