Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added sync "checker" task to check that the permissions of players ar…

…e correctly set every 10 ticks.

Shouldn't be too much of a performance hit as we're just performing an .equals(String)

@TnT wanna test this one for me?
  • Loading branch information...
commit 54fec0d130bf0d16a630a9e2e6162b2d189717bb 1 parent c745c99
@codename-B authored
View
3  src/de/bananaco/bpermissions/imp/Permissions.java
@@ -33,6 +33,9 @@
@Override
public void onDisable() {
+ // Cancel tasks
+ getServer().getScheduler().cancelTasks(this);
+
super.onDisable();
if(wm != null) {
for(World world : wm.getAllWorlds())
View
11 src/de/bananaco/bpermissions/imp/SuperPermissionHandler.java
@@ -29,6 +29,8 @@
private WorldManager wm = WorldManager.getInstance();
private Map<Player, PermissionAttachment> attachments = new HashMap<Player, PermissionAttachment>();
private Permissions plugin;
+
+ private WorldChecker checker;
private static Field permissions;
@@ -63,6 +65,8 @@ public static void setPermissions(PermissionAttachment att, Map<String, Boolean>
att.getPermissible().recalculatePermissions();
}
+ // Main constructor
+
protected SuperPermissionHandler(Permissions plugin) {
this.plugin = plugin;
// This next bit is simply to make bPermissions.* work with superperms, since I now have my bulk adding, I will concede to this
@@ -70,6 +74,10 @@ protected SuperPermissionHandler(Permissions plugin) {
children.put("bPermissions.admin", true);
Permission permission = new Permission("bPermissions.*", PermissionDefault.OP, children);
plugin.getServer().getPluginManager().addPermission(permission);
+
+ checker = new WorldChecker(plugin.getServer(), this);
+
+ plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, checker, 10, 10);
}
/**
@@ -127,6 +135,9 @@ public void setupPlayer(Player player, World world) {
// Then whack it onto the player
// TODO wait for the bukkit team to get their finger out, we'll use our reflection here!
try {
+ // The world
+ perms.put("world."+player.getWorld().getName(), true);
+ Debugger.log("world."+world.getName()+" set for "+player.getName());
setPermissions(att, perms);
} catch (IllegalArgumentException e) {
e.printStackTrace();
View
65 src/de/bananaco/bpermissions/imp/WorldChecker.java
@@ -0,0 +1,65 @@
+package de.bananaco.bpermissions.imp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.bukkit.Server;
+import org.bukkit.entity.Player;
+
+public class WorldChecker implements Runnable {
+
+ private final Server server;
+ private final SuperPermissionHandler handler;
+
+ private Map<Integer, String> worlds = new HashMap<Integer, String>();
+
+ protected WorldChecker(Server server, SuperPermissionHandler handler) {
+ this.server = server;
+ this.handler = handler;
+ }
+
+ private void update() {
+ Player[] players = server.getOnlinePlayers().clone();
+ for(Player player : players) {
+ if(needsUpdating(player)) {
+ updateEntry(player);
+ handler.setupPlayer(player.getName());
+ Debugger.log(player.getName()+" updated via the WorldChecker sync task");
+ }
+ }
+ }
+
+ private boolean hasEntry(Player player) {
+ return worlds.containsKey(player.hashCode());
+ }
+
+ private boolean needsUpdating(Player player) {
+ if(!player.isPermissionSet("world."+player.getWorld().getName())) {
+ Debugger.log("Wrong world set!");
+ return true;
+ }
+ if(!hasEntry(player)) {
+ Debugger.log("First entry created!");
+ return true;
+ }
+ if(getEntry(player).equals(player.getWorld().getName())) {
+ return false;
+ }
+ Debugger.log("Unknown error!");
+ return true;
+ }
+
+ private String getEntry(Player player) {
+ return worlds.get(player.hashCode());
+ }
+
+ private void updateEntry(Player player) {
+ worlds.put(player.hashCode(), player.getWorld().getName());
+ }
+
+ @Override
+ public void run() {
+ update();
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.