mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-13 06:14:25 +01:00
Cleanup a bit
This commit is contained in:
parent
281060a972
commit
9dc2278083
@ -135,8 +135,7 @@ public class MetaUtils {
|
||||
for (Node n : toRemove) {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {
|
||||
}
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
}
|
||||
|
||||
Node.Builder metaNode = LuckPerms.getApi().buildNode("meta." + node + "." + value).setValue(true);
|
||||
|
@ -34,15 +34,11 @@ import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.lucko.luckperms.api.MetaUtils.escapeCharacters;
|
||||
import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters;
|
||||
@ -75,15 +71,7 @@ public class VaultChatHook extends Chat {
|
||||
perms.log("Setting meta: '" + node + "' for " + holder.getObjectName() + " on world " + world + ", server " + perms.getServer());
|
||||
|
||||
perms.getScheduler().execute(() -> {
|
||||
List<Node> toRemove = holder.getNodes().stream()
|
||||
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(node))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
holder.removeIf(n -> n.isMeta() && n.getMeta().getKey().equals(node));
|
||||
|
||||
Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true);
|
||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||
@ -93,10 +81,7 @@ public class VaultChatHook extends Chat {
|
||||
metaNode.setWorld(finalWorld);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(metaNode.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
holder.setPermissionUnchecked(metaNode.build());
|
||||
perms.save(holder);
|
||||
});
|
||||
}
|
||||
@ -111,15 +96,7 @@ public class VaultChatHook extends Chat {
|
||||
perms.getScheduler().execute(() -> {
|
||||
|
||||
// remove all prefixes/suffixes directly set on the user/group
|
||||
List<Node> toRemove = holder.getNodes().stream()
|
||||
.filter(n -> prefix ? n.isPrefix() : n.isSuffix())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
holder.removeIf(n -> prefix ? n.isPrefix() : n.isSuffix());
|
||||
|
||||
// find the max inherited priority & add 10
|
||||
MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(perms.createContextForWorld(finalWorld)));
|
||||
@ -134,10 +111,7 @@ public class VaultChatHook extends Chat {
|
||||
chatMetaNode.setWorld(finalWorld);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(chatMetaNode.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
holder.setPermissionUnchecked(chatMetaNode.build());
|
||||
perms.save(holder);
|
||||
});
|
||||
}
|
||||
|
@ -88,12 +88,7 @@ public class MetaRemovePrefix extends SharedSubCommand {
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {
|
||||
}
|
||||
});
|
||||
toRemove.forEach(holder::unsetPermissionUnchecked);
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(holder, sender, plugin);
|
||||
|
@ -88,12 +88,7 @@ public class MetaRemoveSuffix extends SharedSubCommand {
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {
|
||||
}
|
||||
});
|
||||
toRemove.forEach(holder::unsetPermissionUnchecked);
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(holder, sender, plugin);
|
||||
|
@ -88,11 +88,7 @@ public class MetaRemoveTempPrefix extends SharedSubCommand {
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
toRemove.forEach(holder::unsetPermissionUnchecked);
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(holder, sender, plugin);
|
||||
|
@ -88,12 +88,7 @@ public class MetaRemoveTempSuffix extends SharedSubCommand {
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {
|
||||
}
|
||||
});
|
||||
toRemove.forEach(holder::unsetPermissionUnchecked);
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(holder, sender, plugin);
|
||||
|
@ -438,6 +438,20 @@ public abstract class PermissionHolder {
|
||||
invalidateCache(false);
|
||||
}
|
||||
|
||||
public boolean removeIfTransient(Predicate<Node> predicate) {
|
||||
boolean result;
|
||||
|
||||
synchronized (nodes) {
|
||||
result = transientNodes.removeIf(predicate);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
invalidateCache(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines and returns this holders nodes in a priority order.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user