Add auto-op. Closes #8
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user