diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index 21f9e5ba3..879bcb201 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -90,6 +90,8 @@ class BukkitListener extends AbstractListener implements Listener { t.printStackTrace(); } + + if (player.isOp()) { // We assume all users are not op, but those who are need extra calculation. diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index f75c45934..9792974ab 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.LuckPermsApi; import me.lucko.luckperms.api.PlatformType; +import me.lucko.luckperms.bukkit.calculators.AutoOPListener; import me.lucko.luckperms.bukkit.calculators.DefaultsProvider; import me.lucko.luckperms.bukkit.vault.VaultHook; import me.lucko.luckperms.common.LuckPermsPlugin; @@ -134,6 +135,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { contextManager.registerCalculator(worldCalculator); contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer())); + if (getConfiguration().isAutoOp()) { + contextManager.registerListener(new AutoOPListener()); + } + int mins = getConfiguration().getSyncTime(); if (mins > 0) { long ticks = mins * 60 * 20; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java index 12e7c06e0..4a9baa1cf 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java @@ -32,6 +32,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerLoginEvent; import java.util.Map; import java.util.UUID; @@ -77,6 +78,15 @@ public class WorldCalculator extends ContextCalculator implements Listen return plugin.getConfiguration().getWorldRewrites().getOrDefault(world, world); } + @EventHandler(priority = EventPriority.LOW) + public void onPlayerJoin(PlayerLoginEvent e) { + pushUpdate( + e.getPlayer(), + Maps.immutableEntry(WORLD_KEY, null), + Maps.immutableEntry(WORLD_KEY, e.getPlayer().getWorld().getName()) + ); + } + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerChangedWorld(PlayerChangedWorldEvent e) { UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java new file mode 100644 index 000000000..b01008e60 --- /dev/null +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.bukkit.calculators; + +import me.lucko.luckperms.api.context.ContextListener; +import me.lucko.luckperms.bukkit.inject.Injector; +import me.lucko.luckperms.bukkit.inject.LPPermissible; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class AutoOPListener implements ContextListener { + + @Override + public void onContextChange(Player subject, Map.Entry before, Map.Entry current) throws Exception { + LPPermissible permissible = Injector.getPermissible(subject.getUniqueId()); + if (permissible == null) { + return; + } + + Map backing = permissible.getUser().getUserData().getPermissionData(permissible.calculateContexts()).getImmutableBacking(); + boolean op = backing.containsKey("luckperms.autoop") && backing.get("luckperms.autoop"); + subject.setOp(op); + } + +} diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java index 50905abfa..0bec27eb6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/LPPermissible.java @@ -40,7 +40,7 @@ import java.util.stream.Collectors; /** * Modified PermissibleBase for LuckPerms */ -public class LPPermissible extends PermissibleBase { // TODO autoop stuff +public class LPPermissible extends PermissibleBase { @Getter private final User user; @@ -64,7 +64,7 @@ public class LPPermissible extends PermissibleBase { // TODO autoop stuff recalculatePermissions(); } - private Contexts calculateContexts() { + public Contexts calculateContexts() { return new Contexts( plugin.getContextManager().giveApplicableContext(parent, new HashMap<>()), plugin.getConfiguration().isIncludingGlobalPerms(), diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index c10b95cef..6efb27c92 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -35,7 +35,6 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import net.milkbowl.vault.permission.Permission; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -198,7 +197,7 @@ public class VaultPermissionHook extends Permission { if (group == null) return false; // This is a nasty call. Groups aren't cached. :( - Map permissions = group.exportNodes(createContext(server, world), Collections.emptyList(), true); + Map permissions = group.exportNodes(createContext(server, world), true); return permissions.containsKey(permission) && permissions.get(permission); } diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 417ab38a1..3a3e27438 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -67,6 +67,10 @@ enable-ops: true # 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 important to note that this setting is only checked when a player first joins the server, and when they switch +# worlds. Therefore, simply removing this permission from a user will not automatically de-op them. A player needs to +# relog to have the change take effect. +# # It is recommended that you use this option instead of assigning a single '*' permission. auto-op: false diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java index 797d4eaf9..9e90824ed 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java @@ -247,7 +247,7 @@ public class PermissionHolderLink implements PermissionHolder { if (world != null && !world.equals("")) { context.put("world", world); } - return master.exportNodes(new Contexts(context, true, true, true, true, true), Collections.emptyList(), false); + return master.exportNodes(new Contexts(context, true, true, true, true, true), false); } @Override @@ -259,7 +259,7 @@ public class PermissionHolderLink implements PermissionHolder { if (world != null && !world.equals("")) { context.put("world", world); } - return master.exportNodes(new Contexts(context, true, true, true, true, true), Collections.emptyList(), false); + return master.exportNodes(new Contexts(context, true, true, true, true, true), false); } @Override @@ -283,7 +283,7 @@ public class PermissionHolderLink implements PermissionHolder { if (world != null && !world.equals("")) { extraContext.put("world", world); } - return master.exportNodes(new Contexts(extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes, false); + return master.exportNodes(new Contexts(extraContext, includeGlobal, includeGlobal, applyGroups, true, true), false); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java b/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java index 967148fd4..0fd7380f7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/UserData.java @@ -27,7 +27,6 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.users.User; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -50,7 +49,7 @@ public class UserData { public PermissionData calculatePermissions(Contexts contexts) { PermissionData data = new PermissionData(contexts, user, calculatorFactory); - data.setPermissions(user.exportNodes(contexts, Collections.emptyList(), true)); + data.setPermissions(user.exportNodes(contexts, true)); return data; } @@ -60,7 +59,7 @@ public class UserData { data = new PermissionData(c, user, calculatorFactory); } - data.comparePermissions(user.exportNodes(c, Collections.emptyList(), true)); + data.comparePermissions(user.exportNodes(c, true)); return data; }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java index 294fa277c..ffcd6fc01 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/PermissionHolder.java @@ -455,23 +455,15 @@ public abstract class PermissionHolder { } /** - * Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands wildcards/regex/shorthand perms + * Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands shorthand perms * @param context the context for this request - * @param possibleNodes a list of possible nodes for wildcards and regex permissions * @return a map of permissions */ - public Map exportNodes(Contexts context, List possibleNodes, boolean lowerCase) { + public Map exportNodes(Contexts context, boolean lowerCase) { Map perms = new HashMap<>(); for (LocalizedNode ln : getAllNodesFiltered(context)) { Node node = ln.getNode(); - if (possibleNodes != null && !possibleNodes.isEmpty()) { - if (node.getPermission().equals("*") || node.getPermission().equals("'*'")) { - if (plugin.getConfiguration().isApplyingWildcards()) { - possibleNodes.forEach(n -> perms.put(lowerCase ? n.toLowerCase() : n, true)); - } - } - } perms.put(lowerCase ? node.getPermission().toLowerCase() : node.getPermission(), node.getValue()); @@ -481,15 +473,6 @@ public abstract class PermissionHolder { .filter(s -> !perms.containsKey(s)) .forEach(s -> perms.put(s, node.getValue())); } - - if (possibleNodes != null && !possibleNodes.isEmpty()) { - if (plugin.getConfiguration().isApplyingWildcards()) { - node.resolveWildcard(possibleNodes).stream() - .map(s -> lowerCase ? s.toLowerCase() : s) - .filter(s -> !perms.containsKey(s)) - .forEach(s -> perms.put(s, node.getValue())); - } - } } return ImmutableMap.copyOf(perms);