mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 03:57:36 +01:00
Reimplement autoop on Bukkit & other misc fixes
This commit is contained in:
parent
699c4d107b
commit
02a75fc32a
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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<Player> 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());
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* 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<Player> {
|
||||
|
||||
@Override
|
||||
public void onContextChange(Player subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception {
|
||||
LPPermissible permissible = Injector.getPermissible(subject.getUniqueId());
|
||||
if (permissible == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Boolean> backing = permissible.getUser().getUserData().getPermissionData(permissible.calculateContexts()).getImmutableBacking();
|
||||
boolean op = backing.containsKey("luckperms.autoop") && backing.get("luckperms.autoop");
|
||||
subject.setOp(op);
|
||||
}
|
||||
|
||||
}
|
@ -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(),
|
||||
|
@ -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<String, Boolean> permissions = group.exportNodes(createContext(server, world), Collections.emptyList(), true);
|
||||
Map<String, Boolean> permissions = group.exportNodes(createContext(server, world), true);
|
||||
|
||||
return permissions.containsKey(permission) && permissions.get(permission);
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
@ -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<String, Boolean> exportNodes(Contexts context, List<String> possibleNodes, boolean lowerCase) {
|
||||
public Map<String, Boolean> exportNodes(Contexts context, boolean lowerCase) {
|
||||
Map<String, Boolean> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user