From 2e16b15b0e2c6778a85e5bcac6f29f8f491a81df Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 14 May 2019 20:32:35 +0100 Subject: [PATCH] Change Sender#getNameWithLocation behaviour --- .../common/context/ContextSetFormatter.java | 55 ------------------- .../lucko/luckperms/common/sender/Sender.java | 26 ++++++--- 2 files changed, 18 insertions(+), 63 deletions(-) delete mode 100644 common/src/main/java/me/lucko/luckperms/common/context/ContextSetFormatter.java diff --git a/common/src/main/java/me/lucko/luckperms/common/context/ContextSetFormatter.java b/common/src/main/java/me/lucko/luckperms/common/context/ContextSetFormatter.java deleted file mode 100644 index 581127063..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/context/ContextSetFormatter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * 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.context; - -import me.lucko.luckperms.api.Contexts; -import me.lucko.luckperms.api.context.ContextSet; - -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -public final class ContextSetFormatter { - private ContextSetFormatter() {} - - public static Optional toMinimalString(ContextSet contextSet) { - Set> entries = contextSet.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(";"))); - } - } - -} diff --git a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java index 360b07910..278cff57d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java +++ b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java @@ -25,16 +25,19 @@ package me.lucko.luckperms.common.sender; +import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; +import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.context.ContextManager; -import me.lucko.luckperms.common.context.ContextSetFormatter; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import net.kyori.text.Component; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; /** * Wrapper interface to represent a CommandSender/CommandSource within the common command implementations. @@ -78,16 +81,23 @@ public interface Sender { return name; } - String location = ContextSetFormatter.toMinimalString(contextManager.getStaticContext()).orElse(null); - if (location == null) { + ImmutableContextSet staticContext = contextManager.getStaticContext(); + + String location; + if (staticContext.isEmpty()) { return name; + } else if (staticContext.size() == 1) { + location = staticContext.iterator().next().getValue(); + } else { + Set servers = staticContext.getValues(Contexts.SERVER_KEY); + if (servers.size() == 1) { + location = servers.iterator().next(); + } else { + location = staticContext.toSet().stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";")); + } } - if (isConsole()) { - return name.toLowerCase() + "@" + location; - } else { - return name + "@" + location; - } + return name + "@" + location; } /**