Minor misc changes
This commit is contained in:
parent
f5c6b9e3d4
commit
cb185e4827
@ -206,10 +206,9 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
|||||||
return getResource(path);
|
return getResource(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(UUID uuid) {
|
public Optional<Player> getPlayer(UUID uuid) {
|
||||||
return getServer().getPlayer(uuid);
|
return Optional.ofNullable(getServer().getPlayer(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -311,11 +311,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Contexts> getContextForUser(User user) {
|
public Optional<Contexts> getContextForUser(User user) {
|
||||||
Player player = this.bootstrap.getPlayer(user.getUuid());
|
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getApplicableContexts(player));
|
||||||
if (player == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(this.contextManager.getApplicableContexts(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,6 +36,7 @@ import net.kyori.text.Component;
|
|||||||
import net.kyori.text.serializer.ComponentSerializers;
|
import net.kyori.text.serializer.ComponentSerializers;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ public class BungeeSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendMessage(CommandSender sender, Component message) {
|
protected void sendMessage(CommandSender sender, Component message) {
|
||||||
sender.sendMessage(net.md_5.bungee.chat.ComponentSerializer.parse(ComponentSerializers.JSON.serialize(message)));
|
sender.sendMessage(ComponentSerializer.parse(ComponentSerializers.JSON.serialize(message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -166,10 +166,9 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
|
|||||||
return getResourceAsStream(path);
|
return getResourceAsStream(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public ProxiedPlayer getPlayer(UUID uuid) {
|
public Optional<ProxiedPlayer> getPlayer(UUID uuid) {
|
||||||
return getProxy().getPlayer(uuid);
|
return Optional.ofNullable(getProxy().getPlayer(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -179,11 +179,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Contexts> getContextForUser(User user) {
|
public Optional<Contexts> getContextForUser(User user) {
|
||||||
ProxiedPlayer player = this.bootstrap.getPlayer(user.getUuid());
|
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getApplicableContexts(player));
|
||||||
if (player == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(this.contextManager.getApplicableContexts(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,6 +42,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.node.HeldPermissionComparator;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.references.HolderType;
|
import me.lucko.luckperms.common.references.HolderType;
|
||||||
@ -108,18 +109,9 @@ public class GroupListMembers extends SubCommand<Group> {
|
|||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
|
private static <T extends Comparable<T>> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
|
||||||
results = new ArrayList<>(results);
|
results = new ArrayList<>(results);
|
||||||
|
results.sort(HeldPermissionComparator.normal());
|
||||||
// we need a deterministic sort order
|
|
||||||
// even though we're comparing uuids here in some cases - it doesn't matter
|
|
||||||
// the import thing is that the order is the same each time the command is executed
|
|
||||||
results.sort((o1, o2) -> {
|
|
||||||
Comparable h1 = (Comparable) o1.getHolder();
|
|
||||||
Comparable h2 = (Comparable) o2.getHolder();
|
|
||||||
//noinspection unchecked
|
|
||||||
return h1.compareTo(h2);
|
|
||||||
});
|
|
||||||
|
|
||||||
int pageIndex = page - 1;
|
int pageIndex = page - 1;
|
||||||
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
|
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
|
||||||
|
@ -41,7 +41,9 @@ import me.lucko.luckperms.common.command.utils.TabCompletions;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
|
import me.lucko.luckperms.common.node.HeldPermissionComparator;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
|
import me.lucko.luckperms.common.node.NodeHeldPermission;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.references.HolderType;
|
import me.lucko.luckperms.common.references.HolderType;
|
||||||
import me.lucko.luckperms.common.sender.Sender;
|
import me.lucko.luckperms.common.sender.Sender;
|
||||||
@ -107,18 +109,9 @@ public class SearchCommand extends SingleCommand {
|
|||||||
return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry());
|
return TabCompletions.getPermissionTabComplete(args, plugin.getPermissionRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
|
private static <T extends Comparable<T>> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
|
||||||
results = new ArrayList<>(results);
|
results = new ArrayList<>(results);
|
||||||
|
results.sort(HeldPermissionComparator.normal());
|
||||||
// we need a deterministic sort order
|
|
||||||
// even though we're comparing uuids here in some cases - it doesn't matter
|
|
||||||
// the import thing is that the order is the same each time the command is executed
|
|
||||||
results.sort((o1, o2) -> {
|
|
||||||
Comparable h1 = (Comparable) o1.getHolder();
|
|
||||||
Comparable h2 = (Comparable) o2.getHolder();
|
|
||||||
//noinspection unchecked
|
|
||||||
return h1.compareTo(h2);
|
|
||||||
});
|
|
||||||
|
|
||||||
int pageIndex = page - 1;
|
int pageIndex = page - 1;
|
||||||
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
|
List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.node;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.HeldPermission;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class HeldPermissionComparator<T extends Comparable<T>> implements Comparator<HeldPermission<T>> {
|
||||||
|
|
||||||
|
public static <T extends Comparable<T>> Comparator<? super HeldPermission<T>> normal() {
|
||||||
|
return new HeldPermissionComparator<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Comparable<T>> Comparator<? super HeldPermission<T>> reverse() {
|
||||||
|
return HeldPermissionComparator.<T>normal().reversed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(HeldPermission<T> o1, HeldPermission<T> o2) {
|
||||||
|
int i = o1.getHolder().compareTo(o2.getHolder());
|
||||||
|
if (i != 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NodeWithContextComparator.normal().compare(o1.asNode(), o2.asNode());
|
||||||
|
}
|
||||||
|
}
|
@ -32,14 +32,14 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
public class NodeComparator implements Comparator<Node> {
|
public class NodeComparator implements Comparator<Node> {
|
||||||
|
|
||||||
private static final Comparator<Node> INSTANCE = new NodeComparator();
|
private static final Comparator<? super Node> INSTANCE = new NodeComparator();
|
||||||
private static final Comparator<Node> REVERSE = INSTANCE.reversed();
|
private static final Comparator<? super Node> REVERSE = INSTANCE.reversed();
|
||||||
|
|
||||||
public static Comparator<Node> normal() {
|
public static Comparator<? super Node> normal() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Comparator<Node> reverse() {
|
public static Comparator<? super Node> reverse() {
|
||||||
return REVERSE;
|
return REVERSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,5 +67,4 @@ public class NodeComparator implements Comparator<Node> {
|
|||||||
|
|
||||||
return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
|
return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,16 @@ import me.lucko.luckperms.api.context.ContextSet;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalLong;
|
import java.util.OptionalLong;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public final class NodeHeldPermission<T> implements HeldPermission<T> {
|
public final class NodeHeldPermission<T extends Comparable<T>> implements HeldPermission<T> {
|
||||||
public static <T> NodeHeldPermission<T> of(T holder, NodeModel nodeModel) {
|
public static <T extends Comparable<T>> NodeHeldPermission<T> of(T holder, NodeModel nodeModel) {
|
||||||
return of(holder, nodeModel.toNode());
|
return of(holder, nodeModel.toNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> NodeHeldPermission<T> of(T holder, Node node) {
|
public static <T extends Comparable<T>> NodeHeldPermission<T> of(T holder, Node node) {
|
||||||
return new NodeHeldPermission<>(holder, node);
|
return new NodeHeldPermission<>(holder, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.node;
|
package me.lucko.luckperms.common.node;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.LocalizedNode;
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.common.utils.CollationKeyCache;
|
import me.lucko.luckperms.common.utils.CollationKeyCache;
|
||||||
|
|
||||||
@ -34,26 +33,23 @@ import java.util.Comparator;
|
|||||||
/**
|
/**
|
||||||
* Compares permission nodes based upon their supposed "priority".
|
* Compares permission nodes based upon their supposed "priority".
|
||||||
*/
|
*/
|
||||||
public class NodeWithContextComparator implements Comparator<LocalizedNode> {
|
public class NodeWithContextComparator implements Comparator<Node> {
|
||||||
|
|
||||||
private static final Comparator<LocalizedNode> INSTANCE = new NodeWithContextComparator();
|
private static final Comparator<? super Node> INSTANCE = new NodeWithContextComparator();
|
||||||
private static final Comparator<LocalizedNode> REVERSE = INSTANCE.reversed();
|
private static final Comparator<? super Node> REVERSE = INSTANCE.reversed();
|
||||||
|
|
||||||
public static Comparator<LocalizedNode> normal() {
|
public static Comparator<? super Node> normal() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Comparator<LocalizedNode> reverse() {
|
public static Comparator<? super Node> reverse() {
|
||||||
return REVERSE;
|
return REVERSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NodeWithContextComparator() {}
|
private NodeWithContextComparator() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(LocalizedNode one, LocalizedNode two) {
|
public int compare(Node o1, Node o2) {
|
||||||
Node o1 = one.getNode();
|
|
||||||
Node o2 = two.getNode();
|
|
||||||
|
|
||||||
if (o1.equals(o2)) {
|
if (o1.equals(o2)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,7 @@ public interface LuckPermsBootstrap {
|
|||||||
* @param uuid the users unique id
|
* @param uuid the users unique id
|
||||||
* @return a player object, or null, if one couldn't be found.
|
* @return a player object, or null, if one couldn't be found.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
Optional<?> getPlayer(UUID uuid);
|
||||||
Object getPlayer(UUID uuid);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a uuid from a username, using the servers internal uuid cache.
|
* Lookup a uuid from a username, using the servers internal uuid cache.
|
||||||
|
@ -169,10 +169,9 @@ public class LPNukkitBootstrap extends PluginBase implements LuckPermsBootstrap
|
|||||||
return getResource(path);
|
return getResource(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(UUID uuid) {
|
public Optional<Player> getPlayer(UUID uuid) {
|
||||||
return getServer().getOnlinePlayers().get(uuid);
|
return Optional.ofNullable(getServer().getOnlinePlayers().get(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -280,11 +280,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Contexts> getContextForUser(User user) {
|
public Optional<Contexts> getContextForUser(User user) {
|
||||||
Player player = this.bootstrap.getPlayer(user.getUuid());
|
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getApplicableContexts(player));
|
||||||
if (player == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(this.contextManager.getApplicableContexts(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -262,14 +262,13 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
|||||||
return getClass().getClassLoader().getResourceAsStream(path);
|
return getClass().getClassLoader().getResourceAsStream(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Player getPlayer(UUID uuid) {
|
public Optional<Player> getPlayer(UUID uuid) {
|
||||||
if (!getGame().isServerAvailable()) {
|
if (!getGame().isServerAvailable()) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getGame().getServer().getPlayer(uuid).orElse(null);
|
return getGame().getServer().getPlayer(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -229,11 +229,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Contexts> getContextForUser(User user) {
|
public Optional<Contexts> getContextForUser(User user) {
|
||||||
Player player = this.bootstrap.getPlayer(user.getUuid());
|
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getApplicableContexts(player));
|
||||||
if (player == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(this.contextManager.getApplicableContexts(player));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user