mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-10-30 23:39:33 +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.MetaStackFactoryDelegate;
|
||||||
import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
|
import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
|
||||||
import me.lucko.luckperms.common.api.delegates.UserDelegate;
|
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.EventFactory;
|
||||||
import me.lucko.luckperms.common.event.LuckPermsEventBus;
|
import me.lucko.luckperms.common.event.LuckPermsEventBus;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
@ -217,7 +218,8 @@ public class ApiProvider implements LuckPermsApi {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void registerContextCalculator(@NonNull ContextCalculator<?> contextCalculator) {
|
public void registerContextCalculator(@NonNull ContextCalculator<?> contextCalculator) {
|
||||||
plugin.getContextManager().registerCalculator(contextCalculator);
|
ContextManager contextManager = plugin.getContextManager();
|
||||||
|
contextManager.registerCalculator(contextCalculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -228,13 +230,15 @@ public class ApiProvider implements LuckPermsApi {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public ContextSet getContextForPlayer(@NonNull Object player) {
|
public ContextSet getContextForPlayer(@NonNull Object player) {
|
||||||
return plugin.getContextManager().getApplicableContext(player);
|
ContextManager contextManager = plugin.getContextManager();
|
||||||
|
return contextManager.getApplicableContext(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Contexts getContextsForPlayer(@NonNull Object player) {
|
public Contexts getContextsForPlayer(@NonNull Object player) {
|
||||||
return plugin.getContextManager().getApplicableContexts(player);
|
ContextManager contextManager = plugin.getContextManager();
|
||||||
|
return contextManager.getApplicableContexts(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.abstraction.SingleCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
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.config.LuckPermsConfiguration;
|
||||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
@ -70,7 +69,7 @@ public class InfoCommand extends SingleCommand {
|
|||||||
|
|
||||||
Message.INFO_MIDDLE.send(sender,
|
Message.INFO_MIDDLE.send(sender,
|
||||||
plugin.getMessagingService().map(ExtendedMessagingService::getName).orElse("None"),
|
plugin.getMessagingService().map(ExtendedMessagingService::getName).orElse("None"),
|
||||||
c.get(ConfigKeys.SERVER),
|
plugin.getContextManager().getStaticContextString().orElse("global"),
|
||||||
plugin.getPlayerCount(),
|
plugin.getPlayerCount(),
|
||||||
plugin.getUniqueConnections().size(),
|
plugin.getUniqueConnections().size(),
|
||||||
DateUtil.formatTimeShort((System.currentTimeMillis() - plugin.getStartTime()) / 1000L),
|
DateUtil.formatTimeShort((System.currentTimeMillis() - plugin.getStartTime()) / 1000L),
|
||||||
|
@ -26,10 +26,9 @@
|
|||||||
package me.lucko.luckperms.common.commands.sender;
|
package me.lucko.luckperms.common.commands.sender;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
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.CommandPermission;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
|
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
@ -65,26 +64,22 @@ public interface Sender {
|
|||||||
default String getNameWithLocation() {
|
default String getNameWithLocation() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
|
|
||||||
LuckPermsConfiguration config = getPlatform().getConfiguration();
|
ContextManager<?> contextManager = getPlatform().getContextManager();
|
||||||
|
if (contextManager == null) {
|
||||||
if (config == null) {
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String location = config.get(ConfigKeys.SERVER);
|
|
||||||
if (location == null || location.equalsIgnoreCase("global")) {
|
String location = contextManager.getStaticContextString().orElse(null);
|
||||||
location = "";
|
if (location == null) {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!location.isEmpty()) {
|
if (isConsole()) {
|
||||||
location = "@" + location;
|
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 me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
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.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract implementation of {@link ContextManager} which caches content lookups.
|
* 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());
|
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
|
@Override
|
||||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||||
return new Contexts(
|
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.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages {@link ContextCalculator}s, and calculates applicable contexts for a
|
* Manages {@link ContextCalculator}s, and calculates applicable contexts for a
|
||||||
* given type.
|
* given type.
|
||||||
@ -69,6 +71,15 @@ public interface ContextManager<T> {
|
|||||||
*/
|
*/
|
||||||
Contexts getStaticContexts();
|
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}.
|
* Forms a {@link Contexts} instance from an {@link ImmutableContextSet}.
|
||||||
*
|
*
|
||||||
|
@ -152,7 +152,7 @@ public interface LuckPermsPlugin {
|
|||||||
*
|
*
|
||||||
* @return the context manager
|
* @return the context manager
|
||||||
*/
|
*/
|
||||||
ContextManager getContextManager();
|
ContextManager<?> getContextManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cached state manager for the platform.
|
* Gets the cached state manager for the platform.
|
||||||
|
Loading…
Reference in New Issue
Block a user