mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-21 02:42:01 +00:00
Stop force removing attachments and let Bukkit handle it's own mess.
This commit is contained in:
parent
72015d42fc
commit
a46497255e
|
@ -187,4 +187,5 @@ v 2.0:
|
||||||
- Only output a Data update message if something has changed.
|
- Only output a Data update message if something has changed.
|
||||||
- Fix loading users with only numerals in their names to be seen as strings.
|
- Fix loading users with only numerals in their names to be seen as strings.
|
||||||
- Ignore any sub folders in the Worlds folder which start with a period (fix for storing data in svn respoitories).
|
- Ignore any sub folders in the Worlds folder which start with a period (fix for storing data in svn respoitories).
|
||||||
- Throw a better error than 'null' when someone removes all groups from a yml.
|
- Throw a better error than 'null' when someone removes all groups from a yml.
|
||||||
|
- Stop force removing attachments and let Bukkit handle it's own mess.
|
|
@ -21,7 +21,6 @@ import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,7 +39,6 @@ import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
@ -57,7 +55,7 @@ import org.bukkit.plugin.PluginManager;
|
||||||
*/
|
*/
|
||||||
public class BukkitPermissions {
|
public class BukkitPermissions {
|
||||||
|
|
||||||
protected WeakHashMap<Player, PermissionAttachment> attachments = new WeakHashMap<Player, PermissionAttachment>();
|
protected WeakHashMap<String, PermissionAttachment> attachments = new WeakHashMap<String, PermissionAttachment>();
|
||||||
protected LinkedHashMap<String, Permission> registeredPermissions = new LinkedHashMap<String, Permission>();
|
protected LinkedHashMap<String, Permission> registeredPermissions = new LinkedHashMap<String, Permission>();
|
||||||
protected GroupManager plugin;
|
protected GroupManager plugin;
|
||||||
protected boolean dumpAllPermissions = true;
|
protected boolean dumpAllPermissions = true;
|
||||||
|
@ -146,19 +144,21 @@ public class BukkitPermissions {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String name = player.getName();
|
||||||
|
|
||||||
// Reset the User objects player reference.
|
// Reset the User objects player reference.
|
||||||
User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName());
|
User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
user.updatePlayer(player);
|
user.updatePlayer(player);
|
||||||
|
|
||||||
PermissionAttachment attachment;
|
PermissionAttachment attachment;
|
||||||
|
|
||||||
// Find the players current attachment, or add a new one.
|
// Find the players current attachment, or add a new one.
|
||||||
if (this.attachments.containsKey(player)) {
|
if (this.attachments.containsKey(name)) {
|
||||||
attachment = this.attachments.get(player);
|
attachment = this.attachments.get(name);
|
||||||
} else {
|
} else {
|
||||||
attachment = player.addAttachment(plugin);
|
attachment = player.addAttachment(plugin);
|
||||||
this.attachments.put(player, attachment);
|
this.attachments.put(name, attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
|
@ -167,7 +167,7 @@ public class BukkitPermissions {
|
||||||
|
|
||||||
// Add all permissions for this player (GM only)
|
// Add all permissions for this player (GM only)
|
||||||
// child nodes will be calculated by Bukkit.
|
// child nodes will be calculated by Bukkit.
|
||||||
List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(player.getName(), false));
|
List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false));
|
||||||
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
|
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
|
||||||
|
|
||||||
// Sort the perm list by parent/child, so it will push to superperms correctly.
|
// Sort the perm list by parent/child, so it will push to superperms correctly.
|
||||||
|
@ -192,13 +192,15 @@ public class BukkitPermissions {
|
||||||
// Then whack our map into there
|
// Then whack our map into there
|
||||||
orig.putAll(newPerms);
|
orig.putAll(newPerms);
|
||||||
// That's all folks!
|
// That's all folks!
|
||||||
//attachment.getPermissible().recalculatePermissions();
|
attachment.getPermissible().recalculatePermissions();
|
||||||
player.recalculatePermissions();
|
//player.recalculatePermissions();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GroupManager.logger.finest("Attachment updated for: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -373,19 +375,10 @@ public class BukkitPermissions {
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
private void removeAttachment(Player player) {
|
private void removeAttachment(String playerName) {
|
||||||
|
|
||||||
if (attachments.containsKey(player)) {
|
if (attachments.containsKey(playerName))
|
||||||
try {
|
attachments.remove(playerName);
|
||||||
player.removeAttachment(attachments.get(player));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
/*
|
|
||||||
* Failed to remove attachment
|
|
||||||
* This usually means Bukkit no longer knows of it.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
attachments.remove(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -393,19 +386,6 @@ public class BukkitPermissions {
|
||||||
*/
|
*/
|
||||||
public void removeAllAttachments() {
|
public void removeAllAttachments() {
|
||||||
|
|
||||||
Iterator<Player> itr = attachments.keySet().iterator();
|
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
Player player = itr.next();
|
|
||||||
try {
|
|
||||||
player.removeAttachment(attachments.get(player));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
/*
|
|
||||||
* Failed to remove attachment
|
|
||||||
* This usually means Bukkit no longer knows of it.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
attachments.clear();
|
attachments.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,13 +400,17 @@ public class BukkitPermissions {
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setPlayer_join(true);
|
setPlayer_join(true);
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
GroupManager.logger.finest("Player Join event: " + player.getName());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tidy up any lose ends
|
* Tidy up any lose ends
|
||||||
*/
|
*/
|
||||||
removeAttachment(player);
|
removeAttachment(player.getName());
|
||||||
|
|
||||||
// force GM to create the player if they are not already listed.
|
// force GM to create the player if they are not already listed.
|
||||||
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
||||||
|
@ -442,18 +426,10 @@ public class BukkitPermissions {
|
||||||
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
|
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
/*
|
||||||
public void onPlayerKick(PlayerKickEvent event) {
|
* Trigger at highest so we tidy up last.
|
||||||
|
*/
|
||||||
Player player = event.getPlayer();
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
|
||||||
/*
|
|
||||||
* force remove any attachments as bukkit may not
|
|
||||||
*/
|
|
||||||
removeAttachment(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
|
||||||
if (!GroupManager.isLoaded())
|
if (!GroupManager.isLoaded())
|
||||||
|
@ -464,7 +440,7 @@ public class BukkitPermissions {
|
||||||
/*
|
/*
|
||||||
* force remove any attachments as bukkit may not
|
* force remove any attachments as bukkit may not
|
||||||
*/
|
*/
|
||||||
removeAttachment(player);
|
removeAttachment(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue