Add auto-op. Closes #8

This commit is contained in:
Luck
2016-09-07 23:21:24 +01:00
Unverified
parent cd6cac1fb6
commit fb0e694155
4 changed files with 36 additions and 7 deletions
@@ -105,11 +105,26 @@ public class BukkitUser extends User {
existing.clear();
existing.putAll(toApply);
boolean op = false;
if (plugin.getConfiguration().getAutoOp()) {
for (Map.Entry<String, Boolean> e : toApply.entrySet()) {
if (e.getKey().equalsIgnoreCase("luckperms.autoop") && e.getValue()) {
op = true;
break;
}
}
}
boolean finalOp = op;
/* Must be called sync, as #recalculatePermissions is an unmodified Bukkit API call that is absolutely not thread safe.
Shouldn't be too taxing on the server. This only gets called when permissions have actually changed,
which is like once per user per login, assuming their permissions don't get modified. */
plugin.doSync(() -> {
attachment.getAttachment().getPermissible().recalculatePermissions();
if (plugin.getConfiguration().getAutoOp()) {
attachment.getAttachment().getPermissible().setOp(finalOp);
}
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
});
@@ -47,14 +47,16 @@ public class BukkitUserManager extends UserManager {
public void preUnload(User user) {
if (user instanceof BukkitUser) {
BukkitUser u = (BukkitUser) user;
if (u.getAttachment() != null) {
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
if (player != null) {
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
if (player != null) {
if (u.getAttachment() != null) {
player.removeAttachment(u.getAttachment().getAttachment());
u.setAttachment(null);
}
if (plugin.getConfiguration().getAutoOp()) {
player.setOp(false);
}
u.setAttachment(null);
}
}
}