mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2024-11-28 13:15:23 +01:00
More fixes on handling of server contexts. Fixes #88
* Server contexts will be automatically added if not found on set. * Flag definitions will automatically add a server context if none is found on deserialization. * Option and Flag GUI will fallback to no server context if none is found.
This commit is contained in:
parent
90d7db65cc
commit
63005e72f8
@ -941,15 +941,24 @@ private Consumer<CommandSender> createCustomFlagConsumer(GDPermissionUser src, G
|
||||
private Consumer<CommandSender> createFlagConsumer(GDPermissionUser src, GDClaim claim, Flag flag, FlagContextHolder flagHolder, Tristate newValue, Set<Context> contexts, MenuType displayType) {
|
||||
final Player player = src.getOnlinePlayer();
|
||||
return consumer -> {
|
||||
Set<Context> newContexts = new HashSet<>();
|
||||
GDCauseStackManager.getInstance().pushCause(player);
|
||||
final boolean isCustom = UIHelper.containsCustomContext(contexts);
|
||||
if (!isCustom && displayType == MenuType.CLAIM) {
|
||||
Set<Context> newContexts = new HashSet<>(contexts);
|
||||
if (displayType == MenuType.CLAIM) {
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Context context = iterator.next();
|
||||
if (context.getKey().equals("gd_claim_default")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
newContexts.add(claim.getContext());
|
||||
} else {
|
||||
newContexts.addAll(contexts);
|
||||
}
|
||||
|
||||
Context serverContext = null;
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
serverContext = new Context("server", serverName);
|
||||
}
|
||||
// Check server context
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
boolean hasServerContext = false;
|
||||
@ -961,11 +970,8 @@ private Consumer<CommandSender> createFlagConsumer(GDPermissionUser src, GDClaim
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
newContexts.add(new Context("server", serverName));
|
||||
}
|
||||
if (!hasServerContext && serverContext != null) {
|
||||
newContexts.add(serverContext);
|
||||
}
|
||||
|
||||
GDFlagPermissionEvent.Set event = new GDFlagPermissionEvent.Set(this.subject, flag, newValue, newContexts);
|
||||
@ -976,6 +982,11 @@ private Consumer<CommandSender> createFlagConsumer(GDPermissionUser src, GDClaim
|
||||
}
|
||||
|
||||
PermissionResult result = PermissionUtil.getInstance().setPermissionValue(this.subject, flag, newValue, newContexts);
|
||||
if (!result.successful()) {
|
||||
// Try again without server context
|
||||
newContexts.remove(serverContext);
|
||||
result = PermissionUtil.getInstance().setPermissionValue(this.subject, flag, newValue, newContexts, false, true);
|
||||
}
|
||||
if (result.successful()) {
|
||||
showFlagPermissions(src, claim, displayType);
|
||||
}
|
||||
|
@ -781,14 +781,23 @@ private Consumer<CommandSender> newOptionValueConsumer(GDPermissionUser src, GDC
|
||||
newValue = value == null ? "undefined" :String.valueOf(value);
|
||||
}
|
||||
|
||||
Set<Context> newContexts = new HashSet<>();
|
||||
final boolean isCustom = this.containsCustomContext(option, contexts);
|
||||
if (!isCustom && displayType == MenuType.CLAIM) {
|
||||
Set<Context> newContexts = new HashSet<>(contexts);
|
||||
if (displayType == MenuType.CLAIM) {
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Context context = iterator.next();
|
||||
if (context.getKey().equals("gd_claim_default")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
newContexts.add(claim.getContext());
|
||||
} else {
|
||||
newContexts.addAll(contexts);
|
||||
}
|
||||
|
||||
Context serverContext = null;
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
serverContext = new Context("server", serverName);
|
||||
}
|
||||
// Check server context
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
boolean hasServerContext = false;
|
||||
@ -800,13 +809,15 @@ private Consumer<CommandSender> newOptionValueConsumer(GDPermissionUser src, GDC
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
newContexts.add(new Context("server", serverName));
|
||||
}
|
||||
if (!hasServerContext && serverContext != null) {
|
||||
newContexts.add(serverContext);
|
||||
}
|
||||
final PermissionResult result = PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts);
|
||||
if (!result.successful()) {
|
||||
// Try again without server context
|
||||
newContexts.remove(serverContext);
|
||||
PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts, false);
|
||||
}
|
||||
if (result.successful()) {
|
||||
if (option == Options.PLAYER_WEATHER) {
|
||||
CommonEntityEventHandler.getInstance().checkPlayerWeather(src, claim, claim, true);
|
||||
|
@ -39,7 +39,7 @@
|
||||
import com.griefdefender.permission.flag.GDFlagData;
|
||||
import com.griefdefender.permission.flag.GDFlagDefinition;
|
||||
import com.griefdefender.registry.FlagRegistryModule;
|
||||
|
||||
import com.griefdefender.util.PermissionUtil;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||
@ -146,6 +146,18 @@ public FlagDefinition deserialize(TypeToken<?> type, ConfigurationNode node) thr
|
||||
contexts.add(new Context(key, value));
|
||||
}
|
||||
}
|
||||
// Check for required server context and add if not found
|
||||
boolean hasServerContext = false;
|
||||
for (Context context : contexts) {
|
||||
if (context.getKey().equalsIgnoreCase("server")) {
|
||||
hasServerContext = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName() == null ? "global" : PermissionUtil.getInstance().getServerName();
|
||||
contexts.add(new Context("server", serverName));
|
||||
}
|
||||
flagDefinition.setContexts(contexts);
|
||||
}
|
||||
return flagDefinition;
|
||||
|
@ -733,8 +733,12 @@ public List<String> getOptionValueList(GDPermissionHolder holder, Option option,
|
||||
return list;
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String key, String value, Set<Context> contexts) {
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String key, String value, Set<Context> contexts, boolean check) {
|
||||
DataMutateResult result = null;
|
||||
if (check) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value);
|
||||
}
|
||||
ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy();
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -768,8 +772,12 @@ public PermissionResult setOptionValue(GDPermissionHolder holder, String key, St
|
||||
return new GDPermissionResult(ResultTypes.FAILURE);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save) {
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
DataMutateResult result = null;
|
||||
if (check) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value.name());
|
||||
}
|
||||
ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy();
|
||||
final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build();
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
@ -803,6 +811,8 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per
|
||||
}
|
||||
|
||||
public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value);
|
||||
MutableContextSet contextSet = this.getLPContexts(contexts);
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -814,6 +824,8 @@ public void setTransientOption(GDPermissionHolder holder, String permission, Str
|
||||
}
|
||||
|
||||
public void setTransientPermission(GDPermissionHolder holder, String permission, Boolean value, Set<Context> contexts) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value.toString());
|
||||
MutableContextSet contextSet = this.getLPContexts(contexts);
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -886,6 +898,20 @@ private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set)
|
||||
holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
|
||||
}
|
||||
|
||||
private void checkServerContext(Set<Context> contexts, String value) {
|
||||
for (Context context : contexts) {
|
||||
if (context.getKey().equalsIgnoreCase("server")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String serverName = this.luckPermsApi.getServerName();
|
||||
if (serverName != null) {
|
||||
contexts.add(new Context("server", serverName));
|
||||
} else {
|
||||
contexts.add(new Context("server", "global"));
|
||||
}
|
||||
}
|
||||
|
||||
private static class DefaultDataQueryOrderFunction implements DataQueryOrderFunction {
|
||||
|
||||
@Override
|
||||
|
@ -300,9 +300,24 @@ public interface PermissionProvider {
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @return The permission result
|
||||
*/
|
||||
PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts);
|
||||
default PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
return this.setOptionValue(holder, permission, value, contexts, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option and value with contexts to a holder.
|
||||
*
|
||||
* @param holder The holder
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @return The permission result
|
||||
*/
|
||||
PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts, boolean check);
|
||||
|
||||
/**
|
||||
* Sets a permission and value with contexts to a holder.
|
||||
@ -314,7 +329,7 @@ public interface PermissionProvider {
|
||||
* @return The permission result
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts) {
|
||||
return this.setPermissionValue(holder, flag, value, contexts, true);
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,11 +339,12 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag
|
||||
* @param flag The flag to use for permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @param save Whether a save should occur
|
||||
* @return The permission result
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, save);
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, check, save);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,7 +357,7 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag
|
||||
* @return Whether the set permission operation was successful
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts) {
|
||||
return this.setPermissionValue(holder, permission, value, contexts, true);
|
||||
return this.setPermissionValue(holder, permission, value, contexts, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,10 +367,11 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, String pe
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @param save Whether a save should occur
|
||||
* @return Whether the set permission operation was successful
|
||||
*/
|
||||
PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save);
|
||||
PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save);
|
||||
|
||||
/**
|
||||
* Sets a transient option and value with contexts to a holder.
|
||||
|
@ -407,7 +407,7 @@ public List<String> getOptionValueList(GDPermissionHolder holder, Option option,
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts, boolean check) {
|
||||
return convertResult(holderToPEXSubject(holder).data().update(data -> data.setOption(contextsGDToPEX(contexts), permission, value))).join();
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ public void refreshCachedData(GDPermissionHolder holder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save) {
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return convertResult(holderToPEXSubject(holder).data().update(data -> data.setPermission(contextsGDToPEX(contexts), permission, intFromTristate(value)))).join();
|
||||
}
|
||||
|
||||
|
@ -196,23 +196,27 @@ public List<String> getOptionValueList(GDPermissionHolder holder, Option option,
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts);
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts, true);
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts, boolean check) {
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts, check);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, true);
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, true, true);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, true);
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, true, true);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, save);
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, check, save);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, save);
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, check, save);
|
||||
}
|
||||
|
||||
public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
|
@ -941,15 +941,24 @@ private Consumer<CommandSource> createCustomFlagConsumer(GDPermissionUser src, G
|
||||
private Consumer<CommandSource> createFlagConsumer(GDPermissionUser src, GDClaim claim, Flag flag, FlagContextHolder flagHolder, Tristate newValue, Set<Context> contexts, MenuType displayType) {
|
||||
final Player player = src.getOnlinePlayer();
|
||||
return consumer -> {
|
||||
Set<Context> newContexts = new HashSet<>();
|
||||
GDCauseStackManager.getInstance().pushCause(player);
|
||||
final boolean isCustom = UIHelper.containsCustomContext(contexts);
|
||||
if (!isCustom && displayType == MenuType.CLAIM) {
|
||||
Set<Context> newContexts = new HashSet<>(contexts);
|
||||
if (displayType == MenuType.CLAIM) {
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Context context = iterator.next();
|
||||
if (context.getKey().equals("gd_claim_default")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
newContexts.add(claim.getContext());
|
||||
} else {
|
||||
newContexts.addAll(contexts);
|
||||
}
|
||||
|
||||
Context serverContext = null;
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
serverContext = new Context("server", serverName);
|
||||
}
|
||||
// Check server context
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
boolean hasServerContext = false;
|
||||
@ -961,11 +970,8 @@ private Consumer<CommandSource> createFlagConsumer(GDPermissionUser src, GDClaim
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
newContexts.add(new Context("server", serverName));
|
||||
}
|
||||
if (!hasServerContext && serverContext != null) {
|
||||
newContexts.add(serverContext);
|
||||
}
|
||||
|
||||
GDFlagPermissionEvent.Set event = new GDFlagPermissionEvent.Set(this.subject, flag, newValue, newContexts);
|
||||
@ -976,6 +982,11 @@ private Consumer<CommandSource> createFlagConsumer(GDPermissionUser src, GDClaim
|
||||
}
|
||||
|
||||
PermissionResult result = PermissionUtil.getInstance().setPermissionValue(this.subject, flag, newValue, newContexts);
|
||||
if (!result.successful()) {
|
||||
// Try again without server context
|
||||
newContexts.remove(serverContext);
|
||||
result = PermissionUtil.getInstance().setPermissionValue(this.subject, flag, newValue, newContexts, false, true);
|
||||
}
|
||||
if (result.successful()) {
|
||||
showFlagPermissions(src, claim, displayType);
|
||||
}
|
||||
|
@ -781,33 +781,43 @@ private Consumer<CommandSource> newOptionValueConsumer(GDPermissionUser src, GDC
|
||||
newValue = value == null ? "undefined" :String.valueOf(value);
|
||||
}
|
||||
|
||||
Set<Context> newContexts = new HashSet<>();
|
||||
final boolean isCustom = this.containsCustomContext(option, contexts);
|
||||
if (!isCustom && displayType == MenuType.CLAIM) {
|
||||
Set<Context> newContexts = new HashSet<>(contexts);
|
||||
if (displayType == MenuType.CLAIM) {
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Context context = iterator.next();
|
||||
if (context.getKey().equals("gd_claim_default")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
newContexts.add(claim.getContext());
|
||||
} else {
|
||||
newContexts.addAll(contexts);
|
||||
}
|
||||
|
||||
Context serverContext = null;
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
serverContext = new Context("server", serverName);
|
||||
}
|
||||
// Check server context
|
||||
final Iterator<Context> iterator = newContexts.iterator();
|
||||
boolean hasServerContext = false;
|
||||
while (iterator.hasNext()) {
|
||||
final Context context = iterator.next();
|
||||
if (context.getKey().equals("server")) {
|
||||
//iterator.remove();
|
||||
hasServerContext = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName();
|
||||
if (serverName != null) {
|
||||
newContexts.add(new Context("server", serverName));
|
||||
}
|
||||
if (!hasServerContext && serverContext != null) {
|
||||
newContexts.add(serverContext);
|
||||
}
|
||||
final PermissionResult result = PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts);
|
||||
if (!result.successful()) {
|
||||
// Try again without server context
|
||||
newContexts.remove(serverContext);
|
||||
PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts, false);
|
||||
}
|
||||
if (result.successful()) {
|
||||
if (option == Options.PLAYER_WEATHER) {
|
||||
CommonEntityEventHandler.getInstance().checkPlayerWeather(src, claim, claim, true);
|
||||
|
@ -39,7 +39,7 @@
|
||||
import com.griefdefender.permission.flag.GDFlagData;
|
||||
import com.griefdefender.permission.flag.GDFlagDefinition;
|
||||
import com.griefdefender.registry.FlagRegistryModule;
|
||||
|
||||
import com.griefdefender.util.PermissionUtil;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||
@ -146,6 +146,17 @@ public FlagDefinition deserialize(TypeToken<?> type, ConfigurationNode node) thr
|
||||
contexts.add(new Context(key, value));
|
||||
}
|
||||
}
|
||||
boolean hasServerContext = false;
|
||||
for (Context context : contexts) {
|
||||
if (context.getKey().equalsIgnoreCase("server")) {
|
||||
hasServerContext = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasServerContext) {
|
||||
final String serverName = PermissionUtil.getInstance().getServerName() == null ? "global" : PermissionUtil.getInstance().getServerName();
|
||||
contexts.add(new Context("server", serverName));
|
||||
}
|
||||
flagDefinition.setContexts(contexts);
|
||||
}
|
||||
return flagDefinition;
|
||||
|
@ -729,8 +729,12 @@ public List<String> getOptionValueList(GDPermissionHolder holder, Option option,
|
||||
return list;
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String key, String value, Set<Context> contexts) {
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String key, String value, Set<Context> contexts, boolean check) {
|
||||
DataMutateResult result = null;
|
||||
if (check) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value);
|
||||
}
|
||||
ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy();
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -764,8 +768,12 @@ public PermissionResult setOptionValue(GDPermissionHolder holder, String key, St
|
||||
return new GDPermissionResult(ResultTypes.FAILURE);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save) {
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
DataMutateResult result = null;
|
||||
if (check) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value.name());
|
||||
}
|
||||
ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy();
|
||||
final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build();
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
@ -799,6 +807,8 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per
|
||||
}
|
||||
|
||||
public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value);
|
||||
MutableContextSet contextSet = this.getLPContexts(contexts);
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -810,6 +820,8 @@ public void setTransientOption(GDPermissionHolder holder, String permission, Str
|
||||
}
|
||||
|
||||
public void setTransientPermission(GDPermissionHolder holder, String permission, Boolean value, Set<Context> contexts) {
|
||||
// If no server context exists, add global
|
||||
this.checkServerContext(contexts, value.toString());
|
||||
MutableContextSet contextSet = this.getLPContexts(contexts);
|
||||
final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
|
||||
if (permissionHolder == null) {
|
||||
@ -882,6 +894,20 @@ private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set)
|
||||
holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey)));
|
||||
}
|
||||
|
||||
private void checkServerContext(Set<Context> contexts, String value) {
|
||||
for (Context context : contexts) {
|
||||
if (context.getKey().equalsIgnoreCase("server")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String serverName = this.luckPermsApi.getServerName();
|
||||
if (serverName != null) {
|
||||
contexts.add(new Context("server", serverName));
|
||||
} else {
|
||||
contexts.add(new Context("server", "global"));
|
||||
}
|
||||
}
|
||||
|
||||
private static class DefaultDataQueryOrderFunction implements DataQueryOrderFunction {
|
||||
|
||||
@Override
|
||||
|
@ -300,9 +300,24 @@ public interface PermissionProvider {
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @return The permission result
|
||||
*/
|
||||
PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts);
|
||||
default PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
return this.setOptionValue(holder, permission, value, contexts, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option and value with contexts to a holder.
|
||||
*
|
||||
* @param holder The holder
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @return The permission result
|
||||
*/
|
||||
PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts, boolean check);
|
||||
|
||||
/**
|
||||
* Sets a permission and value with contexts to a holder.
|
||||
@ -314,7 +329,7 @@ public interface PermissionProvider {
|
||||
* @return The permission result
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts) {
|
||||
return this.setPermissionValue(holder, flag, value, contexts, true);
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,11 +339,12 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag
|
||||
* @param flag The flag to use for permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @param save Whether a save should occur
|
||||
* @return The permission result
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, save);
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return this.setPermissionValue(holder, flag.getPermission(), value, contexts, check, save);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,7 +357,7 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag
|
||||
* @return Whether the set permission operation was successful
|
||||
*/
|
||||
default PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts) {
|
||||
return this.setPermissionValue(holder, permission, value, contexts, true);
|
||||
return this.setPermissionValue(holder, permission, value, contexts, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,10 +367,11 @@ default PermissionResult setPermissionValue(GDPermissionHolder holder, String pe
|
||||
* @param permission The permission
|
||||
* @param value The value
|
||||
* @param contexts The contexts
|
||||
* @param check Whether to check and apply a server context if none exists
|
||||
* @param save Whether a save should occur
|
||||
* @return Whether the set permission operation was successful
|
||||
*/
|
||||
PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save);
|
||||
PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save);
|
||||
|
||||
/**
|
||||
* Sets a transient option and value with contexts to a holder.
|
||||
|
@ -190,23 +190,27 @@ public List<String> getOptionValueList(GDPermissionHolder holder, Option option,
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts);
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts, true);
|
||||
}
|
||||
|
||||
public PermissionResult setOptionValue(GDPermissionHolder holder, String permission, String value, Set<Context> contexts, boolean check) {
|
||||
return PERMISSION_PROVIDER.setOptionValue(holder, permission, value, contexts, check);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, true);
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, true, true);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, true);
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, true, true);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, save);
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, flag, value, contexts, check, save);
|
||||
}
|
||||
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, save);
|
||||
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
|
||||
return PERMISSION_PROVIDER.setPermissionValue(holder, permission, value, contexts, check, save);
|
||||
}
|
||||
|
||||
public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set<Context> contexts) {
|
||||
|
Loading…
Reference in New Issue
Block a user