Events rewrite, remove most deprecated API methods (v3.0)

This commit is contained in:
Luck 2017-02-19 14:57:06 +00:00
parent 89ff3b169b
commit 6798fb21b2
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
148 changed files with 2955 additions and 1948 deletions

View File

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

View File

@ -24,8 +24,6 @@ package me.lucko.luckperms.api;
import me.lucko.luckperms.api.context.ContextSet;
import java.util.Map;
/**
* Context and options for a permission lookup.
*
@ -51,18 +49,6 @@ public class Contexts {
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
}
@SuppressWarnings("deprecation")
@Deprecated
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);
}
@SuppressWarnings("deprecation")
@Deprecated
public static Contexts of(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
}
/**
* The contexts that apply for this lookup
* The keys for servers and worlds are defined as static values.
@ -115,17 +101,6 @@ public class Contexts {
this.op = op;
}
@Deprecated
public Contexts(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
this(context == null ? null : ContextSet.fromMap(context), includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
}
@SuppressWarnings("deprecation")
@Deprecated
public Contexts(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) {
this(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, false);
}
/**
* Gets the contexts that apply for this lookup
*
@ -136,17 +111,6 @@ public class Contexts {
return this.context;
}
/**
* Gets the contexts that apply for this lookup
*
* @return an immutable map of context key value pairs
* @deprecated in favour of {@link #getContexts()}
*/
@Deprecated
public Map<String, String> getContext() {
return this.context.toMap();
}
/**
* Gets if OP defaults should be included
*

View File

@ -1,185 +0,0 @@
/*
* 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 me.lucko.luckperms.api.data.Callback;
import java.util.Set;
import java.util.UUID;
/**
* Deprecated Storage interface. Use {@link Storage} instead.
*
* @deprecated as of version 2.14 in favour of {@link Storage}.
*/
@Deprecated
public interface Datastore {
String getName();
boolean isAcceptingLogins();
@Deprecated
Sync sync();
@Deprecated
Async async();
@Deprecated
Future future();
@Deprecated
interface Sync {
boolean logAction(LogEntry entry);
Log getLog();
@Deprecated
boolean loadOrCreateUser(UUID uuid, String username);
@Deprecated
boolean loadUser(UUID uuid);
boolean loadUser(UUID uuid, String username);
boolean saveUser(User user);
boolean cleanupUsers();
Set<UUID> getUniqueUsers();
boolean createAndLoadGroup(String name);
boolean loadGroup(String name);
boolean loadAllGroups();
boolean saveGroup(Group group);
boolean deleteGroup(Group group);
boolean createAndLoadTrack(String name);
boolean loadTrack(String name);
boolean loadAllTracks();
boolean saveTrack(Track track);
boolean deleteTrack(Track track);
boolean saveUUIDData(String username, UUID uuid);
UUID getUUID(String username);
}
@Deprecated
interface Async {
void logAction(LogEntry entry, Callback<Boolean> callback);
void getLog(Callback<Log> callback);
@Deprecated
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
@Deprecated
void loadUser(UUID uuid, Callback<Boolean> callback);
void loadUser(UUID uuid, String username, Callback<Boolean> callback);
void saveUser(User user, Callback<Boolean> callback);
void cleanupUsers(Callback<Boolean> callback);
void getUniqueUsers(Callback<Set<UUID>> callback);
void createAndLoadGroup(String name, Callback<Boolean> callback);
void loadGroup(String name, Callback<Boolean> callback);
void loadAllGroups(Callback<Boolean> callback);
void saveGroup(Group group, Callback<Boolean> callback);
void deleteGroup(Group group, Callback<Boolean> callback);
void createAndLoadTrack(String name, Callback<Boolean> callback);
void loadTrack(String name, Callback<Boolean> callback);
void loadAllTracks(Callback<Boolean> callback);
void saveTrack(Track track, Callback<Boolean> callback);
void deleteTrack(Track track, Callback<Boolean> callback);
void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback);
void getUUID(String username, Callback<UUID> callback);
}
@Deprecated
interface Future {
java.util.concurrent.Future<Boolean> logAction(LogEntry entry);
java.util.concurrent.Future<Log> getLog();
@Deprecated
java.util.concurrent.Future<Boolean> loadOrCreateUser(UUID uuid, String username);
@Deprecated
java.util.concurrent.Future<Boolean> loadUser(UUID uuid);
java.util.concurrent.Future<Boolean> loadUser(UUID uuid, String username);
java.util.concurrent.Future<Boolean> saveUser(User user);
java.util.concurrent.Future<Boolean> cleanupUsers();
java.util.concurrent.Future<Set<UUID>> getUniqueUsers();
java.util.concurrent.Future<Boolean> createAndLoadGroup(String name);
java.util.concurrent.Future<Boolean> loadGroup(String name);
java.util.concurrent.Future<Boolean> loadAllGroups();
java.util.concurrent.Future<Boolean> saveGroup(Group group);
java.util.concurrent.Future<Boolean> deleteGroup(Group group);
java.util.concurrent.Future<Boolean> createAndLoadTrack(String name);
java.util.concurrent.Future<Boolean> loadTrack(String name);
java.util.concurrent.Future<Boolean> loadAllTracks();
java.util.concurrent.Future<Boolean> saveTrack(Track track);
java.util.concurrent.Future<Boolean> deleteTrack(Track track);
java.util.concurrent.Future<Boolean> saveUUIDData(String username, UUID uuid);
java.util.concurrent.Future<UUID> getUUID(String username);
}
}

View File

@ -23,7 +23,6 @@
package me.lucko.luckperms.api;
import me.lucko.luckperms.api.data.DatastoreConfiguration;
import me.lucko.luckperms.api.data.MySQLConfiguration;
import java.util.Map;
@ -44,22 +43,6 @@ public interface LPConfiguration {
*/
int getSyncTime();
/**
* Returns the default group, in a node representation
* @return the default group, in a node representation
* @deprecated as of 2.6, the default group is always "default"
*/
@Deprecated
String getDefaultGroupNode();
/**
* Returns the name of the default group
* @return the name of the default group
* @deprecated as of 2.6, the default group is always "default"
*/
@Deprecated
String getDefaultGroupName();
/**
* Returns if the users on this server will have their global permissions applied
* @return if the users on this server will have their global permissions applied
@ -118,15 +101,6 @@ public interface LPConfiguration {
*/
boolean getLogNotify();
/**
* Returns true if permission checks are being recorded / debugged
* @return true if permission checks are being recorded / debugged
* @since 2.9
* @deprecated as this value is now always false. Functionality was replaced by the verbose command.
*/
@Deprecated
boolean getDebugPermissionChecks();
/**
* Returns true if the vanilla op system is enabled
* @return true if the vanilla op system is enabled
@ -162,15 +136,6 @@ public interface LPConfiguration {
*/
boolean getVaultIncludeGlobal();
/**
* Returns the database values set in the configuration
* @return the database values set in the configuration
* @deprecated use {@link #getDatastoreConfig()}
*/
@SuppressWarnings("deprecation")
@Deprecated
MySQLConfiguration getDatabaseValues();
/**
* Returns the values set for data storage in the configuration
* @return the values set for data storage in the configuration

View File

@ -22,10 +22,9 @@
package me.lucko.luckperms.api;
import me.lucko.luckperms.api.context.ContextListener;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.IContextCalculator;
import me.lucko.luckperms.api.event.LPListener;
import me.lucko.luckperms.api.event.EventBus;
import java.util.Optional;
import java.util.Set;
@ -42,37 +41,31 @@ public interface LuckPermsApi {
void runUpdateTask();
/**
* Gets the API version
* @return the version of the API running on the platform
* @since 2.6
*/
double getApiVersion();
/**
* Gets the plugin version
* @return the version of the plugin running on the platform
*/
String getVersion();
/**
* Gets the platform LuckPerms is running on
* @return the platform LuckPerms is running on
* @since 2.7
*/
PlatformType getPlatformType();
/**
* Registers a listener to be sent LuckPerms events
*
* @param listener the listener instance
* @throws NullPointerException if the listener is null
* Gets the event bus, used for subscribing to events
* @return the event bus
* @since 3.0
*/
void registerListener(LPListener listener);
/**
* Unregisters a previously registered listener from the EventBus
*
* @param listener the listener instance to unregister
* @throws NullPointerException if the listener is null
*/
void unregisterListener(LPListener listener);
EventBus getEventBus();
/**
* Gets a wrapped {@link LPConfiguration} instance, with read only access
@ -89,16 +82,6 @@ public interface LuckPermsApi {
*/
Storage getStorage();
/**
* Gets a wrapped Datastore instance.
*
* @return a datastore instance
* @deprecated in favour of {@link #getStorage()}
*/
@SuppressWarnings("deprecation")
@Deprecated
Datastore getDatastore();
/**
* Gets the messaging service in use on the platform, if present.
*
@ -274,15 +257,7 @@ public interface LuckPermsApi {
* @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);
void registerContextCalculator(ContextCalculator<?> contextCalculator);
/**
* Gets a calculated context instance for the user using the rules of the platform.
@ -295,7 +270,7 @@ public interface LuckPermsApi {
Optional<Contexts> getContextForUser(User user);
/**
* Gets set of contexts applicable to a player using the platforms {@link IContextCalculator}s.
* Gets set of contexts applicable to a player using the platforms {@link ContextCalculator}s.
*
* @param player the player to calculate for. Must be the player instance for the platform.
* @return a set of contexts.

View File

@ -133,31 +133,6 @@ public interface Node extends Map.Entry<String, Boolean> {
*/
boolean shouldApplyWithContext(ContextSet 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
* @deprecated in favour of {@link #shouldApplyWithContext(ContextSet, boolean)}
*/
@Deprecated
default boolean shouldApplyWithContext(Map<String, String> context, boolean worldAndServer) {
return shouldApplyWithContext(ContextSet.fromMap(context), worldAndServer);
}
/**
* If this node should apply in the given context
*
* @param context the context key value pairs
* @return true if the node should apply
* @deprecated in favour of {@link #shouldApplyWithContext(ContextSet)}
*/
@Deprecated
default boolean shouldApplyWithContext(Map<String, String> context) {
return shouldApplyWithContext(ContextSet.fromMap(context));
}
/**
* Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List
*
@ -227,15 +202,6 @@ public interface Node extends Map.Entry<String, Boolean> {
*/
boolean hasExpired();
/**
* @return the extra contexts required for this node to apply
* @deprecated in favour of {@link #getContexts()}
*/
@Deprecated
default Map<String, String> getExtraContexts() {
return getContexts().toMap();
}
/**
* @return the extra contexts required for this node to apply
* @since 2.13

View File

@ -25,7 +25,6 @@ package me.lucko.luckperms.api;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
@ -73,17 +72,6 @@ public interface PermissionHolder {
*/
Set<? extends Node> getTransientPermissions();
/**
* 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
@ -117,15 +105,6 @@ public interface PermissionHolder {
*/
Map<String, Boolean> exportNodes(Contexts contexts, boolean lowerCase);
/**
* Gets an immutable Map of the objects permission nodes
*
* @return an immutable map of permissions
* @deprecated in favour of {@link #getPermissions()}
*/
@Deprecated
Map<String, Boolean> getNodes();
/**
* Removes temporary permissions that have expired
*/
@ -631,86 +610,4 @@ public interface PermissionHolder {
*/
Set<Node> getTemporaryPermissionNodes();
/**
* Gets the permissions and inherited permissions that apply to a specific server and world
*
* @param server The server to get nodes for
* @param world The world to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
* @return a {@link Map} of the permissions
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
*/
@Deprecated
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes);
/**
* Gets the permissions and inherited permissions that apply to a specific server and world
*
* @param server The server to get nodes for
* @param world The world to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @return a {@link Map} of the permissions
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
*/
@Deprecated
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups);
/**
* Gets the permissions and inherited permissions that apply to a specific server
*
* @param server The server to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
* @return a {@link Map} of the permissions
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
*/
@Deprecated
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups, List<String> possibleNodes);
/**
* Gets the permissions and inherited permissions that apply to a specific server
*
* @param server The server to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @return a {@link Map} of the permissions
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
*/
@Deprecated
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups);
/**
* Convert the holders nodes into a Map of permissions to be applied on the platform
*
* @param server the server
* @param world the world
* @param extraContext any extra context to filter by
* @param includeGlobal whether to include global nodes
* @param possibleNodes a list of possible permissions for resolving wildcards
* @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);
/**
* Processes the nodes and returns the temporary ones.
*
* @return a map of temporary nodes
* @deprecated in favour of {@link #getTemporaryPermissionNodes()}
*/
@Deprecated
Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes();
/**
* Processes the nodes and returns the non-temporary ones.
*
* @return a map of permanent nodes
* @deprecated in favour of {@link #getPermanentPermissionNodes()}
*/
@Deprecated
Map<String, Boolean> getPermanentNodes();
}

View File

@ -31,12 +31,7 @@ public enum PlatformType {
BUKKIT("Bukkit"),
BUNGEE("Bungee"),
SPONGE("Sponge"),
/**
* @since 2.9
*/
STANDALONE("Standalone");
SPONGE("Sponge");
private final String friendlyName;

View File

@ -22,55 +22,34 @@
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}
* Calculates whether contexts are applicable to {@link T}
*
* @param <T> the subject type
* <p>Somewhat inspired by the system used on Sponge.
*
* @param <T> the subject type. Is ALWAYS the player class of the platform.
*/
public abstract class ContextCalculator<T> implements IContextCalculator<T> {
private final List<ContextListener<T>> listeners = new CopyOnWriteArrayList<>();
public interface ContextCalculator<T> {
/**
* Pushes an update to all registered {@link ContextListener}s.
* Make sure any changes are applied internally before this method is called.
* Gives the subject all of the applicable contexts they meet
*
* @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
* @param subject the subject to add contexts to
* @param accumulator a map of contexts to add to
* @return the map
* @since 2.13
*/
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");
}
MutableContextSet giveApplicableContext(T subject, MutableContextSet accumulator);
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);
}
/**
* 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);
}

View File

@ -1,63 +0,0 @@
/*
* 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 to
* @param accumulator a map of contexts to add to
* @return the map
* @since 2.13
*/
MutableContextSet giveApplicableContext(T subject, MutableContextSet 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);
}

View File

@ -1,78 +0,0 @@
/*
* 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.data;
import java.util.function.Consumer;
/**
* A callback used to wait for the completion of asynchronous operations.
* All callbacks are ran on the main server thread.
*
* @param <T> the return type
* @deprecated in favour of {@link Consumer}
*/
@Deprecated
public interface Callback<T> {
static <T> Callback<T> empty() {
return t -> {
};
}
static <T> Callback<T> of(Runnable runnable) {
if (runnable == null) {
throw new NullPointerException("runnable");
}
return t -> runnable.run();
}
static <T> Callback<T> of(Consumer<T> consumer) {
if (consumer == null) {
throw new NullPointerException("consumer");
}
return consumer::accept;
}
/**
* Helper method for converting old {@link Callback}s to use the new {@link me.lucko.luckperms.api.Storage}
* interface.
*
* @param callback the callback to convert
* @param <T> the return type
* @return a consumer instance
* @since 2.14
* @deprecated in favour of just using {@link Consumer}s.
*/
@Deprecated
static <T> Consumer<T> convertToConsumer(Callback<T> callback) {
return callback::onComplete;
}
/**
* Called when the operation completes.
*
* @param t the return value, may be null
*/
void onComplete(T t);
}

View File

@ -26,8 +26,7 @@ package me.lucko.luckperms.api.data;
* Represents the data section of the main LuckPerms configuration.
* All methods could return null.
*/
@SuppressWarnings("deprecation")
public interface DatastoreConfiguration extends MySQLConfiguration {
public interface DatastoreConfiguration {
String getAddress();

View File

@ -1,57 +0,0 @@
/*
* 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.event;
import me.lucko.luckperms.api.PermissionHolder;
import java.util.Optional;
public class AbstractPermissionAddEvent extends TargetedEvent<PermissionHolder> {
private final String server;
private final String world;
private final long expiry;
protected AbstractPermissionAddEvent(String eventName, PermissionHolder target, String server, String world, long expiry) {
super(eventName, target);
this.server = server;
this.world = world;
this.expiry = expiry;
}
public Optional<String> getServer() {
return Optional.ofNullable(server);
}
public Optional<String> getWorld() {
return Optional.ofNullable(world);
}
public boolean isTemporary() {
return expiry != 0L;
}
public long getExpiry() {
return expiry;
}
}

View File

@ -22,21 +22,18 @@
package me.lucko.luckperms.api.event;
import me.lucko.luckperms.api.User;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Represents an event acting upon a user.
* Represents an event that can be cancelled
*/
public class UserEvent extends LPEvent {
public interface Cancellable {
private final User user;
/**
* Gets an {@link AtomicBoolean} holding the cancellation state of the event
*
* @return the cancellation
*/
AtomicBoolean getCancellationState();
protected UserEvent(String eventName, User user) {
super(eventName);
this.user = user;
}
public User getUser() {
return user;
}
}

View File

@ -22,39 +22,33 @@
package me.lucko.luckperms.api.event;
import me.lucko.luckperms.api.LuckPermsApi;
import java.util.Set;
import java.util.function.Consumer;
/**
* Abstract LuckPerms Event class.
* The LuckPerms event bus. Used for subscribing (or registering listeners) to events.
*
* @since 3.0
*/
public abstract class LPEvent {
public interface EventBus {
/**
* A friendly name of the event
* Subscribe to an event
*
* @param eventClass the event class
* @param handler the event handler
* @param <T> the event class
* @return an event handler instance representing this subscription
*/
private final String eventName;
<T extends LuckPermsEvent> EventHandler<T> subscribe(Class<T> eventClass, Consumer<T> handler);
/**
* A link to the API instance provided for convenience.
* Gets a set of all registered handlers for a given event
*
* @param eventClass the event to find handlers for
* @param <T> the event class
* @return an immutable set of event handlers
*/
private LuckPermsApi api = null;
protected LPEvent(String eventName) {
this.eventName = eventName;
}
public String getEventName() {
return eventName;
}
public LuckPermsApi getApi() {
return api;
}
public void setApi(LuckPermsApi api) {
if (this.api != null) {
throw new IllegalStateException("API can only be set once.");
}
this.api = api;
}
<T extends LuckPermsEvent> Set<EventHandler<T>> getHandlers(Class<T> eventClass);
}

View File

@ -22,41 +22,48 @@
package me.lucko.luckperms.api.event;
import me.lucko.luckperms.api.PermissionHolder;
import java.util.function.Consumer;
import java.util.Optional;
public class AbstractPermissionRemoveEvent extends TargetedEvent<PermissionHolder> {
private final String server;
private final String world;
private final boolean temporary;
protected AbstractPermissionRemoveEvent(String eventName, PermissionHolder target, String server, String world, boolean temporary) {
super(eventName, target);
this.server = server;
this.world = world;
this.temporary = temporary;
}
public Optional<String> getServer() {
return Optional.ofNullable(server);
}
public Optional<String> getWorld() {
return Optional.ofNullable(world);
}
/**
* Represents a handler for a LuckPerms event
*
* @param <T> the event class
*/
public interface EventHandler<T extends LuckPermsEvent> {
/**
* @deprecated use {@link #isTemporary()}
* Gets the class this handler is listening to
*
* @return the event class
*/
@Deprecated
public boolean getTemporary() {
return temporary;
}
Class<T> getEventClass();
public boolean isTemporary() {
return temporary;
}
/**
* Returns true if this handler is active
*
* @return true if this handler is still active
*/
boolean isActive();
/**
* Unregisters this handler from the event bus
*
* @return true if the handler wasn't already unregistered
*/
boolean unregister();
/**
* Gets the event consumer responsible for handling the event
*
* @return the event consumer
*/
Consumer<T> getConsumer();
/**
* Gets the number of times this handler has been called
*
* @return the number of times this handler has been called
*/
int getCallCount();
}

View File

@ -22,21 +22,20 @@
package me.lucko.luckperms.api.event;
import me.lucko.luckperms.api.LuckPermsApi;
/**
* Represents an event acting upon a target
* The base event interface
*
* @param <T> the target type
* @since 3.0
*/
public class TargetedEvent<T> extends LPEvent {
public interface LuckPermsEvent {
private final T target;
/**
* Get the API instance this event was dispatched from
*
* @return the api instance
*/
LuckPermsApi getApi();
protected TargetedEvent(String eventName, T target) {
super(eventName);
this.target = target;
}
public T getTarget() {
return target;
}
}

View File

@ -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.api.event.cause;
/**
* The cause of a group/track creation
*/
public enum CreationCause {
/**
* The creation was caused by a command
*/
COMMAND,
/**
* The creation was caused by an API call
*/
API,
/**
* The creation was caused by a LuckPerms internal
*/
INTERNAL;
}

View File

@ -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.api.event.cause;
/**
* The cause of a group/track deletion
*/
public enum DeletionCause {
/**
* The deletion was caused by a command
*/
COMMAND,
/**
* The deletion was caused by an API call
*/
API,
/**
* The deletion was caused by a LuckPerms internal
*/
INTERNAL;
}

View File

@ -1,47 +0,0 @@
/*
* 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.event.events;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
/**
* Called whenever a user or group is removed from / stops inheriting another group
*/
public class GroupRemoveEvent extends AbstractPermissionRemoveEvent {
/**
* The name of group being removed from the target.
* Be aware that this group may have already been deleted, and and instance may therefore not exist internally.
*/
private final String group;
public GroupRemoveEvent(PermissionHolder target, String group, String server, String world, boolean temporary) {
super("Group Remove Event", target, server, world, temporary);
this.group = group;
}
public String getGroup() {
return group;
}
}

View File

@ -1,46 +0,0 @@
/*
* 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.event.events;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.TargetedEvent;
/**
* Called when a permission expires for an object.
*
* @deprecated in favour of {@link PermissionNodeExpireEvent}
*/
@Deprecated
public class PermissionExpireEvent extends TargetedEvent<PermissionHolder> {
private final String node;
public PermissionExpireEvent(PermissionHolder target, String node) {
super("Permission Expire Event", target);
this.node = node;
}
public String getNode() {
return node;
}
}

View File

@ -1,59 +0,0 @@
/*
* 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.event.events;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.AbstractPermissionAddEvent;
import java.util.AbstractMap;
import java.util.Map;
/**
* Called whenever a user or group has a permission set.
*
* @deprecated in favour of {@link PermissionNodeSetEvent}
*/
@Deprecated
public class PermissionSetEvent extends AbstractPermissionAddEvent {
private final String node;
private final boolean value;
public PermissionSetEvent(PermissionHolder target, String node, boolean value, String server, String world, long expiry) {
super("Permission Set Event", target, server, world, expiry);
this.node = node;
this.value = value;
}
public String getNode() {
return node;
}
public boolean getValue() {
return value;
}
public Map.Entry<String, Boolean> getEntry() {
return new AbstractMap.SimpleEntry<>(node, value);
}
}

View File

@ -1,46 +0,0 @@
/*
* 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.event.events;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
/**
* Called whenever a user or group has a permission unset.
*
* @deprecated in favour of {@link PermissionNodeUnsetEvent}
*/
@Deprecated
public class PermissionUnsetEvent extends AbstractPermissionRemoveEvent {
private final String node;
public PermissionUnsetEvent(PermissionHolder target, String node, String server, String world, boolean temporary) {
super("Permission Unset Event", target, server, world, temporary);
this.node = node;
}
public String getNode() {
return node;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.event.group;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.CreationCause;
/**
* Called when a group is created
*/
public interface GroupCreateEvent extends LuckPermsEvent {
/**
* Gets the new group
*
* @return the new group
*/
Group getGroup();
/**
* Gets the cause of the creation
*
* @return the cause of the creation
*/
CreationCause getCause();
}

View File

@ -20,19 +20,38 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.group;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.AbstractPermissionEvent;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import java.util.Set;
/**
* Called when a permission node is unset from a holder
*
* @since 2.6
* Called when a group is deleted
*/
public class PermissionNodeUnsetEvent extends AbstractPermissionEvent {
public PermissionNodeUnsetEvent(PermissionHolder target, Node node) {
super("Permission Node Unset Event", target, node);
}
public interface GroupDeleteEvent extends LuckPermsEvent {
/**
* Gets the name of the deleted group
*
* @return the name of the deleted group
*/
String getGroupName();
/**
* Gets an immutable copy of the groups existing data
*
* @return a copy of the groups existing data
*/
Set<Node> getExistingData();
/**
* Gets the cause of the deletion
*
* @return the cause of the deletion
*/
DeletionCause getCause();
}

View File

@ -0,0 +1,34 @@
/*
* 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.event.group;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when all groups have been loaded in from storage.
*
* <p>Usually only called on startup and in sync tasks.</p>
*/
public interface GroupLoadAllEvent extends LuckPermsEvent {
}

View File

@ -20,24 +20,23 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event;
package me.lucko.luckperms.api.event.group;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Event that allows listeners to set the cancelled state of an event.
* Called when a group is loaded into memory from the storage.
*
* Note that this event is not the same as {@link GroupCreateEvent}
*/
public abstract class CancellableEvent extends LPEvent {
public interface GroupLoadEvent extends LuckPermsEvent {
private boolean cancelled = false;
/**
* Gets the group that was loaded
*
* @return the group that was loaded
*/
Group getGroup();
protected CancellableEvent(String eventName) {
super(eventName);
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -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.event.log;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when a log entry is about to be sent to notifiable players on the platform
*/
public interface LogBroadcastEvent extends LuckPermsEvent, Cancellable {
/**
* Gets the log entry to be broadcasted
*
* @return the log entry to be broadcasted
*/
LogEntry getEntry();
}

View File

@ -20,24 +20,22 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event;
package me.lucko.luckperms.api.event.log;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* @since 2.6
* Called when a log is about to be published to the storage file/table
*/
public class AbstractPermissionEvent extends TargetedEvent<PermissionHolder> {
public interface LogPublishEvent extends LuckPermsEvent, Cancellable {
private final Node node;
/**
* Gets the log entry to be published
*
* @return the log entry to be published
*/
LogEntry getEntry();
protected AbstractPermissionEvent(String eventName, PermissionHolder target, Node node) {
super(eventName, target);
this.node = node;
}
public Node getNode() {
return node;
}
}

View File

@ -20,19 +20,20 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.data;
package me.lucko.luckperms.api.event.node;
import me.lucko.luckperms.api.Node;
/**
* @deprecated Use {@link DatastoreConfiguration}. This is now used by multiple datastores, not just MySQL.
* Called when a node is added to a holder
*/
@Deprecated
public interface MySQLConfiguration {
public interface NodeAddEvent extends NodeMutateEvent {
String getAddress();
/**
* Gets the node that was added
*
* @return the node that was added
*/
Node getNode();
String getDatabase();
String getUsername();
String getPassword();
}

View File

@ -0,0 +1,30 @@
/*
* 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.event.node;
/**
* Called when a holder has their nodes cleared
*/
public interface NodeClearEvent extends NodeMutateEvent {
}

View File

@ -0,0 +1,75 @@
/*
* 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.event.node;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.Set;
/**
* Called when a node is added to/removed from a user/group
*/
public interface NodeMutateEvent extends LuckPermsEvent {
/**
* Gets the target of the event
*
* @return the event target
*/
PermissionHolder getTarget();
/**
* Gets an immutable copy of the holders data before the change
*
* @return the data before the change
*/
Set<Node> getDataBefore();
/**
* Gets an immutable copy of the holders data after the change
*
* @return the data after the change
*/
Set<Node> getDataAfter();
/**
* Gets whether the target of this event is a {@link me.lucko.luckperms.api.User}
*
* <p>This is equivalent to checking if getTarget() instanceof User</p>
*
* @return if the event is targeting a user
*/
boolean isUser();
/**
* Gets whether the target of this event is a {@link me.lucko.luckperms.api.Group}
*
* <p>This is equivalent to checking if getTarget() instanceof Group</p>
*
* @return if the event is targeting a group
*/
boolean isGroup();
}

View File

@ -0,0 +1,39 @@
/*
* 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.event.node;
import me.lucko.luckperms.api.Node;
/**
* Called when a node is removed from a holder
*/
public interface NodeRemoveEvent extends NodeMutateEvent {
/**
* Gets the node that was removed
*
* @return the node that was removed
*/
Node getNode();
}

View File

@ -0,0 +1,32 @@
/*
* 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.event.sync;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when the configuration is reloaded
*/
public interface ConfigReloadEvent extends LuckPermsEvent {
}

View File

@ -20,17 +20,13 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.sync;
import me.lucko.luckperms.api.event.LPEvent;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called after the sync task has ran.
* Called when an sync task has been completed
*/
public class PostSyncEvent extends LPEvent {
public PostSyncEvent() {
super("Post Sync Event");
}
public interface PostSyncEvent extends LuckPermsEvent {
}

View File

@ -0,0 +1,42 @@
/*
* 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.event.sync;
import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.UUID;
/**
* Called before a network sync task runs
*/
public interface PreNetworkSyncEvent extends LuckPermsEvent, Cancellable {
/**
* Gets the ID of the sync request
*
* @return the id of the sync request
*/
UUID getSyncId();
}

View File

@ -20,18 +20,14 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.sync;
import me.lucko.luckperms.api.event.CancellableEvent;
import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called before the sync task is about to run.
* Set this event to cancelled to prevent the sync task from running.
* Called before a sync task runs
*/
public class PreSyncEvent extends CancellableEvent {
public PreSyncEvent() {
super("Pre Sync Event");
}
public interface PreSyncEvent extends LuckPermsEvent, Cancellable {
}

View File

@ -0,0 +1,48 @@
/*
* 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.event.track;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.CreationCause;
/**
* Called when a track is created
*/
public interface TrackCreateEvent extends LuckPermsEvent {
/**
* Gets the new track
*
* @return the new track
*/
Track getTrack();
/**
* Gets the cause of the creation
*
* @return the cause of the creation
*/
CreationCause getCause();
}

View File

@ -20,24 +20,37 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.context;
package me.lucko.luckperms.api.event.track;
import java.util.Map;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import java.util.List;
/**
* Listens to context changes
*
* @param <T> the subject type, Is ALWAYS the player class of the platform.
* Called when a track is deleted
*/
public interface ContextListener<T> {
public interface TrackDeleteEvent extends LuckPermsEvent {
/**
* Called whenever a context changes on the
* Gets the name of the deleted track
*
* @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)
* @return the name of the deleted track
*/
void onContextChange(T subject, Map.Entry<String, String> before, Map.Entry<String, String> current) throws Exception;
String getTrackName();
/**
* Gets an immutable copy of the tracks existing data
*
* @return a copy of the tracks existing data
*/
List<String> getExistingData();
/**
* Gets the cause of the deletion
*
* @return the cause of the deletion
*/
DeletionCause getCause();
}

View File

@ -0,0 +1,34 @@
/*
* 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.event.track;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when all tracks have been loaded in from storage.
*
* <p>Usually only called on startup and in sync tasks.</p>
*/
public interface TrackLoadAllEvent extends LuckPermsEvent {
}

View File

@ -0,0 +1,42 @@
/*
* 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.event.track;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when a track is loaded into memory from the storage.
*
* Note that this event is not the same as {@link TrackCreateEvent}
*/
public interface TrackLoadEvent extends LuckPermsEvent {
/**
* Gets the track that was loaded
*
* @return the track that was loaded
*/
Track getTrack();
}

View File

@ -0,0 +1,37 @@
/*
* 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.event.track.mutate;
/**
* Called when a group is added to a track
*/
public interface TrackAddGroupEvent extends TrackMutateEvent {
/**
* Gets the group that was added
*
* @return the group that was added
*/
String getGroup();
}

View File

@ -20,10 +20,11 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event;
package me.lucko.luckperms.api.event.track.mutate;
/**
* Used to mark a class that listens for LuckPerms events
* Called when a track is cleared
*/
public interface LPListener {
public interface TrackClearEvent extends TrackMutateEvent {
}

View File

@ -20,30 +20,37 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.track.mutate;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.event.CancellableEvent;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.List;
/**
* Called before a LogEntry is broadcasted to players only with the notify permission.
* The log entry will still be recorded in the datastore, regardless of the cancellation state of this event.
* Cancelling this event only stops the broadcast.
* Called when a track is changed
*/
public class LogNotifyEvent extends CancellableEvent {
public interface TrackMutateEvent extends LuckPermsEvent {
/**
* The log entry to be broadcasted
* Gets the track that was mutated
*
* @return the track that was mutated
*/
private final LogEntry entry;
Track getTrack();
public LogNotifyEvent(LogEntry entry) {
super("Log Notify Event");
this.entry = entry;
}
/**
* Gets an immutable copy of the tracks data before the change
*
* @return the data before the change
*/
List<String> getDataBefore();
public LogEntry getEntry() {
return entry;
}
/**
* Gets an immutable copy of the tracks data after the change
*
* @return the data after the change
*/
List<String> getDataAfter();
}

View File

@ -0,0 +1,37 @@
/*
* 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.event.track.mutate;
/**
* Called when a group is removed from a track
*/
public interface TrackRemoveGroupEvent extends TrackMutateEvent {
/**
* Gets the group that was removed
*
* @return the group that was removed
*/
String getGroup();
}

View File

@ -0,0 +1,48 @@
/*
* 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.event.user;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when a users {@link me.lucko.luckperms.api.caching.UserData} is loaded.
*/
public interface UserCacheLoadEvent extends LuckPermsEvent {
/**
* Gets the user whose data was loaded
*
* @return the user
*/
User getUser();
/**
* Gets the data that was loaded
*
* @return the loaded data
*/
UserData getLoadedData();
}

View File

@ -0,0 +1,48 @@
/*
* 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.event.user;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called when a users cached data is refreshed
*/
public interface UserDataRecalculateEvent extends LuckPermsEvent {
/**
* Gets the user whose data was recalculated
*
* @return the user
*/
User getUser();
/**
* Gets the data that was recalculated
*
* @return the data
*/
UserData getData();
}

View File

@ -20,35 +20,37 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.user;
import me.lucko.luckperms.api.event.LPEvent;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.UUID;
/**
* Called when the user logs into the network for the first time. Particularly useful for networks with multiple
* lobbies, who want to welcome a user when they join for the first time.
* Called when the user logs into the network for the first time.
*
* <p>Particularly useful for networks with multiple
* lobbies, who want to welcome a user when they join for the first time.</p>
*
* <p>This event is fired before the player has actually joined the game on the async login / auth event. If you want to
* do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e.
* do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e.</p>
*
* <p>The users data will not be loaded when this event is called.</p>
*/
public class UserFirstLoginEvent extends LPEvent {
public interface UserFirstLoginEvent extends LuckPermsEvent {
private final UUID uuid;
private final String username;
/**
* Gets the UUID of the user
*
* @return the uuid of the user
*/
UUID getUuid();
public UserFirstLoginEvent(UUID uuid, String username) {
super("User First Join Event");
this.uuid = uuid;
this.username = username;
}
/**
* Gets the username of the user
*
* @return the username of the user
*/
String getUsername();
public UUID getUuid() {
return uuid;
}
public String getUsername() {
return username;
}
}

View File

@ -20,19 +20,21 @@
* SOFTWARE.
*/
package me.lucko.luckperms.api.event.events;
package me.lucko.luckperms.api.event.user;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.TrackEvent;
import me.lucko.luckperms.api.event.LuckPermsEvent;
/**
* Called whenever a user is demoted down a track
* Called when a user is loaded into memory from the storage.
*/
public class UserDemoteEvent extends TrackEvent {
public interface UserLoadEvent extends LuckPermsEvent {
public UserDemoteEvent(Track track, User user, String from, String to) {
super("User Demote Event", track, user, from, to);
}
/**
* Gets the user that was loaded
*
* @return the user that was loaded
*/
User getUser();
}

View File

@ -0,0 +1,40 @@
/*
* 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.event.user.track;
/**
* Represents the type of action performed in a {@link UserTrackEvent}
*/
public enum TrackAction {
/**
* The user was promoted up a track
*/
PROMOTION,
/**
* The user was demoted down a track
*/
DEMOTION;
}

View File

@ -0,0 +1,32 @@
/*
* 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.event.user.track;
/**
* Called when a user is demoted down a track.
*
* <p>{@link #getAction()} is always {@link TrackAction#DEMOTION}</p>
*/
public interface UserDemoteEvent extends UserTrackEvent {
}

View File

@ -0,0 +1,32 @@
/*
* 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.event.user.track;
/**
* Called when a user is promoted up a track.
*
* <p>{@link #getAction()} is always {@link TrackAction#PROMOTION}</p>
*/
public interface UserPromoteEvent extends UserTrackEvent {
}

View File

@ -0,0 +1,73 @@
/*
* 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.event.user.track;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import java.util.Optional;
/**
* Called when a user interacts with a track through a promotion or demotion
*/
public interface UserTrackEvent extends LuckPermsEvent {
/**
* Gets the track involved in the event
*
* @return the track involved in the event
*/
Track getTrack();
/**
* Gets the user who was promoted or demoted
*
* @return the user involved in the event
*/
User getUser();
/**
* Gets the action performed
*
* @return the action performed
*/
TrackAction getAction();
/**
* Gets the group the user was promoted/demoted from.
*
* <p>May be {@link Optional#empty()} if the user wasn't already placed on the track.</p>
*
* @return the group the user was promoted/demoted from
*/
Optional<String> getGroupFrom();
/**
* Gets the group the user was promoted/demoted to
*
* @return the group the user was promoted/demoted to
*/
Optional<String> getGroupTo();
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>2.17-SNAPSHOT</version>
<version>3.0-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.17-SNAPSHOT</version>
<version>3.0-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.17-SNAPSHOT</version>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -246,14 +246,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
uuidCache = new UuidCache(this);
userManager = new GenericUserManager(this);
groupManager = new GenericGroupManager(this);
trackManager = new GenericTrackManager();
trackManager = new GenericTrackManager(this);
importer = new Importer(commandManager);
calculatorFactory = new BukkitCalculatorFactory(this);
cachedStateManager = new CachedStateManager(this);
contextManager = new ContextManager<>();
worldCalculator = new WorldCalculator(this);
pm.registerEvents(worldCalculator, this);
contextManager.registerCalculator(worldCalculator);
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration()));

View File

@ -32,12 +32,11 @@ import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import java.util.Map;
@RequiredArgsConstructor
public class WorldCalculator extends ContextCalculator<Player> implements Listener {
public class WorldCalculator implements ContextCalculator<Player> {
private static final String WORLD_KEY = "world";
private final LuckPermsPlugin plugin;

View File

@ -30,6 +30,7 @@ import de.bananaco.bpermissions.api.World;
import de.bananaco.bpermissions.api.WorldManager;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
@ -114,7 +115,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
}
// Make a LuckPerms group for the one being migrated.
plugin.getStorage().createAndLoadGroup(groupName).join();
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName);
migrateHolder(log, world, group, lpGroup);

View File

@ -24,6 +24,7 @@ package me.lucko.luckperms.bukkit.migration;
import com.google.common.collect.Maps;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -90,7 +91,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
AtomicInteger globalGroupCount = new AtomicInteger(0);
for (Group g : gg.getGroupList()) {
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
for (String node : g.getPermissionList()) {
@ -214,7 +215,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
plugin.getStorage().createAndLoadGroup(e.getKey()).join();
plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
@ -99,7 +100,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
int groupWeight = maxWeight - group.getRank();
final String name = group.getName().toLowerCase();
plugin.getStorage().createAndLoadGroup(name).join();
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
Group lpGroup = plugin.getGroupManager().getIfLoaded(name);
try {

View File

@ -31,6 +31,7 @@ import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable;
import com.google.common.util.concurrent.ListenableFuture;
import com.zaxxer.hikari.HikariDataSource;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
@ -224,7 +225,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
AtomicInteger groupCount = new AtomicInteger(0);
Map<Integer, Group> groups = pm.getGroups(); // All versions
for (Group g : groups.values()) {
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
for (Permission p : g.getOwnPermissions()) { // All versions

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.bukkit.migration;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
@ -90,7 +91,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
for (String g : service.getAllGroups()) {
plugin.getStorage().createAndLoadGroup(g.toLowerCase()).join();
plugin.getStorage().createAndLoadGroup(g.toLowerCase(), CreationCause.INTERNAL).join();
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
PermissionEntity entity = internalService.getEntity(g, null, true);
@ -105,7 +106,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
log.log("Starting track migration.");
AtomicInteger trackCount = new AtomicInteger(0);
for (String t : service.getAllTracks()) {
plugin.getStorage().createAndLoadTrack(t.toLowerCase()).join();
plugin.getStorage().createAndLoadTrack(t.toLowerCase(), CreationCause.INTERNAL).join();
Track track = plugin.getTrackManager().getIfLoaded(t.toLowerCase());
track.setGroups(service.getTrackGroups(t));
plugin.getStorage().saveTrack(track);

View File

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

View File

@ -28,13 +28,10 @@ import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
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 {
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
private static final String WORLD_KEY = "world";
private static String getServer(ProxiedPlayer player) {
@ -61,9 +58,4 @@ public class BackendServerCalculator extends ContextCalculator<ProxiedPlayer> im
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())));
}
}

View File

@ -23,7 +23,6 @@
package me.lucko.luckperms.bungee;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.event.events.UserFirstLoginEvent;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.UuidCache;
@ -104,14 +103,14 @@ public class BungeeListener extends AbstractListener implements Listener {
cache.addToCache(c.getUniqueId(), uuid);
} else {
// No previous data for this player
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
plugin.getApiProvider().getEventFactory().handleUserFirstLogin(c.getUniqueId(), c.getName());
cache.addToCache(c.getUniqueId(), c.getUniqueId());
plugin.getStorage().force().saveUUIDData(c.getName(), c.getUniqueId()).join();
}
} else {
String name = plugin.getStorage().getName(c.getUniqueId()).join();
if (name == null) {
plugin.getApiProvider().fireEventAsync(new UserFirstLoginEvent(c.getUniqueId(), c.getName()));
plugin.getApiProvider().getEventFactory().handleUserFirstLogin(c.getUniqueId(), c.getName());
}
// Online mode, no cache needed. This is just for name -> uuid lookup.

View File

@ -192,14 +192,13 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
uuidCache = new UuidCache(this);
userManager = new GenericUserManager(this);
groupManager = new GenericGroupManager(this);
trackManager = new GenericTrackManager();
trackManager = new GenericTrackManager(this);
importer = new Importer(commandManager);
calculatorFactory = new BungeeCalculatorFactory(this);
cachedStateManager = new CachedStateManager(this);
contextManager = new ContextManager<>();
BackendServerCalculator serverCalculator = new BackendServerCalculator();
getProxy().getPluginManager().registerListener(this, serverCalculator);
contextManager.registerCalculator(serverCalculator);
contextManager.registerCalculator(new ServerCalculator<>(configuration));

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.bungee.migration;
import me.lucko.luckperms.api.MetaUtils;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SubCommand;
@ -68,7 +69,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
for (Group g : bp.getPermissionsManager().getBackEnd().loadGroups()) {
// Make a LuckPerms group for the one being migrated
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
// Migrate global perms

View File

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

View File

@ -22,13 +22,10 @@
package me.lucko.luckperms.common.api;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import com.google.common.eventbus.EventBus;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Datastore;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.LPConfiguration;
import me.lucko.luckperms.api.Logger;
@ -41,21 +38,14 @@ import me.lucko.luckperms.api.Storage;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.UuidCache;
import me.lucko.luckperms.api.context.ContextListener;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.IContextCalculator;
import me.lucko.luckperms.api.event.LPEvent;
import me.lucko.luckperms.api.event.LPListener;
import me.lucko.luckperms.common.api.delegate.DatastoreDelegate;
import me.lucko.luckperms.common.api.delegate.GroupDelegate;
import me.lucko.luckperms.common.api.delegate.LPConfigurationDelegate;
import me.lucko.luckperms.common.api.delegate.NodeFactoryDelegate;
import me.lucko.luckperms.common.api.delegate.StorageDelegate;
import me.lucko.luckperms.common.api.delegate.TrackDelegate;
import me.lucko.luckperms.common.api.delegate.UserDelegate;
import me.lucko.luckperms.common.api.delegate.UuidCacheDelegate;
import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
import me.lucko.luckperms.common.api.delegates.UserDelegate;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.UserIdentifier;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.event.LuckPermsEventBus;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.Optional;
@ -66,23 +56,19 @@ import java.util.stream.Collectors;
/**
* Implements the LuckPerms API using the plugin instance
*/
@AllArgsConstructor
public class ApiProvider implements LuckPermsApi {
private final LuckPermsPlugin plugin;
private final EventBus eventBus = new EventBus("LuckPerms");
public void fireEventAsync(LPEvent event) {
plugin.doAsync(() -> fireEvent(event));
}
@Getter
private final LuckPermsEventBus eventBus;
public void fireEvent(LPEvent event) {
try {
event.setApi(this);
eventBus.post(event);
} catch (Exception e) {
getLogger().severe("Couldn't fire LuckPerms Event: " + event.getEventName());
e.printStackTrace();
}
@Getter
private final EventFactory eventFactory;
public ApiProvider(LuckPermsPlugin plugin) {
this.plugin = plugin;
this.eventBus = new LuckPermsEventBus(plugin);
this.eventFactory = new EventFactory(eventBus);
}
@Override
@ -92,7 +78,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public double getApiVersion() {
return 2.17;
return 3.0;
}
@Override
@ -105,30 +91,14 @@ public class ApiProvider implements LuckPermsApi {
return plugin.getServerType();
}
@Override
public void registerListener(@NonNull LPListener listener) {
eventBus.register(listener);
}
@Override
public void unregisterListener(@NonNull LPListener listener) {
eventBus.unregister(listener);
}
@Override
public LPConfiguration getConfiguration() {
return new LPConfigurationDelegate(plugin.getConfiguration());
return plugin.getConfiguration().getDelegate();
}
@Override
public Storage getStorage() {
return new StorageDelegate(plugin, plugin.getStorage());
}
@SuppressWarnings("deprecation")
@Override
public Datastore getDatastore() {
return new DatastoreDelegate(plugin, plugin.getStorage());
return plugin.getStorage().getDelegate();
}
@Override
@ -138,7 +108,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public UuidCache getUuidCache() {
return new UuidCacheDelegate(plugin.getUuidCache());
return plugin.getUuidCache().getDelegate();
}
@Override
@ -149,7 +119,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public User getUser(@NonNull UUID uuid) {
final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(uuid);
return user == null ? null : new UserDelegate(user);
return user == null ? null : user.getDelegate();
}
@Override
@ -160,7 +130,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public User getUser(@NonNull String name) {
final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().getByUsername(name);
return user == null ? null : new UserDelegate(user);
return user == null ? null : user.getDelegate();
}
@Override
@ -170,7 +140,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public Set<User> getUsers() {
return plugin.getUserManager().getAll().values().stream().map(UserDelegate::new).collect(Collectors.toSet());
return plugin.getUserManager().getAll().values().stream().map(u -> u.getDelegate()).collect(Collectors.toSet());
}
@Override
@ -187,7 +157,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public Group getGroup(@NonNull String name) {
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name);
return group == null ? null : new GroupDelegate(group);
return group == null ? null : group.getDelegate();
}
@Override
@ -197,7 +167,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public Set<Group> getGroups() {
return plugin.getGroupManager().getAll().values().stream().map(GroupDelegate::new).collect(Collectors.toSet());
return plugin.getGroupManager().getAll().values().stream().map(g -> g.getDelegate()).collect(Collectors.toSet());
}
@Override
@ -208,7 +178,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public Track getTrack(@NonNull String name) {
final me.lucko.luckperms.common.core.model.Track track = plugin.getTrackManager().getIfLoaded(name);
return track == null ? null : new TrackDelegate(track);
return track == null ? null : track.getDelegate();
}
@Override
@ -218,7 +188,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public Set<Track> getTracks() {
return plugin.getTrackManager().getAll().values().stream().map(TrackDelegate::new).collect(Collectors.toSet());
return plugin.getTrackManager().getAll().values().stream().map(t -> t.getDelegate()).collect(Collectors.toSet());
}
@Override
@ -238,16 +208,10 @@ public class ApiProvider implements LuckPermsApi {
@SuppressWarnings("unchecked")
@Override
public void registerContextCalculator(IContextCalculator<?> contextCalculator) {
public void registerContextCalculator(ContextCalculator<?> contextCalculator) {
plugin.getContextManager().registerCalculator(contextCalculator);
}
@SuppressWarnings("unchecked")
@Override
public void registerContextListener(ContextListener<?> contextListener) {
plugin.getContextManager().registerListener(contextListener);
}
@Override
public Optional<Contexts> getContextForUser(User user) {
ApiUtils.checkUser(user);

View File

@ -29,9 +29,9 @@ import com.google.common.base.Preconditions;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.common.api.delegate.GroupDelegate;
import me.lucko.luckperms.common.api.delegate.TrackDelegate;
import me.lucko.luckperms.common.api.delegate.UserDelegate;
import me.lucko.luckperms.common.api.delegates.GroupDelegate;
import me.lucko.luckperms.common.api.delegates.TrackDelegate;
import me.lucko.luckperms.common.api.delegates.UserDelegate;
import me.lucko.luckperms.common.utils.ArgumentChecker;
@UtilityClass

View File

@ -1,440 +0,0 @@
/*
* 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.common.api.delegate;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import me.lucko.luckperms.api.Datastore;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.Log;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.Storage;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import static me.lucko.luckperms.common.api.ApiUtils.checkGroup;
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
import static me.lucko.luckperms.common.api.ApiUtils.checkTrack;
import static me.lucko.luckperms.common.api.ApiUtils.checkUser;
import static me.lucko.luckperms.common.api.ApiUtils.checkUsername;
@SuppressWarnings("deprecation")
public class DatastoreDelegate implements Datastore {
private final LuckPermsPlugin plugin;
private final Storage master;
private final Async async;
private final Sync sync;
private final Future future;
public DatastoreDelegate(@NonNull LuckPermsPlugin plugin, @NonNull Storage master) {
this.plugin = plugin;
this.master = master;
this.async = new Async(master);
this.sync = new Sync(master);
this.future = new Future(master);
}
private <T> void registerCallback(CompletableFuture<T> fut, Callback<T> c) {
if (c != null) {
fut.thenAcceptAsync(Callback.convertToConsumer(c), plugin.getScheduler().getSyncExecutor());
}
}
@Override
public String getName() {
return master.getName();
}
@Override
public boolean isAcceptingLogins() {
return master.isAcceptingLogins();
}
@Override
public Datastore.Async async() {
return async;
}
@Override
public Datastore.Sync sync() {
return sync;
}
@Override
public Datastore.Future future() {
return future;
}
@AllArgsConstructor
public class Async implements Datastore.Async {
private final me.lucko.luckperms.common.storage.Storage master;
@Override
public void logAction(@NonNull LogEntry entry, Callback<Boolean> callback) {
registerCallback(master.force().logAction(entry), callback);
}
@Override
public void getLog(@NonNull Callback<Log> callback) {
master.force().getLog().thenAcceptAsync(log -> callback.onComplete(new LogDelegate(log)), plugin.getScheduler().getSyncExecutor());
}
@Override
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
registerCallback(master.force().loadUser(uuid, checkUsername(username)), callback);
}
@Override
public void loadUser(@NonNull UUID uuid, Callback<Boolean> callback) {
registerCallback(master.force().loadUser(uuid, "null"), callback);
}
@Override
public void loadUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
registerCallback(master.force().loadUser(uuid, checkUsername(username)), callback);
}
@Override
public void saveUser(@NonNull User user, Callback<Boolean> callback) {
checkUser(user);
registerCallback(master.force().saveUser(((UserDelegate) user).getMaster()), callback);
}
@Override
public void cleanupUsers(Callback<Boolean> callback) {
registerCallback(master.force().cleanupUsers(), callback);
}
@Override
public void getUniqueUsers(Callback<Set<UUID>> callback) {
registerCallback(master.force().getUniqueUsers(), callback);
}
@Override
public void createAndLoadGroup(@NonNull String name, Callback<Boolean> callback) {
registerCallback(master.force().createAndLoadGroup(checkName(name)), callback);
}
@Override
public void loadGroup(@NonNull String name, Callback<Boolean> callback) {
registerCallback(master.force().loadGroup(checkName(name)), callback);
}
@Override
public void loadAllGroups(Callback<Boolean> callback) {
registerCallback(master.force().loadAllGroups(), callback);
}
@Override
public void saveGroup(@NonNull Group group, Callback<Boolean> callback) {
checkGroup(group);
registerCallback(master.force().saveGroup(((GroupDelegate) group).getMaster()), callback);
}
@Override
public void deleteGroup(@NonNull Group group, Callback<Boolean> callback) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
registerCallback(master.force().deleteGroup(((GroupDelegate) group).getMaster()), callback);
}
@Override
public void createAndLoadTrack(@NonNull String name, Callback<Boolean> callback) {
registerCallback(master.force().createAndLoadTrack(checkName(name)), callback);
}
@Override
public void loadTrack(@NonNull String name, Callback<Boolean> callback) {
registerCallback(master.force().loadTrack(checkName(name)), callback);
}
@Override
public void loadAllTracks(Callback<Boolean> callback) {
registerCallback(master.force().loadAllTracks(), callback);
}
@Override
public void saveTrack(@NonNull Track track, Callback<Boolean> callback) {
checkTrack(track);
registerCallback(master.force().saveTrack(((TrackDelegate) track).getMaster()), callback);
}
@Override
public void deleteTrack(@NonNull Track track, Callback<Boolean> callback) {
checkTrack(track);
registerCallback(master.force().deleteTrack(((TrackDelegate) track).getMaster()), callback);
}
@Override
public void saveUUIDData(@NonNull String username, @NonNull UUID uuid, Callback<Boolean> callback) {
registerCallback(master.force().saveUUIDData(checkUsername(username), uuid), callback);
}
@Override
public void getUUID(@NonNull String username, Callback<UUID> callback) {
registerCallback(master.force().getUUID(checkUsername(username)), callback);
}
}
@AllArgsConstructor
public class Sync implements Datastore.Sync {
private final Storage master;
@Override
public boolean logAction(@NonNull LogEntry entry) {
return master.force().logAction(entry).join();
}
@Override
public Log getLog() {
me.lucko.luckperms.common.data.Log log = master.force().getLog().join();
if (log == null) {
return null;
}
return new LogDelegate(log);
}
@Override
public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
return master.force().loadUser(uuid, checkUsername(username)).join();
}
@Override
public boolean loadUser(@NonNull UUID uuid) {
return master.force().loadUser(uuid, "null").join();
}
@Override
public boolean loadUser(@NonNull UUID uuid, @NonNull String username) {
return master.force().loadUser(uuid, checkUsername(username)).join();
}
@Override
public boolean saveUser(@NonNull User user) {
checkUser(user);
return master.force().saveUser(((UserDelegate) user).getMaster()).join();
}
@Override
public boolean cleanupUsers() {
return master.force().cleanupUsers().join();
}
@Override
public Set<UUID> getUniqueUsers() {
return master.force().getUniqueUsers().join();
}
@Override
public boolean createAndLoadGroup(@NonNull String name) {
return master.force().createAndLoadGroup(checkName(name)).join();
}
@Override
public boolean loadGroup(@NonNull String name) {
return master.force().loadGroup(checkName(name)).join();
}
@Override
public boolean loadAllGroups() {
return master.force().loadAllGroups().join();
}
@Override
public boolean saveGroup(@NonNull Group group) {
checkGroup(group);
return master.force().saveGroup(((GroupDelegate) group).getMaster()).join();
}
@Override
public boolean deleteGroup(@NonNull Group group) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster()).join();
}
@Override
public boolean createAndLoadTrack(@NonNull String name) {
return master.force().createAndLoadTrack(checkName(name)).join();
}
@Override
public boolean loadTrack(@NonNull String name) {
return master.force().loadTrack(checkName(name)).join();
}
@Override
public boolean loadAllTracks() {
return master.force().loadAllTracks().join();
}
@Override
public boolean saveTrack(@NonNull Track track) {
checkTrack(track);
return master.force().saveTrack(((TrackDelegate) track).getMaster()).join();
}
@Override
public boolean deleteTrack(@NonNull Track track) {
checkTrack(track);
return master.force().deleteTrack(((TrackDelegate) track).getMaster()).join();
}
@Override
public boolean saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
return master.force().saveUUIDData(checkUsername(username), uuid).join();
}
@Override
public UUID getUUID(@NonNull String username) {
return master.force().getUUID(checkUsername(username)).join();
}
}
@AllArgsConstructor
public class Future implements Datastore.Future {
private final Storage master;
@Override
public java.util.concurrent.Future<Boolean> logAction(@NonNull LogEntry entry) {
return master.force().logAction(entry);
}
@Override
public java.util.concurrent.Future<Log> getLog() {
return master.force().getLog().thenApply(log -> log == null ? null : new LogDelegate(log));
}
@Override
public java.util.concurrent.Future<Boolean> loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
return master.force().loadUser(uuid, checkUsername(username));
}
@Override
public java.util.concurrent.Future<Boolean> loadUser(@NonNull UUID uuid) {
return master.force().loadUser(uuid, "null");
}
@Override
public java.util.concurrent.Future<Boolean> loadUser(@NonNull UUID uuid, @NonNull String username) {
return master.force().loadUser(uuid, checkUsername(username));
}
@Override
public java.util.concurrent.Future<Boolean> saveUser(@NonNull User user) {
checkUser(user);
return master.force().saveUser(((UserDelegate) user).getMaster());
}
@Override
public java.util.concurrent.Future<Boolean> cleanupUsers() {
return master.force().cleanupUsers();
}
@Override
public java.util.concurrent.Future<Set<UUID>> getUniqueUsers() {
return master.force().getUniqueUsers();
}
@Override
public java.util.concurrent.Future<Boolean> createAndLoadGroup(@NonNull String name) {
return master.force().createAndLoadGroup(checkName(name));
}
@Override
public java.util.concurrent.Future<Boolean> loadGroup(@NonNull String name) {
return master.force().loadGroup(checkName(name));
}
@Override
public java.util.concurrent.Future<Boolean> loadAllGroups() {
return master.force().loadAllGroups();
}
@Override
public java.util.concurrent.Future<Boolean> saveGroup(@NonNull Group group) {
checkGroup(group);
return master.force().saveGroup(((GroupDelegate) group).getMaster());
}
@Override
public java.util.concurrent.Future<Boolean> deleteGroup(@NonNull Group group) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster());
}
@Override
public java.util.concurrent.Future<Boolean> createAndLoadTrack(@NonNull String name) {
return master.force().createAndLoadTrack(checkName(name));
}
@Override
public java.util.concurrent.Future<Boolean> loadTrack(@NonNull String name) {
return master.force().loadTrack(checkName(name));
}
@Override
public java.util.concurrent.Future<Boolean> loadAllTracks() {
return master.force().loadAllTracks();
}
@Override
public java.util.concurrent.Future<Boolean> saveTrack(@NonNull Track track) {
checkTrack(track);
return master.force().saveTrack(((TrackDelegate) track).getMaster());
}
@Override
public java.util.concurrent.Future<Boolean> deleteTrack(@NonNull Track track) {
checkTrack(track);
return master.force().deleteTrack(((TrackDelegate) track).getMaster());
}
@Override
public java.util.concurrent.Future<Boolean> saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
return master.force().saveUUIDData(checkUsername(username), uuid);
}
@Override
public java.util.concurrent.Future<UUID> getUUID(@NonNull String username) {
return master.force().getUUID(checkUsername(username));
}
}
}

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;

View File

@ -20,13 +20,12 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.LPConfiguration;
import me.lucko.luckperms.api.data.DatastoreConfiguration;
import me.lucko.luckperms.api.data.MySQLConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
@ -49,16 +48,6 @@ public class LPConfigurationDelegate implements LPConfiguration {
return master.get(ConfigKeys.SYNC_TIME);
}
@Override
public String getDefaultGroupNode() {
return master.get(ConfigKeys.DEFAULT_GROUP_NODE);
}
@Override
public String getDefaultGroupName() {
return master.get(ConfigKeys.DEFAULT_GROUP_NAME);
}
@Override
public boolean getIncludeGlobalPerms() {
return master.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
@ -104,11 +93,6 @@ public class LPConfigurationDelegate implements LPConfiguration {
return master.get(ConfigKeys.LOG_NOTIFY);
}
@Override
public boolean getDebugPermissionChecks() {
return false;
}
@Override
public boolean getEnableOps() {
return master.get(ConfigKeys.OPS_ENABLED);
@ -134,12 +118,6 @@ public class LPConfigurationDelegate implements LPConfiguration {
return master.get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
}
@SuppressWarnings("deprecation")
@Override
public MySQLConfiguration getDatabaseValues() {
return getDatastoreConfig();
}
@Override
public DatastoreConfiguration getDatastoreConfig() {
return master.get(ConfigKeys.DATABASE_VALUES);

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AllArgsConstructor;
import lombok.NonNull;

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.NonNull;

View File

@ -20,12 +20,11 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
@ -34,22 +33,18 @@ import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PermissionHolder;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLegacy;
/**
* Provides a link between {@link PermissionHolder} and {@link me.lucko.luckperms.common.core.model.PermissionHolder}
@ -79,11 +74,6 @@ public class PermissionHolderDelegate implements PermissionHolder {
return ImmutableSet.copyOf(master.getTransientNodes());
}
@Override
public Set<Node> getAllNodes() {
return ImmutableSet.copyOf(master.getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll())));
}
@Override
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
return new TreeSet<>(master.getAllNodes(null, ExtractedContexts.generate(contexts)));
@ -99,11 +89,6 @@ public class PermissionHolderDelegate implements PermissionHolder {
return new HashMap<>(master.exportNodes(contexts, lowerCase));
}
@Override
public Map<String, Boolean> getNodes() {
return ImmutableMap.copyOf(exportToLegacy(master.getNodes()));
}
@Override
public Tristate hasPermission(@NonNull Node node) {
return master.hasPermission(node, false);
@ -314,75 +299,11 @@ public class PermissionHolderDelegate implements PermissionHolder {
master.clearTransientNodes();
}
@Override
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes) {
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 master.exportNodes(new Contexts(ContextSet.fromMap(context), true, true, true, true, true, false), false);
}
@Override
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
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 master.exportNodes(new Contexts(ContextSet.fromMap(context), true, true, true, true, true, false), false);
}
@Override
public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups, List<String> possibleNodes) {
return getLocalPermissions(server, null, excludedGroups, possibleNodes);
}
@Override
public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) {
return getLocalPermissions(server, null, excludedGroups, null);
}
@Override
public Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups) {
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(ContextSet.fromMap(extraContext), includeGlobal, includeGlobal, applyGroups, true, true, false), false);
}
@Override
public Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes() {
Map<Map.Entry<String, Boolean>, Long> m = new HashMap<>();
for (Node node : master.getTemporaryNodes()) {
m.put(new AbstractMap.SimpleEntry<>(node.getKey(), node.getValue()), node.getExpiryUnixTime());
}
return m;
}
@Override
public Set<Node> getTemporaryPermissionNodes() {
return master.getTemporaryNodes();
}
@Override
public Map<String, Boolean> getPermanentNodes() {
return exportToLegacy(master.getPermanentNodes());
}
@Override
public Set<Node> getPermanentPermissionNodes() {
return master.getPermanentNodes();

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AllArgsConstructor;
import lombok.NonNull;
@ -32,6 +32,8 @@ import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.Storage;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -113,7 +115,7 @@ public class StorageDelegate implements Storage {
@Override
public CompletableFuture<Boolean> createAndLoadGroup(String name) {
return master.force().createAndLoadGroup(checkName(name));
return master.force().createAndLoadGroup(checkName(name), CreationCause.API);
}
@Override
@ -138,7 +140,7 @@ public class StorageDelegate implements Storage {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster());
return master.force().deleteGroup(((GroupDelegate) group).getMaster(), DeletionCause.API);
}
@Override
@ -148,7 +150,7 @@ public class StorageDelegate implements Storage {
@Override
public CompletableFuture<Boolean> createAndLoadTrack(String name) {
return master.force().createAndLoadTrack(checkName(name));
return master.force().createAndLoadTrack(checkName(name), CreationCause.API);
}
@Override
@ -170,7 +172,7 @@ public class StorageDelegate implements Storage {
@Override
public CompletableFuture<Boolean> deleteTrack(Track track) {
checkTrack(track);
return master.force().deleteTrack(((TrackDelegate) track).getMaster());
return master.force().deleteTrack(((TrackDelegate) track).getMaster(), DeletionCause.API);
}
@Override

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
@ -40,7 +40,6 @@ import static me.lucko.luckperms.common.api.ApiUtils.checkGroup;
* Provides a link between {@link Track} and {@link me.lucko.luckperms.common.core.model.Track}
*/
@EqualsAndHashCode(of = {"name"})
@SuppressWarnings("unused")
public class TrackDelegate implements Track {
@Getter(AccessLevel.PACKAGE)

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -43,7 +43,6 @@ import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
* Provides a link between {@link User} and {@link me.lucko.luckperms.common.core.model.User}
*/
@EqualsAndHashCode(of = {"uuid"}, callSuper = false)
@SuppressWarnings("unused")
public class UserDelegate extends PermissionHolderDelegate implements User {
@Getter

View File

@ -20,7 +20,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.delegate;
package me.lucko.luckperms.common.api.delegates;
import lombok.AllArgsConstructor;
import lombok.NonNull;

View File

@ -22,9 +22,6 @@
package me.lucko.luckperms.common.commands.generic.parent;
import me.lucko.luckperms.api.event.events.GroupAddEvent;
import me.lucko.luckperms.common.api.delegate.GroupDelegate;
import me.lucko.luckperms.common.api.delegate.PermissionHolderDelegate;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -93,21 +90,18 @@ public class ParentAddTemp extends SharedSubCommand {
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
DateUtil.formatDateDiff(duration)
);
plugin.getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(holder), new GroupDelegate(group), null, null, duration));
break;
case SERVER:
duration = holder.setPermission(new NodeBuilder("group." + group.getName()).setValue(true).setServer(server).setExpiry(duration).build(), modifier).getExpiryUnixTime();
Message.SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
server, DateUtil.formatDateDiff(duration)
);
plugin.getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(holder), new GroupDelegate(group), server, null, duration));
break;
case SERVER_AND_WORLD:
duration = holder.setPermission(new NodeBuilder("group." + group.getName()).setValue(true).setServer(server).setWorld(world).setExpiry(duration).build(), modifier).getExpiryUnixTime();
Message.SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(),
server, world, DateUtil.formatDateDiff(duration)
);
plugin.getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(holder), new GroupDelegate(group), server, world, duration));
break;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.group;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
@ -62,7 +63,7 @@ public class CreateGroup extends SingleCommand {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadGroup(groupName).join()) {
if (!plugin.getStorage().createAndLoadGroup(groupName, CreationCause.COMMAND).join()) {
Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.group;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
@ -73,7 +74,7 @@ public class DeleteGroup extends SingleCommand {
return CommandResult.LOADING_ERROR;
}
if (!plugin.getStorage().deleteGroup(group).join()) {
if (!plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).join()) {
Message.DELETE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.group;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -57,7 +58,7 @@ public class GroupClone extends SubCommand<Group> {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadGroup(newGroupName).join()) {
if (!plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).join()) {
Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,8 @@
package me.lucko.luckperms.common.commands.group;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -57,7 +59,7 @@ public class GroupRename extends SubCommand<Group> {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadGroup(newGroupName).join()) {
if (!plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).join()) {
Message.CREATE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}
@ -68,7 +70,7 @@ public class GroupRename extends SubCommand<Group> {
return CommandResult.LOADING_ERROR;
}
if (!plugin.getStorage().deleteGroup(group).join()) {
if (!plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).join()) {
Message.DELETE_GROUP_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.track;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
@ -62,7 +63,7 @@ public class CreateTrack extends SingleCommand {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadTrack(trackName).join()) {
if (!plugin.getStorage().createAndLoadTrack(trackName, CreationCause.COMMAND).join()) {
Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.track;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
@ -66,7 +67,7 @@ public class DeleteTrack extends SingleCommand {
return CommandResult.LOADING_ERROR;
}
if (!plugin.getStorage().deleteTrack(track).join()) {
if (!plugin.getStorage().deleteTrack(track, DeletionCause.COMMAND).join()) {
Message.DELETE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.track;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -57,7 +58,7 @@ public class TrackClone extends SubCommand<Track> {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadTrack(newTrackName).join()) {
if (!plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.INTERNAL).join()) {
Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -22,6 +22,8 @@
package me.lucko.luckperms.common.commands.track;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -57,7 +59,7 @@ public class TrackRename extends SubCommand<Track> {
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().createAndLoadTrack(newTrackName).join()) {
if (!plugin.getStorage().createAndLoadTrack(newTrackName, CreationCause.COMMAND).join()) {
Message.CREATE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}
@ -68,7 +70,7 @@ public class TrackRename extends SubCommand<Track> {
return CommandResult.LOADING_ERROR;
}
if (!plugin.getStorage().deleteTrack(track).join()) {
if (!plugin.getStorage().deleteTrack(track, DeletionCause.COMMAND).join()) {
Message.DELETE_TRACK_ERROR.send(sender);
return CommandResult.FAILURE;
}

View File

@ -25,9 +25,6 @@ package me.lucko.luckperms.common.commands.user;
import com.google.common.base.Objects;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.event.events.UserDemoteEvent;
import me.lucko.luckperms.common.api.delegate.TrackDelegate;
import me.lucko.luckperms.common.api.delegate.UserDelegate;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -150,7 +147,7 @@ public class UserDemote extends SubCommand<User> {
.action("demote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackDelegate(track), new UserDelegate(user), old, null));
plugin.getApiProvider().getEventFactory().handleUserDemote(user, track, old, null);
return CommandResult.SUCCESS;
}
@ -194,7 +191,7 @@ public class UserDemote extends SubCommand<User> {
.action("demote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackDelegate(track), new UserDelegate(user), old, previousGroup.getName()));
plugin.getApiProvider().getEventFactory().handleUserDemote(user, track, old, previousGroup.getName());
return CommandResult.SUCCESS;
}

View File

@ -25,9 +25,6 @@ package me.lucko.luckperms.common.commands.user;
import com.google.common.base.Objects;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.event.events.UserPromoteEvent;
import me.lucko.luckperms.common.api.delegate.TrackDelegate;
import me.lucko.luckperms.common.api.delegate.UserDelegate;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@ -147,7 +144,7 @@ public class UserPromote extends SubCommand<User> {
.action("promote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackDelegate(track), new UserDelegate(user), null, first));
plugin.getApiProvider().getEventFactory().handleUserPromote(user, track, null, first);
return CommandResult.SUCCESS;
}
@ -211,7 +208,7 @@ public class UserPromote extends SubCommand<User> {
.action("promote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackDelegate(track), new UserDelegate(user), old, nextGroup.getName()));
plugin.getApiProvider().getEventFactory().handleUserPromote(user, track, old, nextGroup.getName());
return CommandResult.SUCCESS;
}

View File

@ -22,10 +22,13 @@
package me.lucko.luckperms.common.config;
import lombok.Getter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import me.lucko.luckperms.common.api.delegates.LPConfigurationDelegate;
import me.lucko.luckperms.common.config.keys.EnduringKey;
import java.util.Optional;
@ -42,6 +45,9 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration {
}
});
@Getter
private final LPConfigurationDelegate delegate = new LPConfigurationDelegate(this);
@Override
public <T> T get(ConfigKey<T> key) {
return (T) cache.getUnchecked(key).orElse(null);
@ -60,5 +66,7 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration {
cache.invalidateAll(toInvalidate);
loadAll();
getPlugin().getApiProvider().getEventFactory().handleConfigReload();
}
}

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.config;
import me.lucko.luckperms.common.api.delegates.LPConfigurationDelegate;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.List;
@ -29,6 +30,8 @@ import java.util.Map;
public interface LuckPermsConfiguration {
LPConfigurationDelegate getDelegate();
LuckPermsPlugin getPlugin();
void init();

View File

@ -26,9 +26,8 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import me.lucko.luckperms.api.context.ContextListener;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.IContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import java.util.List;
@ -37,8 +36,7 @@ import java.util.concurrent.TimeUnit;
public class ContextManager<T> {
private final List<IContextCalculator<T>> calculators = new CopyOnWriteArrayList<>();
private final List<ContextListener<T>> listeners = new CopyOnWriteArrayList<>();
private final List<ContextCalculator<T>> calculators = new CopyOnWriteArrayList<>();
private final LoadingCache<T, ContextSet> cache = CacheBuilder.newBuilder()
.weakKeys()
@ -51,7 +49,7 @@ public class ContextManager<T> {
});
private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) {
for (IContextCalculator<T> calculator : calculators) {
for (ContextCalculator<T> calculator : calculators) {
calculator.giveApplicableContext(subject, accumulator);
}
return accumulator;
@ -61,19 +59,10 @@ public class ContextManager<T> {
return cache.getUnchecked(subject);
}
public void registerCalculator(IContextCalculator<T> calculator) {
listeners.forEach(calculator::addListener);
public void registerCalculator(ContextCalculator<T> calculator) {
calculators.add(calculator);
}
public void registerListener(ContextListener<T> listener) {
for (IContextCalculator<T> calculator : calculators) {
calculator.addListener(listener);
}
listeners.add(listener);
}
public int getCalculatorsSize() {
return calculators.size();
}

View File

@ -34,7 +34,7 @@ import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import java.util.Map;
@AllArgsConstructor
public class ServerCalculator<T> extends ContextCalculator<T> {
public class ServerCalculator<T> implements ContextCalculator<T> {
private final LuckPermsConfiguration config;
@Override

View File

@ -22,12 +22,14 @@
package me.lucko.luckperms.common.core;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import me.lucko.luckperms.common.api.delegates.UuidCacheDelegate;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -43,6 +45,9 @@ public class UuidCache {
// External UUID --> Internal UUID
private final BiMap<UUID, UUID> cache = Maps.synchronizedBiMap(HashBiMap.create());
@Getter
private final UuidCacheDelegate delegate = new UuidCacheDelegate(this);
public UUID getUUID(UUID external) {
return plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE) ? external : cache.getOrDefault(external, external);
}

View File

@ -26,6 +26,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import me.lucko.luckperms.common.api.delegates.GroupDelegate;
import me.lucko.luckperms.common.caching.handlers.GroupReference;
import me.lucko.luckperms.common.caching.handlers.HolderReference;
import me.lucko.luckperms.common.config.ConfigKeys;
@ -42,6 +43,9 @@ public class Group extends PermissionHolder implements Identifiable<String> {
@Getter
private final String name;
@Getter
private final GroupDelegate delegate = new GroupDelegate(this);
public Group(String name, LuckPermsPlugin plugin) {
super(name, plugin);
this.name = name;

View File

@ -39,13 +39,7 @@ 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.GroupAddEvent;
import me.lucko.luckperms.api.event.events.GroupRemoveEvent;
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.common.api.delegate.GroupDelegate;
import me.lucko.luckperms.common.api.delegate.PermissionHolderDelegate;
import me.lucko.luckperms.common.api.delegates.PermissionHolderDelegate;
import me.lucko.luckperms.common.caching.MetaHolder;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
import me.lucko.luckperms.common.caching.handlers.GroupReference;
@ -384,6 +378,7 @@ public abstract class PermissionHolder {
public abstract String getFriendlyName();
public abstract HolderReference<?> toReference();
public abstract PermissionHolderDelegate getDelegate();
public Set<Node> getNodes() {
return enduringCache.get();
@ -549,6 +544,8 @@ public abstract class PermissionHolder {
boolean work = false;
Set<Node> removed = new HashSet<>();
ImmutableSet<Node> before = ImmutableSet.copyOf(getPermissions(true));
synchronized (nodes) {
Iterator<Node> it = nodes.iterator();
while (it.hasNext()) {
@ -586,9 +583,10 @@ public abstract class PermissionHolder {
return false;
}
PermissionHolderDelegate link = new PermissionHolderDelegate(this);
ImmutableSet<Node> after = ImmutableSet.copyOf(getPermissions(true));
for (Node r : removed) {
plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(link, r));
plugin.getApiProvider().getEventFactory().handleNodeRemove(r, this, before, after);
}
return true;
@ -704,12 +702,16 @@ public abstract class PermissionHolder {
throw new ObjectAlreadyHasException();
}
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
nodes.add(node);
}
invalidateCache(true);
plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), node));
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
}
/**
@ -733,6 +735,8 @@ public abstract class PermissionHolder {
// Create a new node with the same properties, but add the expiry dates together
Node newNode = NodeFactory.builderFromExisting(node).setExpiry(previous.getExpiryUnixTime() + node.getSecondsTilExpiry()).build();
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
// Remove the old node & add the new one.
synchronized (nodes) {
nodes.remove(previous);
@ -740,8 +744,8 @@ public abstract class PermissionHolder {
}
invalidateCache(true);
plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), previous));
plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), newNode));
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeAdd(newNode, this, before, after);
return newNode;
}
@ -756,14 +760,16 @@ public abstract class PermissionHolder {
// Only replace if the new expiry time is greater than the old one.
if (node.getExpiryUnixTime() > previous.getExpiryUnixTime()) {
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
nodes.remove(previous);
nodes.add(node);
}
invalidateCache(true);
plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), previous));
plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), node));
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
return node;
}
}
@ -788,12 +794,16 @@ public abstract class PermissionHolder {
throw new ObjectAlreadyHasException();
}
ImmutableSet<Node> before = ImmutableSet.copyOf(getTransientNodes());
synchronized (transientNodes) {
transientNodes.add(node);
}
invalidateCache(false);
plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), node));
ImmutableSet<Node> after = ImmutableSet.copyOf(getTransientNodes());
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
}
public void setPermission(String node, boolean value) throws ObjectAlreadyHasException {
@ -831,17 +841,15 @@ public abstract class PermissionHolder {
throw new ObjectLacksException();
}
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
nodes.removeIf(e -> e.almostEquals(node));
}
invalidateCache(true);
if (node.isGroupNode()) {
plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderDelegate(this),
node.getGroupName(), node.getServer().orElse(null), node.getWorld().orElse(null), node.isTemporary()));
} else {
plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), node));
}
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
}
/**
@ -855,17 +863,15 @@ public abstract class PermissionHolder {
throw new ObjectLacksException();
}
ImmutableSet<Node> before = ImmutableSet.copyOf(getTransientNodes());
synchronized (transientNodes) {
transientNodes.removeIf(e -> e.almostEquals(node));
}
invalidateCache(false);
if (node.isGroupNode()) {
plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderDelegate(this),
node.getGroupName(), node.getServer().orElse(null), node.getWorld().orElse(null), node.isTemporary()));
} else {
plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), node));
}
ImmutableSet<Node> after = ImmutableSet.copyOf(getTransientNodes());
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
}
public void unsetPermission(String node, boolean temporary) throws ObjectLacksException {
@ -910,7 +916,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), null, null, 0L));
}
public void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException {
@ -919,7 +924,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true, server);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, null, 0L));
}
public void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException {
@ -928,7 +932,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true, server, world);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, world, 0L));
}
public void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException {
@ -937,7 +940,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true, expireAt);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), null, null, expireAt));
}
public void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException {
@ -946,7 +948,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true, server, expireAt);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, null, expireAt));
}
public void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException {
@ -955,7 +956,6 @@ public abstract class PermissionHolder {
}
setPermission("group." + group.getName(), true, server, world, expireAt);
getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, world, expireAt));
}
public void unsetInheritGroup(Group group) throws ObjectLacksException {
@ -986,27 +986,34 @@ public abstract class PermissionHolder {
* Clear all of the holders permission nodes
*/
public void clearNodes() {
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
nodes.clear();
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearNodes(String server) {
String finalServer = Optional.ofNullable(server).orElse("global");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
if (!nodes.removeIf(n -> n.getServer().orElse("global").equalsIgnoreCase(finalServer))) {
return;
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearNodes(String server, String world) {
String finalServer = Optional.ofNullable(server).orElse("global");
String finalWorld = Optional.ofNullable(world).orElse("null");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
n.getServer().orElse("global").equalsIgnoreCase(finalServer) &&
@ -1016,9 +1023,13 @@ public abstract class PermissionHolder {
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearParents() {
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(Node::isGroupNode);
if (!b) {
@ -1029,11 +1040,14 @@ public abstract class PermissionHolder {
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearParents(String server) {
String finalServer = Optional.ofNullable(server).orElse("global");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
n.isGroupNode() && n.getServer().orElse("global").equalsIgnoreCase(finalServer)
@ -1046,12 +1060,15 @@ public abstract class PermissionHolder {
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearParents(String server, String world) {
String finalServer = Optional.ofNullable(server).orElse("global");
String finalWorld = Optional.ofNullable(world).orElse("null");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
n.isGroupNode() &&
@ -1066,20 +1083,27 @@ public abstract class PermissionHolder {
plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearMeta() {
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
if (!nodes.removeIf(n -> n.isMeta() || n.isPrefix() || n.isSuffix())) {
return;
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearMeta(String server) {
String finalServer = Optional.ofNullable(server).orElse("global");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
(n.isMeta() || n.isPrefix() || n.isSuffix()) &&
@ -1090,12 +1114,15 @@ public abstract class PermissionHolder {
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearMeta(String server, String world) {
String finalServer = Optional.ofNullable(server).orElse("global");
String finalWorld = Optional.ofNullable(world).orElse("null");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
(n.isMeta() || n.isPrefix() || n.isSuffix()) && (
@ -1108,12 +1135,15 @@ public abstract class PermissionHolder {
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearMetaKeys(String key, String server, String world, boolean temp) {
String finalServer = Optional.ofNullable(server).orElse("global");
String finalWorld = Optional.ofNullable(world).orElse("null");
ImmutableSet<Node> before = ImmutableSet.copyOf(getNodes());
synchronized (nodes) {
boolean b = nodes.removeIf(n ->
n.isMeta() && (n.isTemporary() == temp) && n.getMeta().getKey().equalsIgnoreCase(key) &&
@ -1125,13 +1155,19 @@ public abstract class PermissionHolder {
}
}
invalidateCache(true);
ImmutableSet<Node> after = ImmutableSet.copyOf(getNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
public void clearTransientNodes() {
ImmutableSet<Node> before = ImmutableSet.copyOf(getTransientNodes());
synchronized (transientNodes) {
transientNodes.clear();
}
invalidateCache(false);
ImmutableSet<Node> after = ImmutableSet.copyOf(getTransientNodes());
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
}
/**

View File

@ -29,6 +29,8 @@ import lombok.ToString;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.api.delegates.TrackDelegate;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Identifiable;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
@ -49,13 +51,20 @@ public class Track implements Identifiable<String> {
*/
@Getter
private final String name;
private final LuckPermsPlugin plugin;
@Getter
private final Lock ioLock = new ReentrantLock();
/**
* The groups within this track
*/
private List<String> groups = Collections.synchronizedList(new ArrayList<>());
@Getter
private final TrackDelegate delegate = new TrackDelegate(this);
@Override
public String getId() {
return name.toLowerCase();
@ -147,8 +156,13 @@ public class Track implements Identifiable<String> {
* @throws ObjectAlreadyHasException if the group is already on this track somewhere
*/
public void appendGroup(Group group) throws ObjectAlreadyHasException {
List<String> before = ImmutableList.copyOf(groups);
assertNotContains(group);
groups.add(group.getName());
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
}
/**
@ -160,8 +174,13 @@ public class Track implements Identifiable<String> {
* @throws IndexOutOfBoundsException if the position is less than 0 or greater than the size of the track
*/
public void insertGroup(Group group, int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException {
List<String> before = ImmutableList.copyOf(groups);
assertNotContains(group);
groups.add(position, group.getName());
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
}
/**
@ -181,8 +200,12 @@ public class Track implements Identifiable<String> {
* @throws ObjectLacksException if the group is not on this track
*/
public void removeGroup(String group) throws ObjectLacksException {
List<String> before = ImmutableList.copyOf(groups);
assertContains(group);
groups.remove(group);
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackRemoveGroup(this, group, before, after);
}
/**
@ -209,7 +232,9 @@ public class Track implements Identifiable<String> {
* Clear all of the groups within this track
*/
public void clearGroups() {
List<String> before = ImmutableList.copyOf(groups);
groups.clear();
plugin.getApiProvider().getEventFactory().handleTrackClear(this, before);
}
private void assertNotContains(Group g) throws ObjectAlreadyHasException {

Some files were not shown because too many files have changed in this diff Show More