mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 03:57:36 +01:00
Use a string version of the full static context, as opposed to the server name
This commit is contained in:
parent
2440a38e82
commit
fad8a38bdf
@ -46,6 +46,7 @@ import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.api.delegates.MetaStackFactoryDelegate;
|
||||
import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
|
||||
import me.lucko.luckperms.common.api.delegates.UserDelegate;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.event.EventFactory;
|
||||
import me.lucko.luckperms.common.event.LuckPermsEventBus;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -217,7 +218,8 @@ public class ApiProvider implements LuckPermsApi {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void registerContextCalculator(@NonNull ContextCalculator<?> contextCalculator) {
|
||||
plugin.getContextManager().registerCalculator(contextCalculator);
|
||||
ContextManager contextManager = plugin.getContextManager();
|
||||
contextManager.registerCalculator(contextCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -228,13 +230,15 @@ public class ApiProvider implements LuckPermsApi {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ContextSet getContextForPlayer(@NonNull Object player) {
|
||||
return plugin.getContextManager().getApplicableContext(player);
|
||||
ContextManager contextManager = plugin.getContextManager();
|
||||
return contextManager.getApplicableContext(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Contexts getContextsForPlayer(@NonNull Object player) {
|
||||
return plugin.getContextManager().getApplicableContexts(player);
|
||||
ContextManager contextManager = plugin.getContextManager();
|
||||
return contextManager.getApplicableContexts(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +29,6 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||
@ -70,7 +69,7 @@ public class InfoCommand extends SingleCommand {
|
||||
|
||||
Message.INFO_MIDDLE.send(sender,
|
||||
plugin.getMessagingService().map(ExtendedMessagingService::getName).orElse("None"),
|
||||
c.get(ConfigKeys.SERVER),
|
||||
plugin.getContextManager().getStaticContextString().orElse("global"),
|
||||
plugin.getPlayerCount(),
|
||||
plugin.getUniqueConnections().size(),
|
||||
DateUtil.formatTimeShort((System.currentTimeMillis() - plugin.getStartTime()) / 1000L),
|
||||
|
@ -26,10 +26,9 @@
|
||||
package me.lucko.luckperms.common.commands.sender;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.constants.Constants;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
@ -65,26 +64,22 @@ public interface Sender {
|
||||
default String getNameWithLocation() {
|
||||
String name = getName();
|
||||
|
||||
LuckPermsConfiguration config = getPlatform().getConfiguration();
|
||||
|
||||
if (config == null) {
|
||||
ContextManager<?> contextManager = getPlatform().getContextManager();
|
||||
if (contextManager == null) {
|
||||
return name;
|
||||
}
|
||||
|
||||
String location = config.get(ConfigKeys.SERVER);
|
||||
if (location == null || location.equalsIgnoreCase("global")) {
|
||||
location = "";
|
||||
|
||||
String location = contextManager.getStaticContextString().orElse(null);
|
||||
if (location == null) {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (!location.isEmpty()) {
|
||||
location = "@" + location;
|
||||
if (isConsole()) {
|
||||
return name.toLowerCase() + "@" + location;
|
||||
} else {
|
||||
return name + "@" + location;
|
||||
}
|
||||
|
||||
if (isConsole() && !location.isEmpty()) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
return name + location;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,8 +39,12 @@ 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;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link ContextManager} which caches content lookups.
|
||||
@ -89,6 +93,23 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
return formContexts(getStaticContext());
|
||||
}
|
||||
|
||||
@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("server"))) {
|
||||
// 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 new Contexts(
|
||||
|
@ -31,6 +31,8 @@ import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Manages {@link ContextCalculator}s, and calculates applicable contexts for a
|
||||
* given type.
|
||||
@ -69,6 +71,15 @@ public interface ContextManager<T> {
|
||||
*/
|
||||
Contexts getStaticContexts();
|
||||
|
||||
/**
|
||||
* Returns a string form of the managers static context
|
||||
*
|
||||
* <p>Returns an empty optional if the set is empty.</p>
|
||||
*
|
||||
* @return a string representation of {@link #getStaticContext()}
|
||||
*/
|
||||
Optional<String> getStaticContextString();
|
||||
|
||||
/**
|
||||
* Forms a {@link Contexts} instance from an {@link ImmutableContextSet}.
|
||||
*
|
||||
|
@ -152,7 +152,7 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return the context manager
|
||||
*/
|
||||
ContextManager getContextManager();
|
||||
ContextManager<?> getContextManager();
|
||||
|
||||
/**
|
||||
* Gets the cached state manager for the platform.
|
||||
|
Loading…
Reference in New Issue
Block a user