Remove lombok from the project
This commit is contained in:
@@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -50,16 +45,18 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An implementation of {@link LogEntry} and {@link LogEntry.Builder},
|
||||
* with helper methods for populating and using the entry using internal
|
||||
* LuckPerms classes.
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ExtendedLogEntry implements LogEntry {
|
||||
|
||||
private static final Comparator<LogEntry> COMPARATOR = Comparator
|
||||
@@ -88,68 +85,84 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
private final String actedName;
|
||||
private final String action;
|
||||
|
||||
private ExtendedLogEntry(long timestamp, UUID actor, String actorName, Type type, UUID acted, String actedName, String action) {
|
||||
this.timestamp = timestamp;
|
||||
this.actor = actor;
|
||||
this.actorName = actorName;
|
||||
this.type = type;
|
||||
this.acted = acted;
|
||||
this.actedName = actedName;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getActor() {
|
||||
return actor;
|
||||
return this.actor;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getActorName() {
|
||||
return actorName;
|
||||
return this.actorName;
|
||||
}
|
||||
|
||||
public String getActorFriendlyString() {
|
||||
if (Strings.isNullOrEmpty(actorName) || actorName.equals("null")) {
|
||||
return actor.toString();
|
||||
if (Strings.isNullOrEmpty(this.actorName) || this.actorName.equals("null")) {
|
||||
return this.actor.toString();
|
||||
}
|
||||
return actorName;
|
||||
return this.actorName;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<UUID> getActed() {
|
||||
return Optional.ofNullable(acted);
|
||||
return Optional.ofNullable(this.acted);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getActedName() {
|
||||
return actedName;
|
||||
return this.actedName;
|
||||
}
|
||||
|
||||
public String getActedFriendlyString() {
|
||||
if (Strings.isNullOrEmpty(actedName) || actedName.equals("null")) {
|
||||
if (acted != null) {
|
||||
return acted.toString();
|
||||
if (Strings.isNullOrEmpty(this.actedName) || this.actedName.equals("null")) {
|
||||
if (this.acted != null) {
|
||||
return this.acted.toString();
|
||||
}
|
||||
}
|
||||
return String.valueOf(actedName);
|
||||
return String.valueOf(this.actedName);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getAction() {
|
||||
return action;
|
||||
return this.action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LogEntry other) {
|
||||
Preconditions.checkNotNull(other, "other");
|
||||
public int compareTo(@Nonnull LogEntry other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return COMPARATOR.compare(this, other);
|
||||
}
|
||||
|
||||
public boolean matchesSearch(String query) {
|
||||
query = Preconditions.checkNotNull(query, "query").toLowerCase();
|
||||
return actorName.toLowerCase().contains(query) ||
|
||||
actedName.toLowerCase().contains(query) ||
|
||||
action.toLowerCase().contains(query);
|
||||
query = Objects.requireNonNull(query, "query").toLowerCase();
|
||||
return this.actorName.toLowerCase().contains(query) ||
|
||||
this.actedName.toLowerCase().contains(query) ||
|
||||
this.action.toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
public void submit(LuckPermsPlugin plugin, Sender sender) {
|
||||
@@ -172,15 +185,15 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof LogEntry)) return false;
|
||||
final LogEntry other = (LogEntry) o;
|
||||
final LogEntry that = (LogEntry) o;
|
||||
|
||||
return this.getTimestamp() == other.getTimestamp() &&
|
||||
this.getActor().equals(other.getActor()) &&
|
||||
this.getActorName().equals(other.getActorName()) &&
|
||||
this.getType() == other.getType() &&
|
||||
this.getActed().equals(other.getActed()) &&
|
||||
this.getActedName().equals(other.getActedName()) &&
|
||||
this.getAction().equals(other.getAction());
|
||||
return this.getTimestamp() == that.getTimestamp() &&
|
||||
this.getActor().equals(that.getActor()) &&
|
||||
this.getActorName().equals(that.getActorName()) &&
|
||||
this.getType() == that.getType() &&
|
||||
this.getActed().equals(that.getActed()) &&
|
||||
this.getActedName().equals(that.getActedName()) &&
|
||||
this.getAction().equals(that.getAction());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,7 +210,6 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static class ExtendedLogEntryBuilder implements LogEntry.Builder {
|
||||
|
||||
private long timestamp = 0L;
|
||||
@@ -208,45 +220,52 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
private String actedName = null;
|
||||
private String action = null;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActor(UUID actor) {
|
||||
this.actor = Preconditions.checkNotNull(actor, "actor");
|
||||
public ExtendedLogEntryBuilder setActor(@Nonnull UUID actor) {
|
||||
this.actor = Objects.requireNonNull(actor, "actor");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActorName(String actorName) {
|
||||
this.actorName = Preconditions.checkNotNull(actorName, "actorName");
|
||||
public ExtendedLogEntryBuilder setActorName(@Nonnull String actorName) {
|
||||
this.actorName = Objects.requireNonNull(actorName, "actorName");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setType(Type type) {
|
||||
this.type = Preconditions.checkNotNull(type, "type");
|
||||
public ExtendedLogEntryBuilder setType(@Nonnull Type type) {
|
||||
this.type = Objects.requireNonNull(type, "type");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActed(UUID acted) {
|
||||
this.acted = acted; // nullable
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setActedName(String actedName) {
|
||||
this.actedName = Preconditions.checkNotNull(actedName, "actedName");
|
||||
public ExtendedLogEntryBuilder setActedName(@Nonnull String actedName) {
|
||||
this.actedName = Objects.requireNonNull(actedName, "actedName");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntryBuilder setAction(String action) {
|
||||
this.action = Preconditions.checkNotNull(action, "action");
|
||||
public ExtendedLogEntryBuilder setAction(@Nonnull String action) {
|
||||
this.action = Objects.requireNonNull(action, "action");
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -333,19 +352,32 @@ public class ExtendedLogEntry implements LogEntry {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedLogEntry build() {
|
||||
if (timestamp == 0L) {
|
||||
if (this.timestamp == 0L) {
|
||||
timestamp(DateUtil.unixSecondsNow());
|
||||
}
|
||||
|
||||
Preconditions.checkNotNull(actor, "actor");
|
||||
Preconditions.checkNotNull(actorName, "actorName");
|
||||
Preconditions.checkNotNull(type, "type");
|
||||
Preconditions.checkNotNull(actedName, "actedName");
|
||||
Preconditions.checkNotNull(action, "action");
|
||||
Objects.requireNonNull(this.actor, "actor");
|
||||
Objects.requireNonNull(this.actorName, "actorName");
|
||||
Objects.requireNonNull(this.type, "type");
|
||||
Objects.requireNonNull(this.actedName, "actedName");
|
||||
Objects.requireNonNull(this.action, "action");
|
||||
|
||||
return new ExtendedLogEntry(timestamp, actor, actorName, type, acted, actedName, action);
|
||||
return new ExtendedLogEntry(this.timestamp, this.actor, this.actorName, this.type, this.acted, this.actedName, this.action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExtendedLogEntry.ExtendedLogEntryBuilder(" +
|
||||
"timestamp=" + this.timestamp + ", " +
|
||||
"actor=" + this.actor + ", " +
|
||||
"actorName=" + this.actorName + ", " +
|
||||
"type=" + this.type + ", " +
|
||||
"acted=" + this.acted + ", " +
|
||||
"actedName=" + this.actedName + ", " +
|
||||
"action=" + this.action + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@@ -77,7 +75,6 @@ public class Log {
|
||||
return (int) Math.ceil((double) size / (double) entries);
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final SortedSet<ExtendedLogEntry> content;
|
||||
|
||||
public Log(SortedSet<ExtendedLogEntry> content) {
|
||||
@@ -85,19 +82,19 @@ public class Log {
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getRecent() {
|
||||
return content;
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public SortedMap<Integer, ExtendedLogEntry> getRecent(int pageNo, int entriesPerPage) {
|
||||
return getPage(content, pageNo, entriesPerPage);
|
||||
return getPage(this.content, pageNo, entriesPerPage);
|
||||
}
|
||||
|
||||
public int getRecentMaxPages(int entriesPerPage) {
|
||||
return getMaxPages(content.size(), entriesPerPage);
|
||||
return getMaxPages(this.content.size(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getRecent(UUID actor) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getActor().equals(actor))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
@@ -107,13 +104,13 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getRecentMaxPages(UUID actor, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getActor().equals(actor))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.USER)
|
||||
.filter(e -> e.getActed().isPresent())
|
||||
.filter(e -> e.getActed().get().equals(uuid))
|
||||
@@ -125,7 +122,7 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getUserHistoryMaxPages(UUID uuid, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.USER)
|
||||
.filter(e -> e.getActed().isPresent())
|
||||
.filter(e -> e.getActed().get().equals(uuid))
|
||||
@@ -133,7 +130,7 @@ public class Log {
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getGroupHistory(String name) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
@@ -144,14 +141,14 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getGroupHistoryMaxPages(String name, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.GROUP)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getTrackHistory(String name) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
@@ -162,14 +159,14 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getTrackHistoryMaxPages(String name, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.getType() == LogEntry.Type.TRACK)
|
||||
.filter(e -> e.getActedName().equals(name))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getSearch(String query) {
|
||||
return content.stream()
|
||||
return this.content.stream()
|
||||
.filter(e -> e.matchesSearch(query))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
@@ -179,22 +176,26 @@ public class Log {
|
||||
}
|
||||
|
||||
public int getSearchMaxPages(String query, int entriesPerPage) {
|
||||
return getMaxPages(content.stream()
|
||||
return getMaxPages(this.content.stream()
|
||||
.filter(e -> e.matchesSearch(query))
|
||||
.mapToInt(x -> 1).sum(), entriesPerPage);
|
||||
}
|
||||
|
||||
public SortedSet<ExtendedLogEntry> getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static class Builder {
|
||||
private final SortedSet<ExtendedLogEntry> content = new TreeSet<>();
|
||||
|
||||
public Builder add(ExtendedLogEntry e) {
|
||||
content.add(e);
|
||||
this.content.add(e);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Log build() {
|
||||
return new Log(content);
|
||||
return new Log(this.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.actionlog;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.impl.log.LogNotify;
|
||||
@@ -38,16 +36,19 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LogDispatcher {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public LogDispatcher(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private void broadcast(ExtendedLogEntry entry, LogBroadcastEvent.Origin origin, Sender sender) {
|
||||
plugin.getOnlineSenders()
|
||||
this.plugin.getOnlineSenders()
|
||||
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
||||
.filter(s -> {
|
||||
boolean shouldCancel = LogNotify.isIgnoring(plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
||||
return !plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
||||
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
|
||||
return !this.plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
|
||||
})
|
||||
.forEach(s -> Message.LOG.send(s,
|
||||
entry.getActorFriendlyString(),
|
||||
@@ -59,8 +60,8 @@ public class LogDispatcher {
|
||||
|
||||
public void dispatch(ExtendedLogEntry entry, Sender sender) {
|
||||
// set the event to cancelled if the sender is import
|
||||
if (!plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
||||
plugin.getStorage().logAction(entry);
|
||||
if (!this.plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
|
||||
this.plugin.getStorage().logAction(entry);
|
||||
}
|
||||
|
||||
// don't dispatch log entries sent by an import process
|
||||
@@ -68,21 +69,21 @@ public class LogDispatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
Optional<ExtendedMessagingService> messagingService = this.plugin.getMessagingService();
|
||||
if (!sender.isImport() && messagingService.isPresent()) {
|
||||
messagingService.get().pushLog(entry);
|
||||
}
|
||||
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchFromApi(ExtendedLogEntry entry) {
|
||||
if (!plugin.getEventFactory().handleLogPublish(false, entry)) {
|
||||
if (!this.plugin.getEventFactory().handleLogPublish(false, entry)) {
|
||||
try {
|
||||
plugin.getStorage().logAction(entry).get();
|
||||
this.plugin.getStorage().logAction(entry).get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -92,17 +93,17 @@ public class LogDispatcher {
|
||||
}
|
||||
|
||||
public void broadcastFromApi(ExtendedLogEntry entry) {
|
||||
plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry));
|
||||
this.plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry));
|
||||
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchFromRemote(ExtendedLogEntry entry) {
|
||||
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||
boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
|
||||
if (!this.plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.common.api;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||
|
||||
@UtilityClass
|
||||
public class ApiUtils {
|
||||
public final class ApiUtils {
|
||||
|
||||
public static String checkUsername(String s) {
|
||||
Preconditions.checkArgument(
|
||||
@@ -50,4 +47,6 @@ public class ApiUtils {
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
private ApiUtils() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.ActionLogger;
|
||||
import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
@@ -56,12 +53,13 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Implements the LuckPerms API using the plugin instance
|
||||
*/
|
||||
public class LuckPermsApiProvider implements LuckPermsApi {
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
private final PlatformInfo platformInfo;
|
||||
@@ -84,74 +82,86 @@ public class LuckPermsApiProvider implements LuckPermsApi {
|
||||
this.metaStackFactory = new ApiMetaStackFactory(plugin);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PlatformInfo getPlatformInfo() {
|
||||
return platformInfo;
|
||||
return this.platformInfo;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return groupManager;
|
||||
return this.groupManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public TrackManager getTrackManager() {
|
||||
return trackManager;
|
||||
return this.trackManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> runUpdateTask() {
|
||||
return plugin.getUpdateTaskBuffer().request();
|
||||
return this.plugin.getUpdateTaskBuffer().request();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EventBus getEventBus() {
|
||||
return plugin.getEventFactory().getEventBus();
|
||||
return this.plugin.getEventFactory().getEventBus();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public LPConfiguration getConfiguration() {
|
||||
return plugin.getConfiguration().getDelegate();
|
||||
return this.plugin.getConfiguration().getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Storage getStorage() {
|
||||
return plugin.getStorage().getDelegate();
|
||||
return this.plugin.getStorage().getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<MessagingService> getMessagingService() {
|
||||
return plugin.getMessagingService().map(Function.identity());
|
||||
return this.plugin.getMessagingService().map(Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionLogger getActionLogger() {
|
||||
return actionLogger;
|
||||
return this.actionLogger;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UuidCache getUuidCache() {
|
||||
return plugin.getUuidCache().getDelegate();
|
||||
return this.plugin.getUuidCache().getDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextManager getContextManager() {
|
||||
return contextManager;
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NodeFactory getNodeFactory() {
|
||||
return ApiNodeFactory.INSTANCE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackFactory getMetaStackFactory() {
|
||||
return metaStackFactory;
|
||||
return this.metaStackFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+54
-32
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
@@ -37,73 +34,98 @@ import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ApiContextManager implements ContextManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.contexts.ContextManager handle;
|
||||
|
||||
public ApiContextManager(LuckPermsPlugin plugin, me.lucko.luckperms.common.contexts.ContextManager handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
private Object checkType(Object subject) {
|
||||
if (!handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
||||
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + handle.getSubjectClass());
|
||||
if (!this.handle.getSubjectClass().isAssignableFrom(subject.getClass())) {
|
||||
throw new IllegalStateException("Subject class " + subject.getClass() + " is not assignable from " + this.handle.getSubjectClass());
|
||||
}
|
||||
return subject;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableContextSet getApplicableContext(@NonNull Object subject) {
|
||||
return handle.getApplicableContext(checkType(subject));
|
||||
public ImmutableContextSet getApplicableContext(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
return this.handle.getApplicableContext(checkType(subject));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getApplicableContexts(@NonNull Object subject) {
|
||||
return handle.getApplicableContexts(checkType(subject));
|
||||
public Contexts getApplicableContexts(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
return this.handle.getApplicableContexts(checkType(subject));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<ImmutableContextSet> lookupApplicableContext(@NonNull User user) {
|
||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
||||
public Optional<ImmutableContextSet> lookupApplicableContext(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user))).map(c -> c.getContexts().makeImmutable());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<Contexts> lookupApplicableContexts(@NonNull User user) {
|
||||
return Optional.ofNullable(plugin.getContextForUser(ApiUser.cast(user)));
|
||||
public Optional<Contexts> lookupApplicableContexts(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return Optional.ofNullable(this.plugin.getContextForUser(ApiUser.cast(user)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableContextSet getStaticContext() {
|
||||
return handle.getStaticContext();
|
||||
return this.handle.getStaticContext();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getStaticContexts() {
|
||||
return handle.getStaticContexts();
|
||||
return this.handle.getStaticContexts();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts formContexts(@Nonnull Object subject, @Nonnull ImmutableContextSet contextSet) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.formContexts(checkType(subject), contextSet);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts formContexts(@Nonnull ImmutableContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.formContexts(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(@NonNull Object subject, @NonNull ImmutableContextSet contextSet) {
|
||||
return handle.formContexts(checkType(subject), contextSet);
|
||||
public void registerCalculator(@Nonnull ContextCalculator<?> calculator) {
|
||||
Objects.requireNonNull(calculator, "calculator");
|
||||
this.handle.registerCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(@NonNull ImmutableContextSet contextSet) {
|
||||
return handle.formContexts(contextSet);
|
||||
public void registerStaticCalculator(@Nonnull StaticContextCalculator calculator) {
|
||||
Objects.requireNonNull(calculator, "calculator");
|
||||
this.handle.registerStaticCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCalculator(@NonNull ContextCalculator<?> calculator) {
|
||||
handle.registerCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticCalculator(@NonNull StaticContextCalculator calculator) {
|
||||
handle.registerStaticCalculator(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache(@NonNull Object subject) {
|
||||
handle.invalidateCache(checkType(subject));
|
||||
public void invalidateCache(@Nonnull Object subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
this.handle.invalidateCache(checkType(subject));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-9
@@ -25,32 +25,38 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.manager.GroupManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiGroupManager implements GroupManager {
|
||||
private final me.lucko.luckperms.common.managers.GroupManager handle;
|
||||
|
||||
public ApiGroupManager(me.lucko.luckperms.common.managers.GroupManager handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.Group group = handle.getIfLoaded(name);
|
||||
public Group getGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.Group group = this.handle.getIfLoaded(name);
|
||||
return group == null ? null : group.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Group> getLoadedGroups() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull String name) {
|
||||
return handle.isLoaded(name);
|
||||
public boolean isLoaded(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.isLoaded(name);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-9
@@ -25,32 +25,38 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.manager.TrackManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiTrackManager implements TrackManager {
|
||||
private final me.lucko.luckperms.common.managers.TrackManager handle;
|
||||
|
||||
public ApiTrackManager(me.lucko.luckperms.common.managers.TrackManager handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Track getTrack(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.Track track = handle.getIfLoaded(name);
|
||||
public Track getTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.Track track = this.handle.getIfLoaded(name);
|
||||
return track == null ? null : track.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Track> getLoadedTracks() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull String name) {
|
||||
return handle.isLoaded(name);
|
||||
public boolean isLoaded(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.isLoaded(name);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-13
@@ -25,48 +25,57 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.manager;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.manager.UserManager;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiUserManager implements UserManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.managers.UserManager handle;
|
||||
|
||||
public ApiUserManager(LuckPermsPlugin plugin, me.lucko.luckperms.common.managers.UserManager handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
me.lucko.luckperms.common.model.User user = handle.getIfLoaded(uuid);
|
||||
public User getUser(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
me.lucko.luckperms.common.model.User user = this.handle.getIfLoaded(uuid);
|
||||
return user == null ? null : user.getDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull String name) {
|
||||
me.lucko.luckperms.common.model.User user = handle.getByUsername(name);
|
||||
public User getUser(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
me.lucko.luckperms.common.model.User user = this.handle.getByUsername(name);
|
||||
return user == null ? null : user.getDelegate();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<User> getLoadedUsers() {
|
||||
return handle.getAll().values().stream().map(me.lucko.luckperms.common.model.User::getDelegate).collect(Collectors.toSet());
|
||||
return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.User::getDelegate).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(@NonNull UUID uuid) {
|
||||
return handle.isLoaded(UserIdentifier.of(uuid, null));
|
||||
public boolean isLoaded(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.isLoaded(UserIdentifier.of(uuid, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(@NonNull User user) {
|
||||
handle.scheduleUnload(plugin.getUuidCache().getExternalUUID(ApiUser.cast(user).getUuid()));
|
||||
public void cleanupUser(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
this.handle.scheduleUnload(this.plugin.getUuidCache().getExternalUUID(ApiUser.cast(user).getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
+18
-10
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.ActionLogger;
|
||||
import me.lucko.luckperms.api.Log;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@@ -36,32 +34,42 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiActionLogger implements ActionLogger {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public ApiActionLogger(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public LogEntry.Builder newEntryBuilder() {
|
||||
return ExtendedLogEntry.build();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Log> getLog() {
|
||||
return plugin.getStorage().noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
return this.plugin.getStorage().noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> submit(LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
||||
public CompletableFuture<Void> submit(@Nonnull LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> this.plugin.getLogDispatcher().dispatchFromApi((ExtendedLogEntry) entry), this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> submitToStorage(LogEntry entry) {
|
||||
return plugin.getStorage().noBuffer().logAction(entry);
|
||||
public CompletableFuture<Void> submitToStorage(@Nonnull LogEntry entry) {
|
||||
return this.plugin.getStorage().noBuffer().logAction(entry);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> broadcastAction(LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> plugin.getLogDispatcher().broadcastFromApi((ExtendedLogEntry) entry), plugin.getScheduler().async());
|
||||
public CompletableFuture<Void> broadcastAction(@Nonnull LogEntry entry) {
|
||||
return CompletableFuture.runAsync(() -> this.plugin.getLogDispatcher().broadcastFromApi((ExtendedLogEntry) entry), this.plugin.getScheduler().async());
|
||||
}
|
||||
}
|
||||
|
||||
+17
-10
@@ -33,6 +33,8 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiConfiguration implements LPConfiguration {
|
||||
private final LuckPermsConfiguration handle;
|
||||
private final Unsafe unsafe;
|
||||
@@ -42,61 +44,66 @@ public class ApiConfiguration implements LPConfiguration {
|
||||
this.unsafe = new UnsafeImpl();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getServer() {
|
||||
return handle.get(ConfigKeys.SERVER);
|
||||
return this.handle.get(ConfigKeys.SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalWorldPerms() {
|
||||
return handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalGroups() {
|
||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalWorldGroups() {
|
||||
return handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getStorageMethod() {
|
||||
return handle.get(ConfigKeys.STORAGE_METHOD);
|
||||
return this.handle.get(ConfigKeys.STORAGE_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSplitStorage() {
|
||||
return handle.get(ConfigKeys.SPLIT_STORAGE);
|
||||
return this.handle.get(ConfigKeys.SPLIT_STORAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, String> getSplitStorageOptions() {
|
||||
return handle.get(ConfigKeys.SPLIT_STORAGE_OPTIONS).entrySet().stream()
|
||||
return this.handle.get(ConfigKeys.SPLIT_STORAGE_OPTIONS).entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(e -> e.getKey().name().toLowerCase(), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
return this.unsafe;
|
||||
}
|
||||
|
||||
private final class UnsafeImpl implements Unsafe {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Object getObject(String key) {
|
||||
ConfigKey<?> configKey = ConfigKeys.getAllKeys().get(key.toUpperCase());
|
||||
if (configKey == null) {
|
||||
throw new IllegalArgumentException("Unknown key: " + key);
|
||||
}
|
||||
return handle.get(configKey);
|
||||
return ApiConfiguration.this.handle.get(configKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-10
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
@@ -38,27 +35,38 @@ import me.lucko.luckperms.common.metastacking.StandardStackElements;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiMetaStackFactory implements MetaStackFactory {
|
||||
public final LuckPermsPlugin plugin;
|
||||
|
||||
@Override
|
||||
public Optional<MetaStackElement> fromString(@NonNull String definition) {
|
||||
return StandardStackElements.parseFromString(plugin, definition);
|
||||
public ApiMetaStackFactory(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<MetaStackElement> fromStrings(@NonNull List<String> definitions) {
|
||||
public Optional<MetaStackElement> fromString(@Nonnull String definition) {
|
||||
Objects.requireNonNull(definition, "definition");
|
||||
return StandardStackElements.parseFromString(this.plugin, definition);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<MetaStackElement> fromStrings(@Nonnull List<String> definitions) {
|
||||
Objects.requireNonNull(definitions, "definitions");
|
||||
if (definitions.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return StandardStackElements.parseList(plugin, definitions);
|
||||
return StandardStackElements.parseList(this.plugin, definitions);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackDefinition createDefinition(List<MetaStackElement> elements, String startSpacer, String middleSpacer, String endSpacer) {
|
||||
public MetaStackDefinition createDefinition(@Nonnull List<MetaStackElement> elements, @Nonnull String startSpacer, @Nonnull String middleSpacer, @Nonnull String endSpacer) {
|
||||
return new SimpleMetaStackDefinition(elements, startSpacer, middleSpacer, endSpacer);
|
||||
}
|
||||
}
|
||||
|
||||
+30
-10
@@ -25,14 +25,16 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiGroup;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory {
|
||||
public static final ApiNodeFactory INSTANCE = new ApiNodeFactory();
|
||||
|
||||
@@ -40,43 +42,61 @@ public final class ApiNodeFactory implements me.lucko.luckperms.api.NodeFactory
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder newBuilder(@NonNull String permission) {
|
||||
public Node.Builder newBuilder(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return NodeFactory.builder(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder newBuilderFromExisting(@NonNull Node other) {
|
||||
public Node.Builder newBuilderFromExisting(@Nonnull Node other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return NodeFactory.builder(other);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeGroupNode(Group group) {
|
||||
public Node.Builder makeGroupNode(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return NodeFactory.buildGroupNode(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeGroupNode(String groupName) {
|
||||
public Node.Builder makeGroupNode(@Nonnull String groupName) {
|
||||
Objects.requireNonNull(groupName, "groupName");
|
||||
return NodeFactory.buildGroupNode(groupName);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeMetaNode(@NonNull String key, @NonNull String value) {
|
||||
public Node.Builder makeMetaNode(@Nonnull String key, @Nonnull String value) {
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(value, "value");
|
||||
return NodeFactory.buildMetaNode(key, value);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeChatMetaNode(@NonNull ChatMetaType type, int priority, @NonNull String value) {
|
||||
public Node.Builder makeChatMetaNode(@Nonnull ChatMetaType type, int priority, @Nonnull String value) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(value, "value");
|
||||
return NodeFactory.buildChatMetaNode(type, priority, value);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makePrefixNode(int priority, @NonNull String prefix) {
|
||||
public Node.Builder makePrefixNode(int priority, @Nonnull String prefix) {
|
||||
Objects.requireNonNull(prefix, "prefix");
|
||||
return NodeFactory.buildPrefixNode(priority, prefix);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Node.Builder makeSuffixNode(int priority, @NonNull String suffix) {
|
||||
public Node.Builder makeSuffixNode(int priority, @Nonnull String suffix) {
|
||||
Objects.requireNonNull(suffix, "suffix");
|
||||
return NodeFactory.buildSuffixNode(priority, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-7
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.platform.PlatformInfo;
|
||||
import me.lucko.luckperms.api.platform.PlatformType;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@@ -35,13 +33,19 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiPlatformInfo implements PlatformInfo {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public ApiPlatformInfo(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getVersion();
|
||||
return this.plugin.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,18 +53,20 @@ public class ApiPlatformInfo implements PlatformInfo {
|
||||
return 4.0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PlatformType getType() {
|
||||
return plugin.getServerType();
|
||||
return this.plugin.getServerType();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return Collections.unmodifiableSet(plugin.getUniqueConnections());
|
||||
return Collections.unmodifiableSet(this.plugin.getUniqueConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return plugin.getStartTime();
|
||||
return this.plugin.getStartTime();
|
||||
}
|
||||
}
|
||||
|
||||
+16
-9
@@ -25,24 +25,31 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.UuidCache;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiUuidCache implements UuidCache {
|
||||
private final me.lucko.luckperms.common.utils.UuidCache handle;
|
||||
|
||||
@Override
|
||||
public UUID getUUID(@NonNull UUID external) {
|
||||
return handle.getUUID(external);
|
||||
public ApiUuidCache(me.lucko.luckperms.common.utils.UuidCache handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getExternalUUID(@NonNull UUID internal) {
|
||||
return handle.getExternalUUID(internal);
|
||||
public UUID getUUID(@Nonnull UUID external) {
|
||||
Objects.requireNonNull(external, "external");
|
||||
return this.handle.getUUID(external);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getExternalUUID(@Nonnull UUID internal) {
|
||||
Objects.requireNonNull(internal, "internal");
|
||||
return this.handle.getExternalUUID(internal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,55 +25,63 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.caching.GroupData;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiGroup extends ApiPermissionHolder implements Group {
|
||||
public static me.lucko.luckperms.common.model.Group cast(Group g) {
|
||||
Preconditions.checkState(g instanceof ApiGroup, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiGroup) g).getHandle();
|
||||
public static me.lucko.luckperms.common.model.Group cast(Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
Preconditions.checkState(group instanceof ApiGroup, "Illegal instance " + group.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiGroup) group).getHandle();
|
||||
}
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.common.model.Group handle;
|
||||
|
||||
public ApiGroup(@NonNull me.lucko.luckperms.common.model.Group handle) {
|
||||
public ApiGroup(me.lucko.luckperms.common.model.Group handle) {
|
||||
super(handle);
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
me.lucko.luckperms.common.model.Group getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public OptionalInt getWeight() {
|
||||
return handle.getWeight();
|
||||
return this.handle.getWeight();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public GroupData getCachedData() {
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiGroup)) return false;
|
||||
|
||||
ApiGroup other = (ApiGroup) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiGroup that = (ApiGroup) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,116 +25,147 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Log;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@AllArgsConstructor
|
||||
public class ApiLog implements Log {
|
||||
private static final int ENTRIES_PER_PAGE = 5;
|
||||
private final me.lucko.luckperms.common.actionlog.Log handle;
|
||||
|
||||
public ApiLog(me.lucko.luckperms.common.actionlog.Log handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getContent() {
|
||||
return (SortedSet) handle.getContent();
|
||||
return (SortedSet) this.handle.getContent();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent() {
|
||||
return (SortedSet) handle.getRecent();
|
||||
return (SortedSet) this.handle.getRecent();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo) {
|
||||
return (SortedMap) handle.getRecent(pageNo, ENTRIES_PER_PAGE);
|
||||
return (SortedMap) this.handle.getRecent(pageNo, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages() {
|
||||
return handle.getRecentMaxPages(ENTRIES_PER_PAGE);
|
||||
return this.handle.getRecentMaxPages(ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent(@Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return (SortedSet) this.handle.getRecent(actor);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return (SortedMap) this.handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getRecent(@NonNull UUID actor) {
|
||||
return (SortedSet) handle.getRecent(actor);
|
||||
public int getRecentMaxPages(@Nonnull UUID actor) {
|
||||
Objects.requireNonNull(actor, "actor");
|
||||
return this.handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getUserHistory(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return (SortedSet) this.handle.getUserHistory(uuid);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return (SortedMap) this.handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getRecent(int pageNo, @NonNull UUID actor) {
|
||||
return (SortedMap) handle.getRecent(pageNo, actor, ENTRIES_PER_PAGE);
|
||||
public int getUserHistoryMaxPages(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getGroupHistory(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedSet) this.handle.getGroupHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedMap) this.handle.getGroupHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecentMaxPages(@NonNull UUID actor) {
|
||||
return handle.getRecentMaxPages(actor, ENTRIES_PER_PAGE);
|
||||
public int getGroupHistoryMaxPages(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.getGroupHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getTrackHistory(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedSet) this.handle.getTrackHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return (SortedMap) this.handle.getTrackHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getUserHistory(@NonNull UUID uuid) {
|
||||
return (SortedSet) handle.getUserHistory(uuid);
|
||||
public int getTrackHistoryMaxPages(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.getTrackHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LogEntry> getSearch(@Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return (SortedSet) this.handle.getSearch(query);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return (SortedMap) this.handle.getSearch(pageNo, query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getUserHistory(int pageNo, @NonNull UUID uuid) {
|
||||
return (SortedMap) handle.getUserHistory(pageNo, uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserHistoryMaxPages(@NonNull UUID uuid) {
|
||||
return handle.getUserHistoryMaxPages(uuid, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getGroupHistory(@NonNull String name) {
|
||||
return (SortedSet) handle.getGroupHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, @NonNull String name) {
|
||||
return (SortedMap) handle.getGroupHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupHistoryMaxPages(@NonNull String name) {
|
||||
return handle.getGroupHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getTrackHistory(@NonNull String name) {
|
||||
return (SortedSet) handle.getTrackHistory(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, @NonNull String name) {
|
||||
return (SortedMap) handle.getTrackHistory(pageNo, checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrackHistoryMaxPages(@NonNull String name) {
|
||||
return handle.getTrackHistoryMaxPages(checkName(name), ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<LogEntry> getSearch(@NonNull String query) {
|
||||
return (SortedSet) handle.getSearch(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Integer, LogEntry> getSearch(int pageNo, @NonNull String query) {
|
||||
return (SortedMap) handle.getSearch(pageNo, query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchMaxPages(@NonNull String query) {
|
||||
return handle.getSearchMaxPages(query, ENTRIES_PER_PAGE);
|
||||
public int getSearchMaxPages(@Nonnull String query) {
|
||||
Objects.requireNonNull(query, "query");
|
||||
return this.handle.getSearchMaxPages(query, ENTRIES_PER_PAGE);
|
||||
}
|
||||
}
|
||||
|
||||
+144
-94
@@ -25,9 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
@@ -44,212 +43,263 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.MetaType;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ApiPermissionHolder implements PermissionHolder {
|
||||
private final me.lucko.luckperms.common.model.PermissionHolder handle;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return handle.getObjectName();
|
||||
public ApiPermissionHolder(me.lucko.luckperms.common.model.PermissionHolder handle) {
|
||||
this.handle = Objects.requireNonNull(handle, "handle");
|
||||
}
|
||||
|
||||
me.lucko.luckperms.common.model.PermissionHolder getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return this.handle.getObjectName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
if (handle.getType().isGroup()) {
|
||||
if (this.handle.getType().isGroup()) {
|
||||
Group group = (Group) this.handle;
|
||||
return group.getDisplayName().orElse(group.getName());
|
||||
}
|
||||
return handle.getFriendlyName();
|
||||
return this.handle.getFriendlyName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CachedData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> refreshCachedData() {
|
||||
return handle.getRefreshBuffer().request();
|
||||
return this.handle.getRefreshBuffer().request();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getNodes() {
|
||||
return handle.getEnduringNodes();
|
||||
return this.handle.getEnduringNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
|
||||
return handle.getTransientNodes();
|
||||
return this.handle.getTransientNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<Node> getOwnNodes() {
|
||||
return handle.getOwnNodes();
|
||||
return ImmutableList.copyOf(this.handle.getOwnNodes());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<? extends Node> getPermissions() {
|
||||
return ImmutableSortedSet.copyOfSorted(handle.getOwnNodesSorted());
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.getOwnNodesSorted());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getEnduringPermissions() {
|
||||
return ImmutableSet.copyOf(handle.getEnduringNodes().values());
|
||||
return ImmutableSet.copyOf(this.handle.getEnduringNodes().values());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getTransientPermissions() {
|
||||
return ImmutableSet.copyOf(handle.getTransientNodes().values());
|
||||
return ImmutableSet.copyOf(this.handle.getTransientNodes().values());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LocalizedNode> getAllNodes(@NonNull Contexts contexts) {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual(contexts));
|
||||
public SortedSet<LocalizedNode> getAllNodes(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.resolveInheritancesAlmostEqual(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedSet<LocalizedNode> getAllNodes() {
|
||||
return new TreeSet<>(handle.resolveInheritancesAlmostEqual());
|
||||
return ImmutableSortedSet.copyOfSorted(this.handle.resolveInheritancesAlmostEqual());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<LocalizedNode> getAllNodesFiltered(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableSet.copyOf(this.handle.getAllNodes(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, Boolean> exportNodes(@Nonnull Contexts contexts, boolean lowerCase) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableMap.copyOf(this.handle.exportNodesAndShorthand(contexts, lowerCase));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate hasPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.hasPermission(node, false);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate hasTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.hasPermission(node, true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate inheritsPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.inheritsPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<LocalizedNode> getAllNodesFiltered(@NonNull Contexts contexts) {
|
||||
return new HashSet<>(handle.getAllNodes(contexts));
|
||||
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.inheritsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> exportNodes(Contexts contexts, boolean lowerCase) {
|
||||
return new HashMap<>(handle.exportNodesAndShorthand(contexts, lowerCase));
|
||||
public boolean inheritsGroup(@Nonnull me.lucko.luckperms.api.Group group, @Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
return this.handle.inheritsGroup(ApiGroup.cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult setPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.setPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult setTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.setTransientPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult unsetPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public DataMutateResult unsetTransientPermission(@Nonnull Node node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
return this.handle.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(@NonNull Node node) {
|
||||
return handle.hasPermission(node, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasTransientPermission(@NonNull Node node) {
|
||||
return handle.hasPermission(node, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate inheritsPermission(@NonNull Node node) {
|
||||
return handle.inheritsPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull me.lucko.luckperms.api.Group group) {
|
||||
return handle.inheritsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull me.lucko.luckperms.api.Group group, @NonNull ContextSet contextSet) {
|
||||
return handle.inheritsGroup(ApiGroup.cast(group), contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setPermission(@NonNull Node node) {
|
||||
return handle.setPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setTransientPermission(@NonNull Node node) {
|
||||
return handle.setTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult unsetPermission(@NonNull Node node) {
|
||||
return handle.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult unsetTransientPermission(@NonNull Node node) {
|
||||
return handle.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatching(@NonNull Predicate<Node> test) {
|
||||
handle.removeIf(test);
|
||||
if (handle.getType().isUser()) {
|
||||
handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) handle, false);
|
||||
public void clearMatching(@Nonnull Predicate<Node> test) {
|
||||
Objects.requireNonNull(test, "test");
|
||||
this.handle.removeIf(test);
|
||||
if (this.handle.getType().isUser()) {
|
||||
this.handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) this.handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMatchingTransient(@NonNull Predicate<Node> test) {
|
||||
handle.removeIfTransient(test);
|
||||
public void clearMatchingTransient(@Nonnull Predicate<Node> test) {
|
||||
Objects.requireNonNull(test, "test");
|
||||
this.handle.removeIfTransient(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes() {
|
||||
handle.clearNodes();
|
||||
this.handle.clearNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes(@NonNull ContextSet contextSet) {
|
||||
handle.clearNodes(contextSet);
|
||||
public void clearNodes(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearNodes(contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents() {
|
||||
handle.clearParents(true);
|
||||
this.handle.clearParents(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearParents(@NonNull ContextSet contextSet) {
|
||||
handle.clearParents(contextSet, true);
|
||||
public void clearParents(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearParents(contextSet, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta() {
|
||||
handle.clearMeta(MetaType.ANY);
|
||||
this.handle.clearMeta(MetaType.ANY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMeta(@NonNull ContextSet contextSet) {
|
||||
handle.clearMeta(MetaType.ANY, contextSet);
|
||||
public void clearMeta(@Nonnull ContextSet contextSet) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
this.handle.clearMeta(MetaType.ANY, contextSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTransientNodes() {
|
||||
handle.clearTransientNodes();
|
||||
this.handle.clearTransientNodes();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances(Contexts contexts) {
|
||||
return handle.resolveInheritances(contexts);
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return ImmutableList.copyOf(this.handle.resolveInheritances(contexts));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<LocalizedNode> resolveInheritances() {
|
||||
return handle.resolveInheritances();
|
||||
return ImmutableList.copyOf(this.handle.resolveInheritances());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getPermanentPermissionNodes() {
|
||||
return handle.getOwnNodes().stream().filter(Node::isPermanent).collect(Collectors.toSet());
|
||||
return this.handle.getOwnNodes().stream().filter(Node::isPermanent).collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Node> getTemporaryPermissionNodes() {
|
||||
return handle.getOwnNodes().stream().filter(Node::isPrefix).collect(Collectors.toSet());
|
||||
return this.handle.getOwnNodes().stream().filter(Node::isPrefix).collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditTemporaryPermissions() {
|
||||
handle.auditTemporaryPermissions();
|
||||
this.handle.auditTemporaryPermissions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+87
-44
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.Log;
|
||||
@@ -48,17 +45,24 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkName;
|
||||
import static me.lucko.luckperms.common.api.ApiUtils.checkUsername;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ApiStorage implements Storage {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final me.lucko.luckperms.common.storage.Storage handle;
|
||||
|
||||
public ApiStorage(LuckPermsPlugin plugin, me.lucko.luckperms.common.storage.Storage handle) {
|
||||
this.plugin = plugin;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,116 +70,155 @@ public class ApiStorage implements Storage {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Executor getSyncExecutor() {
|
||||
return plugin.getScheduler().sync();
|
||||
return this.plugin.getScheduler().sync();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
return plugin.getScheduler().async();
|
||||
return this.plugin.getScheduler().async();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> logAction(@NonNull LogEntry entry) {
|
||||
return handle.noBuffer().logAction(entry).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> logAction(@Nonnull LogEntry entry) {
|
||||
Objects.requireNonNull(entry, "entry");
|
||||
return this.handle.noBuffer().logAction(entry).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Log> getLog() {
|
||||
return handle.noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
return this.handle.noBuffer().getLog().thenApply(log -> log == null ? null : new ApiLog(log));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadUser(@NonNull UUID uuid, String username) {
|
||||
return handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> loadUser(@Nonnull UUID uuid, String username) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().loadUser(uuid, username == null ? null : checkUsername(username)).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveUser(@NonNull User user) {
|
||||
return handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveUser(@Nonnull User user) {
|
||||
Objects.requireNonNull(user, "user");
|
||||
return this.handle.noBuffer().saveUser(ApiUser.cast(user)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Set<UUID>> getUniqueUsers() {
|
||||
return handle.noBuffer().getUniqueUsers();
|
||||
return this.handle.noBuffer().getUniqueUsers();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@NonNull String permission) {
|
||||
return handle.noBuffer().getUsersWithPermission(permission);
|
||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return this.handle.noBuffer().getUsersWithPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> createAndLoadGroup(@NonNull String name) {
|
||||
return handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> createAndLoadGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().createAndLoadGroup(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadGroup(@NonNull String name) {
|
||||
return handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
||||
public CompletableFuture<Boolean> loadGroup(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().loadGroup(checkName(name)).thenApply(Optional::isPresent);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadAllGroups() {
|
||||
return handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
||||
return this.handle.noBuffer().loadAllGroups().thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveGroup(@NonNull Group group) {
|
||||
return handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.noBuffer().saveGroup(ApiGroup.cast(group)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> deleteGroup(@NonNull Group group) {
|
||||
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
public CompletableFuture<Boolean> deleteGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (group.getName().equalsIgnoreCase(this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
||||
}
|
||||
return handle.noBuffer().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenApply(x -> true);
|
||||
return this.handle.noBuffer().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@NonNull String permission) {
|
||||
return handle.noBuffer().getGroupsWithPermission(permission);
|
||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@Nonnull String permission) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
return this.handle.noBuffer().getGroupsWithPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> createAndLoadTrack(@NonNull String name) {
|
||||
return handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
public CompletableFuture<Boolean> createAndLoadTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().createAndLoadTrack(checkName(name), CreationCause.API).thenApply(Objects::nonNull);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadTrack(@NonNull String name) {
|
||||
return handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
||||
public CompletableFuture<Boolean> loadTrack(@Nonnull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return this.handle.noBuffer().loadTrack(checkName(name)).thenApply(Optional::isPresent);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> loadAllTracks() {
|
||||
return handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
||||
return this.handle.noBuffer().loadAllTracks().thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveTrack(@NonNull Track track) {
|
||||
return handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveTrack(@Nonnull Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
return this.handle.noBuffer().saveTrack(ApiTrack.cast(track)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> deleteTrack(@NonNull Track track) {
|
||||
return handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> deleteTrack(@Nonnull Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
return this.handle.noBuffer().deleteTrack(ApiTrack.cast(track), DeletionCause.API).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Boolean> saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
|
||||
return handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
||||
public CompletableFuture<Boolean> saveUUIDData(@Nonnull String username, @Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(username, "username");
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().saveUUIDData(uuid, checkUsername(username)).thenApply(x -> true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<UUID> getUUID(@NonNull String username) {
|
||||
return handle.noBuffer().getUUID(checkUsername(username));
|
||||
public CompletableFuture<UUID> getUUID(@Nonnull String username) {
|
||||
Objects.requireNonNull(username, "username");
|
||||
return this.handle.noBuffer().getUUID(checkUsername(username));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<String> getName(@NonNull UUID uuid) {
|
||||
return handle.noBuffer().getName(uuid);
|
||||
public CompletableFuture<String> getName(@Nonnull UUID uuid) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
return this.handle.noBuffer().getName(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
@@ -37,94 +32,115 @@ import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@AllArgsConstructor
|
||||
public final class ApiTrack implements Track {
|
||||
public static me.lucko.luckperms.common.model.Track cast(Track g) {
|
||||
Preconditions.checkState(g instanceof ApiTrack, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiTrack) g).getHandle();
|
||||
public static me.lucko.luckperms.common.model.Track cast(Track track) {
|
||||
Objects.requireNonNull(track, "track");
|
||||
Preconditions.checkState(track instanceof ApiTrack, "Illegal instance " + track.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiTrack) track).getHandle();
|
||||
}
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.common.model.Track handle;
|
||||
|
||||
public ApiTrack(me.lucko.luckperms.common.model.Track handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
me.lucko.luckperms.common.model.Track getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
return this.handle.getName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<String> getGroups() {
|
||||
return handle.getGroups();
|
||||
return this.handle.getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return handle.getSize();
|
||||
return this.handle.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNext(@NonNull Group current) {
|
||||
public String getNext(@Nonnull Group current) {
|
||||
Objects.requireNonNull(current, "current");
|
||||
try {
|
||||
return handle.getNext(ApiGroup.cast(current));
|
||||
return this.handle.getNext(ApiGroup.cast(current));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrevious(@NonNull Group current) {
|
||||
public String getPrevious(@Nonnull Group current) {
|
||||
Objects.requireNonNull(current, "current");
|
||||
try {
|
||||
return handle.getPrevious(ApiGroup.cast(current));
|
||||
return this.handle.getPrevious(ApiGroup.cast(current));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult appendGroup(@NonNull Group group) {
|
||||
return handle.appendGroup(ApiGroup.cast(group));
|
||||
public DataMutateResult appendGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.appendGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult insertGroup(@NonNull Group group, @NonNull int position) throws IndexOutOfBoundsException {
|
||||
return handle.insertGroup(ApiGroup.cast(group), position);
|
||||
public DataMutateResult insertGroup(@Nonnull Group group, int position) throws IndexOutOfBoundsException {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.insertGroup(ApiGroup.cast(group), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult removeGroup(@NonNull Group group) {
|
||||
return handle.removeGroup(ApiGroup.cast(group));
|
||||
public DataMutateResult removeGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.removeGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult removeGroup(@NonNull String group) {
|
||||
return handle.removeGroup(group);
|
||||
public DataMutateResult removeGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.removeGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull Group group) {
|
||||
return handle.containsGroup(ApiGroup.cast(group));
|
||||
public boolean containsGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.containsGroup(ApiGroup.cast(group));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull String group) {
|
||||
return handle.containsGroup(group);
|
||||
public boolean containsGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
return this.handle.containsGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearGroups() {
|
||||
handle.clearGroups();
|
||||
this.handle.clearGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiTrack)) return false;
|
||||
|
||||
ApiTrack other = (ApiTrack) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiTrack that = (ApiTrack) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.api.delegates.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
@@ -35,77 +32,89 @@ import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.caching.UserData;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ApiUser extends ApiPermissionHolder implements User {
|
||||
public static me.lucko.luckperms.common.model.User cast(User u) {
|
||||
Preconditions.checkState(u instanceof ApiUser, "Illegal instance " + u.getClass() + " cannot be handled by this implementation.");
|
||||
return ((ApiUser) u).getHandle();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final me.lucko.luckperms.common.model.User handle;
|
||||
|
||||
public ApiUser(@NonNull me.lucko.luckperms.common.model.User handle) {
|
||||
@Override
|
||||
me.lucko.luckperms.common.model.User getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
public ApiUser(me.lucko.luckperms.common.model.User handle) {
|
||||
super(handle);
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return handle.getUuid();
|
||||
return this.handle.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName().orElse(null);
|
||||
return this.handle.getName().orElse(null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getPrimaryGroup() {
|
||||
return handle.getPrimaryGroup().getValue();
|
||||
return this.handle.getPrimaryGroup().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataMutateResult setPrimaryGroup(@NonNull String s) {
|
||||
if (getPrimaryGroup().equalsIgnoreCase(s)) {
|
||||
public DataMutateResult setPrimaryGroup(@Nonnull String group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (getPrimaryGroup().equalsIgnoreCase(group)) {
|
||||
return DataMutateResult.ALREADY_HAS;
|
||||
}
|
||||
|
||||
if (!handle.hasPermission(NodeFactory.buildGroupNode(s.toLowerCase()).build()).asBoolean()) {
|
||||
if (!this.handle.hasPermission(NodeFactory.buildGroupNode(group.toLowerCase()).build()).asBoolean()) {
|
||||
return DataMutateResult.FAIL;
|
||||
}
|
||||
|
||||
handle.getPrimaryGroup().setStoredValue(s.toLowerCase());
|
||||
this.handle.getPrimaryGroup().setStoredValue(group.toLowerCase());
|
||||
return DataMutateResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public UserData getCachedData() {
|
||||
return handle.getCachedData();
|
||||
return this.handle.getCachedData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void refreshPermissions() {
|
||||
handle.getRefreshBuffer().requestDirectly();
|
||||
this.handle.getRefreshBuffer().requestDirectly();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setupDataCache() {
|
||||
handle.preCalculateData();
|
||||
this.handle.preCalculateData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ApiUser)) return false;
|
||||
|
||||
ApiUser other = (ApiUser) o;
|
||||
return handle.equals(other.handle);
|
||||
ApiUser that = (ApiUser) o;
|
||||
return this.handle.equals(that.handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@ public class AssignmentExpression {
|
||||
|
||||
Predicate<Node> checker = node -> holder.hasPermission(node) == tristate;
|
||||
|
||||
String exp = expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining())
|
||||
String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining())
|
||||
.replace("&", "&&").replace("|", "||");
|
||||
|
||||
try {
|
||||
@@ -123,12 +123,12 @@ public class AssignmentExpression {
|
||||
|
||||
@Override
|
||||
public String forExpression(Predicate<Node> checker) {
|
||||
return string;
|
||||
return this.string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string;
|
||||
return this.string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +143,12 @@ public class AssignmentExpression {
|
||||
|
||||
@Override
|
||||
public String forExpression(Predicate<Node> checker) {
|
||||
return Boolean.toString(checker.test(node));
|
||||
return Boolean.toString(checker.test(this.node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<" + permission + ">";
|
||||
return "<" + this.permission + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.assignments;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@@ -36,8 +33,6 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
public class AssignmentRule {
|
||||
private final AssignmentExpression hasTrueExpression;
|
||||
private final AssignmentExpression hasFalseExpression;
|
||||
@@ -57,9 +52,9 @@ public class AssignmentRule {
|
||||
}
|
||||
|
||||
public boolean apply(User user) {
|
||||
if (hasTrueExpression != null) {
|
||||
if (this.hasTrueExpression != null) {
|
||||
try {
|
||||
boolean b = hasTrueExpression.parse(user, Tristate.TRUE);
|
||||
boolean b = this.hasTrueExpression.parse(user, Tristate.TRUE);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@@ -71,9 +66,9 @@ public class AssignmentRule {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFalseExpression != null) {
|
||||
if (this.hasFalseExpression != null) {
|
||||
try {
|
||||
boolean b = hasFalseExpression.parse(user, Tristate.FALSE);
|
||||
boolean b = this.hasFalseExpression.parse(user, Tristate.FALSE);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@@ -85,9 +80,9 @@ public class AssignmentRule {
|
||||
}
|
||||
}
|
||||
|
||||
if (lacksExpression != null) {
|
||||
if (this.lacksExpression != null) {
|
||||
try {
|
||||
boolean b = lacksExpression.parse(user, Tristate.UNDEFINED);
|
||||
boolean b = this.lacksExpression.parse(user, Tristate.UNDEFINED);
|
||||
if (!b) {
|
||||
// The holder does not meet this requirement
|
||||
return false;
|
||||
@@ -100,18 +95,53 @@ public class AssignmentRule {
|
||||
}
|
||||
|
||||
// The holder meets all of the requirements of this rule.
|
||||
for (Node n : toTake) {
|
||||
for (Node n : this.toTake) {
|
||||
user.unsetPermission(n);
|
||||
}
|
||||
|
||||
for (Node n : toGive) {
|
||||
for (Node n : this.toGive) {
|
||||
user.setPermission(n);
|
||||
}
|
||||
|
||||
if (setPrimaryGroup != null) {
|
||||
user.getPrimaryGroup().setStoredValue(setPrimaryGroup);
|
||||
if (this.setPrimaryGroup != null) {
|
||||
user.getPrimaryGroup().setStoredValue(this.setPrimaryGroup);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public AssignmentExpression getHasTrueExpression() {
|
||||
return this.hasTrueExpression;
|
||||
}
|
||||
|
||||
public AssignmentExpression getHasFalseExpression() {
|
||||
return this.hasFalseExpression;
|
||||
}
|
||||
|
||||
public AssignmentExpression getLacksExpression() {
|
||||
return this.lacksExpression;
|
||||
}
|
||||
|
||||
public List<Node> getToGive() {
|
||||
return this.toGive;
|
||||
}
|
||||
|
||||
public List<Node> getToTake() {
|
||||
return this.toTake;
|
||||
}
|
||||
|
||||
public String getSetPrimaryGroup() {
|
||||
return this.setPrimaryGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AssignmentRule(" +
|
||||
"hasTrueExpression=" + this.getHasTrueExpression() + ", " +
|
||||
"hasFalseExpression=" + this.getHasFalseExpression() + ", " +
|
||||
"lacksExpression=" + this.getLacksExpression() + ", " +
|
||||
"toGive=" + this.getToGive() + ", " +
|
||||
"toTake=" + this.getToTake() + ", " +
|
||||
"setPrimaryGroup=" + this.getSetPrimaryGroup() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.backup;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
@@ -37,7 +35,6 @@ import net.kyori.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public abstract class DummySender implements Sender {
|
||||
private final LuckPermsPlugin platform;
|
||||
|
||||
@@ -77,4 +74,18 @@ public abstract class DummySender implements Sender {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsPlugin getPlatform() {
|
||||
return this.platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,29 +83,29 @@ public class Exporter implements Runnable {
|
||||
this.executor = executor;
|
||||
this.filePath = filePath;
|
||||
|
||||
log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(executor);
|
||||
this.log = new ProgressLogger(null, Message.EXPORT_LOG, Message.EXPORT_LOG_PROGRESS);
|
||||
this.log.addListener(plugin.getConsoleSender());
|
||||
this.log.addListener(executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8)) {
|
||||
log.log("Starting.");
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(this.filePath, StandardCharsets.UTF_8)) {
|
||||
this.log.log("Starting.");
|
||||
|
||||
write(writer, "# LuckPerms Export File");
|
||||
write(writer, "# Generated by " + executor.getNameWithLocation() + " at " + DATE_FORMAT.format(new Date(System.currentTimeMillis())));
|
||||
write(writer, "# Generated by " + this.executor.getNameWithLocation() + " at " + DATE_FORMAT.format(new Date(System.currentTimeMillis())));
|
||||
write(writer, "");
|
||||
|
||||
// Export Groups
|
||||
log.log("Starting group export.");
|
||||
this.log.log("Starting group export.");
|
||||
|
||||
// Create the actual groups first
|
||||
write(writer, "# Create groups");
|
||||
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
|
||||
List<? extends Group> groups = plugin.getGroupManager().getAll().values().stream()
|
||||
List<? extends Group> groups = this.plugin.getGroupManager().getAll().values().stream()
|
||||
// export groups in order of weight
|
||||
.sorted((o1, o2) -> {
|
||||
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
|
||||
@@ -128,18 +128,18 @@ public class Exporter implements Runnable {
|
||||
write(writer, "/lp " + NodeFactory.nodeAsCommand(node, group.getName(), HolderType.GROUP, true));
|
||||
}
|
||||
write(writer, "");
|
||||
log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
|
||||
this.log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
|
||||
}
|
||||
|
||||
log.log("Exported " + groupCount.get() + " groups.");
|
||||
this.log.log("Exported " + groupCount.get() + " groups.");
|
||||
|
||||
write(writer, "");
|
||||
write(writer, "");
|
||||
|
||||
// Export tracks
|
||||
log.log("Starting track export.");
|
||||
this.log.log("Starting track export.");
|
||||
|
||||
Collection<? extends Track> tracks = plugin.getTrackManager().getAll().values();
|
||||
Collection<? extends Track> tracks = this.plugin.getTrackManager().getAll().values();
|
||||
if (!tracks.isEmpty()) {
|
||||
|
||||
// Create the actual tracks first
|
||||
@@ -151,32 +151,32 @@ public class Exporter implements Runnable {
|
||||
write(writer, "");
|
||||
|
||||
AtomicInteger trackCount = new AtomicInteger(0);
|
||||
for (Track track : plugin.getTrackManager().getAll().values()) {
|
||||
for (Track track : this.plugin.getTrackManager().getAll().values()) {
|
||||
write(writer, "# Export track: " + track.getName());
|
||||
for (String group : track.getGroups()) {
|
||||
write(writer, "/lp track " + track.getName() + " append " + group);
|
||||
}
|
||||
write(writer, "");
|
||||
log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
||||
this.log.logAllProgress("Exported {} tracks so far.", trackCount.incrementAndGet());
|
||||
}
|
||||
|
||||
write(writer, "");
|
||||
write(writer, "");
|
||||
}
|
||||
|
||||
log.log("Exported " + tracks.size() + " tracks.");
|
||||
this.log.log("Exported " + tracks.size() + " tracks.");
|
||||
|
||||
|
||||
// Users are migrated in separate threads.
|
||||
// This is because there are likely to be a lot of them, and because we can.
|
||||
// It's a big speed improvement, since the database/files are split up and can handle concurrent reads.
|
||||
|
||||
log.log("Starting user export. Finding a list of unique users to export.");
|
||||
this.log.log("Starting user export. Finding a list of unique users to export.");
|
||||
|
||||
// Find all of the unique users we need to export
|
||||
Storage ds = plugin.getStorage();
|
||||
Storage ds = this.plugin.getStorage();
|
||||
Set<UUID> users = ds.getUniqueUsers().join();
|
||||
log.log("Found " + users.size() + " unique users to export.");
|
||||
this.log.log("Found " + users.size() + " unique users to export.");
|
||||
|
||||
write(writer, "# Export users");
|
||||
|
||||
@@ -186,7 +186,7 @@ public class Exporter implements Runnable {
|
||||
userPools.next().add(uuid);
|
||||
}
|
||||
|
||||
log.log("Split users into " + userPools.getBacking().size() + " threads for export.");
|
||||
this.log.log("Split users into " + userPools.getBacking().size() + " threads for export.");
|
||||
|
||||
// Setup a file writing lock. We don't want multiple threads writing at the same time.
|
||||
// The write function accepts a list of strings, as we want a user's data to be grouped together.
|
||||
@@ -220,8 +220,8 @@ public class Exporter implements Runnable {
|
||||
// actually export the user. this output will be fed to the writing function when we have all of the user's data.
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
plugin.getStorage().loadUser(uuid, null).join();
|
||||
User user = plugin.getUserManager().getIfLoaded(uuid);
|
||||
this.plugin.getStorage().loadUser(uuid, null).join();
|
||||
User user = this.plugin.getUserManager().getIfLoaded(uuid);
|
||||
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
|
||||
|
||||
boolean inDefault = false;
|
||||
@@ -242,25 +242,25 @@ public class Exporter implements Runnable {
|
||||
output.add("/lp user " + user.getUuid().toString() + " parent remove default");
|
||||
}
|
||||
|
||||
plugin.getUserManager().cleanup(user);
|
||||
this.plugin.getUserManager().cleanup(user);
|
||||
writeFunction.accept(output);
|
||||
|
||||
log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
||||
this.log.logProgress("Exported {} users so far.", userCount.incrementAndGet());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, plugin.getScheduler().async()));
|
||||
}, this.plugin.getScheduler().async()));
|
||||
}
|
||||
|
||||
// all of the threads have been scheduled now and are running. we just need to wait for them all to complete
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).join();
|
||||
|
||||
log.log("Exported " + userCount.get() + " users.");
|
||||
this.log.log("Exported " + userCount.get() + " users.");
|
||||
|
||||
writer.flush();
|
||||
log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, filePath.toFile().getAbsolutePath()));
|
||||
this.log.getListeners().forEach(l -> Message.LOG_EXPORT_SUCCESS.send(l, this.filePath.toFile().getAbsolutePath()));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.backup;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@@ -81,13 +78,13 @@ public class Importer implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
notify.forEach(s -> Message.IMPORT_START.send(s));
|
||||
this.notify.forEach(s -> Message.IMPORT_START.send(s));
|
||||
|
||||
// form instances for all commands, and register them
|
||||
int index = 1;
|
||||
for (String command : commands) {
|
||||
ImportCommand cmd = new ImportCommand(commandManager, index, command);
|
||||
toExecute.add(cmd);
|
||||
for (String command : this.commands) {
|
||||
ImportCommand cmd = new ImportCommand(this.commandManager, index, command);
|
||||
this.toExecute.add(cmd);
|
||||
|
||||
if (cmd.getCommand().startsWith("creategroup ") || cmd.getCommand().startsWith("createtrack ")) {
|
||||
cmd.process(); // process immediately
|
||||
@@ -100,7 +97,7 @@ public class Importer implements Runnable {
|
||||
Cycle<List<ImportCommand>> commandPools = new Cycle<>(CommandUtils.nInstances(128, ArrayList::new));
|
||||
|
||||
String lastTarget = null;
|
||||
for (ImportCommand cmd : toExecute) {
|
||||
for (ImportCommand cmd : this.toExecute) {
|
||||
// if the last target isn't the same, skip to a new pool
|
||||
if (lastTarget == null || !lastTarget.equals(cmd.getTarget())) {
|
||||
commandPools.next();
|
||||
@@ -126,7 +123,7 @@ public class Importer implements Runnable {
|
||||
cmd.process();
|
||||
processedCount.incrementAndGet();
|
||||
}
|
||||
}, commandManager.getPlugin().getScheduler().async()));
|
||||
}, this.commandManager.getPlugin().getScheduler().async()));
|
||||
}
|
||||
|
||||
// all of the threads have been scheduled now and are running. we just need to wait for them all to complete
|
||||
@@ -153,24 +150,24 @@ public class Importer implements Runnable {
|
||||
long endTime = System.currentTimeMillis();
|
||||
double seconds = (endTime - startTime) / 1000;
|
||||
|
||||
int errors = (int) toExecute.stream().filter(v -> !v.getResult().asBoolean()).count();
|
||||
int errors = (int) this.toExecute.stream().filter(v -> !v.getResult().asBoolean()).count();
|
||||
|
||||
switch (errors) {
|
||||
case 0:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE.send(s, seconds));
|
||||
break;
|
||||
case 1:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR_SIN.send(s, seconds, errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR_SIN.send(s, seconds, errors));
|
||||
break;
|
||||
default:
|
||||
notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR.send(s, seconds, errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_END_COMPLETE_ERR.send(s, seconds, errors));
|
||||
break;
|
||||
}
|
||||
|
||||
AtomicInteger errIndex = new AtomicInteger(1);
|
||||
for (ImportCommand e : toExecute) {
|
||||
for (ImportCommand e : this.toExecute) {
|
||||
if (e.getResult() != null && !e.getResult().asBoolean()) {
|
||||
notify.forEach(s -> {
|
||||
this.notify.forEach(s -> {
|
||||
Message.IMPORT_END_ERROR_HEADER.send(s, errIndex.get(), e.getId(), e.getCommand(), e.getResult().toString());
|
||||
for (String out : e.getOutput()) {
|
||||
Message.IMPORT_END_ERROR_CONTENT.send(s, out);
|
||||
@@ -184,17 +181,16 @@ public class Importer implements Runnable {
|
||||
}
|
||||
|
||||
private void sendProgress(int processedCount) {
|
||||
int percent = (processedCount * 100) / commands.size();
|
||||
int errors = (int) toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
||||
int percent = (processedCount * 100) / this.commands.size();
|
||||
int errors = (int) this.toExecute.stream().filter(v -> v.isCompleted() && !v.getResult().asBoolean()).count();
|
||||
|
||||
if (errors == 1) {
|
||||
notify.forEach(s -> Message.IMPORT_PROGRESS_SIN.send(s, percent, processedCount, commands.size(), errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_PROGRESS_SIN.send(s, percent, processedCount, this.commands.size(), errors));
|
||||
} else {
|
||||
notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, commands.size(), errors));
|
||||
this.notify.forEach(s -> Message.IMPORT_PROGRESS.send(s, percent, processedCount, this.commands.size(), errors));
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static class ImportCommand extends DummySender {
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
||||
@@ -205,12 +201,10 @@ public class Importer implements Runnable {
|
||||
|
||||
private final String target;
|
||||
|
||||
@Setter
|
||||
private boolean completed = false;
|
||||
|
||||
private final List<String> output = new ArrayList<>();
|
||||
|
||||
@Setter
|
||||
private CommandResult result = CommandResult.FAILURE;
|
||||
|
||||
ImportCommand(CommandManager commandManager, int id, String command) {
|
||||
@@ -223,7 +217,7 @@ public class Importer implements Runnable {
|
||||
|
||||
@Override
|
||||
protected void consumeMessage(String s) {
|
||||
output.add(s);
|
||||
this.output.add(s);
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@@ -233,7 +227,7 @@ public class Importer implements Runnable {
|
||||
|
||||
try {
|
||||
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
||||
CommandResult result = commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
CommandResult result = this.commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
setResult(result);
|
||||
} catch (Exception e) {
|
||||
setResult(CommandResult.FAILURE);
|
||||
@@ -287,6 +281,37 @@ public class Importer implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
return this.completed;
|
||||
}
|
||||
|
||||
public List<String> getOutput() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public CommandResult getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public void setCompleted(boolean completed) {
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
public void setResult(CommandResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,15 +25,10 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
@@ -60,17 +55,19 @@ public class Buffer<T, R> implements Runnable {
|
||||
this.dequeueFunc = dequeueFunc;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> enqueue(@NonNull T t) {
|
||||
lock.lock();
|
||||
public CompletableFuture<R> enqueue(T object) {
|
||||
Objects.requireNonNull(object, "object");
|
||||
|
||||
this.lock.lock();
|
||||
try {
|
||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator();
|
||||
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator();
|
||||
|
||||
BufferedObject<T, R> o = null;
|
||||
|
||||
while (it.hasNext()) {
|
||||
BufferedObject<T, R> obj = it.next();
|
||||
|
||||
if (obj.getObject().equals(t)) {
|
||||
if (obj.getObject().equals(object)) {
|
||||
o = obj;
|
||||
it.remove();
|
||||
break;
|
||||
@@ -78,28 +75,28 @@ public class Buffer<T, R> implements Runnable {
|
||||
}
|
||||
|
||||
if (o == null) {
|
||||
o = new BufferedObject<>(System.currentTimeMillis(), t, new CompletableFuture<R>());
|
||||
o = new BufferedObject<>(System.currentTimeMillis(), object, new CompletableFuture<R>());
|
||||
} else {
|
||||
o.setBufferTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
buffer.add(o);
|
||||
this.buffer.add(o);
|
||||
return o.getFuture();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected R dequeue(T t) {
|
||||
return dequeueFunc.apply(t);
|
||||
return this.dequeueFunc.apply(t);
|
||||
}
|
||||
|
||||
public void flush(long flushTime) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
ListIterator<BufferedObject<T, R>> it = buffer.listIterator(buffer.size());
|
||||
ListIterator<BufferedObject<T, R>> it = this.buffer.listIterator(this.buffer.size());
|
||||
|
||||
while (it.hasPrevious()) {
|
||||
BufferedObject<T, R> obj = it.previous();
|
||||
@@ -114,7 +111,7 @@ public class Buffer<T, R> implements Runnable {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,15 +120,45 @@ public class Buffer<T, R> implements Runnable {
|
||||
flush(DEFAULT_FLUSH_TIME);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(of = "object")
|
||||
@AllArgsConstructor
|
||||
private static final class BufferedObject<T, R> {
|
||||
|
||||
@Setter
|
||||
private long bufferTime;
|
||||
private final T object;
|
||||
private final CompletableFuture<R> future;
|
||||
|
||||
public BufferedObject(long bufferTime, T object, CompletableFuture<R> future) {
|
||||
this.bufferTime = bufferTime;
|
||||
this.object = object;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
public long getBufferTime() {
|
||||
return this.bufferTime;
|
||||
}
|
||||
|
||||
public void setBufferTime(long bufferTime) {
|
||||
this.bufferTime = bufferTime;
|
||||
}
|
||||
|
||||
public T getObject() {
|
||||
return this.object;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> getFuture() {
|
||||
return this.future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Buffer.BufferedObject)) return false;
|
||||
final BufferedObject that = (BufferedObject) o;
|
||||
return Objects.equals(this.getObject(), that.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -42,7 +39,6 @@ import java.util.function.Supplier;
|
||||
*
|
||||
* @param <T> the return type
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class BufferedRequest<T> {
|
||||
private final long bufferTimeMillis;
|
||||
private final long sleepInterval;
|
||||
@@ -51,23 +47,29 @@ public abstract class BufferedRequest<T> {
|
||||
private WeakReference<Processor<T>> processor = null;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public BufferedRequest(long bufferTimeMillis, long sleepInterval, Executor executor) {
|
||||
this.bufferTimeMillis = bufferTimeMillis;
|
||||
this.sleepInterval = sleepInterval;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public CompletableFuture<T> request() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (processor != null) {
|
||||
Processor<T> p = processor.get();
|
||||
if (this.processor != null) {
|
||||
Processor<T> p = this.processor.get();
|
||||
if (p != null && p.isUsable()) {
|
||||
return p.getAndExtend();
|
||||
}
|
||||
}
|
||||
|
||||
Processor<T> p = new Processor<>(bufferTimeMillis, sleepInterval, this::perform);
|
||||
executor.execute(p);
|
||||
processor = new WeakReference<>(p);
|
||||
Processor<T> p = new Processor<>(this.bufferTimeMillis, this.sleepInterval, this::perform);
|
||||
this.executor.execute(p);
|
||||
this.processor = new WeakReference<>(p);
|
||||
return p.get();
|
||||
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,62 +79,70 @@ public abstract class BufferedRequest<T> {
|
||||
|
||||
protected abstract T perform();
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class Processor<R> implements Runnable {
|
||||
private final long delayMillis;
|
||||
private final long sleepMillis;
|
||||
private final Supplier<R> supplier;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final CompletableFuture<R> future = new CompletableFuture<>();
|
||||
@Getter
|
||||
private boolean usable = true;
|
||||
private long executionTime;
|
||||
|
||||
public Processor(long delayMillis, long sleepMillis, Supplier<R> supplier) {
|
||||
this.delayMillis = delayMillis;
|
||||
this.sleepMillis = sleepMillis;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
executionTime = System.currentTimeMillis() + delayMillis;
|
||||
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (System.currentTimeMillis() > executionTime) {
|
||||
usable = false;
|
||||
if (System.currentTimeMillis() > this.executionTime) {
|
||||
this.usable = false;
|
||||
break;
|
||||
}
|
||||
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepMillis);
|
||||
Thread.sleep(this.sleepMillis);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
R result = supplier.get();
|
||||
future.complete(result);
|
||||
R result = this.supplier.get();
|
||||
this.future.complete(result);
|
||||
}
|
||||
|
||||
public CompletableFuture<R> get() {
|
||||
return future;
|
||||
return this.future;
|
||||
}
|
||||
|
||||
public CompletableFuture<R> getAndExtend() {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
executionTime = System.currentTimeMillis() + delayMillis;
|
||||
this.executionTime = System.currentTimeMillis() + this.delayMillis;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
return future;
|
||||
return this.future;
|
||||
}
|
||||
|
||||
public boolean isUsable() {
|
||||
return this.usable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
@@ -35,58 +33,56 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
*
|
||||
* @param <T> the type being stored
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class Cache<T> {
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private T cached = null;
|
||||
|
||||
protected abstract T supply();
|
||||
|
||||
public final T get() {
|
||||
// try to just read from the cached value
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
if (this.cached != null) {
|
||||
return this.cached;
|
||||
}
|
||||
} finally {
|
||||
// we have to release the read lock, as it is not possible
|
||||
// to acquire the write lock whilst holding a read lock
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
|
||||
lock.writeLock().lock();
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
// Since the lock was unlocked momentarily, we need
|
||||
// to check again for a cached value
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
if (this.cached != null) {
|
||||
return this.cached;
|
||||
}
|
||||
|
||||
// call the supplier and set the cached value
|
||||
cached = supply();
|
||||
return cached;
|
||||
this.cached = supply();
|
||||
return this.cached;
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public final Optional<T> getIfPresent() {
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
return Optional.ofNullable(cached);
|
||||
return Optional.ofNullable(this.cached);
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public final void invalidate() {
|
||||
lock.writeLock().lock();
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
cached = null;
|
||||
this.cached = null;
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
|
||||
|
||||
@Override
|
||||
protected Void perform() {
|
||||
new UpdateTask(plugin, false).run();
|
||||
new UpdateTask(this.plugin, false).run();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,26 +25,18 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
||||
import me.lucko.luckperms.common.bulkupdate.constraint.Constraint;
|
||||
import me.lucko.luckperms.common.node.NodeModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a query to be applied to a set of data.
|
||||
* Queries can either be applied to im-memory sets of data, or converted to SQL syntax to be executed remotely.
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class BulkUpdate {
|
||||
public final class BulkUpdate {
|
||||
|
||||
// the data types which this query should apply to
|
||||
private final DataType dataType;
|
||||
@@ -55,6 +47,12 @@ public class BulkUpdate {
|
||||
// a set of constraints which data must match to be acted upon
|
||||
private final List<Constraint> constraints;
|
||||
|
||||
public BulkUpdate(DataType dataType, Action action, List<Constraint> constraints) {
|
||||
this.dataType = dataType;
|
||||
this.action = action;
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a Node instance satisfies the constrints of this query
|
||||
*
|
||||
@@ -62,7 +60,7 @@ public class BulkUpdate {
|
||||
* @return true if satisfied
|
||||
*/
|
||||
public boolean satisfiesConstraints(NodeModel node) {
|
||||
for (Constraint constraint : constraints) {
|
||||
for (Constraint constraint : this.constraints) {
|
||||
if (!constraint.isSatisfiedBy(node)) {
|
||||
return false;
|
||||
}
|
||||
@@ -81,7 +79,7 @@ public class BulkUpdate {
|
||||
return from; // make no change
|
||||
}
|
||||
|
||||
return action.apply(from);
|
||||
return this.action.apply(from);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,17 +95,17 @@ public class BulkUpdate {
|
||||
|
||||
// add the action
|
||||
// (DELETE FROM or UPDATE)
|
||||
sb.append(action.getAsSql());
|
||||
sb.append(this.action.getAsSql());
|
||||
|
||||
// if there are no constraints, just return without a WHERE clause
|
||||
if (constraints.isEmpty()) {
|
||||
if (this.constraints.isEmpty()) {
|
||||
return sb.append(";").toString();
|
||||
}
|
||||
|
||||
// append constraints
|
||||
sb.append(" WHERE");
|
||||
for (int i = 0; i < constraints.size(); i++) {
|
||||
Constraint constraint = constraints.get(i);
|
||||
for (int i = 0; i < this.constraints.size(); i++) {
|
||||
Constraint constraint = this.constraints.get(i);
|
||||
|
||||
sb.append(" ");
|
||||
if (i != 0) {
|
||||
@@ -141,4 +139,39 @@ public class BulkUpdate {
|
||||
return "'" + s + "'";
|
||||
}
|
||||
|
||||
public DataType getDataType() {
|
||||
return this.dataType;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public List<Constraint> getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof BulkUpdate)) return false;
|
||||
final BulkUpdate that = (BulkUpdate) o;
|
||||
|
||||
return Objects.equals(this.getDataType(), that.getDataType()) &&
|
||||
Objects.equals(this.getAction(), that.getAction()) &&
|
||||
Objects.equals(this.getConstraints(), that.getConstraints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getDataType(), getAction(), getConstraints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BulkUpdate(" +
|
||||
"dataType=" + this.getDataType() + ", " +
|
||||
"action=" + this.getAction() + ", " +
|
||||
"constraints=" + this.getConstraints() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.action.Action;
|
||||
@@ -39,10 +36,12 @@ import java.util.Set;
|
||||
/**
|
||||
* Responsible for building a {@link BulkUpdate}
|
||||
*/
|
||||
@ToString
|
||||
@NoArgsConstructor(staticName = "create")
|
||||
public class BulkUpdateBuilder {
|
||||
|
||||
public static BulkUpdateBuilder create() {
|
||||
return new BulkUpdateBuilder();
|
||||
}
|
||||
|
||||
// the data type this query should affect
|
||||
private DataType dataType = DataType.ALL;
|
||||
|
||||
@@ -52,6 +51,9 @@ public class BulkUpdateBuilder {
|
||||
// a set of constraints which data must match to be acted upon
|
||||
private final Set<Constraint> constraints = new LinkedHashSet<>();
|
||||
|
||||
private BulkUpdateBuilder() {
|
||||
}
|
||||
|
||||
public BulkUpdateBuilder action(Action action) {
|
||||
this.action = action;
|
||||
return this;
|
||||
@@ -63,15 +65,23 @@ public class BulkUpdateBuilder {
|
||||
}
|
||||
|
||||
public BulkUpdateBuilder constraint(Constraint constraint) {
|
||||
constraints.add(constraint);
|
||||
this.constraints.add(constraint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BulkUpdate build() {
|
||||
if (action == null) {
|
||||
if (this.action == null) {
|
||||
throw new IllegalStateException("no action specified");
|
||||
}
|
||||
|
||||
return new BulkUpdate(dataType, action, ImmutableList.copyOf(constraints));
|
||||
return new BulkUpdate(this.dataType, this.action, ImmutableList.copyOf(this.constraints));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BulkUpdateBuilder(" +
|
||||
"dataType=" + this.dataType + ", " +
|
||||
"action=" + this.action + ", " +
|
||||
"constraints=" + this.constraints + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Represents the data sets a query should apply to
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DataType {
|
||||
|
||||
ALL("all", true, true),
|
||||
@@ -43,4 +38,21 @@ public enum DataType {
|
||||
private final boolean includingUsers;
|
||||
private final boolean includingGroups;
|
||||
|
||||
DataType(String name, boolean includingUsers, boolean includingGroups) {
|
||||
this.name = name;
|
||||
this.includingUsers = includingUsers;
|
||||
this.includingGroups = includingGroups;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isIncludingUsers() {
|
||||
return this.includingUsers;
|
||||
}
|
||||
|
||||
public boolean isIncludingGroups() {
|
||||
return this.includingGroups;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,17 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate.action;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.node.NodeModel;
|
||||
|
||||
@AllArgsConstructor(staticName = "create")
|
||||
public class DeleteAction implements Action {
|
||||
|
||||
public static DeleteAction create() {
|
||||
return new DeleteAction();
|
||||
}
|
||||
|
||||
private DeleteAction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "delete";
|
||||
|
||||
@@ -25,21 +25,27 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate.action;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
|
||||
import me.lucko.luckperms.common.bulkupdate.constraint.QueryField;
|
||||
import me.lucko.luckperms.common.node.NodeModel;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class UpdateAction implements Action {
|
||||
|
||||
public static UpdateAction of(QueryField field, String value) {
|
||||
return new UpdateAction(field, value);
|
||||
}
|
||||
|
||||
// the field we're updating
|
||||
private final QueryField field;
|
||||
|
||||
// the new value of the field
|
||||
private final String value;
|
||||
|
||||
private UpdateAction(QueryField field, String value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "update";
|
||||
@@ -47,13 +53,13 @@ public class UpdateAction implements Action {
|
||||
|
||||
@Override
|
||||
public NodeModel apply(NodeModel from) {
|
||||
switch (field) {
|
||||
switch (this.field) {
|
||||
case PERMISSION:
|
||||
return from.setPermission(value);
|
||||
return from.setPermission(this.value);
|
||||
case SERVER:
|
||||
return from.setServer(value);
|
||||
return from.setServer(this.value);
|
||||
case WORLD:
|
||||
return from.setWorld(value);
|
||||
return from.setWorld(this.value);
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
}
|
||||
@@ -61,6 +67,6 @@ public class UpdateAction implements Action {
|
||||
|
||||
@Override
|
||||
public String getAsSql() {
|
||||
return "UPDATE {table} SET " + field.getSqlName() + "=" + BulkUpdate.escapeStringForSql(value);
|
||||
return "UPDATE {table} SET " + this.field.getSqlName() + "=" + BulkUpdate.escapeStringForSql(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate.comparisons;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.comparisons.impl.ComparisonEqual;
|
||||
import me.lucko.luckperms.common.bulkupdate.comparisons.impl.ComparisonNotEqual;
|
||||
import me.lucko.luckperms.common.bulkupdate.comparisons.impl.ComparisonNotSimilar;
|
||||
@@ -35,7 +33,6 @@ import me.lucko.luckperms.common.bulkupdate.comparisons.impl.ComparisonSimilar;
|
||||
/**
|
||||
* An enumeration of all {@link Comparison}s.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public enum ComparisonType {
|
||||
|
||||
EQUAL("==", new ComparisonEqual()),
|
||||
@@ -46,12 +43,17 @@ public enum ComparisonType {
|
||||
private final String symbol;
|
||||
private final Comparison instance;
|
||||
|
||||
ComparisonType(String symbol, Comparison instance) {
|
||||
this.symbol = symbol;
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public Comparison getComparison() {
|
||||
return instance;
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public static ComparisonType parseComparison(String s) {
|
||||
|
||||
+30
-14
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate.constraint;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
|
||||
import me.lucko.luckperms.common.bulkupdate.comparisons.ComparisonType;
|
||||
import me.lucko.luckperms.common.node.NodeModel;
|
||||
@@ -35,10 +32,12 @@ import me.lucko.luckperms.common.node.NodeModel;
|
||||
/**
|
||||
* Represents a query constraint
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class Constraint {
|
||||
|
||||
public static Constraint of(QueryField field, ComparisonType comparisonType, String value) {
|
||||
return new Constraint(field, comparisonType, value);
|
||||
}
|
||||
|
||||
// the field this constraint is comparing against
|
||||
private final QueryField field;
|
||||
|
||||
@@ -48,6 +47,12 @@ public class Constraint {
|
||||
// the expression being compared against
|
||||
private final String value;
|
||||
|
||||
private Constraint(QueryField field, ComparisonType comparisonType, String value) {
|
||||
this.field = field;
|
||||
this.comparisonType = comparisonType;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the given node satisfies this constraint
|
||||
*
|
||||
@@ -55,31 +60,42 @@ public class Constraint {
|
||||
* @return true if satisfied
|
||||
*/
|
||||
public boolean isSatisfiedBy(NodeModel node) {
|
||||
switch (field) {
|
||||
switch (this.field) {
|
||||
case PERMISSION:
|
||||
return comparisonType.getComparison().matches(node.getPermission(), value);
|
||||
return this.comparisonType.getComparison().matches(node.getPermission(), this.value);
|
||||
case SERVER:
|
||||
return comparisonType.getComparison().matches(node.getServer(), value);
|
||||
return this.comparisonType.getComparison().matches(node.getServer(), this.value);
|
||||
case WORLD:
|
||||
return comparisonType.getComparison().matches(node.getWorld(), value);
|
||||
return this.comparisonType.getComparison().matches(node.getWorld(), this.value);
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public String getAsSql() {
|
||||
switch (comparisonType) {
|
||||
switch (this.comparisonType) {
|
||||
case EQUAL:
|
||||
return field.getSqlName() + " = " + BulkUpdate.escapeStringForSql(value);
|
||||
return this.field.getSqlName() + " = " + BulkUpdate.escapeStringForSql(this.value);
|
||||
case NOT_EQUAL:
|
||||
return field.getSqlName() + " != " + BulkUpdate.escapeStringForSql(value);
|
||||
return this.field.getSqlName() + " != " + BulkUpdate.escapeStringForSql(this.value);
|
||||
case SIMILAR:
|
||||
return field.getSqlName() + " LIKE " + BulkUpdate.escapeStringForSql(value);
|
||||
return this.field.getSqlName() + " LIKE " + BulkUpdate.escapeStringForSql(this.value);
|
||||
case NOT_SIMILAR:
|
||||
return field.getSqlName() + " NOT LIKE " + BulkUpdate.escapeStringForSql(value);
|
||||
return this.field.getSqlName() + " NOT LIKE " + BulkUpdate.escapeStringForSql(this.value);
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public QueryField getField() {
|
||||
return this.field;
|
||||
}
|
||||
|
||||
public ComparisonType getComparisonType() {
|
||||
return this.comparisonType;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-5
@@ -25,14 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.bulkupdate.constraint;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Represents a field being used in an update
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum QueryField {
|
||||
|
||||
PERMISSION("permission"),
|
||||
@@ -48,4 +43,12 @@ public enum QueryField {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
QueryField(String sqlName) {
|
||||
this.sqlName = sqlName;
|
||||
}
|
||||
|
||||
public String getSqlName() {
|
||||
return this.sqlName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ public class GroupCachedData extends HolderCachedData<Group> implements GroupDat
|
||||
|
||||
@Override
|
||||
protected String getHolderName() {
|
||||
return holder.getName();
|
||||
return this.holder.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.caching;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
@@ -46,14 +43,16 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Holds an easily accessible cache of a holders data in a number of contexts
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class HolderCachedData<T extends PermissionHolder> implements CachedData {
|
||||
|
||||
/**
|
||||
@@ -75,6 +74,10 @@ public abstract class HolderCachedData<T extends PermissionHolder> implements Ca
|
||||
.expireAfterAccess(2, TimeUnit.MINUTES)
|
||||
.build(new MetaCacheLoader());
|
||||
|
||||
public HolderCachedData(T holder) {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
protected abstract String getHolderName();
|
||||
|
||||
/**
|
||||
@@ -84,16 +87,18 @@ public abstract class HolderCachedData<T extends PermissionHolder> implements Ca
|
||||
* @param data an old data instance to try to reuse - ignored if null
|
||||
* @return the calculated instance
|
||||
*/
|
||||
private PermissionCache calculatePermissions(@NonNull Contexts contexts, PermissionCache data) {
|
||||
private PermissionCache calculatePermissions(Contexts contexts, PermissionCache data) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
if (data == null) {
|
||||
PermissionCalculatorMetadata metadata = PermissionCalculatorMetadata.of(holder.getType(), getHolderName(), contexts.getContexts());
|
||||
data = new PermissionCache(contexts, metadata, holder.getPlugin().getCalculatorFactory());
|
||||
PermissionCalculatorMetadata metadata = PermissionCalculatorMetadata.of(this.holder.getType(), getHolderName(), contexts.getContexts());
|
||||
data = new PermissionCache(contexts, metadata, this.holder.getPlugin().getCalculatorFactory());
|
||||
}
|
||||
|
||||
if (contexts == Contexts.allowAll()) {
|
||||
data.setPermissions(holder.exportNodesAndShorthand(true));
|
||||
data.setPermissions(this.holder.exportNodesAndShorthand(true));
|
||||
} else {
|
||||
data.setPermissions(holder.exportNodesAndShorthand(contexts, true));
|
||||
data.setPermissions(this.holder.exportNodesAndShorthand(contexts, true));
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -106,122 +111,153 @@ public abstract class HolderCachedData<T extends PermissionHolder> implements Ca
|
||||
* @param data an old data instance to try to reuse - ignored if null
|
||||
* @return the calculated instance
|
||||
*/
|
||||
private MetaCache calculateMeta(@NonNull MetaContexts contexts, MetaCache data) {
|
||||
private MetaCache calculateMeta(MetaContexts contexts, MetaCache data) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
if (data == null) {
|
||||
data = new MetaCache(contexts);
|
||||
}
|
||||
|
||||
if (contexts.getContexts() == Contexts.allowAll()) {
|
||||
data.loadMeta(holder.accumulateMeta(newAccumulator(contexts), null));
|
||||
data.loadMeta(this.holder.accumulateMeta(newAccumulator(contexts), null));
|
||||
} else {
|
||||
data.loadMeta(holder.accumulateMeta(newAccumulator(contexts), null, contexts.getContexts()));
|
||||
data.loadMeta(this.holder.accumulateMeta(newAccumulator(contexts), null, contexts.getContexts()));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionCache getPermissionData(@NonNull Contexts contexts) {
|
||||
public PermissionCache getPermissionData(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
//noinspection ConstantConditions
|
||||
return permission.get(contexts);
|
||||
return this.permission.get(contexts);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaCache getMetaData(@NonNull MetaContexts contexts) {
|
||||
public MetaCache getMetaData(@Nonnull MetaContexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
//noinspection ConstantConditions
|
||||
return meta.get(contexts);
|
||||
return this.meta.get(contexts);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaCache getMetaData(@NonNull Contexts contexts) {
|
||||
return getMetaData(makeFromMetaContextsConfig(contexts, holder.getPlugin()));
|
||||
public MetaCache getMetaData(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return getMetaData(makeFromMetaContextsConfig(contexts, this.holder.getPlugin()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionCache calculatePermissions(@NonNull Contexts contexts) {
|
||||
public PermissionCache calculatePermissions(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return calculatePermissions(contexts, null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaCache calculateMeta(@NonNull MetaContexts contexts) {
|
||||
public MetaCache calculateMeta(@Nonnull MetaContexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return calculateMeta(contexts, null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaCache calculateMeta(@NonNull Contexts contexts) {
|
||||
return calculateMeta(makeFromMetaContextsConfig(contexts, holder.getPlugin()));
|
||||
public MetaCache calculateMeta(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return calculateMeta(makeFromMetaContextsConfig(contexts, this.holder.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions(@NonNull Contexts contexts) {
|
||||
permission.refresh(contexts);
|
||||
public void recalculatePermissions(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
this.permission.refresh(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateMeta(@NonNull MetaContexts contexts) {
|
||||
meta.refresh(contexts);
|
||||
public void recalculateMeta(@Nonnull MetaContexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
this.meta.refresh(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateMeta(@NonNull Contexts contexts) {
|
||||
recalculateMeta(makeFromMetaContextsConfig(contexts, holder.getPlugin()));
|
||||
public void recalculateMeta(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
recalculateMeta(makeFromMetaContextsConfig(contexts, this.holder.getPlugin()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<PermissionCache> reloadPermissions(@NonNull Contexts contexts) {
|
||||
public CompletableFuture<PermissionCache> reloadPermissions(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
// get the previous value - to use when recalculating
|
||||
PermissionCache previous = permission.getIfPresent(contexts);
|
||||
PermissionCache previous = this.permission.getIfPresent(contexts);
|
||||
|
||||
// invalidate the entry
|
||||
permission.invalidate(contexts);
|
||||
this.permission.invalidate(contexts);
|
||||
|
||||
// repopulate the cache
|
||||
return CompletableFuture.supplyAsync(() -> permission.get(contexts, c -> calculatePermissions(c, previous)));
|
||||
return CompletableFuture.supplyAsync(() -> this.permission.get(contexts, c -> calculatePermissions(c, previous)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<MetaCache> reloadMeta(@NonNull MetaContexts contexts) {
|
||||
public CompletableFuture<MetaCache> reloadMeta(@Nonnull MetaContexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
// get the previous value - to use when recalculating
|
||||
MetaCache previous = meta.getIfPresent(contexts);
|
||||
MetaCache previous = this.meta.getIfPresent(contexts);
|
||||
|
||||
// invalidate the entry
|
||||
meta.invalidate(contexts);
|
||||
this.meta.invalidate(contexts);
|
||||
|
||||
// repopulate the cache
|
||||
return CompletableFuture.supplyAsync(() -> meta.get(contexts, c -> calculateMeta(c, previous)));
|
||||
return CompletableFuture.supplyAsync(() -> this.meta.get(contexts, c -> calculateMeta(c, previous)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<MetaCache> reloadMeta(@NonNull Contexts contexts) {
|
||||
return reloadMeta(makeFromMetaContextsConfig(contexts, holder.getPlugin()));
|
||||
public CompletableFuture<MetaCache> reloadMeta(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return reloadMeta(makeFromMetaContextsConfig(contexts, this.holder.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
Set<Contexts> keys = permission.asMap().keySet();
|
||||
Set<Contexts> keys = this.permission.asMap().keySet();
|
||||
keys.forEach(this::recalculatePermissions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateMeta() {
|
||||
Set<MetaContexts> keys = meta.asMap().keySet();
|
||||
Set<MetaContexts> keys = this.meta.asMap().keySet();
|
||||
keys.forEach(this::recalculateMeta);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> reloadPermissions() {
|
||||
Set<Contexts> keys = new HashSet<>(permission.asMap().keySet());
|
||||
Set<Contexts> keys = new HashSet<>(this.permission.asMap().keySet());
|
||||
return CompletableFuture.allOf(keys.stream().map(this::reloadPermissions).toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<Void> reloadMeta() {
|
||||
Set<MetaContexts> keys = new HashSet<>(meta.asMap().keySet());
|
||||
Set<MetaContexts> keys = new HashSet<>(this.meta.asMap().keySet());
|
||||
return CompletableFuture.allOf(keys.stream().map(this::reloadMeta).toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preCalculate(@NonNull Contexts contexts) {
|
||||
public void preCalculate(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
// pre-calculate just by requesting the data from this cache.
|
||||
// if the data isn't already loaded, it will be calculated.
|
||||
getPermissionData(contexts);
|
||||
@@ -229,55 +265,58 @@ public abstract class HolderCachedData<T extends PermissionHolder> implements Ca
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidatePermissions(Contexts contexts) {
|
||||
permission.invalidate(contexts);
|
||||
public void invalidatePermissions(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
this.permission.invalidate(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateMeta(MetaContexts contexts) {
|
||||
meta.invalidate(contexts);
|
||||
public void invalidateMeta(@Nonnull MetaContexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
this.meta.invalidate(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateMeta(Contexts contexts) {
|
||||
meta.invalidate(makeFromMetaContextsConfig(contexts, holder.getPlugin()));
|
||||
public void invalidateMeta(@Nonnull Contexts contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
this.meta.invalidate(makeFromMetaContextsConfig(contexts, this.holder.getPlugin()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidatePermissionCalculators() {
|
||||
permission.asMap().values().forEach(PermissionCache::invalidateCache);
|
||||
this.permission.asMap().values().forEach(PermissionCache::invalidateCache);
|
||||
}
|
||||
|
||||
public void invalidateCaches() {
|
||||
permission.invalidateAll();
|
||||
meta.invalidateAll();
|
||||
this.permission.invalidateAll();
|
||||
this.meta.invalidateAll();
|
||||
}
|
||||
|
||||
public void doCacheCleanup() {
|
||||
permission.cleanUp();
|
||||
meta.cleanUp();
|
||||
this.permission.cleanUp();
|
||||
this.meta.cleanUp();
|
||||
}
|
||||
|
||||
private final class PermissionCacheLoader implements CacheLoader<Contexts, PermissionCache> {
|
||||
@Override
|
||||
public PermissionCache load(Contexts contexts) {
|
||||
public PermissionCache load(@Nonnull Contexts contexts) {
|
||||
return calculatePermissions(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCache reload(Contexts contexts, PermissionCache oldData) {
|
||||
public PermissionCache reload(@Nonnull Contexts contexts, @Nonnull PermissionCache oldData) {
|
||||
return calculatePermissions(contexts, oldData);
|
||||
}
|
||||
}
|
||||
|
||||
private final class MetaCacheLoader implements CacheLoader<MetaContexts, MetaCache> {
|
||||
@Override
|
||||
public MetaCache load(MetaContexts contexts) {
|
||||
public MetaCache load(@Nonnull MetaContexts contexts) {
|
||||
return calculateMeta(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaCache reload(MetaContexts contexts, MetaCache oldData) {
|
||||
public MetaCache reload(@Nonnull MetaContexts contexts, @Nonnull MetaCache oldData) {
|
||||
return calculateMeta(contexts, oldData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ public class UserCachedData extends HolderCachedData<User> implements UserData {
|
||||
|
||||
@Override
|
||||
protected String getHolderName() {
|
||||
return holder.getFriendlyName();
|
||||
return this.holder.getFriendlyName();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -54,7 +54,7 @@ public class CachedStateManager {
|
||||
Set<HolderReference> set = new HashSet<>();
|
||||
set.add(holder);
|
||||
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
while (true) {
|
||||
Set<HolderReference> clone = new HashSet<>(set);
|
||||
@@ -62,7 +62,7 @@ public class CachedStateManager {
|
||||
boolean work = false;
|
||||
|
||||
for (HolderReference s : clone) {
|
||||
if (set.addAll(map.get(s))) {
|
||||
if (set.addAll(this.map.get(s))) {
|
||||
work = true;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class CachedStateManager {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
set.remove(holder);
|
||||
@@ -86,15 +86,15 @@ public class CachedStateManager {
|
||||
* @param inheritedGroups a list of groups the holder inherits from
|
||||
*/
|
||||
public void putAll(HolderReference holder, Set<HolderReference> inheritedGroups) {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
map.entries().removeIf(entry -> entry.getValue().equals(holder));
|
||||
this.map.entries().removeIf(entry -> entry.getValue().equals(holder));
|
||||
|
||||
for (HolderReference child : inheritedGroups) {
|
||||
map.put(child, holder);
|
||||
this.map.put(child, holder);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,11 +104,11 @@ public class CachedStateManager {
|
||||
* @param holder the holder name to clear
|
||||
*/
|
||||
public void clear(HolderReference holder) {
|
||||
lock.lock();
|
||||
this.lock.lock();
|
||||
try {
|
||||
map.entries().removeIf(entry -> entry.getValue().equals(holder));
|
||||
this.map.entries().removeIf(entry -> entry.getValue().equals(holder));
|
||||
} finally {
|
||||
lock.unlock();
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.caching.type;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
|
||||
@@ -43,6 +38,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -50,8 +46,6 @@ import java.util.TreeMap;
|
||||
* Holds temporary mutable meta whilst this object is passed up the
|
||||
* inheritance tree to accumulate meta from parents
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
public class MetaAccumulator {
|
||||
public static MetaAccumulator makeFromConfig(LuckPermsPlugin plugin) {
|
||||
return new MetaAccumulator(
|
||||
@@ -60,7 +54,6 @@ public class MetaAccumulator {
|
||||
);
|
||||
}
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final ListMultimap<String, String> meta;
|
||||
private final SortedMap<Integer, String> prefixes;
|
||||
private final SortedMap<Integer, String> suffixes;
|
||||
@@ -69,7 +62,9 @@ public class MetaAccumulator {
|
||||
private final MetaStack prefixStack;
|
||||
private final MetaStack suffixStack;
|
||||
|
||||
public MetaAccumulator(@NonNull MetaStack prefixStack, @NonNull MetaStack suffixStack) {
|
||||
public MetaAccumulator(MetaStack prefixStack, MetaStack suffixStack) {
|
||||
Objects.requireNonNull(prefixStack, "prefixStack");
|
||||
Objects.requireNonNull(suffixStack, "suffixStack");
|
||||
this.meta = ArrayListMultimap.create();
|
||||
this.prefixes = new TreeMap<>(Comparator.reverseOrder());
|
||||
this.suffixes = new TreeMap<>(Comparator.reverseOrder());
|
||||
@@ -80,19 +75,19 @@ public class MetaAccumulator {
|
||||
public void accumulateNode(LocalizedNode n) {
|
||||
if (n.isMeta()) {
|
||||
Map.Entry<String, String> entry = n.getMeta();
|
||||
meta.put(entry.getKey(), entry.getValue());
|
||||
this.meta.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
if (n.isPrefix()) {
|
||||
Map.Entry<Integer, String> value = n.getPrefix();
|
||||
prefixes.putIfAbsent(value.getKey(), value.getValue());
|
||||
prefixStack.accumulateToAll(n);
|
||||
this.prefixes.putIfAbsent(value.getKey(), value.getValue());
|
||||
this.prefixStack.accumulateToAll(n);
|
||||
}
|
||||
|
||||
if (n.isSuffix()) {
|
||||
Map.Entry<Integer, String> value = n.getSuffix();
|
||||
suffixes.putIfAbsent(value.getKey(), value.getValue());
|
||||
suffixStack.accumulateToAll(n);
|
||||
this.suffixes.putIfAbsent(value.getKey(), value.getValue());
|
||||
this.suffixStack.accumulateToAll(n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,11 +107,41 @@ public class MetaAccumulator {
|
||||
}
|
||||
|
||||
public Map<Integer, String> getChatMeta(ChatMetaType type) {
|
||||
return type == ChatMetaType.PREFIX ? prefixes : suffixes;
|
||||
return type == ChatMetaType.PREFIX ? this.prefixes : this.suffixes;
|
||||
}
|
||||
|
||||
public MetaStack getStack(ChatMetaType type) {
|
||||
return type == ChatMetaType.PREFIX ? prefixStack : suffixStack;
|
||||
return type == ChatMetaType.PREFIX ? this.prefixStack : this.suffixStack;
|
||||
}
|
||||
|
||||
public SortedMap<Integer, String> getPrefixes() {
|
||||
return this.prefixes;
|
||||
}
|
||||
|
||||
public SortedMap<Integer, String> getSuffixes() {
|
||||
return this.suffixes;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return this.weight;
|
||||
}
|
||||
|
||||
public MetaStack getPrefixStack() {
|
||||
return this.prefixStack;
|
||||
}
|
||||
|
||||
public MetaStack getSuffixStack() {
|
||||
return this.suffixStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MetaAccumulator(" +
|
||||
"meta=" + this.getMeta() + ", " +
|
||||
"prefixes=" + this.getPrefixes() + ", " +
|
||||
"suffixes=" + this.getSuffixes() + ", " +
|
||||
"weight=" + this.getWeight() + ", " +
|
||||
"prefixStack=" + this.getPrefixStack() + ", " +
|
||||
"suffixStack=" + this.getSuffixStack() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.caching.type;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
@@ -46,13 +42,12 @@ import java.util.SortedMap;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Holds cached meta for a given context
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class MetaCache implements MetaData {
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
/**
|
||||
@@ -67,8 +62,12 @@ public class MetaCache implements MetaData {
|
||||
private MetaStack prefixStack = null;
|
||||
private MetaStack suffixStack = null;
|
||||
|
||||
public MetaCache(MetaContexts metaContexts) {
|
||||
this.metaContexts = metaContexts;
|
||||
}
|
||||
|
||||
public void loadMeta(MetaAccumulator meta) {
|
||||
lock.writeLock().lock();
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
this.metaMultimap = ImmutableListMultimap.copyOf(meta.getMeta());
|
||||
|
||||
@@ -91,43 +90,76 @@ public class MetaCache implements MetaData {
|
||||
this.prefixStack = meta.getPrefixStack();
|
||||
this.suffixStack = meta.getSuffixStack();
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
return prefixStack == null ? null : prefixStack.toFormattedString();
|
||||
return this.prefixStack == null ? null : this.prefixStack.toFormattedString();
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
lock.readLock().lock();
|
||||
this.lock.readLock().lock();
|
||||
try {
|
||||
return suffixStack == null ? null : suffixStack.toFormattedString();
|
||||
return this.suffixStack == null ? null : this.suffixStack.toFormattedString();
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
this.lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackDefinition getPrefixStackDefinition() {
|
||||
return prefixStack.getDefinition();
|
||||
return this.prefixStack.getDefinition();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaStackDefinition getSuffixStackDefinition() {
|
||||
return suffixStack.getDefinition();
|
||||
return this.suffixStack.getDefinition();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getContexts() {
|
||||
return metaContexts.getContexts();
|
||||
return this.metaContexts.getContexts();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MetaContexts getMetaContexts() {
|
||||
return this.metaContexts;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ListMultimap<String, String> getMetaMultimap() {
|
||||
return this.metaMultimap;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, String> getMeta() {
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, String> getPrefixes() {
|
||||
return this.prefixes;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SortedMap<Integer, String> getSuffixes() {
|
||||
return this.suffixes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.caching.type;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.caching.PermissionData;
|
||||
@@ -40,6 +37,8 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Holds cached permissions data for a given context
|
||||
*/
|
||||
@@ -48,7 +47,6 @@ public class PermissionCache implements PermissionData {
|
||||
/**
|
||||
* The contexts this container is holding data for
|
||||
*/
|
||||
@Getter
|
||||
private final Contexts contexts;
|
||||
|
||||
/**
|
||||
@@ -70,42 +68,56 @@ public class PermissionCache implements PermissionData {
|
||||
|
||||
public PermissionCache(Contexts contexts, PermissionCalculatorMetadata metadata, CalculatorFactory calculatorFactory) {
|
||||
this.contexts = contexts;
|
||||
permissions = new ConcurrentHashMap<>();
|
||||
permissionsUnmodifiable = Collections.unmodifiableMap(permissions);
|
||||
this.permissions = new ConcurrentHashMap<>();
|
||||
this.permissionsUnmodifiable = Collections.unmodifiableMap(this.permissions);
|
||||
|
||||
calculator = calculatorFactory.build(contexts, metadata);
|
||||
calculator.updateBacking(permissions); // Initial setup.
|
||||
this.calculator = calculatorFactory.build(contexts, metadata);
|
||||
this.calculator.updateBacking(this.permissions); // Initial setup.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache() {
|
||||
calculator.invalidateCache();
|
||||
this.calculator.invalidateCache();
|
||||
}
|
||||
|
||||
private void setPermissionsInternal(Map<String, Boolean> permissions) {
|
||||
this.permissions.clear();
|
||||
this.permissions.putAll(permissions);
|
||||
calculator.updateBacking(this.permissions);
|
||||
this.calculator.updateBacking(this.permissions);
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
public void setPermissions(Map<String, Boolean> toApply) {
|
||||
if (!permissions.equals(toApply)) {
|
||||
if (!this.permissions.equals(toApply)) {
|
||||
setPermissionsInternal(toApply);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, Boolean> getImmutableBacking() {
|
||||
return permissionsUnmodifiable;
|
||||
return this.permissionsUnmodifiable;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull String permission) {
|
||||
return calculator.getPermissionValue(permission, CheckOrigin.API);
|
||||
public Tristate getPermissionValue(@Nonnull String permission) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
return this.calculator.getPermissionValue(permission, CheckOrigin.API);
|
||||
}
|
||||
|
||||
public Tristate getPermissionValue(@NonNull String permission, CheckOrigin origin) {
|
||||
return calculator.getPermissionValue(permission, origin);
|
||||
public Tristate getPermissionValue(String permission, CheckOrigin origin) {
|
||||
if (permission == null) {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
return this.calculator.getPermissionValue(permission, origin);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts getContexts() {
|
||||
return this.contexts;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,13 +34,13 @@ public abstract class AbstractCalculatorFactory implements CalculatorFactory {
|
||||
private final Set<PermissionCalculator> calculators = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
||||
|
||||
protected PermissionCalculator registerCalculator(PermissionCalculator calculator) {
|
||||
calculators.add(calculator);
|
||||
this.calculators.add(calculator);
|
||||
return calculator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateAll() {
|
||||
for (PermissionCalculator calculator : calculators) {
|
||||
for (PermissionCalculator calculator : this.calculators) {
|
||||
calculator.invalidateCache();
|
||||
}
|
||||
}
|
||||
|
||||
+15
-10
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.calculators;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
@@ -39,10 +37,11 @@ import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Calculates and caches permissions
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionCalculator implements CacheLoader<String, Tristate> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final PermissionCalculatorMetadata metadata;
|
||||
@@ -51,8 +50,14 @@ public class PermissionCalculator implements CacheLoader<String, Tristate> {
|
||||
// caches lookup calls.
|
||||
private final LoadingCache<String, Tristate> lookupCache = Caffeine.newBuilder().build(this);
|
||||
|
||||
public PermissionCalculator(LuckPermsPlugin plugin, PermissionCalculatorMetadata metadata, List<PermissionProcessor> processors) {
|
||||
this.plugin = plugin;
|
||||
this.metadata = metadata;
|
||||
this.processors = processors;
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
lookupCache.invalidateAll();
|
||||
this.lookupCache.invalidateAll();
|
||||
}
|
||||
|
||||
public Tristate getPermissionValue(String permission, CheckOrigin origin) {
|
||||
@@ -62,24 +67,24 @@ public class PermissionCalculator implements CacheLoader<String, Tristate> {
|
||||
permission = permission.toLowerCase().intern();
|
||||
|
||||
// get the result
|
||||
Tristate result = lookupCache.get(permission);
|
||||
Tristate result = this.lookupCache.get(permission);
|
||||
|
||||
// log this permission lookup to the verbose handler
|
||||
plugin.getVerboseHandler().offerCheckData(origin, metadata.getObjectName(), metadata.getContext(), permission, result);
|
||||
this.plugin.getVerboseHandler().offerCheckData(origin, this.metadata.getObjectName(), this.metadata.getContext(), permission, result);
|
||||
|
||||
// return the result
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate load(String permission) {
|
||||
public Tristate load(@Nonnull String permission) {
|
||||
|
||||
// offer the permission to the permission vault
|
||||
// we only need to do this once per permission, so it doesn't matter
|
||||
// that this call is behind the cache.
|
||||
plugin.getPermissionVault().offer(permission);
|
||||
this.plugin.getPermissionVault().offer(permission);
|
||||
|
||||
for (PermissionProcessor processor : processors) {
|
||||
for (PermissionProcessor processor : this.processors) {
|
||||
Tristate result = processor.hasPermission(permission);
|
||||
if (result == Tristate.UNDEFINED) {
|
||||
continue;
|
||||
@@ -92,7 +97,7 @@ public class PermissionCalculator implements CacheLoader<String, Tristate> {
|
||||
}
|
||||
|
||||
public synchronized void updateBacking(Map<String, Boolean> map) {
|
||||
for (PermissionProcessor processor : processors) {
|
||||
for (PermissionProcessor processor : this.processors) {
|
||||
processor.updateBacking(map);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-5
@@ -25,16 +25,15 @@
|
||||
|
||||
package me.lucko.luckperms.common.calculators;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.references.HolderType;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class PermissionCalculatorMetadata {
|
||||
|
||||
public static PermissionCalculatorMetadata of(HolderType holderType, String objectName, ContextSet context) {
|
||||
return new PermissionCalculatorMetadata(holderType, objectName, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the object which owns the permission calculator
|
||||
*/
|
||||
@@ -50,4 +49,21 @@ public class PermissionCalculatorMetadata {
|
||||
*/
|
||||
private final ContextSet context;
|
||||
|
||||
private PermissionCalculatorMetadata(HolderType holderType, String objectName, ContextSet context) {
|
||||
this.holderType = holderType;
|
||||
this.objectName = objectName;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public HolderType getHolderType() {
|
||||
return this.holderType;
|
||||
}
|
||||
|
||||
public String getObjectName() {
|
||||
return this.objectName;
|
||||
}
|
||||
|
||||
public ContextSet getContext() {
|
||||
return this.context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class Arg {
|
||||
public static Arg create(String name, boolean required, String description) {
|
||||
return new Arg(name, required, description);
|
||||
@@ -46,8 +40,25 @@ public class Arg {
|
||||
private final boolean required;
|
||||
private final String description;
|
||||
|
||||
public String asPrettyString() {
|
||||
return required ? "&8<&7" + name + "&8>" : "&8[&7" + name + "&8]";
|
||||
private Arg(String name, boolean required, String description) {
|
||||
this.name = name;
|
||||
this.required = required;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String asPrettyString() {
|
||||
return this.required ? "&8<&7" + this.name + "&8>" : "&8[&7" + this.name + "&8]";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
@@ -40,8 +38,7 @@ import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class ArgumentPermissions {
|
||||
public final class ArgumentPermissions {
|
||||
private static final String USER_MODIFY_SELF = CommandPermission.ROOT + "modify.user.self";
|
||||
private static final String USER_MODIFY_OTHERS = CommandPermission.ROOT + "modify.user.others";
|
||||
private static final Function<String, String> GROUP_MODIFY = s -> CommandPermission.ROOT + "modify.group." + s;
|
||||
@@ -217,5 +214,7 @@ public class ArgumentPermissions {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private ArgumentPermissions() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.commands.abstraction.Command;
|
||||
@@ -90,13 +88,11 @@ public class CommandManager {
|
||||
public static final char SECTION_CHAR = '\u00A7'; // §
|
||||
public static final char AMPERSAND_CHAR = '&';
|
||||
|
||||
@Getter
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
// the default executor to run commands on
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Getter
|
||||
private final List<Command> mainCommands;
|
||||
|
||||
public CommandManager(LuckPermsPlugin plugin) {
|
||||
@@ -104,7 +100,7 @@ public class CommandManager {
|
||||
|
||||
LocaleManager locale = plugin.getLocaleManager();
|
||||
|
||||
mainCommands = ImmutableList.<Command>builder()
|
||||
this.mainCommands = ImmutableList.<Command>builder()
|
||||
.add(new UserMainCommand(locale))
|
||||
.add(new GroupMainCommand(locale))
|
||||
.add(new TrackMainCommand(locale))
|
||||
@@ -132,8 +128,12 @@ public class CommandManager {
|
||||
.build();
|
||||
}
|
||||
|
||||
public LuckPermsPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) {
|
||||
return onCommand(sender, label, args, executor);
|
||||
return onCommand(sender, label, args, this.executor);
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args, Executor executor) {
|
||||
@@ -141,7 +141,7 @@ public class CommandManager {
|
||||
try {
|
||||
return execute(sender, label, args);
|
||||
} catch (Throwable e) {
|
||||
plugin.getLog().severe("Exception whilst executing command: " + args.toString());
|
||||
this.plugin.getLog().severe("Exception whilst executing command: " + args.toString());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -154,9 +154,9 @@ public class CommandManager {
|
||||
handleRewrites(arguments, true);
|
||||
|
||||
// Handle no arguments
|
||||
if (arguments.size() == 0 || (arguments.size() == 1 && arguments.get(0).trim().isEmpty())) {
|
||||
CommandUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2.");
|
||||
if (mainCommands.stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender))) {
|
||||
if (arguments.isEmpty() || (arguments.size() == 1 && arguments.get(0).trim().isEmpty())) {
|
||||
CommandUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getVersion() + "&2.");
|
||||
if (this.mainCommands.stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender))) {
|
||||
Message.VIEW_AVAILABLE_COMMANDS_PROMPT.send(sender, label);
|
||||
} else {
|
||||
Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender);
|
||||
@@ -165,7 +165,7 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
// Look for the main command.
|
||||
Optional<Command> o = mainCommands.stream()
|
||||
Optional<Command> o = this.mainCommands.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(arguments.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
@@ -194,7 +194,7 @@ public class CommandManager {
|
||||
// Try to execute the command.
|
||||
CommandResult result;
|
||||
try {
|
||||
result = main.execute(plugin, sender, null, arguments, label);
|
||||
result = main.execute(this.plugin, sender, null, arguments, label);
|
||||
} catch (CommandException e) {
|
||||
result = handleException(e, sender, label, main);
|
||||
} catch (Throwable e) {
|
||||
@@ -219,7 +219,7 @@ public class CommandManager {
|
||||
// we rewrite tab completions too!
|
||||
handleRewrites(arguments, false);
|
||||
|
||||
final List<Command> mains = mainCommands.stream()
|
||||
final List<Command> mains = this.mainCommands.stream()
|
||||
.filter(Command::shouldDisplay)
|
||||
.filter(m -> m.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
@@ -249,12 +249,12 @@ public class CommandManager {
|
||||
arguments.remove(0); // remove the main command arg.
|
||||
|
||||
// Pass the processing onto the main command
|
||||
return o.map(cmd -> cmd.tabComplete(plugin, sender, arguments)).orElseGet(Collections::emptyList);
|
||||
return o.map(cmd -> cmd.tabComplete(this.plugin, sender, arguments)).orElseGet(Collections::emptyList);
|
||||
}
|
||||
|
||||
private void sendCommandUsage(Sender sender, String label) {
|
||||
CommandUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2.");
|
||||
mainCommands.stream()
|
||||
CommandUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getVersion() + "&2.");
|
||||
this.mainCommands.stream()
|
||||
.filter(Command::shouldDisplay)
|
||||
.filter(c -> c.isAuthorized(sender))
|
||||
.forEach(c -> {
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
|
||||
import static me.lucko.luckperms.common.commands.CommandPermission.Type.GROUP;
|
||||
@@ -173,7 +170,6 @@ public enum CommandPermission {
|
||||
|
||||
private final String node;
|
||||
|
||||
@Getter
|
||||
private final Type type;
|
||||
|
||||
CommandPermission(String node, Type type) {
|
||||
@@ -187,15 +183,17 @@ public enum CommandPermission {
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return node;
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return sender.hasPermission(this);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
|
||||
NONE(null),
|
||||
@@ -207,6 +205,13 @@ public enum CommandPermission {
|
||||
|
||||
private final String tag;
|
||||
|
||||
Type(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum CommandResult {
|
||||
SUCCESS(true),
|
||||
FAILURE(false),
|
||||
@@ -41,10 +38,14 @@ public enum CommandResult {
|
||||
return b ? SUCCESS : FAILURE;
|
||||
}
|
||||
|
||||
private boolean value;
|
||||
private final boolean value;
|
||||
|
||||
CommandResult(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.abstraction;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
@@ -50,13 +48,11 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public abstract class Command<T, S> {
|
||||
|
||||
@Getter
|
||||
private final LocalizedSpec spec;
|
||||
|
||||
/**
|
||||
* The name of the command. Should be properly capitalised.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
@@ -67,7 +63,6 @@ public abstract class Command<T, S> {
|
||||
/**
|
||||
* A predicate used for testing the size of the arguments list passed to this command
|
||||
*/
|
||||
@Getter
|
||||
private final Predicate<Integer> argumentCheck;
|
||||
|
||||
/**
|
||||
@@ -97,6 +92,18 @@ public abstract class Command<T, S> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public LocalizedSpec getSpec() {
|
||||
return this.spec;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Predicate<Integer> getArgumentCheck() {
|
||||
return this.argumentCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a brief command usage message to the Sender.
|
||||
* If this command has child commands, the children are listed. Otherwise, a basic usage message is sent.
|
||||
@@ -126,7 +133,7 @@ public abstract class Command<T, S> {
|
||||
* @return true if the sender has permission to use this command
|
||||
*/
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return permission == null || permission.isAuthorized(sender);
|
||||
return this.permission == null || this.permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +146,7 @@ public abstract class Command<T, S> {
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return spec.description();
|
||||
return this.spec.description();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,20 +155,19 @@ public abstract class Command<T, S> {
|
||||
* @return the usage of this command.
|
||||
*/
|
||||
public String getUsage() {
|
||||
String usage = spec.usage();
|
||||
String usage = this.spec.usage();
|
||||
return usage == null ? "" : usage;
|
||||
}
|
||||
|
||||
public Optional<CommandPermission> getPermission() {
|
||||
return Optional.ofNullable(permission);
|
||||
return Optional.ofNullable(this.permission);
|
||||
}
|
||||
|
||||
public Optional<List<Arg>> getArgs() {
|
||||
return Optional.ofNullable(spec.args());
|
||||
return Optional.ofNullable(this.spec.args());
|
||||
}
|
||||
|
||||
public Optional<List<Command<S, ?>>> getChildren() {
|
||||
return Optional.ofNullable(children);
|
||||
return Optional.ofNullable(this.children);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -54,14 +54,14 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) throws CommandException {
|
||||
if (args.size() < minArgs) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
|
||||
if (args.size() < this.minArgs) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<Command<T, ?>> o = getChildren().get().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(minArgs - 1)))
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(this.minArgs - 1)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
@@ -77,8 +77,8 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > minArgs) {
|
||||
strippedArgs.addAll(args.subList(minArgs, args.size()));
|
||||
if (args.size() > this.minArgs) {
|
||||
strippedArgs.addAll(args.subList(this.minArgs, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getArgumentCheck().test(strippedArgs.size())) {
|
||||
@@ -169,7 +169,7 @@ public abstract class MainCommand<T, I> extends Command<Void, T> {
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (subs.size() > 0) {
|
||||
if (!subs.isEmpty()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format(getUsage(), label) + " ...)");
|
||||
|
||||
for (Command s : subs) {
|
||||
|
||||
+11
-11
@@ -63,13 +63,13 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) throws CommandException {
|
||||
if (args.size() == 0) {
|
||||
sendUsageDetailed(sender, user, label);
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageDetailed(sender, this.user, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<SharedSubCommand> o = secondaryCommands.stream()
|
||||
Optional<SharedSubCommand> o = this.secondaryCommands.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
@@ -80,7 +80,7 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
||||
}
|
||||
|
||||
final SharedSubCommand sub = o.get();
|
||||
if (!sub.isAuthorized(sender, user)) {
|
||||
if (!sub.isAuthorized(sender, this.user)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
||||
|
||||
CommandResult result;
|
||||
try {
|
||||
result = sub.execute(plugin, sender, t, strippedArgs, label, user ? sub.getUserPermission() : sub.getGroupPermission());
|
||||
result = sub.execute(plugin, sender, t, strippedArgs, label, this.user ? sub.getUserPermission() : sub.getGroupPermission());
|
||||
} catch (CommandException e) {
|
||||
result = handleException(e, sender, sub);
|
||||
}
|
||||
@@ -106,8 +106,8 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
final List<SharedSubCommand> subs = secondaryCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, user))
|
||||
final List<SharedSubCommand> subs = this.secondaryCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, this.user))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
@@ -134,15 +134,15 @@ public class SharedMainCommand<T extends PermissionHolder> extends SubCommand<T>
|
||||
|
||||
@Override
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return secondaryCommands.stream().anyMatch(sc -> sc.isAuthorized(sender, user));
|
||||
return this.secondaryCommands.stream().anyMatch(sc -> sc.isAuthorized(sender, this.user));
|
||||
}
|
||||
|
||||
private void sendUsageDetailed(Sender sender, boolean user, String label) {
|
||||
List<SharedSubCommand> subs = secondaryCommands.stream()
|
||||
List<SharedSubCommand> subs = this.secondaryCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, user))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (subs.size() > 0) {
|
||||
if (!subs.isEmpty()) {
|
||||
if (user) {
|
||||
CommandUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s user <user> " + getName().toLowerCase() + " ...)", label));
|
||||
} else {
|
||||
|
||||
+23
-6
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.abstraction;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
@@ -47,7 +45,6 @@ import java.util.function.Predicate;
|
||||
* A sub command which can be be applied to both groups and users.
|
||||
* This doesn't extend the other Command or SubCommand classes to avoid generics hell.
|
||||
*/
|
||||
@Getter
|
||||
public abstract class SharedSubCommand {
|
||||
|
||||
private final LocalizedSpec spec;
|
||||
@@ -82,6 +79,26 @@ public abstract class SharedSubCommand {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public LocalizedSpec getSpec() {
|
||||
return this.spec;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public CommandPermission getUserPermission() {
|
||||
return this.userPermission;
|
||||
}
|
||||
|
||||
public CommandPermission getGroupPermission() {
|
||||
return this.groupPermission;
|
||||
}
|
||||
|
||||
public Predicate<? super Integer> getArgumentCheck() {
|
||||
return this.argumentCheck;
|
||||
}
|
||||
|
||||
public void sendUsage(Sender sender) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (getArgs() != null) {
|
||||
@@ -106,15 +123,15 @@ public abstract class SharedSubCommand {
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender, boolean user) {
|
||||
return user ? userPermission.isAuthorized(sender) : groupPermission.isAuthorized(sender);
|
||||
return user ? this.userPermission.isAuthorized(sender) : this.groupPermission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return spec.description();
|
||||
return this.spec.description();
|
||||
}
|
||||
|
||||
public List<Arg> getArgs() {
|
||||
return spec.args();
|
||||
return this.spec.args();
|
||||
}
|
||||
|
||||
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.abstraction;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
@@ -56,7 +54,6 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* Abstract SubCommand class
|
||||
*/
|
||||
@Getter
|
||||
public abstract class SubCommand<T> extends Command<T, Void> {
|
||||
|
||||
public SubCommand(LocalizedSpec spec, String name, CommandPermission permission, Predicate<Integer> argumentCheck) {
|
||||
|
||||
+5
-5
@@ -82,24 +82,24 @@ public class MetaAddChatMeta extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
||||
DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
|
||||
if (result.asBoolean()) {
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
|
||||
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
|
||||
'¥'
|
||||
));
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "add" + type.name().toLowerCase(), priority, meta, context)
|
||||
.action("meta" , "add" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -89,27 +89,27 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
Map.Entry<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.buildChatMetaNode(type, priority, meta).setExpiry(duration).withExtraContext(context).build(), modifier);
|
||||
Map.Entry<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(duration).withExtraContext(context).build(), modifier);
|
||||
|
||||
if (ret.getKey().asBoolean()) {
|
||||
duration = ret.getValue().getExpiryUnixTime();
|
||||
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
|
||||
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
|
||||
'¥'
|
||||
));
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "addtemp" + type.name().toLowerCase(), priority, meta, duration, context)
|
||||
.action("meta" , "addtemp" + this.type.name().toLowerCase(), priority, meta, duration, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class MetaClear extends SharedSubCommand {
|
||||
}
|
||||
|
||||
MetaType type = null;
|
||||
if (args.size() > 0) {
|
||||
if (!args.isEmpty()) {
|
||||
String typeId = args.get(0).toLowerCase();
|
||||
if (typeId.equals("any") || typeId.equals("all") || typeId.equals("*")) {
|
||||
type = MetaType.ANY;
|
||||
|
||||
+1
-2
@@ -30,7 +30,6 @@ import com.google.common.collect.Maps;
|
||||
import me.lucko.luckperms.api.ChatMetaType;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@@ -71,7 +70,7 @@ public class MetaInfo extends SharedSubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+9
-9
@@ -85,40 +85,40 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(n ->
|
||||
type.matches(n) &&
|
||||
type.getEntry(n).getKey() == priority &&
|
||||
this.type.matches(n) &&
|
||||
this.type.getEntry(n).getKey() == priority &&
|
||||
!n.isTemporary() &&
|
||||
n.getFullContexts().makeImmutable().equals(context.makeImmutable())
|
||||
);
|
||||
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), priority, CommandUtils.contextSetToString(context));
|
||||
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, CommandUtils.contextSetToString(context));
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "remove" + type.name().toLowerCase(), priority, "*", context)
|
||||
.action("meta" , "remove" + this.type.name().toLowerCase(), priority, "*", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(type, priority, meta).withExtraContext(context).build());
|
||||
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
|
||||
|
||||
if (result.asBoolean()) {
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
|
||||
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
|
||||
'¥'
|
||||
));
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "remove" + type.name().toLowerCase(), priority, meta, context)
|
||||
.action("meta" , "remove" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
Message.DOES_NOT_HAVE_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -85,40 +85,40 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
// Handle bulk removal
|
||||
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
|
||||
holder.removeIf(n ->
|
||||
type.matches(n) &&
|
||||
type.getEntry(n).getKey() == priority &&
|
||||
this.type.matches(n) &&
|
||||
this.type.getEntry(n).getKey() == priority &&
|
||||
!n.isPermanent() &&
|
||||
n.getFullContexts().makeImmutable().equals(context.makeImmutable())
|
||||
);
|
||||
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), priority, CommandUtils.contextSetToString(context));
|
||||
Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, CommandUtils.contextSetToString(context));
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "removetemp" + type.name().toLowerCase(), priority, "*", context)
|
||||
.action("meta" , "removetemp" + this.type.name().toLowerCase(), priority, "*", context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(type, priority, meta).setExpiry(10L).withExtraContext(context).build());
|
||||
DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(10L).withExtraContext(context).build());
|
||||
|
||||
if (result.asBoolean()) {
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
|
||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(
|
||||
"¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta,
|
||||
"¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta,
|
||||
'¥'
|
||||
));
|
||||
builder.applyDeep(c -> c.hoverEvent(event));
|
||||
sender.sendMessage(builder.build());
|
||||
|
||||
ExtendedLogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta" , "removetemp" + type.name().toLowerCase(), priority, meta, context)
|
||||
.action("meta" , "removetemp" + this.type.name().toLowerCase(), priority, meta, context)
|
||||
.build().submit(plugin, sender);
|
||||
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context));
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -31,7 +31,6 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -61,7 +60,7 @@ public class HolderEditor<T extends PermissionHolder> extends SubCommand<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -55,7 +54,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-2
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.commands.impl.generic.parent;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@@ -67,7 +66,7 @@ public class ParentInfo extends SharedSubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ public class ParentSetTrack extends SharedSubCommand {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (args.size() == 0 || args.size() == 1) {
|
||||
if (args.isEmpty() || args.size() == 1) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.commands.impl.generic.permission;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@@ -67,7 +66,7 @@ public class PermissionInfo extends SharedSubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CreateGroup extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DeleteGroup extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.commands.impl.group;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -49,7 +48,7 @@ public class GroupClone extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.group;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -51,7 +50,7 @@ public class GroupInfo extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-2
@@ -32,7 +32,6 @@ import com.google.common.collect.Maps;
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@@ -70,7 +69,7 @@ public class GroupListMembers extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class GroupMainCommand extends MainCommand<Group, String> {
|
||||
|
||||
@Override
|
||||
protected ReentrantLock getLockForTarget(String target) {
|
||||
return locks.get(target);
|
||||
return this.locks.get(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.common.commands.impl.group;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.api.event.cause.DeletionCause;
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -49,7 +48,7 @@ public class GroupRename extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String newGroupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender, newGroupName);
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.group;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -49,7 +48,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), group)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -52,7 +51,7 @@ public class LogGroupHistory extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String group = args.get(0).toLowerCase();
|
||||
int page = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class LogMainCommand extends MainCommand<Log, Object> {
|
||||
|
||||
@Override
|
||||
protected ReentrantLock getLockForTarget(Object target) {
|
||||
return lock; // all commands target the same log, so we share a lock between all "targets"
|
||||
return this.lock; // all commands target the same log, so we share a lock between all "targets"
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -82,14 +81,14 @@ public class LogNotify extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
if (sender.isConsole() || sender.isImport()) {
|
||||
Message.LOG_NOTIFY_CONSOLE.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
final UUID uuid = sender.getUuid();
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
if (isIgnoring(plugin, uuid)) {
|
||||
// toggle on
|
||||
setIgnoring(plugin, uuid, false);
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -55,8 +54,8 @@ public class LogRecent extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
if (args.size() == 0) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
if (args.isEmpty()) {
|
||||
// No page or user
|
||||
return showLog(log.getRecentMaxPages(ENTRIES_PER_PAGE), null, sender, log);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -52,7 +51,7 @@ public class LogSearch extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
int page = Integer.MIN_VALUE;
|
||||
if (args.size() > 1) {
|
||||
try {
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -52,7 +51,7 @@ public class LogTrackHistory extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String track = args.get(0).toLowerCase();
|
||||
int page = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
+1
-2
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.log;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.actionlog.Log;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -55,7 +54,7 @@ public class LogUserHistory extends SubCommand<Log> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Log log, List<String> args, String label) {
|
||||
String target = args.get(0);
|
||||
int page = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
+9
-10
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.migration;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.Command;
|
||||
@@ -72,22 +71,22 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
|
||||
@Override
|
||||
public synchronized Optional<List<Command<Object, ?>>> getChildren() {
|
||||
if (commands == null) {
|
||||
commands = getAvailableCommands(getSpec().getLocaleManager());
|
||||
if (this.commands == null) {
|
||||
this.commands = getAvailableCommands(getSpec().getLocaleManager());
|
||||
|
||||
// Add dummy command to show in the list.
|
||||
if (commands.isEmpty()) {
|
||||
display = false;
|
||||
commands.add(new SubCommand<Object>(CommandSpec.MIGRATION_COMMAND.spec(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
|
||||
if (this.commands.isEmpty()) {
|
||||
this.display = false;
|
||||
this.commands.add(new SubCommand<Object>(CommandSpec.MIGRATION_COMMAND.spec(getSpec().getLocaleManager()), "No available plugins to migrate from", CommandPermission.MIGRATION, Predicates.alwaysFalse()) {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.of(commands);
|
||||
return Optional.of(this.commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +97,7 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
@Override
|
||||
public boolean shouldDisplay() {
|
||||
getChildren();
|
||||
return display;
|
||||
return this.display;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -117,7 +116,7 @@ public class MigrationMainCommand extends MainCommand<Object, Object> {
|
||||
|
||||
@Override
|
||||
protected ReentrantLock getLockForTarget(Object target) {
|
||||
return lock; // share a lock between all migration commands
|
||||
return this.lock; // share a lock between all migration commands
|
||||
}
|
||||
|
||||
/* Dummy */
|
||||
|
||||
+3
-4
@@ -25,14 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.migration;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
|
||||
@UtilityClass
|
||||
public class MigrationUtils {
|
||||
public final class MigrationUtils {
|
||||
|
||||
public static Node.Builder parseNode(String permission, boolean value) {
|
||||
if (permission.startsWith("-") || permission.startsWith("!")) {
|
||||
@@ -63,4 +60,6 @@ public class MigrationUtils {
|
||||
return string.trim().replace(':', '-').replace(' ', '-').replace('.', '-').toLowerCase();
|
||||
}
|
||||
|
||||
private MigrationUtils() {}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -31,7 +31,6 @@ import com.google.gson.JsonObject;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.ArgumentPermissions;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
|
||||
@@ -60,7 +59,7 @@ public class ApplyEditsCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
String code = args.get(0);
|
||||
String who = args.size() == 2 ? args.get(1) : null;
|
||||
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ public class BulkUpdateCommand extends SingleCommand {
|
||||
if (args.size() == 2 && args.get(0).equalsIgnoreCase("confirm")) {
|
||||
|
||||
String id = args.get(1);
|
||||
BulkUpdate operation = pendingOperations.asMap().remove(id);
|
||||
BulkUpdate operation = this.pendingOperations.asMap().remove(id);
|
||||
|
||||
if (operation == null) {
|
||||
Message.BULK_UPDATE_UNKNOWN_ID.send(sender, id);
|
||||
@@ -147,7 +147,7 @@ public class BulkUpdateCommand extends SingleCommand {
|
||||
|
||||
BulkUpdate bulkUpdate = bulkUpdateBuilder.build();
|
||||
|
||||
pendingOperations.put(id, bulkUpdate);
|
||||
this.pendingOperations.put(id, bulkUpdate);
|
||||
|
||||
Message.BULK_UPDATE_QUEUED.send(sender, bulkUpdate.buildAsSql().replace("{table}", bulkUpdate.getDataType().getName()));
|
||||
Message.BULK_UPDATE_CONFIRM.send(sender, label, id);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.common.commands.impl.misc;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||
@@ -51,7 +50,7 @@ public class CheckCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
String target = args.get(0);
|
||||
String permission = args.get(1);
|
||||
|
||||
|
||||
+3
-3
@@ -52,7 +52,7 @@ public class ExportCommand extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (running.get()) {
|
||||
if (this.running.get()) {
|
||||
Message.EXPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class ExportCommand extends SingleCommand {
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
if (!running.compareAndSet(false, true)) {
|
||||
if (!this.running.compareAndSet(false, true)) {
|
||||
Message.EXPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class ExportCommand extends SingleCommand {
|
||||
try {
|
||||
exporter.run();
|
||||
} finally {
|
||||
running.set(false);
|
||||
this.running.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -53,7 +53,7 @@ public class ImportCommand extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (running.get()) {
|
||||
if (this.running.get()) {
|
||||
Message.IMPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class ImportCommand extends SingleCommand {
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
if (!running.compareAndSet(false, true)) {
|
||||
if (!this.running.compareAndSet(false, true)) {
|
||||
Message.IMPORT_ALREADY_RUNNING.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class ImportCommand extends SingleCommand {
|
||||
try {
|
||||
importer.run();
|
||||
} finally {
|
||||
running.set(false);
|
||||
this.running.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.misc;
|
||||
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||
@@ -44,7 +43,7 @@ public class ReloadConfigCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
plugin.getConfiguration().reload();
|
||||
Message.RELOAD_CONFIG_SUCCESS.send(sender);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
+1
-2
@@ -31,7 +31,6 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@@ -69,7 +68,7 @@ public class SearchCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
String query = args.get(0);
|
||||
int page = ArgumentUtils.handleIntOrElse(1, args, 1);
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.common.commands.impl.misc;
|
||||
|
||||
import me.lucko.luckperms.common.caching.type.PermissionCache;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||
@@ -57,12 +56,12 @@ public class TreeCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
String selection = ".";
|
||||
int maxLevel = 5;
|
||||
String player = null;
|
||||
|
||||
if (args.size() > 0) {
|
||||
if (!args.isEmpty()) {
|
||||
selection = args.get(0);
|
||||
}
|
||||
if (args.size() > 1) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CreateTrack extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DeleteTrack extends SingleCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsage(sender, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.track;
|
||||
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -50,7 +49,7 @@ public class TrackAppend extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
sendDetailedUsage(sender, label);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.common.commands.impl.track;
|
||||
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -46,7 +45,7 @@ public class TrackClear extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
track.clearGroups();
|
||||
Message.TRACK_CLEAR.send(sender, track.getName());
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.commands.impl.track;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -48,7 +47,7 @@ public class TrackClone extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String newTrackName = args.get(0).toLowerCase();
|
||||
if (!DataConstraints.TRACK_NAME_TEST.test(newTrackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender, newTrackName);
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.impl.track;
|
||||
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -46,7 +45,7 @@ public class TrackInfo extends SubCommand<Track> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
Message.TRACK_INFO.send(sender, track.getName(), CommandUtils.listToArrowSep(track.getGroups()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user