add option to ignore vault world parameters

This commit is contained in:
Luck 2016-10-08 15:01:54 +01:00
parent 687804de2c
commit ed5892eb56
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 50 additions and 22 deletions

View File

@ -75,6 +75,7 @@ public class VaultChatHook extends Chat {
} }
private void saveMeta(PermissionHolder holder, String world, String node, String value) { private void saveMeta(PermissionHolder holder, String world, String node, String value) {
String finalWorld = perms.isIgnoreWorld() ? null : world;
if (holder == null) return; if (holder == null) return;
if (node.equals("")) return; if (node.equals("")) return;
@ -96,8 +97,8 @@ public class VaultChatHook extends Chat {
if (!perms.getServer().equalsIgnoreCase("global")) { if (!perms.getServer().equalsIgnoreCase("global")) {
metaNode.setServer(perms.getServer()); metaNode.setServer(perms.getServer());
} }
if (world != null && !world.equals("")) { if (finalWorld != null && !finalWorld.equals("")) {
metaNode.setServer(perms.getServer()).setWorld(world); metaNode.setServer(perms.getServer()).setWorld(finalWorld);
} }
try { try {
@ -109,6 +110,7 @@ public class VaultChatHook extends Chat {
} }
private void setChatMeta(boolean prefix, PermissionHolder holder, String value, String world) { private void setChatMeta(boolean prefix, PermissionHolder holder, String value, String world) {
String finalWorld = perms.isIgnoreWorld() ? null : world;
if (holder == null) return; if (holder == null) return;
if (value.equals("")) return; if (value.equals("")) return;
@ -119,8 +121,8 @@ public class VaultChatHook extends Chat {
node.setServer(perms.getServer()); node.setServer(perms.getServer());
} }
if (world != null && !world.equals("")) { if (finalWorld != null && !finalWorld.equals("")) {
node.setServer(perms.getServer()).setWorld(world); node.setServer(perms.getServer()).setWorld(finalWorld);
} }
try { try {
@ -132,6 +134,7 @@ public class VaultChatHook extends Chat {
} }
private String getUserMeta(User user, String world, String node, String defaultValue) { private String getUserMeta(User user, String world, String node, String defaultValue) {
world = perms.isIgnoreWorld() ? null : world;
if (user == null) return defaultValue; if (user == null) return defaultValue;
node = escapeCharacters(node); node = escapeCharacters(node);
@ -151,6 +154,7 @@ public class VaultChatHook extends Chat {
} }
private String getUserChatMeta(boolean prefix, User user, String world) { private String getUserChatMeta(boolean prefix, User user, String world) {
world = perms.isIgnoreWorld() ? null : world;
if (user == null) return ""; if (user == null) return "";
if (!perms.getVaultUserManager().containsUser(user.getUuid())) { 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) { private String getGroupMeta(Group group, String world, String node, String defaultValue) {
world = perms.isIgnoreWorld() ? null : world;
if (group == null) return defaultValue; if (group == null) return defaultValue;
if (node.equals("")) return defaultValue; if (node.equals("")) return defaultValue;
node = escapeCharacters(node); node = escapeCharacters(node);
@ -200,6 +205,7 @@ public class VaultChatHook extends Chat {
} }
private String getGroupChatMeta(boolean prefix, Group group, String world) { private String getGroupChatMeta(boolean prefix, Group group, String world) {
world = perms.isIgnoreWorld() ? null : world;
if (group == null) return ""; if (group == null) return "";
int priority = Integer.MIN_VALUE; int priority = Integer.MIN_VALUE;

View File

@ -42,6 +42,7 @@ public class VaultHook {
permissionHook.setPlugin(plugin); permissionHook.setPlugin(plugin);
permissionHook.setServer(plugin.getConfiguration().getVaultServer()); permissionHook.setServer(plugin.getConfiguration().getVaultServer());
permissionHook.setIncludeGlobal(plugin.getConfiguration().isVaultIncludingGlobal()); permissionHook.setIncludeGlobal(plugin.getConfiguration().isVaultIncludingGlobal());
permissionHook.setIncludeGlobal(plugin.getConfiguration().isVaultIgnoreWorld());
permissionHook.setup(); permissionHook.setup();
if (chatHook == null) { if (chatHook == null) {

View File

@ -61,6 +61,10 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Setter @Setter
private boolean includeGlobal = true; private boolean includeGlobal = true;
@Getter
@Setter
private boolean ignoreWorld = false;
public void setup() { public void setup() {
vaultUserManager = new VaultUserManager(plugin, this); vaultUserManager = new VaultUserManager(plugin, this);
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 1L, 1L); plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 1L, 1L);
@ -164,6 +168,7 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public boolean playerHas(String world, @NonNull String player, @NonNull String permission) { 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); log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + server);
User user = plugin.getUserManager().get(player); User user = plugin.getUserManager().get(player);
if (user == null) return false; if (user == null) return false;
@ -184,22 +189,25 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) { 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); final User user = plugin.getUserManager().get(player);
scheduleTask(() -> add(world, user, permission)); scheduleTask(() -> add(finalWorld, user, permission));
return true; return true;
} }
@Override @Override
public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) { 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); final User user = plugin.getUserManager().get(player);
scheduleTask(() -> remove(world, user, permission)); scheduleTask(() -> remove(finalWorld, user, permission));
return true; return true;
} }
@Override @Override
public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) { 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); log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + server);
final Group group = plugin.getGroupManager().get(groupName); final Group group = plugin.getGroupManager().get(groupName);
return objectHas(world, group, permission); return objectHas(world, group, permission);
@ -207,30 +215,33 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) { 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); final Group group = plugin.getGroupManager().get(groupName);
scheduleTask(() -> add(world, group, permission)); scheduleTask(() -> add(finalWorld, group, permission));
return true; return true;
} }
@Override @Override
public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) { 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); final Group group = plugin.getGroupManager().get(groupName);
scheduleTask(() -> remove(world, group, permission)); scheduleTask(() -> remove(finalWorld, group, permission));
return true; return true;
} }
@Override @Override
public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) { 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); final User user = plugin.getUserManager().get(player);
if (user == null) return false; if (user == null) return false;
return user.getNodes().stream() return user.getNodes().stream()
.filter(Node::isGroupNode) .filter(Node::isGroupNode)
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false)) .filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
.filter(n -> n.shouldApplyOnWorld(world, true, false)) .filter(n -> n.shouldApplyOnWorld(finalWorld, true, false))
.map(Node::getGroupName) .map(Node::getGroupName)
.filter(s -> s.equalsIgnoreCase(group)) .filter(s -> s.equalsIgnoreCase(group))
.findAny().isPresent(); .findAny().isPresent();
@ -238,7 +249,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) { 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); final User user = plugin.getUserManager().get(player);
if (user == null) return false; if (user == null) return false;
@ -247,8 +259,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
scheduleTask(() -> { scheduleTask(() -> {
try { try {
if (world != null && !world.equals("")) { if (finalWorld != null && !finalWorld.equals("")) {
user.addGroup(group, server, world); user.addGroup(group, server, finalWorld);
} else { } else {
user.addGroup(group, server); user.addGroup(group, server);
} }
@ -260,7 +272,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) { 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); final User user = plugin.getUserManager().get(player);
if (user == null) return false; if (user == null) return false;
@ -269,8 +282,8 @@ public class VaultPermissionHook extends Permission implements Runnable {
scheduleTask(() -> { scheduleTask(() -> {
try { try {
if (world != null && !world.equals("")) { if (finalWorld != null && !finalWorld.equals("")) {
user.removeGroup(group, server, world); user.removeGroup(group, server, finalWorld);
} else { } else {
user.removeGroup(group, server); user.removeGroup(group, server);
} }
@ -282,14 +295,15 @@ public class VaultPermissionHook extends Permission implements Runnable {
@Override @Override
public String[] getPlayerGroups(String world, @NonNull String player) { 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); User user = plugin.getUserManager().get(player);
if (user == null) return new String[0]; if (user == null) return new String[0];
return user.getNodes().stream() return user.getNodes().stream()
.filter(Node::isGroupNode) .filter(Node::isGroupNode)
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false)) .filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
.filter(n -> n.shouldApplyOnWorld(world, true, false)) .filter(n -> n.shouldApplyOnWorld(finalWorld, true, false))
.map(Node::getGroupName) .map(Node::getGroupName)
.toArray(String[]::new); .toArray(String[]::new);
} }

View File

@ -80,6 +80,9 @@ vault-server: global
# If global permissions should be considered when retrieving meta or player groups # If global permissions should be considered when retrieving meta or player groups
vault-include-global: true 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 # 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. # will be sent forward for permission calculation instead.
world-rewrite: world-rewrite:

View File

@ -62,6 +62,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
private boolean autoOp; private boolean autoOp;
private String vaultServer; private String vaultServer;
private boolean vaultIncludingGlobal; private boolean vaultIncludingGlobal;
private boolean vaultIgnoreWorld;
private Map<String, String> worldRewrites; private Map<String, String> worldRewrites;
private Map<String, String> groupNameRewrites; private Map<String, String> groupNameRewrites;
private DatastoreConfiguration databaseValues; private DatastoreConfiguration databaseValues;
@ -101,6 +102,7 @@ public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implement
commandsAllowOp = getBoolean("commands-allow-op", true); commandsAllowOp = getBoolean("commands-allow-op", true);
vaultServer = getString("vault-server", "global"); vaultServer = getString("vault-server", "global");
vaultIncludingGlobal = getBoolean("vault-include-global", true); vaultIncludingGlobal = getBoolean("vault-include-global", true);
vaultIgnoreWorld = getBoolean("vault-ignore-world", false);
worldRewrites = ImmutableMap.copyOf(getMap("world-rewrite", Collections.emptyMap())); worldRewrites = ImmutableMap.copyOf(getMap("world-rewrite", Collections.emptyMap()));
groupNameRewrites = ImmutableMap.copyOf(getMap("group-name-rewrite", Collections.emptyMap())); groupNameRewrites = ImmutableMap.copyOf(getMap("group-name-rewrite", Collections.emptyMap()));
databaseValues = new DatastoreConfiguration( databaseValues = new DatastoreConfiguration(

View File

@ -74,6 +74,8 @@ public interface LPConfiguration {
boolean isVaultIncludingGlobal(); boolean isVaultIncludingGlobal();
boolean isVaultIgnoreWorld();
Map<String, String> getWorldRewrites(); Map<String, String> getWorldRewrites();
Map<String, String> getGroupNameRewrites(); Map<String, String> getGroupNameRewrites();