- Fix permission tests being done too early on PlayerJoin.

- Closes https://github.com/TownyAdvanced/Towny/issues/4615
This commit is contained in:
Llm Dl committed 2020-12-21 14:50:45 -06:00
1 parent 99d0433b3e
commit 6b7aeaaf61
3 files changed
+28 -26

No files matched your search

+3 -1
View File
@@ -362,4 +362,6 @@ v0.84:
- Closes https://github.com/TownyAdvanced/Towny/issues/3133.
- Bump minimum Towny version to 0.96.3.0.
v0.85:
- Bump minimum Towny version to 0.96.5.5.
- Bump minimum Towny version to 0.96.5.5.
- Fix permission tests being done too early on PlayerJoin.
- Closes https://github.com/TownyAdvanced/Towny/issues/4615
@@ -125,16 +125,13 @@ public abstract class Channel {
* Used to reset channel settings for a given player
*/
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(player);
} else {
if (playerIgnoringThisChannel(player)
|| !player.hasPermission(getPermission())
|| !autojoin)
leave(player);
}
else
join(player);
}
/*
@@ -145,7 +142,12 @@ public abstract class Channel {
absentPlayers = new ConcurrentHashMap<String, Integer> ();
}
Integer res = absentPlayers.put(player.getName(), 1);
playerAddIgnoreMeta(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))
playerAddIgnoreMeta(player);
return (res == null || res == 0);
}
@@ -13,6 +13,8 @@ import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Translation;
import com.palmergames.bukkit.towny.TownyUniverse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -35,25 +37,21 @@ public class TownyChatPlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event) {
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> loginPlayer(event.getPlayer()), 1l);
}
private void loginPlayer(Player player) {
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
channel.forgetPlayer(player);
}
Channel channel = plugin.getChannelsHandler().getDefaultChannel();
if (channel != null) {
// See if we have permissions for the default channel
channel = plugin.getChannelsHandler().getChannel(player, channel.getCommands().get(0));
if (channel != null) {
// Schedule it as delayed task because Towny may not have processed this just yet
// and would reset the mode otherwise
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new onPlayerJoinTask(plugin, player, channel), 5);
}
if (channel != null && player.hasPermission(channel.getPermission())) {
// Schedule it as delayed task because Towny may not have processed this just yet
// and would reset the mode otherwise
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new onPlayerJoinTask(plugin, player, channel), 5);
}
}