mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 19:46:32 +01:00
Proper context implementation - WIP
This commit is contained in:
parent
d8221f466a
commit
5ee6db02ff
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
|
import me.lucko.luckperms.api.context.IContextCalculator;
|
||||||
import me.lucko.luckperms.api.event.LPListener;
|
import me.lucko.luckperms.api.event.LPListener;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -218,4 +220,18 @@ public interface LuckPermsApi {
|
|||||||
*/
|
*/
|
||||||
Node.Builder buildNode(String permission) throws IllegalArgumentException;
|
Node.Builder buildNode(String permission) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a custom context calculator to the server
|
||||||
|
* @param contextCalculator the context calculator to register. The type MUST be the player class of the platform.
|
||||||
|
* @throws ClassCastException if the type is not the player class of the platform.
|
||||||
|
*/
|
||||||
|
void registerContextCalculator(IContextCalculator<?> contextCalculator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a custom context listener to the server,
|
||||||
|
* @param contextListener the context listener to register. The type MUST be the player class of the platform.
|
||||||
|
* @throws ClassCastException if the type is not the player class of the platform.
|
||||||
|
*/
|
||||||
|
void registerContextListener(ContextListener<?> contextListener);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,15 @@ public interface Node extends Map.Entry<String, Boolean> {
|
|||||||
boolean shouldApplyOnWorld(String world, boolean includeGlobal, boolean applyRegex);
|
boolean shouldApplyOnWorld(String world, boolean includeGlobal, boolean applyRegex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this node should apply given the specific context
|
* If this node should apply in the given context
|
||||||
|
* @param context the context key value pairs
|
||||||
|
* @param worldAndServer if world and server contexts should be checked
|
||||||
|
* @return true if the node should apply
|
||||||
|
*/
|
||||||
|
boolean shouldApplyWithContext(Map<String, String> context, boolean worldAndServer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this node should apply in the given context
|
||||||
* @param context the context key value pairs
|
* @param context the context key value pairs
|
||||||
* @return true if the node should apply
|
* @return true if the node should apply
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.context;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple implementation of the listener aspects of {@link IContextCalculator<T>}
|
||||||
|
* @param <T> the subject type
|
||||||
|
*/
|
||||||
|
public abstract class ContextCalculator<T> implements IContextCalculator<T> {
|
||||||
|
private final List<ContextListener<T>> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes an update to all registered {@link ContextListener}s.
|
||||||
|
* Make sure any changes are applied internally before this method is called.
|
||||||
|
* @param subject the subject that changed
|
||||||
|
* @param before the context state before the change
|
||||||
|
* @param current the context state after the change (now)
|
||||||
|
* @throws NullPointerException if any parameters are null
|
||||||
|
*/
|
||||||
|
protected void pushUpdate(T subject, Map.Entry<String, String> before, Map.Entry<String, String> current) {
|
||||||
|
if (subject == null) {
|
||||||
|
throw new NullPointerException("subject");
|
||||||
|
}
|
||||||
|
if (before == null) {
|
||||||
|
throw new NullPointerException("before");
|
||||||
|
}
|
||||||
|
if (current == null) {
|
||||||
|
throw new NullPointerException("current");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ContextListener<T> listener : listeners) {
|
||||||
|
try {
|
||||||
|
listener.onContextChange(subject, before, current);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Exception whilst passing context change to listener: " + listener);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addListener(ContextListener<T> listener) {
|
||||||
|
if (listener == null) {
|
||||||
|
throw new NullPointerException("listener");
|
||||||
|
}
|
||||||
|
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.context;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens to context changes
|
||||||
|
* @param <T> the subject type, Is ALWAYS the player class of the platform.
|
||||||
|
*/
|
||||||
|
public interface ContextListener<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever a context changes on the
|
||||||
|
* @param subject the subject that had context changed
|
||||||
|
* @param before the context state before the change
|
||||||
|
* @param current the context state after the change (now)
|
||||||
|
*/
|
||||||
|
void onContextChange(T subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.context;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates whether contexts are applicable to {@link T}
|
||||||
|
*
|
||||||
|
* <p>Somewhat inspired by the system used on Sponge.
|
||||||
|
* @param <T> the subject type. Is ALWAYS the player class of the platform.
|
||||||
|
*/
|
||||||
|
public interface IContextCalculator<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives the subject all of the applicable contexts they meet
|
||||||
|
* @param subject the subject to add contexts tp
|
||||||
|
* @param accumulator a map of contexts to add to
|
||||||
|
* @return the map
|
||||||
|
*/
|
||||||
|
Map<String, String> giveApplicableContext(T subject, Map<String, String> accumulator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a context is applicable to a subject
|
||||||
|
* @param subject the subject to check against
|
||||||
|
* @param context the context to check for
|
||||||
|
* @return true if met, or false if not. If this calculator does not calculate the given context, return false.
|
||||||
|
*/
|
||||||
|
boolean isContextApplicable(T subject, Map.Entry<String, String> context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a listener to be called whenever a context handled by this calculator changes
|
||||||
|
* @param listener the listener instance
|
||||||
|
* @throws NullPointerException if listener is null
|
||||||
|
*/
|
||||||
|
void addListener(ContextListener<T> listener);
|
||||||
|
|
||||||
|
}
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms;
|
package me.lucko.luckperms;
|
||||||
|
|
||||||
import me.lucko.luckperms.core.AbstractConfiguration;
|
import me.lucko.luckperms.config.AbstractConfiguration;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
@ -84,21 +84,13 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
// Refresh permissions again
|
// Refresh permissions again
|
||||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
||||||
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
|
plugin.getWorldCalculator().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
|
||||||
plugin.doAsync(() -> refreshPlayer(internal));
|
plugin.doAsync(() -> refreshPlayer(internal));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
|
|
||||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
|
||||||
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
|
|
||||||
plugin.doAsync(() -> refreshPlayer(internal));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
plugin.getUserManager().getWorldCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
plugin.getWorldCalculator().getWorldCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||||
onLeave(e.getPlayer().getUniqueId());
|
onLeave(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,11 @@ import me.lucko.luckperms.api.implementation.ApiProvider;
|
|||||||
import me.lucko.luckperms.api.vault.VaultHook;
|
import me.lucko.luckperms.api.vault.VaultHook;
|
||||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.contexts.ContextManager;
|
||||||
|
import me.lucko.luckperms.contexts.ServerCalculator;
|
||||||
|
import me.lucko.luckperms.contexts.WorldCalculator;
|
||||||
import me.lucko.luckperms.core.UuidCache;
|
import me.lucko.luckperms.core.UuidCache;
|
||||||
import me.lucko.luckperms.data.Importer;
|
import me.lucko.luckperms.data.Importer;
|
||||||
import me.lucko.luckperms.groups.GroupManager;
|
import me.lucko.luckperms.groups.GroupManager;
|
||||||
@ -72,6 +75,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
private ConsecutiveExecutor consecutiveExecutor;
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
private DefaultsProvider defaultsProvider;
|
private DefaultsProvider defaultsProvider;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private ContextManager<Player> contextManager;
|
||||||
|
private WorldCalculator worldCalculator;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -116,6 +121,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
|
contextManager = new ContextManager<>();
|
||||||
|
worldCalculator = new WorldCalculator(this);
|
||||||
|
pm.registerEvents(worldCalculator, this);
|
||||||
|
contextManager.registerCalculator(worldCalculator);
|
||||||
|
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||||
|
contextManager.registerListener(userManager);
|
||||||
|
|
||||||
int mins = getConfiguration().getSyncTime();
|
int mins = getConfiguration().getSyncTime();
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
long ticks = mins * 60 * 20;
|
long ticks = mins * 60 * 20;
|
||||||
|
@ -26,11 +26,11 @@ import lombok.NonNull;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.lucko.luckperms.LPBukkitPlugin;
|
import me.lucko.luckperms.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.core.PermissionHolder;
|
import me.lucko.luckperms.core.PermissionHolder;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -90,7 +90,7 @@ public class VaultChatHook extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.Builder metaNode = new me.lucko.luckperms.utils.Node.Builder("meta." + node + "." + value).setValue(true);
|
Node.Builder metaNode = new me.lucko.luckperms.core.Node.Builder("meta." + node + "." + value).setValue(true);
|
||||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||||
metaNode.setServer(perms.getServer());
|
metaNode.setServer(perms.getServer());
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ public class VaultChatHook extends Chat {
|
|||||||
if (holder == null) return;
|
if (holder == null) return;
|
||||||
if (value.equals("")) return;
|
if (value.equals("")) return;
|
||||||
|
|
||||||
Node.Builder node = new me.lucko.luckperms.utils.Node.Builder(prefix ? "prefix" : "suffix" + ".1000." + escapeCharacters(value));
|
Node.Builder node = new me.lucko.luckperms.core.Node.Builder(prefix ? "prefix" : "suffix" + ".1000." + escapeCharacters(value));
|
||||||
node.setValue(true);
|
node.setValue(true);
|
||||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||||
node.setServer(perms.getServer());
|
node.setServer(perms.getServer());
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WorldCalculator extends ContextCalculator<Player> implements Listener {
|
||||||
|
private static final String WORLD_KEY = "world";
|
||||||
|
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Map<UUID, String> worldCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> giveApplicableContext(Player subject, Map<String, String> accumulator) {
|
||||||
|
String world = getWorld(subject);
|
||||||
|
|
||||||
|
if (world != null) {
|
||||||
|
accumulator.put(WORLD_KEY, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) {
|
||||||
|
if (!context.getKey().equals(WORLD_KEY)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String world = getWorld(subject);
|
||||||
|
return world != null && world.equals(context.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getWorld(Player player) {
|
||||||
|
UUID internal = plugin.getUuidCache().getUUID(player.getUniqueId());
|
||||||
|
if (!worldCache.containsKey(internal)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String world = worldCache.get(internal);
|
||||||
|
return plugin.getConfiguration().getWorldRewrites().getOrDefault(world, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
|
||||||
|
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
||||||
|
worldCache.put(internal, e.getPlayer().getWorld().getName());
|
||||||
|
pushUpdate(
|
||||||
|
e.getPlayer(),
|
||||||
|
Maps.immutableEntry(WORLD_KEY, e.getFrom().getName()),
|
||||||
|
Maps.immutableEntry(WORLD_KEY, e.getPlayer().getWorld().getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -27,8 +27,8 @@ import lombok.Getter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.utils.PermissionCalculator;
|
import me.lucko.luckperms.calculators.PermissionCalculator;
|
||||||
import me.lucko.luckperms.utils.PermissionProcessor;
|
import me.lucko.luckperms.calculators.PermissionProcessor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.permissions.*;
|
import org.bukkit.permissions.*;
|
||||||
|
@ -27,11 +27,13 @@ import lombok.Setter;
|
|||||||
import me.lucko.luckperms.LPBukkitPlugin;
|
import me.lucko.luckperms.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
||||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.inject.LPPermissible;
|
import me.lucko.luckperms.inject.LPPermissible;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -60,17 +62,14 @@ public class BukkitUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the permissions that should be applied. This is done async, who cares about how long it takes or how often it's done.
|
// Calculate the permissions that should be applied. This is done async, who cares about how long it takes or how often it's done.
|
||||||
String world = plugin.getUserManager().getWorldCache().get(getUuid());
|
|
||||||
Map<String, Boolean> toApply = exportNodes(
|
Map<String, Boolean> toApply = exportNodes(
|
||||||
new Contexts(
|
new Contexts(
|
||||||
getPlugin().getConfiguration().getServer(),
|
plugin.getContextManager().giveApplicableContext((Player) lpPermissible.getParent(), new HashMap<>()),
|
||||||
getPlugin().getConfiguration().getWorldRewrites().getOrDefault(world, world),
|
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||||
null,
|
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||||
getPlugin().getConfiguration().isIncludingGlobalPerms(),
|
|
||||||
getPlugin().getConfiguration().isIncludingGlobalWorldPerms(),
|
|
||||||
true,
|
true,
|
||||||
getPlugin().getConfiguration().isApplyingGlobalGroups(),
|
plugin.getConfiguration().isApplyingGlobalGroups(),
|
||||||
getPlugin().getConfiguration().isApplyingGlobalWorldGroups()
|
plugin.getConfiguration().isApplyingGlobalWorldGroups()
|
||||||
),
|
),
|
||||||
Collections.emptyList()
|
Collections.emptyList()
|
||||||
);
|
);
|
||||||
|
@ -22,23 +22,19 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.users;
|
package me.lucko.luckperms.users;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import me.lucko.luckperms.LPBukkitPlugin;
|
import me.lucko.luckperms.LPBukkitPlugin;
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
import me.lucko.luckperms.inject.Injector;
|
import me.lucko.luckperms.inject.Injector;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BukkitUserManager extends UserManager {
|
public class BukkitUserManager extends UserManager implements ContextListener<Player> {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Map<UUID, String> worldCache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public BukkitUserManager(LPBukkitPlugin plugin) {
|
public BukkitUserManager(LPBukkitPlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -89,4 +85,14 @@ public class BukkitUserManager extends UserManager {
|
|||||||
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u, "null")));
|
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u, "null")));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextChange(Player subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception {
|
||||||
|
UUID internal = plugin.getUuidCache().getUUID(subject.getUniqueId());
|
||||||
|
|
||||||
|
User user = get(internal);
|
||||||
|
if (user != null) {
|
||||||
|
plugin.doAsync(user::refreshPermissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms;
|
package me.lucko.luckperms;
|
||||||
|
|
||||||
import me.lucko.luckperms.core.AbstractConfiguration;
|
import me.lucko.luckperms.config.AbstractConfiguration;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
@ -118,9 +118,4 @@ public class BungeeListener extends AbstractListener implements Listener {
|
|||||||
plugin.getPlayerCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
plugin.getPlayerCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||||
onLeave(e.getPlayer().getUniqueId());
|
onLeave(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerServerSwitch(ServerSwitchEvent e) {
|
|
||||||
refreshPlayer(e.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@
|
|||||||
package me.lucko.luckperms;
|
package me.lucko.luckperms;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.lucko.luckperms.utils.PermissionCalculator;
|
import me.lucko.luckperms.calculators.PermissionCalculator;
|
||||||
import me.lucko.luckperms.utils.PermissionProcessor;
|
import me.lucko.luckperms.calculators.PermissionProcessor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,9 +29,12 @@ import me.lucko.luckperms.api.implementation.ApiProvider;
|
|||||||
import me.lucko.luckperms.commands.CommandManager;
|
import me.lucko.luckperms.commands.CommandManager;
|
||||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.contexts.BackendServerCalculator;
|
||||||
|
import me.lucko.luckperms.contexts.ContextManager;
|
||||||
|
import me.lucko.luckperms.contexts.ServerCalculator;
|
||||||
import me.lucko.luckperms.core.UuidCache;
|
import me.lucko.luckperms.core.UuidCache;
|
||||||
import me.lucko.luckperms.data.Importer;
|
import me.lucko.luckperms.data.Importer;
|
||||||
import me.lucko.luckperms.groups.GroupManager;
|
import me.lucko.luckperms.groups.GroupManager;
|
||||||
@ -41,7 +44,6 @@ import me.lucko.luckperms.storage.Datastore;
|
|||||||
import me.lucko.luckperms.storage.StorageFactory;
|
import me.lucko.luckperms.storage.StorageFactory;
|
||||||
import me.lucko.luckperms.tracks.TrackManager;
|
import me.lucko.luckperms.tracks.TrackManager;
|
||||||
import me.lucko.luckperms.users.BungeeUserManager;
|
import me.lucko.luckperms.users.BungeeUserManager;
|
||||||
import me.lucko.luckperms.users.UserManager;
|
|
||||||
import me.lucko.luckperms.utils.LocaleManager;
|
import me.lucko.luckperms.utils.LocaleManager;
|
||||||
import me.lucko.luckperms.utils.LogFactory;
|
import me.lucko.luckperms.utils.LogFactory;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -58,7 +60,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
private final Map<UUID, BungeePlayerCache> playerCache = new ConcurrentHashMap<>();
|
private final Map<UUID, BungeePlayerCache> playerCache = new ConcurrentHashMap<>();
|
||||||
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
||||||
private LPConfiguration configuration;
|
private LPConfiguration configuration;
|
||||||
private UserManager userManager;
|
private BungeeUserManager userManager;
|
||||||
private GroupManager groupManager;
|
private GroupManager groupManager;
|
||||||
private TrackManager trackManager;
|
private TrackManager trackManager;
|
||||||
private Datastore datastore;
|
private Datastore datastore;
|
||||||
@ -68,6 +70,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
private Importer importer;
|
private Importer importer;
|
||||||
private ConsecutiveExecutor consecutiveExecutor;
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private ContextManager<ProxiedPlayer> contextManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -108,6 +111,13 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
|
contextManager = new ContextManager<>();
|
||||||
|
BackendServerCalculator serverCalculator = new BackendServerCalculator();
|
||||||
|
getProxy().getPluginManager().registerListener(this, serverCalculator);
|
||||||
|
contextManager.registerCalculator(serverCalculator);
|
||||||
|
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||||
|
contextManager.registerListener(userManager);
|
||||||
|
|
||||||
int mins = getConfiguration().getSyncTime();
|
int mins = getConfiguration().getSyncTime();
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES);
|
getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES);
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BackendServerCalculator extends ContextCalculator<ProxiedPlayer> implements Listener {
|
||||||
|
private static final String WORLD_KEY = "world";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> giveApplicableContext(ProxiedPlayer subject, Map<String, String> accumulator) {
|
||||||
|
String server = getServer(subject);
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
accumulator.put(WORLD_KEY, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContextApplicable(ProxiedPlayer subject, Map.Entry<String, String> context) {
|
||||||
|
if (!context.getKey().equals(WORLD_KEY)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String server = getServer(subject);
|
||||||
|
return server != null && server.equals(context.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerServerSwitch(ServerSwitchEvent e) {
|
||||||
|
pushUpdate(e.getPlayer(), Maps.immutableEntry("null", "null"), Maps.immutableEntry(WORLD_KEY, getServer(e.getPlayer())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getServer(ProxiedPlayer player) {
|
||||||
|
return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
||||||
|
}
|
||||||
|
}
|
@ -26,10 +26,11 @@ import me.lucko.luckperms.BungeePlayerCache;
|
|||||||
import me.lucko.luckperms.LPBungeePlugin;
|
import me.lucko.luckperms.LPBungeePlugin;
|
||||||
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
||||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -58,14 +59,10 @@ public class BungeeUser extends User {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String server = player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
|
||||||
|
|
||||||
// Calculate the permissions that should be applied. This is done async.
|
// Calculate the permissions that should be applied. This is done async.
|
||||||
Map<String, Boolean> toApply = exportNodes(
|
Map<String, Boolean> toApply = exportNodes(
|
||||||
new Contexts(
|
new Contexts(
|
||||||
plugin.getConfiguration().getServer(),
|
plugin.getContextManager().giveApplicableContext(player, new HashMap<>()),
|
||||||
plugin.getConfiguration().getWorldRewrites().getOrDefault(server, server),
|
|
||||||
null,
|
|
||||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||||
true,
|
true,
|
||||||
|
@ -23,10 +23,13 @@
|
|||||||
package me.lucko.luckperms.users;
|
package me.lucko.luckperms.users;
|
||||||
|
|
||||||
import me.lucko.luckperms.LPBungeePlugin;
|
import me.lucko.luckperms.LPBungeePlugin;
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BungeeUserManager extends UserManager {
|
public class BungeeUserManager extends UserManager implements ContextListener<ProxiedPlayer> {
|
||||||
private final LPBungeePlugin plugin;
|
private final LPBungeePlugin plugin;
|
||||||
|
|
||||||
public BungeeUserManager(LPBungeePlugin plugin) {
|
public BungeeUserManager(LPBungeePlugin plugin) {
|
||||||
@ -57,4 +60,14 @@ public class BungeeUserManager extends UserManager {
|
|||||||
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
||||||
.forEach(u -> plugin.getDatastore().loadUser(u, "null"));
|
.forEach(u -> plugin.getDatastore().loadUser(u, "null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextChange(ProxiedPlayer subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception {
|
||||||
|
UUID internal = plugin.getUuidCache().getUUID(subject.getUniqueId());
|
||||||
|
|
||||||
|
User user = get(internal);
|
||||||
|
if (user != null) {
|
||||||
|
plugin.doAsync(user::refreshPermissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,9 @@ import me.lucko.luckperms.api.PlatformType;
|
|||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.core.UuidCache;
|
import me.lucko.luckperms.core.UuidCache;
|
||||||
import me.lucko.luckperms.data.Importer;
|
import me.lucko.luckperms.data.Importer;
|
||||||
import me.lucko.luckperms.groups.GroupManager;
|
import me.lucko.luckperms.groups.GroupManager;
|
||||||
@ -62,6 +63,7 @@ public interface LuckPermsPlugin {
|
|||||||
Importer getImporter();
|
Importer getImporter();
|
||||||
ConsecutiveExecutor getConsecutiveExecutor();
|
ConsecutiveExecutor getConsecutiveExecutor();
|
||||||
LocaleManager getLocaleManager();
|
LocaleManager getLocaleManager();
|
||||||
|
ContextManager getContextManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the version of the plugin
|
* @return the version of the plugin
|
||||||
|
@ -27,6 +27,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.api.*;
|
import me.lucko.luckperms.api.*;
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
|
import me.lucko.luckperms.api.context.IContextCalculator;
|
||||||
import me.lucko.luckperms.api.event.LPEvent;
|
import me.lucko.luckperms.api.event.LPEvent;
|
||||||
import me.lucko.luckperms.api.event.LPListener;
|
import me.lucko.luckperms.api.event.LPListener;
|
||||||
import me.lucko.luckperms.api.implementation.internal.*;
|
import me.lucko.luckperms.api.implementation.internal.*;
|
||||||
@ -208,6 +210,18 @@ public class ApiProvider implements LuckPermsApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node.Builder buildNode(@NonNull String permission) throws IllegalArgumentException {
|
public Node.Builder buildNode(@NonNull String permission) throws IllegalArgumentException {
|
||||||
return new me.lucko.luckperms.utils.Node.Builder(checkNode(permission));
|
return new me.lucko.luckperms.core.Node.Builder(checkNode(permission));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void registerContextCalculator(IContextCalculator<?> contextCalculator) {
|
||||||
|
plugin.getContextManager().registerCalculator(contextCalculator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void registerContextListener(ContextListener<?> contextListener) {
|
||||||
|
plugin.getContextManager().registerListener(contextListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,11 @@ import me.lucko.luckperms.api.data.MySQLConfiguration;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.core.LPConfiguration}
|
* Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.config.LPConfiguration}
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class LPConfigurationLink implements LPConfiguration {
|
public class LPConfigurationLink implements LPConfiguration {
|
||||||
private final me.lucko.luckperms.core.LPConfiguration master;
|
private final me.lucko.luckperms.config.LPConfiguration master;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getServer() {
|
public String getServer() {
|
||||||
|
@ -27,9 +27,9 @@ import lombok.NonNull;
|
|||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
import me.lucko.luckperms.api.PermissionHolder;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -253,7 +253,16 @@ public class PermissionHolderLink implements PermissionHolder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups) {
|
public Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups) {
|
||||||
return master.exportNodes(new Contexts(server, world, extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes);
|
if (extraContext == null) {
|
||||||
|
extraContext = new HashMap<>();
|
||||||
|
}
|
||||||
|
if (server != null && !server.equals("")) {
|
||||||
|
extraContext.put("server", server);
|
||||||
|
}
|
||||||
|
if (world != null && !world.equals("")) {
|
||||||
|
extraContext.put("world", world);
|
||||||
|
}
|
||||||
|
return master.exportNodes(new Contexts(extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.utils;
|
package me.lucko.luckperms.calculators;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.utils;
|
package me.lucko.luckperms.calculators;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
|
@ -27,8 +27,8 @@ import me.lucko.luckperms.api.Node;
|
|||||||
import me.lucko.luckperms.commands.*;
|
import me.lucko.luckperms.commands.*;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ import me.lucko.luckperms.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.commands.CommandResult;
|
import me.lucko.luckperms.commands.CommandResult;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ import me.lucko.luckperms.api.Node;
|
|||||||
import me.lucko.luckperms.commands.*;
|
import me.lucko.luckperms.commands.*;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.core;
|
package me.lucko.luckperms.config;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.core;
|
package me.lucko.luckperms.config;
|
||||||
|
|
||||||
import me.lucko.luckperms.storage.DatastoreConfiguration;
|
import me.lucko.luckperms.storage.DatastoreConfiguration;
|
||||||
|
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
|
import me.lucko.luckperms.api.context.IContextCalculator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class ContextManager<T> {
|
||||||
|
|
||||||
|
private final List<IContextCalculator<T>> calculators = new CopyOnWriteArrayList<>();
|
||||||
|
private final List<ContextListener<T>> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
public void registerCalculator(IContextCalculator<T> calculator) {
|
||||||
|
listeners.forEach(calculator::addListener);
|
||||||
|
calculators.add(calculator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerListener(ContextListener<T> listener) {
|
||||||
|
for (IContextCalculator<T> calculator : calculators) {
|
||||||
|
calculator.addListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> giveApplicableContext(T subject, Map<String, String> accumulator) {
|
||||||
|
for (IContextCalculator<T> calculator : calculators) {
|
||||||
|
calculator.giveApplicableContext(subject, accumulator);
|
||||||
|
}
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContextApplicable(T subject, Map.Entry<String, String> context) {
|
||||||
|
for (IContextCalculator<T> calculator : calculators) {
|
||||||
|
if (calculator.isContextApplicable(subject, context)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -20,11 +20,10 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.utils;
|
package me.lucko.luckperms.contexts;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -32,26 +31,11 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class Contexts {
|
public class Contexts {
|
||||||
public static Contexts fromConfig(LPConfiguration configuration) {
|
|
||||||
return new Contexts(
|
|
||||||
configuration.getServer(),
|
|
||||||
null,
|
|
||||||
Collections.emptyMap(),
|
|
||||||
configuration.isIncludingGlobalPerms(),
|
|
||||||
configuration.isIncludingGlobalWorldPerms(),
|
|
||||||
true,
|
|
||||||
configuration.isApplyingGlobalGroups(),
|
|
||||||
configuration.isApplyingGlobalWorldGroups()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Contexts allowAll() {
|
public static Contexts allowAll() {
|
||||||
return new Contexts(null, null, Collections.emptyMap(), true, true, true, true, true);
|
return new Contexts(Collections.emptyMap(), true, true, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String server;
|
private final Map<String, String> context;
|
||||||
private final String world;
|
|
||||||
private final Map<String, String> extraContext;
|
|
||||||
private final boolean includeGlobal;
|
private final boolean includeGlobal;
|
||||||
private final boolean includeGlobalWorld;
|
private final boolean includeGlobalWorld;
|
||||||
private final boolean applyGroups;
|
private final boolean applyGroups;
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ServerCalculator<T> extends ContextCalculator<T> {
|
||||||
|
private final String server;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> giveApplicableContext(T subject, Map<String, String> accumulator) {
|
||||||
|
accumulator.put("server", server);
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContextApplicable(T subject, Map.Entry<String, String> context) {
|
||||||
|
return context.getKey().equals("server") && server.equals(context.getValue());
|
||||||
|
}
|
||||||
|
}
|
@ -20,13 +20,14 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.utils;
|
package me.lucko.luckperms.core;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.constants.Patterns;
|
import me.lucko.luckperms.constants.Patterns;
|
||||||
|
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -100,7 +101,7 @@ public class Node implements me.lucko.luckperms.api.Node {
|
|||||||
|
|
||||||
private long expireAt = 0L;
|
private long expireAt = 0L;
|
||||||
|
|
||||||
private final Map<String, String> extraContexts = new HashMap<>();
|
private final Map<String, String> extraContexts;
|
||||||
|
|
||||||
// Cache the state
|
// Cache the state
|
||||||
private Tristate isPrefix = Tristate.UNDEFINED;
|
private Tristate isPrefix = Tristate.UNDEFINED;
|
||||||
@ -140,9 +141,11 @@ public class Node implements me.lucko.luckperms.api.Node {
|
|||||||
this.server = server;
|
this.server = server;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
|
ImmutableMap.Builder<String, String> contexts = ImmutableMap.builder();
|
||||||
if (extraContexts != null) {
|
if (extraContexts != null) {
|
||||||
this.extraContexts.putAll(extraContexts);
|
contexts.putAll(extraContexts);
|
||||||
}
|
}
|
||||||
|
this.extraContexts = contexts.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -225,36 +228,65 @@ public class Node implements me.lucko.luckperms.api.Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldApplyWithContext(Map<String, String> context) {
|
public boolean shouldApplyWithContext(Map<String, String> context, boolean worldAndServer) {
|
||||||
if (context == null || context.isEmpty()) {
|
if (extraContexts.isEmpty() && !isServerSpecific() && !isWorldSpecific()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> c : context.entrySet()) {
|
if (worldAndServer) {
|
||||||
if (c.getKey().equals("server")) {
|
if (isWorldSpecific()) {
|
||||||
if (shouldApplyOnServer(c.getValue(), false, false)) {
|
if (context == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.containsKey("world")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.get("world").equalsIgnoreCase(world)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.getKey().equals("world")) {
|
if (isServerSpecific()) {
|
||||||
if (shouldApplyOnWorld(c.getValue(), false, false)) {
|
if (context == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.containsKey("server")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.get("server").equalsIgnoreCase(server)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!getExtraContexts().containsKey(c.getKey())) {
|
if (!extraContexts.isEmpty()) {
|
||||||
|
if (context == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getExtraContexts().get(c.getKey()).equalsIgnoreCase(c.getValue())) {
|
for (Map.Entry<String, String> c : extraContexts.entrySet()) {
|
||||||
return false;
|
if (!context.containsKey(c.getKey())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.get(c.getKey()).equalsIgnoreCase(c.getValue())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyWithContext(Map<String, String> context) {
|
||||||
|
return shouldApplyWithContext(context, true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldApplyOnAnyServers(List<String> servers, boolean includeGlobal) {
|
public boolean shouldApplyOnAnyServers(List<String> servers, boolean includeGlobal) {
|
||||||
for (String s : servers) {
|
for (String s : servers) {
|
@ -33,10 +33,10 @@ import me.lucko.luckperms.api.event.events.PermissionNodeExpireEvent;
|
|||||||
import me.lucko.luckperms.api.event.events.PermissionNodeSetEvent;
|
import me.lucko.luckperms.api.event.events.PermissionNodeSetEvent;
|
||||||
import me.lucko.luckperms.api.event.events.PermissionNodeUnsetEvent;
|
import me.lucko.luckperms.api.event.events.PermissionNodeUnsetEvent;
|
||||||
import me.lucko.luckperms.api.implementation.internal.PermissionHolderLink;
|
import me.lucko.luckperms.api.implementation.internal.PermissionHolderLink;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -157,16 +157,27 @@ public abstract class PermissionHolder {
|
|||||||
.filter(Node::isGroupNode)
|
.filter(Node::isGroupNode)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
Map<String, String> contexts = new HashMap<>(context.getContext());
|
||||||
|
String server = contexts.get("server");
|
||||||
|
String world = contexts.get("world");
|
||||||
|
contexts.remove("server");
|
||||||
|
contexts.remove("world");
|
||||||
|
|
||||||
Iterator<Node> iterator = parents.iterator();
|
Iterator<Node> iterator = parents.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Node node = iterator.next();
|
Node node = iterator.next();
|
||||||
|
|
||||||
if (!node.shouldApplyOnServer(context.getServer(), context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex())) {
|
if (!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex())) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.shouldApplyOnWorld(context.getWorld(), context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex())) {
|
if (!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex())) {
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!node.shouldApplyWithContext(contexts, false)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -212,17 +223,23 @@ public abstract class PermissionHolder {
|
|||||||
allNodes = getPermissions(true);
|
allNodes = getPermissions(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> contexts = new HashMap<>(context.getContext());
|
||||||
|
String server = contexts.get("server");
|
||||||
|
String world = contexts.get("world");
|
||||||
|
contexts.remove("server");
|
||||||
|
contexts.remove("world");
|
||||||
|
|
||||||
all:
|
all:
|
||||||
for (Node node : allNodes) {
|
for (Node node : allNodes) {
|
||||||
if (!node.shouldApplyOnServer(context.getServer(), context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex())) {
|
if (!node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.shouldApplyOnWorld(context.getWorld(), context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex())) {
|
if (!node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.shouldApplyWithContext(context.getExtraContext())) {
|
if (!node.shouldApplyWithContext(contexts, false)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +316,7 @@ public abstract class PermissionHolder {
|
|||||||
|
|
||||||
// Convenience method
|
// Convenience method
|
||||||
private static Node.Builder buildNode(String permission) {
|
private static Node.Builder buildNode(String permission) {
|
||||||
return new me.lucko.luckperms.utils.Node.Builder(permission);
|
return new me.lucko.luckperms.core.Node.Builder(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -307,7 +324,7 @@ public abstract class PermissionHolder {
|
|||||||
this.nodes.clear();
|
this.nodes.clear();
|
||||||
|
|
||||||
this.nodes.addAll(nodes.entrySet().stream()
|
this.nodes.addAll(nodes.entrySet().stream()
|
||||||
.map(e -> me.lucko.luckperms.utils.Node.fromSerialisedNode(e.getKey(), e.getValue()))
|
.map(e -> me.lucko.luckperms.core.Node.fromSerialisedNode(e.getKey(), e.getValue()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
auditTemporaryPermissions();
|
auditTemporaryPermissions();
|
||||||
@ -552,12 +569,26 @@ public abstract class PermissionHolder {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes) {
|
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes) {
|
||||||
return exportNodes(new Contexts(server, world, Collections.emptyMap(), plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList());
|
Map<String, String> context = new HashMap<>();
|
||||||
|
if (server != null && !server.equals("")) {
|
||||||
|
context.put("server", server);
|
||||||
|
}
|
||||||
|
if (world != null && !world.equals("")) {
|
||||||
|
context.put("world", world);
|
||||||
|
}
|
||||||
|
return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
|
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
|
||||||
return exportNodes(new Contexts(server, world, Collections.emptyMap(), plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList());
|
Map<String, String> context = new HashMap<>();
|
||||||
|
if (server != null && !server.equals("")) {
|
||||||
|
context.put("server", server);
|
||||||
|
}
|
||||||
|
if (world != null && !world.equals("")) {
|
||||||
|
context.put("world", world);
|
||||||
|
}
|
||||||
|
return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -26,10 +26,10 @@ import com.google.gson.stream.JsonReader;
|
|||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.core.Node;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.tracks.Track;
|
import me.lucko.luckperms.tracks.Track;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.Node;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -24,10 +24,10 @@ package me.lucko.luckperms.storage.methods;
|
|||||||
|
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import me.lucko.luckperms.LuckPermsPlugin;
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.core.Node;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.tracks.Track;
|
import me.lucko.luckperms.tracks.Track;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.Node;
|
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
@ -30,9 +30,13 @@ import me.lucko.luckperms.api.implementation.ApiProvider;
|
|||||||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.contexts.ContextManager;
|
||||||
|
import me.lucko.luckperms.contexts.ContextUpdateTask;
|
||||||
|
import me.lucko.luckperms.contexts.ServerCalculator;
|
||||||
|
import me.lucko.luckperms.contexts.WorldCalculator;
|
||||||
import me.lucko.luckperms.core.UuidCache;
|
import me.lucko.luckperms.core.UuidCache;
|
||||||
import me.lucko.luckperms.data.Importer;
|
import me.lucko.luckperms.data.Importer;
|
||||||
import me.lucko.luckperms.groups.GroupManager;
|
import me.lucko.luckperms.groups.GroupManager;
|
||||||
@ -42,7 +46,6 @@ import me.lucko.luckperms.storage.Datastore;
|
|||||||
import me.lucko.luckperms.storage.StorageFactory;
|
import me.lucko.luckperms.storage.StorageFactory;
|
||||||
import me.lucko.luckperms.tracks.TrackManager;
|
import me.lucko.luckperms.tracks.TrackManager;
|
||||||
import me.lucko.luckperms.users.SpongeUserManager;
|
import me.lucko.luckperms.users.SpongeUserManager;
|
||||||
import me.lucko.luckperms.users.UserManager;
|
|
||||||
import me.lucko.luckperms.utils.LocaleManager;
|
import me.lucko.luckperms.utils.LocaleManager;
|
||||||
import me.lucko.luckperms.utils.LogFactory;
|
import me.lucko.luckperms.utils.LogFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -86,7 +89,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
||||||
private LPConfiguration configuration;
|
private LPConfiguration configuration;
|
||||||
private UserManager userManager;
|
private SpongeUserManager userManager;
|
||||||
private GroupManager groupManager;
|
private GroupManager groupManager;
|
||||||
private TrackManager trackManager;
|
private TrackManager trackManager;
|
||||||
private Datastore datastore;
|
private Datastore datastore;
|
||||||
@ -97,6 +100,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
private ConsecutiveExecutor consecutiveExecutor;
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
private LuckPermsService service;
|
private LuckPermsService service;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private ContextManager<Player> contextManager;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void onEnable(GamePreInitializationEvent event) {
|
public void onEnable(GamePreInitializationEvent event) {
|
||||||
@ -135,6 +139,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
|
contextManager = new ContextManager<>();
|
||||||
|
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||||
|
contextManager.registerCalculator(new WorldCalculator());
|
||||||
|
contextManager.registerListener(userManager);
|
||||||
|
|
||||||
getLog().info("Registering PermissionService...");
|
getLog().info("Registering PermissionService...");
|
||||||
Sponge.getServiceManager().setProvider(this, PermissionService.class, (service = new LuckPermsService(this)));
|
Sponge.getServiceManager().setProvider(this, PermissionService.class, (service = new LuckPermsService(this)));
|
||||||
|
|
||||||
@ -155,6 +164,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get(this)).submit(this);
|
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get(this)).submit(this);
|
||||||
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
||||||
scheduler.createTaskBuilder().async().intervalTicks(20L).execute(consecutiveExecutor).submit(this);
|
scheduler.createTaskBuilder().async().intervalTicks(20L).execute(consecutiveExecutor).submit(this);
|
||||||
|
scheduler.createTaskBuilder().async().intervalTicks(600L).execute(new ContextUpdateTask(service.getUserSubjects())).submit(this);
|
||||||
|
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
package me.lucko.luckperms;
|
package me.lucko.luckperms;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import me.lucko.luckperms.core.AbstractConfiguration;
|
import me.lucko.luckperms.config.AbstractConfiguration;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.sponge;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.calculators.PermissionCalculator;
|
||||||
|
import me.lucko.luckperms.calculators.PermissionProcessor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class ContextData {
|
||||||
|
private final LuckPermsUserSubject parent;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Map<String, String> context;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Map<String, Boolean> permissionCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private final PermissionCalculator calculator;
|
||||||
|
|
||||||
|
public ContextData(LuckPermsUserSubject parent, Map<String, String> context, LuckPermsService service) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
List<PermissionProcessor> processors = new ArrayList<>(5);
|
||||||
|
processors.add(new PermissionCalculator.MapProcessor(permissionCache));
|
||||||
|
if (service.getPlugin().getConfiguration().isApplyingWildcards()) {
|
||||||
|
processors.add(new LuckPermsUserSubject.SpongeWildcardProcessor(permissionCache));
|
||||||
|
processors.add(new PermissionCalculator.WildcardProcessor(permissionCache));
|
||||||
|
}
|
||||||
|
if (service.getPlugin().getConfiguration().isApplyingRegex()) {
|
||||||
|
processors.add(new PermissionCalculator.RegexProcessor(permissionCache));
|
||||||
|
}
|
||||||
|
processors.add(new LuckPermsUserSubject.SpongeDefaultsProcessor(service));
|
||||||
|
|
||||||
|
calculator = new PermissionCalculator(service.getPlugin(), parent.getUser().getName(), service.getPlugin().getConfiguration().isDebugPermissionChecks(), processors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void invalidateCache() {
|
||||||
|
calculator.invalidateCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tristate getPermissionValue(@NonNull String permission) {
|
||||||
|
me.lucko.luckperms.api.Tristate t = calculator.getPermissionValue(permission);
|
||||||
|
if (t != me.lucko.luckperms.api.Tristate.UNDEFINED) {
|
||||||
|
return Tristate.fromBoolean(t.asBoolean());
|
||||||
|
} else {
|
||||||
|
return Tristate.UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.LPSpongePlugin;
|
|||||||
import me.lucko.luckperms.api.sponge.collections.GroupCollection;
|
import me.lucko.luckperms.api.sponge.collections.GroupCollection;
|
||||||
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
||||||
import me.lucko.luckperms.api.sponge.simple.SimpleCollection;
|
import me.lucko.luckperms.api.sponge.simple.SimpleCollection;
|
||||||
|
import me.lucko.luckperms.contexts.SpongeCalculatorLink;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.context.ContextCalculator;
|
import org.spongepowered.api.service.context.ContextCalculator;
|
||||||
import org.spongepowered.api.service.permission.*;
|
import org.spongepowered.api.service.permission.*;
|
||||||
@ -54,7 +55,6 @@ public class LuckPermsService implements PermissionService {
|
|||||||
private final Set<PermissionDescription> descriptionSet;
|
private final Set<PermissionDescription> descriptionSet;
|
||||||
|
|
||||||
private final Map<String, SubjectCollection> subjects;
|
private final Map<String, SubjectCollection> subjects;
|
||||||
private final Set<ContextCalculator<Subject>> contextCalculators; // TODO actually use context calculators, idk...
|
|
||||||
|
|
||||||
public LuckPermsService(LPSpongePlugin plugin) {
|
public LuckPermsService(LPSpongePlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -67,7 +67,6 @@ public class LuckPermsService implements PermissionService {
|
|||||||
subjects.put(PermissionService.SUBJECTS_GROUP, groupSubjects);
|
subjects.put(PermissionService.SUBJECTS_GROUP, groupSubjects);
|
||||||
|
|
||||||
descriptionSet = ConcurrentHashMap.newKeySet();
|
descriptionSet = ConcurrentHashMap.newKeySet();
|
||||||
contextCalculators = ConcurrentHashMap.newKeySet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectData getDefaultData() {
|
public SubjectData getDefaultData() {
|
||||||
@ -121,7 +120,7 @@ public class LuckPermsService implements PermissionService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerContextCalculator(@NonNull ContextCalculator<Subject> contextCalculator) {
|
public void registerContextCalculator(@NonNull ContextCalculator<Subject> contextCalculator) {
|
||||||
contextCalculators.add(contextCalculator);
|
plugin.getContextManager().registerCalculator(new SpongeCalculatorLink(contextCalculator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -30,12 +30,12 @@ import lombok.Getter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.data.Callback;
|
import me.lucko.luckperms.api.data.Callback;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.core.PermissionHolder;
|
import me.lucko.luckperms.core.PermissionHolder;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
@ -124,7 +124,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
context.put(c.getKey(), c.getValue());
|
context.put(c.getKey(), c.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (holder.inheritsPermission(new me.lucko.luckperms.utils.Node.Builder(node).withExtraContext(context).build())) {
|
switch (holder.inheritsPermission(new me.lucko.luckperms.core.Node.Builder(node).withExtraContext(context).build())) {
|
||||||
case UNDEFINED:
|
case UNDEFINED:
|
||||||
return Tristate.UNDEFINED;
|
return Tristate.UNDEFINED;
|
||||||
case TRUE:
|
case TRUE:
|
||||||
@ -277,7 +277,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
public boolean setPermission(Set<Context> set, String s, Tristate tristate) {
|
public boolean setPermission(Set<Context> set, String s, Tristate tristate) {
|
||||||
if (tristate == Tristate.UNDEFINED) {
|
if (tristate == Tristate.UNDEFINED) {
|
||||||
// Unset
|
// Unset
|
||||||
Node.Builder builder = new me.lucko.luckperms.utils.Node.Builder(s);
|
Node.Builder builder = new me.lucko.luckperms.core.Node.Builder(s);
|
||||||
|
|
||||||
for (Context ct : set) {
|
for (Context ct : set) {
|
||||||
builder.withExtraContext(ct.getKey(), ct.getValue());
|
builder.withExtraContext(ct.getKey(), ct.getValue());
|
||||||
@ -290,7 +290,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.Builder builder = new me.lucko.luckperms.utils.Node.Builder(s)
|
Node.Builder builder = new me.lucko.luckperms.core.Node.Builder(s)
|
||||||
.setValue(tristate.asBoolean());
|
.setValue(tristate.asBoolean());
|
||||||
|
|
||||||
for (Context ct : set) {
|
for (Context ct : set) {
|
||||||
@ -384,7 +384,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setPermission(new me.lucko.luckperms.utils.Node.Builder("group." + permsSubject.getIdentifier())
|
holder.setPermission(new me.lucko.luckperms.core.Node.Builder("group." + permsSubject.getIdentifier())
|
||||||
.withExtraContext(contexts)
|
.withExtraContext(contexts)
|
||||||
.build());
|
.build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
@ -403,7 +403,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.unsetPermission(new me.lucko.luckperms.utils.Node.Builder("group." + permsSubject.getIdentifier())
|
holder.unsetPermission(new me.lucko.luckperms.core.Node.Builder("group." + permsSubject.getIdentifier())
|
||||||
.withExtraContext(contexts)
|
.withExtraContext(contexts)
|
||||||
.build());
|
.build());
|
||||||
} catch (ObjectLacksException ignored) {}
|
} catch (ObjectLacksException ignored) {}
|
||||||
@ -514,7 +514,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
value = escapeCharacters(value);
|
value = escapeCharacters(value);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setPermission(new me.lucko.luckperms.utils.Node.Builder("meta." + key + "." + value)
|
holder.setPermission(new me.lucko.luckperms.core.Node.Builder("meta." + key + "." + value)
|
||||||
.withExtraContext(context)
|
.withExtraContext(context)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
@ -613,7 +613,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
if (tristate == Tristate.UNDEFINED) {
|
if (tristate == Tristate.UNDEFINED) {
|
||||||
// Unset
|
// Unset
|
||||||
|
|
||||||
Node.Builder builder = new me.lucko.luckperms.utils.Node.Builder(s);
|
Node.Builder builder = new me.lucko.luckperms.core.Node.Builder(s);
|
||||||
|
|
||||||
for (Context ct : set) {
|
for (Context ct : set) {
|
||||||
builder.withExtraContext(ct.getKey(), ct.getValue());
|
builder.withExtraContext(ct.getKey(), ct.getValue());
|
||||||
@ -625,7 +625,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.Builder builder = new me.lucko.luckperms.utils.Node.Builder(s)
|
Node.Builder builder = new me.lucko.luckperms.core.Node.Builder(s)
|
||||||
.setValue(tristate.asBoolean());
|
.setValue(tristate.asBoolean());
|
||||||
|
|
||||||
for (Context ct : set) {
|
for (Context ct : set) {
|
||||||
@ -709,7 +709,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setTransientPermission(new me.lucko.luckperms.utils.Node.Builder("group." + permsSubject.getIdentifier())
|
holder.setTransientPermission(new me.lucko.luckperms.core.Node.Builder("group." + permsSubject.getIdentifier())
|
||||||
.withExtraContext(contexts)
|
.withExtraContext(contexts)
|
||||||
.build());
|
.build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
@ -727,7 +727,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> contexts = set.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.unsetTransientPermission(new me.lucko.luckperms.utils.Node.Builder("group." + permsSubject.getIdentifier())
|
holder.unsetTransientPermission(new me.lucko.luckperms.core.Node.Builder("group." + permsSubject.getIdentifier())
|
||||||
.withExtraContext(contexts)
|
.withExtraContext(contexts)
|
||||||
.build());
|
.build());
|
||||||
} catch (ObjectLacksException ignored) {}
|
} catch (ObjectLacksException ignored) {}
|
||||||
@ -827,7 +827,7 @@ public class LuckPermsSubject implements Subject {
|
|||||||
value = escapeCharacters(value);
|
value = escapeCharacters(value);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setTransientPermission(new me.lucko.luckperms.utils.Node.Builder("meta." + key + "." + value)
|
holder.setTransientPermission(new me.lucko.luckperms.core.Node.Builder("meta." + key + "." + value)
|
||||||
.withExtraContext(context)
|
.withExtraContext(context)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
@ -25,17 +25,21 @@ package me.lucko.luckperms.api.sponge;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
||||||
|
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||||
|
import me.lucko.luckperms.calculators.PermissionProcessor;
|
||||||
|
import me.lucko.luckperms.contexts.Contexts;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
import me.lucko.luckperms.utils.PermissionCalculator;
|
|
||||||
import me.lucko.luckperms.utils.PermissionProcessor;
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
import org.spongepowered.api.util.Tristate;
|
import org.spongepowered.api.util.Tristate;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class LuckPermsUserSubject extends LuckPermsSubject {
|
public class LuckPermsUserSubject extends LuckPermsSubject {
|
||||||
public static LuckPermsUserSubject wrapUser(User user, LuckPermsService service) {
|
public static LuckPermsUserSubject wrapUser(User user, LuckPermsService service) {
|
||||||
@ -45,37 +49,22 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
@Getter
|
@Getter
|
||||||
private final User user;
|
private final User user;
|
||||||
|
|
||||||
private final PermissionCalculator calculator;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Map<String, Boolean> permissionCache = new ConcurrentHashMap<>();
|
private final Map<Map<String, String>, ContextData> contextData;
|
||||||
|
|
||||||
private LuckPermsUserSubject(User user, LuckPermsService service) {
|
private LuckPermsUserSubject(User user, LuckPermsService service) {
|
||||||
super(user, service);
|
super(user, service);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
List<PermissionProcessor> processors = new ArrayList<>(5);
|
contextData = new ConcurrentHashMap<>();
|
||||||
processors.add(new PermissionCalculator.MapProcessor(permissionCache));
|
|
||||||
if (service.getPlugin().getConfiguration().isApplyingWildcards()) {
|
|
||||||
processors.add(new SpongeWildcardProcessor(permissionCache));
|
|
||||||
processors.add(new PermissionCalculator.WildcardProcessor(permissionCache));
|
|
||||||
}
|
|
||||||
if (service.getPlugin().getConfiguration().isApplyingRegex()) {
|
|
||||||
processors.add(new PermissionCalculator.RegexProcessor(permissionCache));
|
|
||||||
}
|
|
||||||
processors.add(new SpongeDefaultsProcessor(service));
|
|
||||||
|
|
||||||
calculator = new PermissionCalculator(service.getPlugin(), user.getName(), service.getPlugin().getConfiguration().isDebugPermissionChecks(), processors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateCache() {
|
|
||||||
calculator.invalidateCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO don't ignore context
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
|
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
|
||||||
me.lucko.luckperms.api.Tristate t = calculator.getPermissionValue(permission);
|
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
ContextData cd = contextData.computeIfAbsent(context, this::calculatePermissions);
|
||||||
|
|
||||||
|
me.lucko.luckperms.api.Tristate t = cd.getPermissionValue(permission);
|
||||||
if (t != me.lucko.luckperms.api.Tristate.UNDEFINED) {
|
if (t != me.lucko.luckperms.api.Tristate.UNDEFINED) {
|
||||||
return Tristate.fromBoolean(t.asBoolean());
|
return Tristate.fromBoolean(t.asBoolean());
|
||||||
} else {
|
} else {
|
||||||
@ -83,6 +72,57 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextData calculatePermissions(Map<String, String> context) {
|
||||||
|
Map<String, Boolean> toApply = user.exportNodes(
|
||||||
|
new Contexts(
|
||||||
|
context,
|
||||||
|
service.getPlugin().getConfiguration().isIncludingGlobalPerms(),
|
||||||
|
service.getPlugin().getConfiguration().isIncludingGlobalWorldPerms(),
|
||||||
|
true,
|
||||||
|
service.getPlugin().getConfiguration().isApplyingGlobalGroups(),
|
||||||
|
service.getPlugin().getConfiguration().isApplyingGlobalWorldGroups()
|
||||||
|
),
|
||||||
|
Collections.emptyList()
|
||||||
|
);
|
||||||
|
|
||||||
|
ContextData existing = contextData.get(context);
|
||||||
|
if (existing == null) {
|
||||||
|
existing = new ContextData(this, context, service);
|
||||||
|
contextData.put(context, existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean different = false;
|
||||||
|
if (toApply.size() != existing.getPermissionCache().size()) {
|
||||||
|
different = true;
|
||||||
|
} else {
|
||||||
|
for (Map.Entry<String, Boolean> e : existing.getPermissionCache().entrySet()) {
|
||||||
|
if (toApply.containsKey(e.getKey()) && toApply.get(e.getKey()) == e.getValue()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
different = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!different) return existing;
|
||||||
|
|
||||||
|
existing.getPermissionCache().clear();
|
||||||
|
existing.invalidateCache();
|
||||||
|
existing.getPermissionCache().putAll(toApply);
|
||||||
|
service.getPlugin().getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(user)));
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePermissions(Set<Context> contexts) {
|
||||||
|
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
|
calculatePermissions(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateActivePermissions() {
|
||||||
|
calculatePermissions(getActiveContexts());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return service.getPlugin().getUuidCache().getExternalUUID(user.getUuid()).toString();
|
return service.getPlugin().getUuidCache().getExternalUUID(user.getUuid()).toString();
|
||||||
@ -100,8 +140,22 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Context> getActiveContexts() {
|
||||||
|
final UUID uuid = service.getPlugin().getUuidCache().getExternalUUID(user.getUuid());
|
||||||
|
Optional<Player> player = Sponge.getServer().getPlayer(uuid);
|
||||||
|
|
||||||
|
if (!player.isPresent()) {
|
||||||
|
return SubjectData.GLOBAL_CONTEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> context = new HashMap<>();
|
||||||
|
service.getPlugin().getContextManager().giveApplicableContext(player.get(), context);
|
||||||
|
return context.entrySet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class SpongeWildcardProcessor implements PermissionProcessor {
|
static class SpongeWildcardProcessor implements PermissionProcessor {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Map<String, Boolean> map;
|
private final Map<String, Boolean> map;
|
||||||
@ -152,7 +206,7 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class SpongeDefaultsProcessor implements PermissionProcessor {
|
static class SpongeDefaultsProcessor implements PermissionProcessor {
|
||||||
private final LuckPermsService service;
|
private final LuckPermsService service;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import me.lucko.luckperms.api.sponge.LuckPermsUserSubject;
|
||||||
|
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ContextUpdateTask implements Runnable {
|
||||||
|
private final UserCollection userCollection;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (LuckPermsUserSubject subject : userCollection.getUsers().values()) {
|
||||||
|
Set<Map<String, String>> contexts = new HashSet<>(subject.getContextData().keySet());
|
||||||
|
contexts.forEach(subject::calculatePermissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.contexts;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.service.context.Context;
|
||||||
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SpongeCalculatorLink extends ContextCalculator<Player> {
|
||||||
|
private final org.spongepowered.api.service.context.ContextCalculator<Subject> calculator;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> giveApplicableContext(Player subject, Map<String, String> accumulator) {
|
||||||
|
Set<Context> contexts = accumulator.entrySet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(Collectors.toSet());
|
||||||
|
calculator.accumulateContexts(subject, contexts);
|
||||||
|
|
||||||
|
contexts.forEach(c -> accumulator.put(c.getKey(), c.getValue()));
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) {
|
||||||
|
Context c = new Context(context.getKey(), context.getValue());
|
||||||
|
return calculator.matches(c, subject);
|
||||||
|
}
|
||||||
|
}
|
@ -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.contexts;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.service.context.Context;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WorldCalculator extends ContextCalculator<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> giveApplicableContext(Player subject, Map<String, String> accumulator) {
|
||||||
|
accumulator.put(Context.WORLD_KEY, subject.getWorld().getName());
|
||||||
|
return accumulator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) {
|
||||||
|
return context.getKey().equals(Context.WORLD_KEY) && subject.getWorld().getName().equals(context.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,14 +23,9 @@
|
|||||||
package me.lucko.luckperms.users;
|
package me.lucko.luckperms.users;
|
||||||
|
|
||||||
import me.lucko.luckperms.LPSpongePlugin;
|
import me.lucko.luckperms.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
|
||||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
|
||||||
import me.lucko.luckperms.api.sponge.LuckPermsUserSubject;
|
import me.lucko.luckperms.api.sponge.LuckPermsUserSubject;
|
||||||
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
||||||
import me.lucko.luckperms.utils.Contexts;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
class SpongeUser extends User {
|
class SpongeUser extends User {
|
||||||
@ -53,47 +48,7 @@ class SpongeUser extends User {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the permissions that should be applied. This is done async, who cares about how long it takes or how often it's done.
|
LuckPermsUserSubject us = uc.getUsers().get(getUuid());
|
||||||
Map<String, Boolean> toApply = exportNodes(
|
us.calculateActivePermissions();
|
||||||
new Contexts(
|
|
||||||
plugin.getConfiguration().getServer(),
|
|
||||||
null, // TODO per world perms
|
|
||||||
null,
|
|
||||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
|
||||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
|
||||||
true,
|
|
||||||
plugin.getConfiguration().isApplyingGlobalGroups(),
|
|
||||||
plugin.getConfiguration().isApplyingGlobalWorldGroups()
|
|
||||||
),
|
|
||||||
Collections.emptyList()
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
LuckPermsUserSubject us = uc.getUsers().get(getUuid());
|
|
||||||
Map<String, Boolean> existing = us.getPermissionCache();
|
|
||||||
|
|
||||||
boolean different = false;
|
|
||||||
if (toApply.size() != existing.size()) {
|
|
||||||
different = true;
|
|
||||||
} else {
|
|
||||||
for (Map.Entry<String, Boolean> e : existing.entrySet()) {
|
|
||||||
if (toApply.containsKey(e.getKey()) && toApply.get(e.getKey()) == e.getValue()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
different = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!different) return;
|
|
||||||
|
|
||||||
existing.clear();
|
|
||||||
us.invalidateCache();
|
|
||||||
existing.putAll(toApply);
|
|
||||||
|
|
||||||
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,13 @@
|
|||||||
package me.lucko.luckperms.users;
|
package me.lucko.luckperms.users;
|
||||||
|
|
||||||
import me.lucko.luckperms.LPSpongePlugin;
|
import me.lucko.luckperms.LPSpongePlugin;
|
||||||
|
import me.lucko.luckperms.api.context.ContextListener;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SpongeUserManager extends UserManager {
|
public class SpongeUserManager extends UserManager implements ContextListener<Player> {
|
||||||
private final LPSpongePlugin plugin;
|
private final LPSpongePlugin plugin;
|
||||||
|
|
||||||
public SpongeUserManager(LPSpongePlugin plugin) {
|
public SpongeUserManager(LPSpongePlugin plugin) {
|
||||||
@ -58,4 +61,14 @@ public class SpongeUserManager extends UserManager {
|
|||||||
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
||||||
.forEach(u -> plugin.getDatastore().loadUser(u, "null"));
|
.forEach(u -> plugin.getDatastore().loadUser(u, "null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextChange(Player subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception {
|
||||||
|
UUID internal = plugin.getUuidCache().getUUID(subject.getUniqueId());
|
||||||
|
|
||||||
|
User user = get(internal);
|
||||||
|
if (user != null) {
|
||||||
|
plugin.doAsync(user::refreshPermissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,11 @@ import me.lucko.luckperms.api.PlatformType;
|
|||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.config.LPConfiguration;
|
||||||
import me.lucko.luckperms.constants.Constants;
|
import me.lucko.luckperms.constants.Constants;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.core.UuidCache;
|
import me.lucko.luckperms.core.UuidCache;
|
||||||
import me.lucko.luckperms.data.Importer;
|
import me.lucko.luckperms.data.Importer;
|
||||||
import me.lucko.luckperms.groups.GroupManager;
|
import me.lucko.luckperms.groups.GroupManager;
|
||||||
@ -146,6 +147,11 @@ public class StandaloneBase implements LuckPermsPlugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContextManager getContextManager() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message getPlayerStatus(UUID uuid) {
|
public Message getPlayerStatus(UUID uuid) {
|
||||||
return Message.PLAYER_OFFLINE;
|
return Message.PLAYER_OFFLINE;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.internal;
|
package me.lucko.luckperms.internal;
|
||||||
|
|
||||||
import me.lucko.luckperms.core.AbstractConfiguration;
|
import me.lucko.luckperms.config.AbstractConfiguration;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user