Add auto-op. Closes #8

This commit is contained in:
Luck 2016-09-07 23:21:24 +01:00
parent cd6cac1fb6
commit fb0e694155
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 36 additions and 7 deletions

View File

@ -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)));
});

View File

@ -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);
}
}
}

View File

@ -49,6 +49,14 @@ log-notify: true
# If the vanilla OP system is enabled. If set to false, all users will be de-opped, and the op/deop commands will be disabled.
enable-ops: true
# If set to true, any user with the permission "luckperms.autoop" will automatically be granted server operator status.
# This permission can be inherited, or set on specific servers/worlds, temporarily, etc.
# Additionally, setting this to true will force the "enable-ops" option above to false. All users will be de-opped unless
# they have the permission node, and the op/deop commands will be disabled.
#
# It is recommended that you use this option instead of assigning a single '*' permission.
auto-op: false
# If opped players should be allowed to use LuckPerms commands. Set to false to only allow users who have the permissions access to the commands
commands-allow-op: true

View File

@ -112,13 +112,17 @@ public abstract class LPConfiguration<T extends LuckPermsPlugin> {
}
public boolean getEnableOps() {
return getBoolean("enable-ops", true);
return !getAutoOp() && getBoolean("enable-ops", true);
}
public boolean getCommandsAllowOp() {
return getBoolean("commands-allow-op", true);
}
public boolean getAutoOp() {
return getBoolean("auto-op", false);
}
public String getVaultServer() {
return getString("vault-server", "global");
}