Skip to content

Commit

Permalink
Merge pull request #41 from TownyAdvanced/fix/town_chat_limbo
Browse files Browse the repository at this point in the history
Fix a player who has lost their town being stuck in /tc or /nc.
  • Loading branch information
LlmDl authored Jan 3, 2023
2 parents 411b131 + f1db14c commit 261c789
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,5 @@ v0.99:
- Update min. Towny version to 0.98.4.0.
v0.100:
- Use internal Essentials object instead of the one found in Towny.
- Fix incorrect lang string called in /ch mutelist {channelname}
- Fix incorrect lang string called in /ch mutelist {channelname}
- Fix a player who has lost their town being stuck in /tc or /nc.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void parseChannelList(Player player) {
TownyMessaging.sendMessage(player, ChatTools.formatTitle("Channels"));
TownyMessaging.sendMessage(player, Colors.Gold + "Channel" + Colors.Gray + " - " + Colors.LightBlue + translator.of("tc_channel_list_status"));
for (Map.Entry<String, Channel> channel : chanList.entrySet()) {
if (player.hasPermission(channel.getValue().getPermission()))
if (channel.getValue().hasPermission(player))
if (channel.getValue().isPresent(player.getName()))
TownyMessaging.sendMessage(player, Colors.Gold + channel.getKey() + Colors.Gray + " - " + Colors.LightBlue + translator.of("tc_channel_list_in"));
else
Expand Down Expand Up @@ -372,8 +372,7 @@ public static void parseChannelJoin(Player player, String[] split) {
// - channel has no permission set OR [by default they don't]
// - channel has permission set AND:
// - player has channel permission
String joinPerm = chan.getPermission();
if ((joinPerm != null && (!TownyUniverse.getInstance().getPermissionSource().has(player, joinPerm)))) {
if (chan.hasPermission(player)) {
TownyMessaging.sendErrorMsg(player, Translatable.of("tc_err_you_cannot_join_channel", chan.getName()));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.palmergames.bukkit.TownyChat.channels.Channel;
import com.palmergames.bukkit.TownyChat.events.PlayerJoinChatChannelEvent;
import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.object.Translatable;
import com.palmergames.bukkit.util.Colors;
import com.palmergames.util.StringMgmt;
Expand Down Expand Up @@ -46,8 +45,7 @@ public boolean execute(CommandSender commandSender, String label, String[] args)
// - channel has no permission set [by default they don't] OR
// - channel has permission set AND:
// - player has channel permission
String joinPerm = channel.getPermission();
if ((joinPerm != null && !TownyUniverse.getInstance().getPermissionSource().has(player, joinPerm))) {
if (!channel.hasPermission(player)) {
TownyMessaging.sendErrorMsg(player, Translatable.of("tc_err_you_cannot_join_channel", channel.getName()));
return true;
}
Expand All @@ -67,8 +65,7 @@ public boolean execute(CommandSender commandSender, String label, String[] args)
// - channel has no permission set [by default they don't] OR
// - channel has permission set AND:
// - player has channel permission
String joinPerm = channel.getPermission();
if ((joinPerm != null && !TownyUniverse.getInstance().getPermissionSource().has(player, joinPerm))) {
if (!channel.hasPermission(player)) {
TownyMessaging.sendErrorMsg(player, Translatable.of("tc_err_you_cannot_join_channel", channel.getName()));
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/com/palmergames/bukkit/TownyChat/channels/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void setRange(double range) {
public void forgetPlayer(Player player) {

if (playerIgnoringThisChannel(player)
|| !player.hasPermission(getPermission())
|| !hasPermission(player)
|| !autojoin)
leave(player);
else
Expand All @@ -145,7 +145,7 @@ public boolean leave(Player player) {

// If the player could see this channel if they wanted to,
// we know they are ignoring the channel by choice.
if (player.hasPermission(getPermission()) && !playerIgnoringThisChannel(player))
if (hasPermission(player) && !playerIgnoringThisChannel(player))
playerAddIgnoreMeta(player);

return (res == null || res == 0);
Expand Down Expand Up @@ -434,4 +434,7 @@ private boolean playerIgnoringSoundMeta(Player player) {
public boolean isGovernmentChannel() {
return type.equals(channelTypes.TOWN) || type.equals(channelTypes.NATION) || type.equals(channelTypes.ALLIANCE);
}
public boolean hasPermission(Player player) {
return getPermission() != null && TownyUniverse.getInstance().getPermissionSource().has(player, getPermission());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.palmergames.bukkit.TownyChat.channels;

import com.palmergames.bukkit.TownyChat.Chat;
import com.palmergames.bukkit.towny.TownyUniverse;
import org.bukkit.entity.Player;

import java.util.HashMap;
Expand Down Expand Up @@ -110,7 +109,7 @@ public Channel getActiveChannel(Player player, channelTypes type, boolean unlimi
for (Channel channel: channels.values()) {
if (!channel.isPresent(name)) continue;
if (!channel.getType().equals(type)) continue;
if (TownyUniverse.getInstance().getPermissionSource().has(player, channel.getPermission()) || (channel.getPermission().isEmpty())) {
if (channel.hasPermission(player)) {
if (channel.getRange() == -1) {
global = channel;
} else if (channel.getRange() == 0) {
Expand Down Expand Up @@ -148,7 +147,7 @@ public Channel getChannel(Player player, channelTypes type) {

for (Channel channel: channels.values()) {
if (!channel.getType().equals(type)) continue;
if (TownyUniverse.getInstance().getPermissionSource().has(player, channel.getPermission()) || (channel.getPermission().isEmpty())){
if (channel.hasPermission(player)){
if (channel.getRange() == -1) {
global = channel;
} else if (channel.getRange() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ 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.
playerList.stream().forEach(p -> refreshPlayer(this, p));
return playerList.stream()
.filter(p -> TownyUniverse.getInstance().getPermissionSource().has(p, getPermission())) // Check permission.
.filter(p -> hasPermission(p)) // Check permission.
.filter(p -> testDistance(sender, p, getRange())) // Within range.
.filter(p -> !plugin.isIgnoredByEssentials(sender, p)) // Check essentials ignore.
.filter(p -> !isAbsent(p.getName())) // Check if player is purposefully absent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void loginPlayer(Player player) {
refreshPlayerChannels(player);

Channel channel = plugin.getChannelsHandler().getDefaultChannel();
if (channel != null && player.hasPermission(channel.getPermission())) {
if (channel != null && channel.hasPermission(player)) {
plugin.setPlayerChannel(player, channel);
if (ChatSettings.getShowChannelMessageOnServerJoin())
TownyMessaging.sendMessage(player, Translatable.of("tc_you_are_now_talking_in_channel", channel.getName()));
Expand Down Expand Up @@ -97,7 +97,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
* Check the player for any channel modes.
*/
Channel channel = plugin.getPlayerChannel(player);
if (!forceGlobal && channel != null) {
if (!forceGlobal && channel != null && channel.hasPermission(player)) {
if (isMutedOrSpam(event, channel, player))
return;
channel.chatProcess(event);
Expand Down

0 comments on commit 261c789

Please sign in to comment.