Force remove player attachments on disconnect, and tidyup during player

join in case of any errors. Fixes a bug of losing permissions.
This commit is contained in:
ElgarL 2012-04-01 03:44:37 +01:00
parent 590357004d
commit 3f73272524
2 changed files with 40 additions and 2 deletions

View File

@ -156,4 +156,5 @@ v 1.9:
- Auto rename all case sensitive world folders to lower case (if possible).
- Update GlobalGroups.yml for new/changed Towny permission nodes.
- Stop attempting to push empty permissions when players edit the yml's incorrectly.
- Catch errors caused by bad indentation in yml's.
- Catch errors caused by bad indentation in yml's.
- Force remove player attachments on disconnect, and tidyup during player join in case of any errors. Fixes a bug of losing permissions.

View File

@ -38,6 +38,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.permissions.Permission;
@ -342,6 +343,18 @@ public class BukkitPermissions {
if (player != null)
this.updatePermissions(player, null);
}
/**
* Force remove any attachments
*
* @param player
*/
private void removeAttachment(Player player) {
if (attachments.containsKey(player)) {
player.removeAttachment(attachments.get(player));
attachments.remove(player);
}
}
/**
* Player events tracked to cause Superperms updates
@ -355,6 +368,12 @@ public class BukkitPermissions {
public void onPlayerJoin(PlayerJoinEvent event) {
setPlayer_join(true);
Player player = event.getPlayer();
/*
* Tidy up any lose ends
*/
removeAttachment(player);
// force GM to create the player if they are not already listed.
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
setPlayer_join(false);
@ -370,7 +389,25 @@ public class BukkitPermissions {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerKick(PlayerKickEvent event) {
attachments.remove(event.getPlayer());
Player player = event.getPlayer();
/*
* force remove any attachments as bukkit may not
*/
removeAttachment(player);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit(PlayerQuitEvent event) {
if (!GroupManager.isLoaded())
return;
Player player = event.getPlayer();
/*
* force remove any attachments as bukkit may not
*/
removeAttachment(player);
}
}