mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
add option to ignore vault world parameters
This commit is contained in:
parent
687804de2c
commit
ed5892eb56
@ -75,6 +75,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private void saveMeta(PermissionHolder holder, String world, String node, String value) {
|
||||
String finalWorld = perms.isIgnoreWorld() ? null : world;
|
||||
if (holder == null) return;
|
||||
if (node.equals("")) return;
|
||||
|
||||
@ -96,8 +97,8 @@ public class VaultChatHook extends Chat {
|
||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||
metaNode.setServer(perms.getServer());
|
||||
}
|
||||
if (world != null && !world.equals("")) {
|
||||
metaNode.setServer(perms.getServer()).setWorld(world);
|
||||
if (finalWorld != null && !finalWorld.equals("")) {
|
||||
metaNode.setServer(perms.getServer()).setWorld(finalWorld);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -109,6 +110,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private void setChatMeta(boolean prefix, PermissionHolder holder, String value, String world) {
|
||||
String finalWorld = perms.isIgnoreWorld() ? null : world;
|
||||
if (holder == null) return;
|
||||
if (value.equals("")) return;
|
||||
|
||||
@ -119,8 +121,8 @@ public class VaultChatHook extends Chat {
|
||||
node.setServer(perms.getServer());
|
||||
}
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
node.setServer(perms.getServer()).setWorld(world);
|
||||
if (finalWorld != null && !finalWorld.equals("")) {
|
||||
node.setServer(perms.getServer()).setWorld(finalWorld);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -132,6 +134,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private String getUserMeta(User user, String world, String node, String defaultValue) {
|
||||
world = perms.isIgnoreWorld() ? null : world;
|
||||
if (user == null) return defaultValue;
|
||||
node = escapeCharacters(node);
|
||||
|
||||
@ -151,6 +154,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private String getUserChatMeta(boolean prefix, User user, String world) {
|
||||
world = perms.isIgnoreWorld() ? null : world;
|
||||
if (user == null) return "";
|
||||
|
||||
if (!perms.getVaultUserManager().containsUser(user.getUuid())) {
|
||||
@ -169,6 +173,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private String getGroupMeta(Group group, String world, String node, String defaultValue) {
|
||||
world = perms.isIgnoreWorld() ? null : world;
|
||||
if (group == null) return defaultValue;
|
||||
if (node.equals("")) return defaultValue;
|
||||
node = escapeCharacters(node);
|
||||
@ -200,6 +205,7 @@ public class VaultChatHook extends Chat {
|
||||
}
|
||||
|
||||
private String getGroupChatMeta(boolean prefix, Group group, String world) {
|
||||
world = perms.isIgnoreWorld() ? null : world;
|
||||
if (group == null) return "";
|
||||
|
||||
int priority = Integer.MIN_VALUE;
|
||||
|
@ -42,6 +42,7 @@ public class VaultHook {
|
||||
permissionHook.setPlugin(plugin);
|
||||
permissionHook.setServer(plugin.getConfiguration().getVaultServer());
|
||||
permissionHook.setIncludeGlobal(plugin.getConfiguration().isVaultIncludingGlobal());
|
||||
permissionHook.setIncludeGlobal(plugin.getConfiguration().isVaultIgnoreWorld());
|
||||
permissionHook.setup();
|
||||
|
||||
if (chatHook == null) {
|
||||
|
@ -61,6 +61,10 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
@Setter
|
||||
private boolean includeGlobal = true;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean ignoreWorld = false;
|
||||
|
||||
public void setup() {
|
||||
vaultUserManager = new VaultUserManager(plugin, this);
|
||||
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 1L, 1L);
|
||||
@ -164,6 +168,7 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, @NonNull String player, @NonNull String permission) {
|
||||
world = ignoreWorld ? null : world;
|
||||
log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + server);
|
||||
User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
@ -184,22 +189,25 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) {
|
||||
log("Adding permission to player " + player + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Adding permission to player " + player + ": '" + permission + "' on world " + finalWorld + ", server " + server);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
scheduleTask(() -> add(world, user, permission));
|
||||
scheduleTask(() -> add(finalWorld, user, permission));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) {
|
||||
log("Removing permission from player " + player + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Removing permission from player " + player + ": '" + permission + "' on world " + finalWorld + ", server " + server);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
scheduleTask(() -> remove(world, user, permission));
|
||||
scheduleTask(() -> remove(finalWorld, user, permission));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
world = ignoreWorld ? null : world;
|
||||
log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + server);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
return objectHas(world, group, permission);
|
||||
@ -207,30 +215,33 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
log("Adding permission to group " + groupName + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Adding permission to group " + groupName + ": '" + permission + "' on world " + finalWorld + ", server " + server);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
scheduleTask(() -> add(world, group, permission));
|
||||
scheduleTask(() -> add(finalWorld, group, permission));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
log("Removing permission from group " + groupName + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Removing permission from group " + groupName + ": '" + permission + "' on world " + finalWorld + ", server " + server);
|
||||
final Group group = plugin.getGroupManager().get(groupName);
|
||||
scheduleTask(() -> remove(world, group, permission));
|
||||
scheduleTask(() -> remove(finalWorld, group, permission));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) {
|
||||
log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Checking if player " + player + " is in group: " + group + " on world " + finalWorld + ", server " + server);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
return user.getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnWorld(world, true, false))
|
||||
.filter(n -> n.shouldApplyOnWorld(finalWorld, true, false))
|
||||
.map(Node::getGroupName)
|
||||
.filter(s -> s.equalsIgnoreCase(group))
|
||||
.findAny().isPresent();
|
||||
@ -238,7 +249,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
log("Adding player " + player + " to group: '" + groupName + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Adding player " + player + " to group: '" + groupName + "' on world " + finalWorld + ", server " + server);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
@ -247,8 +259,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
scheduleTask(() -> {
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.addGroup(group, server, world);
|
||||
if (finalWorld != null && !finalWorld.equals("")) {
|
||||
user.addGroup(group, server, finalWorld);
|
||||
} else {
|
||||
user.addGroup(group, server);
|
||||
}
|
||||
@ -260,7 +272,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
log("Removing player " + player + " from group: '" + groupName + "' on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Removing player " + player + " from group: '" + groupName + "' on world " + finalWorld + ", server " + server);
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return false;
|
||||
|
||||
@ -269,8 +282,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
scheduleTask(() -> {
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.removeGroup(group, server, world);
|
||||
if (finalWorld != null && !finalWorld.equals("")) {
|
||||
user.removeGroup(group, server, finalWorld);
|
||||
} else {
|
||||
user.removeGroup(group, server);
|
||||
}
|
||||
@ -282,14 +295,15 @@ public class VaultPermissionHook extends Permission implements Runnable {
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, @NonNull String player) {
|
||||
log("Getting groups of player: " + player + ", on world " + world + ", server " + server);
|
||||
String finalWorld = ignoreWorld ? null : world;
|
||||
log("Getting groups of player: " + player + ", on world " + finalWorld + ", server " + server);
|
||||
User user = plugin.getUserManager().get(player);
|
||||
if (user == null) return new String[0];
|
||||
|
||||
return user.getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnWorld(world, true, false))
|
||||
.filter(n -> n.shouldApplyOnWorld(finalWorld, true, false))
|
||||
.map(Node::getGroupName)
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
@ -80,6 +80,9 @@ vault-server: global
|
||||
# If global permissions should be considered when retrieving meta or player groups
|
||||
vault-include-global: true
|
||||
|
||||
# If Vault operations should ignore any world arguments if supplied.
|
||||
vault-ignore-world: false
|
||||
|
||||
# Mirrors world names. Whenever LuckPerms checks what world a user is in, if the world name is in this list, the value assigned
|
||||
# will be sent forward for permission calculation instead.
|
||||
world-rewrite:
|
||||
|
@ -62,6 +62,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
|
||||
private boolean autoOp;
|
||||
private String vaultServer;
|
||||
private boolean vaultIncludingGlobal;
|
||||
private boolean vaultIgnoreWorld;
|
||||
private Map<String, String> worldRewrites;
|
||||
private Map<String, String> groupNameRewrites;
|
||||
private DatastoreConfiguration databaseValues;
|
||||
@ -101,6 +102,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
|
||||
commandsAllowOp = getBoolean("commands-allow-op", true);
|
||||
vaultServer = getString("vault-server", "global");
|
||||
vaultIncludingGlobal = getBoolean("vault-include-global", true);
|
||||
vaultIgnoreWorld = getBoolean("vault-ignore-world", false);
|
||||
worldRewrites = ImmutableMap.copyOf(getMap("world-rewrite", Collections.emptyMap()));
|
||||
groupNameRewrites = ImmutableMap.copyOf(getMap("group-name-rewrite", Collections.emptyMap()));
|
||||
databaseValues = new DatastoreConfiguration(
|
||||
|
@ -74,6 +74,8 @@ public interface LPConfiguration {
|
||||
|
||||
boolean isVaultIncludingGlobal();
|
||||
|
||||
boolean isVaultIgnoreWorld();
|
||||
|
||||
Map<String, String> getWorldRewrites();
|
||||
|
||||
Map<String, String> getGroupNameRewrites();
|
||||
|
Loading…
Reference in New Issue
Block a user