remove some unnecessary interfaces
This commit is contained in:
parent
8b181b877b
commit
e4acc133a9
@ -53,13 +53,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||
import me.lucko.luckperms.common.listener.ConnectionListener;
|
||||
import me.lucko.luckperms.common.managers.group.StandardGroupManager;
|
||||
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.managers.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
@ -350,7 +350,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionListener getConnectionListener() {
|
||||
public AbstractConnectionListener getConnectionListener() {
|
||||
return this.connectionListener;
|
||||
}
|
||||
|
||||
|
@ -30,13 +30,13 @@ import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class BukkitContextManager extends AbstractContextManager<Player> {
|
||||
public class BukkitContextManager extends ContextManager<Player> {
|
||||
public BukkitContextManager(LPBukkitPlugin plugin) {
|
||||
super(plugin, Player.class);
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.PermissibleInjector;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.listener.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
import me.lucko.luckperms.common.utils.Uuids;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -38,7 +38,6 @@ import me.lucko.luckperms.common.command.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@ -48,6 +47,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.model.UserIdentifier;
|
||||
@ -44,6 +43,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
import me.lucko.luckperms.common.utils.Uuids;
|
||||
|
||||
import org.anjocaido.groupmanager.GlobalGroups;
|
||||
|
@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@ -43,6 +42,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.model.Track;
|
||||
@ -45,6 +44,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
@ -41,7 +41,6 @@ import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||
@ -50,6 +49,7 @@ import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.StorageType;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
@ -34,7 +34,6 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.model.Track;
|
||||
@ -45,6 +44,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.bungee;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
@ -41,13 +41,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||
import me.lucko.luckperms.common.listener.ConnectionListener;
|
||||
import me.lucko.luckperms.common.managers.group.StandardGroupManager;
|
||||
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.managers.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
@ -209,7 +209,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionListener getConnectionListener() {
|
||||
public AbstractConnectionListener getConnectionListener() {
|
||||
return this.connectionListener;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,11 @@ package me.lucko.luckperms.bungee.contexts;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class BungeeContextManager extends AbstractContextManager<ProxiedPlayer> {
|
||||
public class BungeeContextManager extends ContextManager<ProxiedPlayer> {
|
||||
public BungeeContextManager(LPBungeePlugin plugin) {
|
||||
super(plugin, ProxiedPlayer.class);
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ package me.lucko.luckperms.bungee.listeners;
|
||||
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.listener.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
|
@ -32,13 +32,13 @@ import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import net.alpenblock.bungeeperms.BungeePerms;
|
||||
import net.alpenblock.bungeeperms.Group;
|
||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.common.backup;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.HolderType;
|
||||
import me.lucko.luckperms.common.model.Track;
|
||||
@ -36,6 +35,7 @@ import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.buffers;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -1,238 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.contexts;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
import me.lucko.luckperms.common.buffers.ExpiringCache;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link ContextManager} which caches content lookups.
|
||||
*
|
||||
* @param <T> the calculator type
|
||||
*/
|
||||
public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
|
||||
protected final LuckPermsPlugin plugin;
|
||||
private final Class<T> subjectClass;
|
||||
|
||||
private final List<ContextCalculator<? super T>> calculators = new CopyOnWriteArrayList<>();
|
||||
private final List<StaticContextCalculator> staticCalculators = new CopyOnWriteArrayList<>();
|
||||
|
||||
// caches the creation of cache instances. cache-ception.
|
||||
// we want to encourage re-use of these instances, it's faster that way
|
||||
private final LoadingCache<T, ContextsCache<T>> subjectCaches = Caffeine.newBuilder()
|
||||
.weakKeys()
|
||||
.build(key -> new ContextsCache<>(key, this));
|
||||
|
||||
// caches static context lookups
|
||||
private final StaticLookupCache staticLookupCache = new StaticLookupCache();
|
||||
|
||||
protected AbstractContextManager(LuckPermsPlugin plugin, Class<T> subjectClass) {
|
||||
this.plugin = plugin;
|
||||
this.subjectClass = subjectClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContextCalculator<? super T>> getCalculators() {
|
||||
return ImmutableList.copyOf(this.calculators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StaticContextCalculator> getStaticCalculators() {
|
||||
return ImmutableList.copyOf(this.staticCalculators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getSubjectClass() {
|
||||
return this.subjectClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getApplicableContext(T subject) {
|
||||
return getCacheFor(subject).getContextSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts getApplicableContexts(T subject) {
|
||||
return getCacheFor(subject).getContexts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextsCache<T> getCacheFor(T subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
return this.subjectCaches.get(subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getStaticContext() {
|
||||
// this is actually already immutable, but the Contexts method signature returns the interface.
|
||||
// using the makeImmutable method is faster than casting
|
||||
return getStaticContexts().getContexts().makeImmutable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts getStaticContexts() {
|
||||
return this.staticLookupCache.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getStaticContextString() {
|
||||
Set<Map.Entry<String, String>> entries = getStaticContext().toSet();
|
||||
if (entries.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// effectively: if entries contains any non-server keys
|
||||
if (entries.stream().anyMatch(pair -> !pair.getKey().equals(Contexts.SERVER_KEY))) {
|
||||
// return all entries in 'key=value' form
|
||||
return Optional.of(entries.stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";")));
|
||||
} else {
|
||||
// just return the server ids, without the 'server='
|
||||
return Optional.of(entries.stream().map(Map.Entry::getValue).collect(Collectors.joining(";")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||
return Contexts.of(contextSet, this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaContexts formMetaContexts(Contexts contexts) {
|
||||
return new MetaContexts(
|
||||
contexts,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCalculator(ContextCalculator<? super T> calculator) {
|
||||
// calculators registered first should have priority (and be checked last.)
|
||||
this.calculators.add(0, calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticCalculator(StaticContextCalculator calculator) {
|
||||
registerCalculator(calculator);
|
||||
this.staticCalculators.add(0, calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache(T subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
|
||||
this.subjectCaches.invalidate(subject);
|
||||
}
|
||||
|
||||
Contexts calculate(T subject) {
|
||||
MutableContextSet accumulator = MutableContextSet.create();
|
||||
|
||||
for (ContextCalculator<? super T> calculator : AbstractContextManager.this.calculators) {
|
||||
try {
|
||||
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
|
||||
//noinspection ConstantConditions
|
||||
if (ret == null) {
|
||||
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
AbstractContextManager.this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formContexts(subject, accumulator.makeImmutable());
|
||||
}
|
||||
|
||||
private Contexts calculateStatic() {
|
||||
MutableContextSet accumulator = MutableContextSet.create();
|
||||
|
||||
for (StaticContextCalculator calculator : this.staticCalculators) {
|
||||
try {
|
||||
MutableContextSet ret = calculator.giveApplicableContext(accumulator);
|
||||
//noinspection ConstantConditions
|
||||
if (ret == null) {
|
||||
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formContexts(accumulator.makeImmutable());
|
||||
}
|
||||
|
||||
private final class StaticLookupCache extends ExpiringCache<Contexts> {
|
||||
StaticLookupCache() {
|
||||
super(50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts supply() {
|
||||
return calculateStatic();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCalculatorClass(ContextCalculator<?> calculator) {
|
||||
Class<?> calculatorClass;
|
||||
if (calculator instanceof ProxiedContextCalculator) {
|
||||
calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass();
|
||||
} else {
|
||||
calculatorClass = calculator.getClass();
|
||||
}
|
||||
return calculatorClass.getName();
|
||||
}
|
||||
|
||||
}
|
@ -25,29 +25,83 @@
|
||||
|
||||
package me.lucko.luckperms.common.contexts;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
import me.lucko.luckperms.common.buffers.ExpiringCache;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Manages {@link ContextCalculator}s, and calculates applicable contexts for a
|
||||
* given type.
|
||||
* Base implementation of {@link ContextManager} which caches content lookups.
|
||||
*
|
||||
* @param <T> the calculator type
|
||||
*/
|
||||
public interface ContextManager<T> {
|
||||
public abstract class ContextManager<T> {
|
||||
|
||||
protected final LuckPermsPlugin plugin;
|
||||
private final Class<T> subjectClass;
|
||||
|
||||
private final List<ContextCalculator<? super T>> calculators = new CopyOnWriteArrayList<>();
|
||||
private final List<StaticContextCalculator> staticCalculators = new CopyOnWriteArrayList<>();
|
||||
|
||||
// caches the creation of cache instances. cache-ception.
|
||||
// we want to encourage re-use of these instances, it's faster that way
|
||||
private final LoadingCache<T, ContextsCache<T>> subjectCaches = Caffeine.newBuilder()
|
||||
.weakKeys()
|
||||
.build(key -> new ContextsCache<>(key, this));
|
||||
|
||||
// caches static context lookups
|
||||
private final StaticLookupCache staticLookupCache = new StaticLookupCache();
|
||||
|
||||
protected ContextManager(LuckPermsPlugin plugin, Class<T> subjectClass) {
|
||||
this.plugin = plugin;
|
||||
this.subjectClass = subjectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the calculators registered on the platform
|
||||
*
|
||||
* @return the registered calculators
|
||||
*/
|
||||
public List<ContextCalculator<? super T>> getCalculators() {
|
||||
return ImmutableList.copyOf(this.calculators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the static calculators registered on the platform
|
||||
*
|
||||
* @return the registered static calculators
|
||||
*/
|
||||
public List<StaticContextCalculator> getStaticCalculators() {
|
||||
return ImmutableList.copyOf(this.staticCalculators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class of the subject handled by this instance
|
||||
*
|
||||
* @return the subject class
|
||||
*/
|
||||
Class<T> getSubjectClass();
|
||||
public Class<T> getSubjectClass() {
|
||||
return this.subjectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the ContextManager for current context values for the subject.
|
||||
@ -55,15 +109,19 @@ public interface ContextManager<T> {
|
||||
* @param subject the subject
|
||||
* @return the applicable context for the subject
|
||||
*/
|
||||
ImmutableContextSet getApplicableContext(T subject);
|
||||
public ImmutableContextSet getApplicableContext(T subject) {
|
||||
return getCacheFor(subject).getContextSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the ContextManager for current context values for the subject.
|
||||
*
|
||||
* @param subject the subject
|
||||
* @return the applicable context for the subject
|
||||
*/
|
||||
Contexts getApplicableContexts(T subject);
|
||||
* Queries the ContextManager for current context values for the subject.
|
||||
*
|
||||
* @param subject the subject
|
||||
* @return the applicable context for the subject
|
||||
*/
|
||||
public Contexts getApplicableContexts(T subject) {
|
||||
return getCacheFor(subject).getContexts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache instance for the given subject.
|
||||
@ -71,21 +129,32 @@ public interface ContextManager<T> {
|
||||
* @param subject the subject
|
||||
* @return the cache
|
||||
*/
|
||||
ContextsCache<T> getCacheFor(T subject);
|
||||
public ContextsCache<T> getCacheFor(T subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
return this.subjectCaches.get(subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contexts from the static calculators in this manager.
|
||||
*
|
||||
* @return the current active static contexts
|
||||
*/
|
||||
ImmutableContextSet getStaticContext();
|
||||
public ImmutableContextSet getStaticContext() {
|
||||
// this is actually already immutable, but the Contexts method signature returns the interface.
|
||||
// using the makeImmutable method is faster than casting
|
||||
return getStaticContexts().getContexts().makeImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contexts from the static calculators in this manager.
|
||||
*
|
||||
* @return the current active static contexts
|
||||
*/
|
||||
Contexts getStaticContexts();
|
||||
public Contexts getStaticContexts() {
|
||||
return this.staticLookupCache.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string form of the managers static context
|
||||
@ -94,16 +163,21 @@ public interface ContextManager<T> {
|
||||
*
|
||||
* @return a string representation of {@link #getStaticContext()}
|
||||
*/
|
||||
Optional<String> getStaticContextString();
|
||||
public Optional<String> getStaticContextString() {
|
||||
Set<Map.Entry<String, String>> entries = getStaticContext().toSet();
|
||||
if (entries.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a {@link Contexts} instance from an {@link ImmutableContextSet}.
|
||||
*
|
||||
* @param subject the subject
|
||||
* @param contextSet the context set
|
||||
* @return a contexts instance
|
||||
*/
|
||||
Contexts formContexts(T subject, ImmutableContextSet contextSet);
|
||||
// effectively: if entries contains any non-server keys
|
||||
if (entries.stream().anyMatch(pair -> !pair.getKey().equals(Contexts.SERVER_KEY))) {
|
||||
// return all entries in 'key=value' form
|
||||
return Optional.of(entries.stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";")));
|
||||
} else {
|
||||
// just return the server ids, without the 'server='
|
||||
return Optional.of(entries.stream().map(Map.Entry::getValue).collect(Collectors.joining(";")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a {@link Contexts} instance from an {@link ImmutableContextSet}.
|
||||
@ -111,7 +185,9 @@ public interface ContextManager<T> {
|
||||
* @param contextSet the context set
|
||||
* @return a contexts instance
|
||||
*/
|
||||
Contexts formContexts(ImmutableContextSet contextSet);
|
||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||
return Contexts.of(contextSet, this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a "default" {@link MetaContexts} instance from {@link Contexts}.
|
||||
@ -119,41 +195,116 @@ public interface ContextManager<T> {
|
||||
* @param contexts the contexts
|
||||
* @return a contexts instance
|
||||
*/
|
||||
MetaContexts formMetaContexts(Contexts contexts);
|
||||
public MetaContexts formMetaContexts(Contexts contexts) {
|
||||
return new MetaContexts(
|
||||
contexts,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.PREFIX_FORMATTING_OPTIONS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.SUFFIX_FORMATTING_OPTIONS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a context calculator with the manager.
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
void registerCalculator(ContextCalculator<? super T> calculator);
|
||||
public void registerCalculator(ContextCalculator<? super T> calculator) {
|
||||
// calculators registered first should have priority (and be checked last.)
|
||||
this.calculators.add(0, calculator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a static context calculator with the manager.
|
||||
*
|
||||
* @param calculator the calculator
|
||||
*/
|
||||
void registerStaticCalculator(StaticContextCalculator calculator);
|
||||
public void registerStaticCalculator(StaticContextCalculator calculator) {
|
||||
registerCalculator(calculator);
|
||||
this.staticCalculators.add(0, calculator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the lookup cache for a given subject
|
||||
*
|
||||
* @param subject the subject
|
||||
*/
|
||||
void invalidateCache(T subject);
|
||||
public void invalidateCache(T subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
|
||||
this.subjectCaches.invalidate(subject);
|
||||
}
|
||||
|
||||
Contexts calculate(T subject) {
|
||||
MutableContextSet accumulator = MutableContextSet.create();
|
||||
|
||||
for (ContextCalculator<? super T> calculator : ContextManager.this.calculators) {
|
||||
try {
|
||||
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
|
||||
//noinspection ConstantConditions
|
||||
if (ret == null) {
|
||||
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
ContextManager.this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formContexts(subject, accumulator.makeImmutable());
|
||||
}
|
||||
|
||||
private Contexts calculateStatic() {
|
||||
MutableContextSet accumulator = MutableContextSet.create();
|
||||
|
||||
for (StaticContextCalculator calculator : this.staticCalculators) {
|
||||
try {
|
||||
MutableContextSet ret = calculator.giveApplicableContext(accumulator);
|
||||
//noinspection ConstantConditions
|
||||
if (ret == null) {
|
||||
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
|
||||
}
|
||||
accumulator = ret;
|
||||
} catch (Exception e) {
|
||||
this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return formContexts(accumulator.makeImmutable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the calculators registered on the platform
|
||||
* Forms a {@link Contexts} instance from an {@link ImmutableContextSet}.
|
||||
*
|
||||
* @return the registered calculators
|
||||
* @param subject the subject
|
||||
* @param contextSet the context set
|
||||
* @return a contexts instance
|
||||
*/
|
||||
List<ContextCalculator<? super T>> getCalculators();
|
||||
public abstract Contexts formContexts(T subject, ImmutableContextSet contextSet);
|
||||
|
||||
/**
|
||||
* Gets the static calculators registered on the platform
|
||||
*
|
||||
* @return the registered static calculators
|
||||
*/
|
||||
List<StaticContextCalculator> getStaticCalculators();
|
||||
private final class StaticLookupCache extends ExpiringCache<Contexts> {
|
||||
StaticLookupCache() {
|
||||
super(50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Contexts supply() {
|
||||
return calculateStatic();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCalculatorClass(ContextCalculator<?> calculator) {
|
||||
Class<?> calculatorClass;
|
||||
if (calculator instanceof ProxiedContextCalculator) {
|
||||
calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass();
|
||||
} else {
|
||||
calculatorClass = calculator.getClass();
|
||||
}
|
||||
return calculatorClass.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,16 +34,16 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Extension of {@link AbstractContextManager} that implements an expiring lookup cache
|
||||
* Extension of {@link ContextManager} that implements an expiring lookup cache
|
||||
* per player.
|
||||
*
|
||||
* @param <T> the player type
|
||||
*/
|
||||
public final class ContextsCache<T> extends ExpiringCache<Contexts> {
|
||||
private final T subject;
|
||||
private final AbstractContextManager<T> contextManager;
|
||||
private final ContextManager<T> contextManager;
|
||||
|
||||
public ContextsCache(T subject, AbstractContextManager<T> contextManager) {
|
||||
public ContextsCache(T subject, ContextManager<T> contextManager) {
|
||||
super(50L, TimeUnit.MILLISECONDS); // expire roughly every tick
|
||||
this.subject = subject;
|
||||
this.contextManager = contextManager;
|
||||
|
@ -33,10 +33,10 @@ import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class LuckPermsCalculator implements StaticContextCalculator {
|
||||
public class LPStaticContextsCalculator implements StaticContextCalculator {
|
||||
private final LuckPermsConfiguration config;
|
||||
|
||||
public LuckPermsCalculator(LuckPermsConfiguration config) {
|
||||
public LPStaticContextsCalculator(LuckPermsConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.listener;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Handles incoming connections on the platform
|
||||
*/
|
||||
public interface ConnectionListener {
|
||||
|
||||
/**
|
||||
* Gets the unique players which have connected to the server since it started.
|
||||
*
|
||||
* @return the unique connections
|
||||
*/
|
||||
Set<UUID> getUniqueConnections();
|
||||
|
||||
}
|
@ -25,17 +25,25 @@
|
||||
|
||||
package me.lucko.luckperms.common.locale;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpecData;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
/**
|
||||
* Manages translations
|
||||
*/
|
||||
public interface LocaleManager {
|
||||
import java.io.BufferedReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
public class LocaleManager {
|
||||
|
||||
private Map<Message, String> messages = ImmutableMap.of();
|
||||
private Map<CommandSpec, CommandSpecData> commands = ImmutableMap.of();
|
||||
|
||||
/**
|
||||
* Tries to load from a locale file, and logs via the plugin if successful.
|
||||
@ -43,7 +51,16 @@ public interface LocaleManager {
|
||||
* @param plugin the plugin to log to
|
||||
* @param file the file to load from
|
||||
*/
|
||||
void tryLoad(LuckPermsPlugin plugin, Path file);
|
||||
public void tryLoad(LuckPermsPlugin plugin, Path file) {
|
||||
if (Files.exists(file)) {
|
||||
plugin.getLogger().info("Found lang.yml - loading messages...");
|
||||
try {
|
||||
loadFromFile(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a locale file
|
||||
@ -51,14 +68,75 @@ public interface LocaleManager {
|
||||
* @param file the file to load from
|
||||
* @throws Exception if the process fails
|
||||
*/
|
||||
void loadFromFile(Path file) throws Exception;
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadFromFile(Path file) throws Exception {
|
||||
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
ImmutableMap.Builder<Message, String> messages = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<CommandSpec, CommandSpecData> commands = ImmutableMap.builder();
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader);
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// might be a message
|
||||
if (entry.getValue() instanceof String) {
|
||||
String key = entry.getKey().toUpperCase().replace('-', '_');
|
||||
String value = (String) entry.getValue();
|
||||
|
||||
try {
|
||||
messages.put(Message.valueOf(key), value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// might be the entries for command specifications - take care for malformed entries of differing types.
|
||||
if (entry.getKey().equals("command-specs") && entry.getValue() instanceof Map) {
|
||||
Map<?, ?> commandKeys = (Map) entry.getValue();
|
||||
|
||||
// key is the command id, value is a map of the commands attributes
|
||||
for (Map.Entry commandKey : commandKeys.entrySet()) {
|
||||
|
||||
// just try catch, can't be bothered with safe casting every single value.
|
||||
try {
|
||||
String id = (String) commandKey.getKey();
|
||||
Map<String, Object> attributes = (Map<String, Object>) commandKey.getValue();
|
||||
CommandSpec spec = CommandSpec.valueOf(id.toUpperCase().replace('-', '_'));
|
||||
|
||||
String description = (String) attributes.get("description");
|
||||
String usage = (String) attributes.get("usage");
|
||||
Map<String, String> args = (Map<String, String>) attributes.get("args");
|
||||
if (args != null && args.isEmpty()) {
|
||||
args = null;
|
||||
}
|
||||
|
||||
CommandSpecData specData = new CommandSpecData(description, usage, args == null ? null : ImmutableMap.copyOf(args));
|
||||
commands.put(spec, specData);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.messages = messages.build();
|
||||
this.commands = commands.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of loaded translations
|
||||
*
|
||||
* @return the size of the loaded translations
|
||||
*/
|
||||
int getSize();
|
||||
public int getSize() {
|
||||
return this.messages.size() + this.commands.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a translation for a given message key
|
||||
@ -66,7 +144,9 @@ public interface LocaleManager {
|
||||
* @param key the key
|
||||
* @return the translation, or null if there isn't any translation available.
|
||||
*/
|
||||
String getTranslation(Message key);
|
||||
public String getTranslation(Message key) {
|
||||
return this.messages.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a translation for a given command spec key
|
||||
@ -74,6 +154,8 @@ public interface LocaleManager {
|
||||
* @param key the key
|
||||
* @return the translation data, or null if there isn't any translation available.
|
||||
*/
|
||||
CommandSpecData getTranslation(CommandSpec key);
|
||||
public CommandSpecData getTranslation(CommandSpec key) {
|
||||
return this.commands.get(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.locale;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.command.CommandSpecData;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleLocaleManager implements LocaleManager {
|
||||
|
||||
private Map<Message, String> messages = ImmutableMap.of();
|
||||
private Map<CommandSpec, CommandSpecData> commands = ImmutableMap.of();
|
||||
|
||||
@Override
|
||||
public void tryLoad(LuckPermsPlugin plugin, Path file) {
|
||||
if (Files.exists(file)) {
|
||||
plugin.getLogger().info("Found lang.yml - loading messages...");
|
||||
try {
|
||||
loadFromFile(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadFromFile(Path file) throws Exception {
|
||||
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
ImmutableMap.Builder<Message, String> messages = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<CommandSpec, CommandSpecData> commands = ImmutableMap.builder();
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader);
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// might be a message
|
||||
if (entry.getValue() instanceof String) {
|
||||
String key = entry.getKey().toUpperCase().replace('-', '_');
|
||||
String value = (String) entry.getValue();
|
||||
|
||||
try {
|
||||
messages.put(Message.valueOf(key), value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// might be the entries for command specifications - take care for malformed entries of differing types.
|
||||
if (entry.getKey().equals("command-specs") && entry.getValue() instanceof Map) {
|
||||
Map<?, ?> commandKeys = (Map) entry.getValue();
|
||||
|
||||
// key is the command id, value is a map of the commands attributes
|
||||
for (Map.Entry commandKey : commandKeys.entrySet()) {
|
||||
|
||||
// just try catch, can't be bothered with safe casting every single value.
|
||||
try {
|
||||
String id = (String) commandKey.getKey();
|
||||
Map<String, Object> attributes = (Map<String, Object>) commandKey.getValue();
|
||||
CommandSpec spec = CommandSpec.valueOf(id.toUpperCase().replace('-', '_'));
|
||||
|
||||
String description = (String) attributes.get("description");
|
||||
String usage = (String) attributes.get("usage");
|
||||
Map<String, String> args = (Map<String, String>) attributes.get("args");
|
||||
if (args != null && args.isEmpty()) {
|
||||
args = null;
|
||||
}
|
||||
|
||||
CommandSpecData specData = new CommandSpecData(description, usage, args == null ? null : ImmutableMap.copyOf(args));
|
||||
commands.put(spec, specData);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.messages = messages.build();
|
||||
this.commands = commands.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return this.messages.size() + this.commands.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslation(Message key) {
|
||||
return this.messages.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSpecData getTranslation(CommandSpec key) {
|
||||
return this.commands.get(key);
|
||||
}
|
||||
|
||||
}
|
@ -25,13 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.common.locale.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* An enumeration of the command defintion/usage messages used in the plugin.
|
||||
@ -570,6 +566,18 @@ public enum CommandSpec {
|
||||
this(description, null, args);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
public List<Argument> getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link LocalizedCommandSpec} for the spec using the platforms locale manager.
|
||||
*
|
||||
@ -577,67 +585,7 @@ public enum CommandSpec {
|
||||
* @return a localized spec instance
|
||||
*/
|
||||
public LocalizedCommandSpec localize(LocaleManager localeManager) {
|
||||
return new Localized(this, localeManager);
|
||||
}
|
||||
|
||||
private static final class Localized implements LocalizedCommandSpec {
|
||||
private final LocaleManager localeManager;
|
||||
private final CommandSpec spec;
|
||||
|
||||
private Localized(CommandSpec spec, LocaleManager localeManager) {
|
||||
this.localeManager = localeManager;
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation != null && translation.getDescription() != null) {
|
||||
return translation.getDescription();
|
||||
}
|
||||
|
||||
// fallback
|
||||
return this.spec.description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation != null && translation.getUsage() != null) {
|
||||
return translation.getUsage();
|
||||
}
|
||||
|
||||
// fallback
|
||||
return this.spec.usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Argument> args() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation == null || translation.getArgs() == null) {
|
||||
// fallback
|
||||
return this.spec.args;
|
||||
}
|
||||
|
||||
List<Argument> args = new ArrayList<>(this.spec.args);
|
||||
ListIterator<Argument> it = args.listIterator();
|
||||
while (it.hasNext()) {
|
||||
Argument next = it.next();
|
||||
String s = translation.getArgs().get(next.getName());
|
||||
|
||||
// if a translation for the given arg key is present, apply the new description.
|
||||
if (s != null) {
|
||||
it.set(Argument.create(next.getName(), next.isRequired(), s));
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableList.copyOf(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleManager getLocaleManager() {
|
||||
return this.localeManager;
|
||||
}
|
||||
return new LocalizedCommandSpec(this, localeManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,26 +25,69 @@
|
||||
|
||||
package me.lucko.luckperms.common.locale.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Represents a localized instance of a {@link CommandSpec}.
|
||||
*/
|
||||
public interface LocalizedCommandSpec {
|
||||
public class LocalizedCommandSpec {
|
||||
private final LocaleManager localeManager;
|
||||
private final CommandSpec spec;
|
||||
|
||||
/**
|
||||
* Gets the locale manager used to translate the {@link CommandSpec}.
|
||||
*
|
||||
* @return the locale manager
|
||||
*/
|
||||
LocaleManager getLocaleManager();
|
||||
public LocalizedCommandSpec(CommandSpec spec, LocaleManager localeManager) {
|
||||
this.localeManager = localeManager;
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
String description();
|
||||
public String description() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation != null && translation.getDescription() != null) {
|
||||
return translation.getDescription();
|
||||
}
|
||||
|
||||
String usage();
|
||||
// fallback
|
||||
return this.spec.getDescription();
|
||||
}
|
||||
|
||||
List<Argument> args();
|
||||
public String usage() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation != null && translation.getUsage() != null) {
|
||||
return translation.getUsage();
|
||||
}
|
||||
|
||||
// fallback
|
||||
return this.spec.getUsage();
|
||||
}
|
||||
|
||||
public List<Argument> args() {
|
||||
CommandSpecData translation = this.localeManager.getTranslation(this.spec);
|
||||
if (translation == null || translation.getArgs() == null) {
|
||||
// fallback
|
||||
return this.spec.getArgs();
|
||||
}
|
||||
|
||||
List<Argument> args = new ArrayList<>(this.spec.getArgs());
|
||||
ListIterator<Argument> it = args.listIterator();
|
||||
while (it.hasNext()) {
|
||||
Argument next = it.next();
|
||||
String s = translation.getArgs().get(next.getName());
|
||||
|
||||
// if a translation for the given arg key is present, apply the new description.
|
||||
if (s != null) {
|
||||
it.set(Argument.create(next.getName(), next.isRequired(), s));
|
||||
}
|
||||
}
|
||||
|
||||
return ImmutableList.copyOf(args);
|
||||
}
|
||||
|
||||
public LocaleManager getLocaleManager() {
|
||||
return this.localeManager;
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.logging;
|
||||
|
||||
/**
|
||||
* Represents the logger instance being used by LuckPerms on the platform.
|
||||
*
|
||||
* <p>Messages sent using the logger are sent prefixed with the LuckPerms tag, and on some implementations will be colored
|
||||
* depending on the message type.</p>
|
||||
*/
|
||||
public interface Logger {
|
||||
|
||||
void info(String s);
|
||||
|
||||
void warn(String s);
|
||||
|
||||
void severe(String s);
|
||||
|
||||
}
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.messaging.sql;
|
||||
|
||||
import me.lucko.luckperms.api.messenger.IncomingMessageConsumer;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
import me.lucko.luckperms.common.storage.dao.sql.SqlDao;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -41,11 +41,10 @@ public class HeldPermissionComparator<T extends Comparable<T>> implements Compar
|
||||
|
||||
@Override
|
||||
public int compare(HeldPermission<T> o1, HeldPermission<T> o2) {
|
||||
int i = o1.getHolder().compareTo(o2.getHolder());
|
||||
int i = NodeWithContextComparator.normal().compare(o1.asNode(), o2.asNode());
|
||||
if (i != 0) {
|
||||
return i;
|
||||
}
|
||||
|
||||
return NodeWithContextComparator.normal().compare(o1.asNode(), o2.asNode());
|
||||
return o1.getHolder().compareTo(o2.getHolder());
|
||||
}
|
||||
}
|
||||
|
@ -37,18 +37,16 @@ import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
||||
import me.lucko.luckperms.common.contexts.LPStaticContextsCalculator;
|
||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||
import me.lucko.luckperms.common.event.EventFactory;
|
||||
import me.lucko.luckperms.common.inheritance.InheritanceHandler;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
|
||||
import me.lucko.luckperms.common.logging.Logger;
|
||||
import me.lucko.luckperms.common.logging.SenderLogger;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.common.plugin.util.PluginLogger;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||
@ -66,7 +64,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
|
||||
// init during load
|
||||
private Logger logger;
|
||||
private PluginLogger logger;
|
||||
private DependencyManager dependencyManager;
|
||||
|
||||
// init during enable
|
||||
@ -90,7 +88,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
public final void load() {
|
||||
// load the sender factory instance and create a new logger for the plugin
|
||||
setupSenderFactory();
|
||||
this.logger = new SenderLogger(this, getConsoleSender());
|
||||
this.logger = new PluginLogger(this, getConsoleSender());
|
||||
|
||||
// load dependencies
|
||||
this.dependencyManager = new DependencyManager(this);
|
||||
@ -111,7 +109,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
this.configuration = new AbstractConfiguration(this, provideConfigurationAdapter());
|
||||
|
||||
// load locale
|
||||
this.localeManager = new SimpleLocaleManager();
|
||||
this.localeManager = new LocaleManager();
|
||||
this.localeManager.tryLoad(this, getBootstrap().getConfigDirectory().resolve("lang.yml"));
|
||||
|
||||
// now the configuration is loaded, we can create a storage factory and load initial dependencies
|
||||
@ -154,7 +152,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
|
||||
// setup contextmanager & register common calculators
|
||||
setupContextManager();
|
||||
getContextManager().registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
getContextManager().registerStaticCalculator(new LPStaticContextsCalculator(getConfiguration()));
|
||||
|
||||
// setup platform hooks
|
||||
setupPlatformHooks();
|
||||
@ -247,7 +245,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
public PluginLogger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
|
@ -37,15 +37,15 @@ import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||
import me.lucko.luckperms.common.event.EventFactory;
|
||||
import me.lucko.luckperms.common.inheritance.InheritanceHandler;
|
||||
import me.lucko.luckperms.common.listener.ConnectionListener;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.logging.Logger;
|
||||
import me.lucko.luckperms.common.managers.group.GroupManager;
|
||||
import me.lucko.luckperms.common.managers.track.TrackManager;
|
||||
import me.lucko.luckperms.common.managers.user.UserManager;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.plugin.util.PluginLogger;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.storage.dao.file.FileWatcher;
|
||||
@ -126,7 +126,7 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return the plugin's logger
|
||||
*/
|
||||
Logger getLogger();
|
||||
PluginLogger getLogger();
|
||||
|
||||
/**
|
||||
* Gets the event factory
|
||||
@ -154,7 +154,7 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return the connection listener
|
||||
*/
|
||||
ConnectionListener getConnectionListener();
|
||||
AbstractConnectionListener getConnectionListener();
|
||||
|
||||
/**
|
||||
* Gets the instance providing locale translations for the plugin
|
||||
|
@ -27,8 +27,6 @@ package me.lucko.luckperms.common.plugin.scheduler;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.plugin.scheduler;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.plugin;
|
||||
package me.lucko.luckperms.common.plugin.scheduler;
|
||||
|
||||
/**
|
||||
* Represents a scheduled task
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.listener;
|
||||
package me.lucko.luckperms.common.plugin.util;
|
||||
|
||||
import me.lucko.luckperms.api.PlayerSaveResult;
|
||||
import me.lucko.luckperms.api.platform.PlatformType;
|
||||
@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Abstract listener utility for handling new player connections
|
||||
*/
|
||||
public abstract class AbstractConnectionListener implements ConnectionListener {
|
||||
public abstract class AbstractConnectionListener {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final Set<UUID> uniqueConnections = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@ -48,7 +48,11 @@ public abstract class AbstractConnectionListener implements ConnectionListener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the unique players which have connected to the server since it started.
|
||||
*
|
||||
* @return the unique connections
|
||||
*/
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return this.uniqueConnections;
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.logging;
|
||||
package me.lucko.luckperms.common.plugin.util;
|
||||
|
||||
import me.lucko.luckperms.common.command.utils.MessageUtils;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -33,26 +33,29 @@ import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SenderLogger implements Logger {
|
||||
/**
|
||||
* Represents the logger instance being used by LuckPerms on the platform.
|
||||
*
|
||||
* <p>Messages sent using the logger are sent prefixed with the LuckPerms tag,
|
||||
* and on some implementations will be colored depending on the message type.</p>
|
||||
*/
|
||||
public class PluginLogger {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final Sender console;
|
||||
|
||||
public SenderLogger(LuckPermsPlugin plugin, Sender console) {
|
||||
public PluginLogger(LuckPermsPlugin plugin, Sender console) {
|
||||
this.plugin = plugin;
|
||||
this.console = console;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String s) {
|
||||
msg(Message.LOG_INFO, Objects.requireNonNull(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String s) {
|
||||
msg(Message.LOG_WARN, Objects.requireNonNull(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String s) {
|
||||
msg(Message.LOG_ERROR, Objects.requireNonNull(s));
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.logging;
|
||||
package me.lucko.luckperms.common.utils;
|
||||
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
@ -25,8 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.utils;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -37,13 +37,13 @@ import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||
import me.lucko.luckperms.common.listener.ConnectionListener;
|
||||
import me.lucko.luckperms.common.managers.group.StandardGroupManager;
|
||||
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.managers.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
@ -314,7 +314,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionListener getConnectionListener() {
|
||||
public AbstractConnectionListener getConnectionListener() {
|
||||
return this.connectionListener;
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class NukkitContextManager extends AbstractContextManager<Player> {
|
||||
public class NukkitContextManager extends ContextManager<Player> {
|
||||
public NukkitContextManager(LPNukkitPlugin plugin) {
|
||||
super(plugin, Player.class);
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
package me.lucko.luckperms.nukkit.listeners;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.listener.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
import me.lucko.luckperms.nukkit.model.permissible.LPPermissible;
|
||||
import me.lucko.luckperms.nukkit.model.permissible.PermissibleInjector;
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.SchedulerTask;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerTask;
|
||||
import me.lucko.luckperms.common.utils.Iterators;
|
||||
|
||||
import org.spongepowered.api.scheduler.Scheduler;
|
||||
|
@ -27,12 +27,12 @@ package me.lucko.luckperms.sponge.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
public class SpongeContextManager extends AbstractContextManager<Subject> {
|
||||
public class SpongeContextManager extends ContextManager<Subject> {
|
||||
public SpongeContextManager(LPSpongePlugin plugin) {
|
||||
super(plugin, Subject.class);
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.listener.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.locale.message.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
Loading…
Reference in New Issue
Block a user