API changes for 2.11

This commit is contained in:
Luck 2016-10-05 21:40:54 +01:00
parent 80d2246634
commit 2429831153
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
29 changed files with 241 additions and 52 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -0,0 +1,155 @@
/*
* 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;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.Map;
/**
* Represents the context and options for a permission lookup.
* All values are immutable.
* @since 2.11
*/
public class Contexts {
public static final String SERVER_KEY = "server";
public static final String WORLD_KEY = "world";
/**
* Gets a context that will allow all nodes
* @return a context that will not apply any filters
*/
public static Contexts allowAll() {
return new Contexts(Collections.emptyMap(), true, true, true, true, true);
}
public static Contexts of(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) {
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups);
}
public Contexts(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) {
if (context == null) {
throw new NullPointerException("context");
}
this.context = ImmutableMap.copyOf(context);
this.includeGlobal = includeGlobal;
this.includeGlobalWorld = includeGlobalWorld;
this.applyGroups = applyGroups;
this.applyGlobalGroups = applyGlobalGroups;
this.applyGlobalWorldGroups = applyGlobalWorldGroups;
}
/**
* The contexts that apply for this lookup
*
* The keys for servers and worlds are defined as static values.
*/
private final Map<String, String> context;
/**
* If global or non server specific nodes should be applied
*/
private final boolean includeGlobal;
/**
* If global or non world specific nodes should be applied
*/
private final boolean includeGlobalWorld;
/**
* If parent groups should be applied
*/
private final boolean applyGroups;
/**
* If global or non server specific group memberships should be applied
*/
private final boolean applyGlobalGroups;
/**
* If global or non world specific group memberships should be applied
*/
private final boolean applyGlobalWorldGroups;
/**
* Gets the contexts that apply for this lookup
* @return an immutable map of context key value pairs
*/
public Map<String, String> getContext() {
return this.context;
}
/**
* Gets if global or non server specific nodes should be applied
* @return true if global or non server specific nodes should be applied
*/
public boolean isIncludeGlobal() {
return this.includeGlobal;
}
/**
* Gets if global or non world specific nodes should be applied
* @return true if global or non world specific nodes should be applied
*/
public boolean isIncludeGlobalWorld() {
return this.includeGlobalWorld;
}
/**
* Gets if parent groups should be applied
* @return true if parent groups should be applied
*/
public boolean isApplyGroups() {
return this.applyGroups;
}
/**
* Gets if global or non server specific group memberships should be applied
* @return true if global or non server specific group memberships should be applied
*/
public boolean isApplyGlobalGroups() {
return this.applyGlobalGroups;
}
/**
* Gets if global or non world specific group memberships should be applied
* @return true if global or non world specific group memberships should be applied
*/
public boolean isApplyGlobalWorldGroups() {
return this.applyGlobalWorldGroups;
}
public String toString() {
return "Contexts(" +
"context=" + this.getContext() + ", " +
"includeGlobal=" + this.isIncludeGlobal() + ", " +
"includeGlobalWorld=" + this.isIncludeGlobalWorld() + ", " +
"applyGroups=" + this.isApplyGroups() + ", " +
"applyGlobalGroups=" + this.isApplyGlobalGroups() + ", " +
"applyGlobalWorldGroups=" + this.isApplyGlobalWorldGroups() +
")";
}
}

View File

@ -20,28 +20,25 @@
* SOFTWARE.
*/
package me.lucko.luckperms.contexts;
package me.lucko.luckperms.api;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
/**
* Represents a Node and where it was inherited from.
* @since 2.11
*/
public interface LocalizedNode extends Node {
import java.util.Collections;
import java.util.Map;
/**
* Gets the node
* @return the node this instance is representing
*/
Node getNode();
@Getter
@ToString
@AllArgsConstructor
public class Contexts {
public static Contexts allowAll() {
return new Contexts(Collections.emptyMap(), true, true, true, true, true);
}
private final Map<String, String> context;
private final boolean includeGlobal;
private final boolean includeGlobalWorld;
private final boolean applyGroups;
private final boolean applyGlobalGroups;
private final boolean applyGlobalWorldGroups;
/**
* Gets the location where the {@link Node} is inherited from
* @return where the node was inherited from. Will not return null.
* @see PermissionHolder#getObjectName()
*/
String getLocation();
}

View File

@ -68,9 +68,34 @@ public interface PermissionHolder {
* Gets an immutable set of the nodes that this object has and inherits
* @return an immutable set of permissions
* @since 2.6
* @deprecated in favour of {@link #getAllNodes(Contexts)}
*/
@Deprecated
Set<Node> getAllNodes();
/**
* Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context
* Unlike {@link #getAllNodesFiltered(Contexts)}, this method will not filter individual nodes. The context is only
* used to determine which groups should apply.
* Nodes are sorted into priority order.
* @param contexts the context for the lookup,
* @return a mutable sorted set of permissions
* @throws NullPointerException if the context is null
* @since 2.11
*/
SortedSet<LocalizedNode> getAllNodes(Contexts contexts);
/**
* Gets a mutable set of the nodes that is objects has and inherits, filtered by context.
* Unlike {@link #getAllNodes(Contexts)}, this method WILL filter individual nodes, and only return ones that fully
* meet the context provided.
* @param contexts the context for the lookup
* @return a mutable set of permissions
* @throws NullPointerException if the context is null
* @since 2.11
*/
Set<LocalizedNode> getAllNodesFiltered(Contexts contexts);
/**
* Gets an immutable Map of the objects permission nodes
* @return an immutable map of permissions
@ -499,7 +524,9 @@ public interface PermissionHolder {
* @param applyGroups if inherited group permissions should be included
* @return a map of permissions
* @since 2.6
* @deprecated in favour of {@link #getAllNodesFiltered(Contexts)}
*/
@Deprecated
Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups);
/**

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -22,8 +22,8 @@
package me.lucko.luckperms;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.inject.Injector;
import me.lucko.luckperms.inject.LPPermissible;
import me.lucko.luckperms.users.BukkitUser;

View File

@ -23,10 +23,10 @@
package me.lucko.luckperms.api.vault;
import lombok.NonNull;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.vault.cache.ChatCache;
import me.lucko.luckperms.api.vault.cache.VaultUser;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.core.PermissionHolder;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;

View File

@ -26,10 +26,10 @@ import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import me.lucko.luckperms.LPBukkitPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.vault.cache.VaultUser;
import me.lucko.luckperms.api.vault.cache.VaultUserManager;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.core.PermissionHolder;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;

View File

@ -25,9 +25,9 @@ package me.lucko.luckperms.api.vault.cache;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.LPBukkitPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.vault.VaultPermissionHook;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.users.User;
import java.util.Collections;

View File

@ -25,9 +25,9 @@ package me.lucko.luckperms.users;
import lombok.Getter;
import lombok.Setter;
import me.lucko.luckperms.LPBukkitPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
import me.lucko.luckperms.api.implementation.internal.UserLink;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.inject.LPPermissible;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -24,9 +24,9 @@ package me.lucko.luckperms.users;
import me.lucko.luckperms.BungeePlayerCache;
import me.lucko.luckperms.LPBungeePlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
import me.lucko.luckperms.api.implementation.internal.UserLink;
import me.lucko.luckperms.contexts.Contexts;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Collections;

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -70,7 +70,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public double getApiVersion() {
return 2.10;
return 2.11;
}
@Override

View File

@ -24,10 +24,7 @@ package me.lucko.luckperms.api.implementation.internal;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.api.*;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -53,7 +50,7 @@ public class PermissionHolderLink implements PermissionHolder {
@Override
public SortedSet<? extends Node> getPermissions() {
return Collections.unmodifiableSortedSet(master.getPermissions(false));
return master.getPermissions(false);
}
@Override
@ -71,6 +68,16 @@ public class PermissionHolderLink implements PermissionHolder {
return Collections.unmodifiableSet(master.getAllNodes(Collections.emptyList(), Contexts.allowAll()));
}
@Override
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
return master.getAllNodes(Collections.emptyList(), contexts);
}
@Override
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
return master.getAllNodesFiltered(contexts);
}
@Override
public Map<String, Boolean> getNodes() {
return exportToLegacy(master.getNodes());

View File

@ -23,11 +23,11 @@
package me.lucko.luckperms.commands;
import lombok.experimental.UtilityClass;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Patterns;
import me.lucko.luckperms.core.LocalizedNode;
import me.lucko.luckperms.utils.DateUtil;
import java.util.*;

View File

@ -23,11 +23,11 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.commands.*;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.groups.Group;
import java.util.*;

View File

@ -23,11 +23,11 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.commands.*;
import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.constants.Permission;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.users.User;
import java.util.AbstractMap.SimpleEntry;

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.core;
import lombok.*;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Tristate;
import java.util.Optional;

View File

@ -29,6 +29,8 @@ import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.event.events.GroupRemoveEvent;
@ -36,7 +38,6 @@ import me.lucko.luckperms.api.event.events.PermissionNodeExpireEvent;
import me.lucko.luckperms.api.event.events.PermissionNodeSetEvent;
import me.lucko.luckperms.api.event.events.PermissionNodeUnsetEvent;
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.ObjectLacksException;
import me.lucko.luckperms.groups.Group;
@ -177,11 +178,11 @@ public abstract class PermissionHolder {
TreeSet<LocalizedNode> combined = new TreeSet<>(PriorityComparator.reverse());
getNodes().stream()
.map(n -> LocalizedNode.of(n, getObjectName()))
.map(n -> me.lucko.luckperms.utils.LocalizedNode.of(n, getObjectName()))
.forEach(combined::add);
getTransientNodes().stream()
.map(n -> LocalizedNode.of(n, getObjectName()))
.map(n -> me.lucko.luckperms.utils.LocalizedNode.of(n, getObjectName()))
.forEach(combined::add);
TreeSet<LocalizedNode> permissions = new TreeSet<>(PriorityComparator.reverse());

View File

@ -24,6 +24,7 @@ package me.lucko.luckperms.core;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;
import java.text.Collator;

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.core;
package me.lucko.luckperms.utils;
import lombok.*;
import me.lucko.luckperms.api.Node;
@ -37,7 +37,7 @@ import java.util.Optional;
@Getter
@ToString
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class LocalizedNode implements me.lucko.luckperms.api.Node {
public class LocalizedNode implements me.lucko.luckperms.api.LocalizedNode {
public static LocalizedNode of(@NonNull me.lucko.luckperms.api.Node node, @NonNull String location) {
return new LocalizedNode(node, location);
}

View File

@ -6,7 +6,7 @@
<groupId>me.lucko.luckperms</groupId>
<artifactId>luckperms</artifactId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
<modules>
<module>common</module>
<module>api</module>
@ -39,7 +39,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<release.version>2.10</release.version>
<release.version>2.11</release.version>
</properties>
<distributionManagement>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -26,8 +26,8 @@ import com.google.common.collect.ImmutableList;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.core.PermissionHolder;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.users.User;

View File

@ -24,9 +24,9 @@ package me.lucko.luckperms.api.sponge;
import lombok.Getter;
import lombok.NonNull;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
import me.lucko.luckperms.api.implementation.internal.UserLink;
import me.lucko.luckperms.contexts.Contexts;
import me.lucko.luckperms.users.User;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.10-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>