mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
misc cleanup
This commit is contained in:
parent
e24a482deb
commit
8d045be0b0
@ -34,7 +34,7 @@ import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.api.event.cause.DeletionCause;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
@ -158,7 +158,7 @@ public class ApiStorage implements Storage {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> deleteGroup(@Nonnull Group group) {
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (group.getName().equalsIgnoreCase(this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
if (group.getName().equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) {
|
||||
throw new IllegalArgumentException("Cannot delete the default group.");
|
||||
}
|
||||
return this.handle.noBuffer().deleteGroup(ApiGroup.cast(group), DeletionCause.API).thenApply(x -> true);
|
||||
|
@ -33,11 +33,11 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
@ -57,7 +57,7 @@ public class DeleteGroup extends SingleCommand {
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
|
||||
if (groupName.equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) {
|
||||
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
@ -36,13 +36,11 @@ import me.lucko.luckperms.common.config.keys.EnduringKey;
|
||||
import me.lucko.luckperms.common.config.keys.IntegerKey;
|
||||
import me.lucko.luckperms.common.config.keys.LowercaseStringKey;
|
||||
import me.lucko.luckperms.common.config.keys.MapKey;
|
||||
import me.lucko.luckperms.common.config.keys.StaticKey;
|
||||
import me.lucko.luckperms.common.config.keys.StringKey;
|
||||
import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition;
|
||||
import me.lucko.luckperms.common.metastacking.StandardStackElements;
|
||||
import me.lucko.luckperms.common.model.TemporaryModifier;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
import me.lucko.luckperms.common.primarygroup.AllParentsByWeightHolder;
|
||||
import me.lucko.luckperms.common.primarygroup.ParentsByWeightHolder;
|
||||
import me.lucko.luckperms.common.primarygroup.PrimaryGroupHolder;
|
||||
@ -84,20 +82,6 @@ public class ConfigKeys {
|
||||
*/
|
||||
public static final ConfigKey<Integer> SYNC_TIME = EnduringKey.wrap(IntegerKey.of("data.sync-minutes", -1));
|
||||
|
||||
/**
|
||||
* The permission node associated with the default group
|
||||
*
|
||||
* Constant since 2.6
|
||||
*/
|
||||
public static final ConfigKey<String> DEFAULT_GROUP_NODE = StaticKey.of(NodeFactory.groupNode(NodeFactory.DEFAULT_GROUP_NAME));
|
||||
|
||||
/**
|
||||
* The name of the default group
|
||||
*
|
||||
* Constant since 2.6
|
||||
*/
|
||||
public static final ConfigKey<String> DEFAULT_GROUP_NAME = StaticKey.of(NodeFactory.DEFAULT_GROUP_NAME);
|
||||
|
||||
/**
|
||||
* If permissions without a server context should be included.
|
||||
*/
|
||||
|
@ -1,46 +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.config.keys;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
|
||||
|
||||
public class StaticKey<T> implements ConfigKey<T> {
|
||||
public static <T> StaticKey<T> of(T val) {
|
||||
return new StaticKey<>(val);
|
||||
}
|
||||
|
||||
private final T val;
|
||||
|
||||
private StaticKey(T val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(ConfigurationAdapter adapter) {
|
||||
return this.val;
|
||||
}
|
||||
}
|
@ -41,6 +41,8 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class AbstractDao {
|
||||
|
||||
protected final LuckPermsPlugin plugin;
|
||||
@ -105,8 +107,10 @@ public abstract class AbstractDao {
|
||||
|
||||
public abstract void saveUUIDData(UUID uuid, String username) throws Exception;
|
||||
|
||||
@Nullable
|
||||
public abstract UUID getUUID(String username) throws Exception;
|
||||
|
||||
@Nullable
|
||||
public abstract String getName(UUID uuid) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -763,7 +763,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String username) {
|
||||
return this.uuidCache.lookupUUID(username);
|
||||
return this.uuidCache.lookup(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +41,8 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FileUuidCache {
|
||||
private static final Splitter KV_SPLIT = Splitter.on('=').omitEmptyStrings();
|
||||
private static final Splitter TIME_SPLIT = Splitter.on('|').omitEmptyStrings();
|
||||
@ -64,7 +66,8 @@ public class FileUuidCache {
|
||||
* @param username the username to lookup with
|
||||
* @return a uuid, or null
|
||||
*/
|
||||
public UUID lookupUUID(String username) {
|
||||
@Nullable
|
||||
public UUID lookup(String username) {
|
||||
Map.Entry<UUID, Long> ret = this.lookupMap.get(username.toLowerCase());
|
||||
return ret == null ? null : ret.getKey();
|
||||
}
|
||||
|
@ -42,6 +42,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FileWatcher implements Runnable {
|
||||
private static final WatchEvent.Kind[] KINDS = new WatchEvent.Kind[]{
|
||||
StandardWatchEventKinds.ENTRY_CREATE,
|
||||
StandardWatchEventKinds.ENTRY_DELETE,
|
||||
StandardWatchEventKinds.ENTRY_MODIFY
|
||||
};
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
private final Map<String, WatchedLocation> keyMap;
|
||||
@ -66,17 +72,15 @@ public class FileWatcher implements Runnable {
|
||||
|
||||
// Register with a delay to ignore changes made at startup
|
||||
this.plugin.getScheduler().asyncLater(() -> {
|
||||
try {
|
||||
// doesn't need to be atomic
|
||||
if (this.keyMap.containsKey(id)) {
|
||||
throw new IllegalArgumentException("id already registered");
|
||||
this.keyMap.computeIfAbsent(id, s -> {
|
||||
WatchKey key;
|
||||
try {
|
||||
key = path.register(this.watchService, KINDS);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
WatchKey key = path.register(this.watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
|
||||
this.keyMap.put(id, new WatchedLocation(path, key, consumer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new WatchedLocation(path, key, consumer);
|
||||
});
|
||||
}, 40L);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
package me.lucko.luckperms.common.tasks;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -62,9 +62,8 @@ public class UpdateTask implements Runnable {
|
||||
|
||||
// Reload all groups
|
||||
this.plugin.getStorage().loadAllGroups().join();
|
||||
String defaultGroup = this.plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME);
|
||||
if (!this.plugin.getGroupManager().isLoaded(defaultGroup)) {
|
||||
this.plugin.getStorage().createAndLoadGroup(defaultGroup, CreationCause.INTERNAL).join();
|
||||
if (!this.plugin.getGroupManager().isLoaded(NodeFactory.DEFAULT_GROUP_NAME)) {
|
||||
this.plugin.getStorage().createAndLoadGroup(NodeFactory.DEFAULT_GROUP_NAME, CreationCause.INTERNAL).join();
|
||||
}
|
||||
|
||||
// Reload all tracks
|
||||
|
Loading…
Reference in New Issue
Block a user