mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Copy prefixes and suffixes during migration processes
This commit is contained in:
parent
f7fa08d5e9
commit
9cd4e01d8e
@ -36,6 +36,8 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static me.lucko.luckperms.utils.ArgumentChecker.escapeCharacters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Vault Chat service through the use of normal permission nodes.
|
* Provides the Vault Chat service through the use of normal permission nodes.
|
||||||
*
|
*
|
||||||
@ -50,7 +52,7 @@ import java.util.regex.Pattern;
|
|||||||
* Permission Nodes = meta.node.value
|
* Permission Nodes = meta.node.value
|
||||||
*
|
*
|
||||||
* Node that special characters used within LuckPerms are escaped:
|
* Node that special characters used within LuckPerms are escaped:
|
||||||
* See {@link #escapeCharacters(String)}
|
* See {@link me.lucko.luckperms.utils.ArgumentChecker#escapeCharacters(String)}
|
||||||
*
|
*
|
||||||
* Registered on normal priority so other plugins can override.
|
* Registered on normal priority so other plugins can override.
|
||||||
*/
|
*/
|
||||||
@ -75,14 +77,6 @@ class VaultChatHook extends Chat {
|
|||||||
return perms.isEnabled();
|
return perms.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String escapeCharacters(String s) {
|
|
||||||
s = s.replace(".", "{SEP}");
|
|
||||||
s = s.replace("/", "{FSEP}");
|
|
||||||
s = s.replace("$", "{DSEP}");
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveMeta(PermissionHolder holder, String world, String node, String value) {
|
private void saveMeta(PermissionHolder holder, String world, String node, String value) {
|
||||||
if (holder == null) return;
|
if (holder == null) return;
|
||||||
if (node.equals("")) return;
|
if (node.equals("")) return;
|
||||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.commands.Sender;
|
|||||||
import me.lucko.luckperms.commands.SubCommand;
|
import me.lucko.luckperms.commands.SubCommand;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||||
import net.alpenblock.bungeeperms.*;
|
import net.alpenblock.bungeeperms.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -92,6 +93,23 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix = u.getPrefix();
|
||||||
|
String suffix = u.getSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
user.setPermission("prefix.100." + prefix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
user.setPermission("suffix.100." + suffix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getDatastore().saveUser(user);
|
plugin.getDatastore().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
}
|
}
|
||||||
@ -134,11 +152,29 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
|||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix = g.getPrefix();
|
||||||
|
String suffix = g.getSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
group.setPermission("prefix.50." + prefix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
group.setPermission("suffix.50." + suffix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plugin.getDatastore().saveGroup(group);
|
plugin.getDatastore().saveGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("BungeePerms Migration: Migrated " + groupCount + " groups");
|
log.info("BungeePerms Migration: Migrated " + groupCount + " groups");
|
||||||
|
|
||||||
log.info("BungeePerms Migration: Success! Completed without any errors.");
|
log.info("BungeePerms Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
||||||
|
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
||||||
|
|
||||||
for (Map.Entry<UUID, Map<String, Boolean>> e : users.entrySet()) {
|
for (Map.Entry<UUID, Map<String, Boolean>> e : users.entrySet()) {
|
||||||
plugin.getDatastore().loadOrCreateUser(e.getKey(), "null");
|
plugin.getDatastore().loadOrCreateUser(e.getKey(), "null");
|
||||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.constants.Permission;
|
|||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
|
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||||
import ru.tehkode.permissions.NativeInterface;
|
import ru.tehkode.permissions.NativeInterface;
|
||||||
import ru.tehkode.permissions.PermissionGroup;
|
import ru.tehkode.permissions.PermissionGroup;
|
||||||
import ru.tehkode.permissions.PermissionManager;
|
import ru.tehkode.permissions.PermissionManager;
|
||||||
@ -120,6 +121,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
log.info("PermissionsEx Migration: Starting user migration.");
|
log.info("PermissionsEx Migration: Starting user migration.");
|
||||||
|
int userCount = 0;
|
||||||
for (PermissionUser user : manager.getUsers()) {
|
for (PermissionUser user : manager.getUsers()) {
|
||||||
UUID u = null;
|
UUID u = null;
|
||||||
|
|
||||||
@ -147,6 +149,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userCount++;
|
||||||
plugin.getDatastore().loadOrCreateUser(u, "null");
|
plugin.getDatastore().loadOrCreateUser(u, "null");
|
||||||
User lpUser = plugin.getUserManager().get(u);
|
User lpUser = plugin.getUserManager().get(u);
|
||||||
|
|
||||||
@ -198,13 +201,34 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix = user.getOwnPrefix();
|
||||||
|
String suffix = user.getOwnSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
lpUser.setPermission("prefix.100." + prefix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
lpUser.setPermission("suffix.100." + suffix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(lpUser);
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
plugin.getDatastore().saveUser(lpUser);
|
plugin.getDatastore().saveUser(lpUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
|
||||||
|
|
||||||
// Migrate all groups.
|
// Migrate all groups.
|
||||||
log.info("PermissionsEx Migration: Starting group migration.");
|
log.info("PermissionsEx Migration: Starting group migration.");
|
||||||
|
int groupCount = 0;
|
||||||
for (PermissionGroup group : manager.getGroupList()) {
|
for (PermissionGroup group : manager.getGroupList()) {
|
||||||
|
groupCount ++;
|
||||||
final String name = group.getName().toLowerCase();
|
final String name = group.getName().toLowerCase();
|
||||||
plugin.getDatastore().createAndLoadGroup(name);
|
plugin.getDatastore().createAndLoadGroup(name);
|
||||||
Group lpGroup = plugin.getGroupManager().get(name);
|
Group lpGroup = plugin.getGroupManager().get(name);
|
||||||
@ -256,8 +280,27 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix = group.getOwnPrefix();
|
||||||
|
String suffix = group.getOwnSuffix();
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("prefix.50." + prefix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
lpGroup.setPermission("suffix.50." + suffix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
|
||||||
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
|||||||
import me.lucko.luckperms.groups.Group;
|
import me.lucko.luckperms.groups.Group;
|
||||||
import me.lucko.luckperms.tracks.Track;
|
import me.lucko.luckperms.tracks.Track;
|
||||||
import me.lucko.luckperms.users.User;
|
import me.lucko.luckperms.users.User;
|
||||||
|
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -97,6 +98,24 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
||||||
|
|
||||||
|
String prefix = service.getPlayerPrefix(u);
|
||||||
|
String suffix = service.getPlayerSuffix(u);
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
prefix = ArgumentChecker.escapeCharacters(prefix);
|
||||||
|
try {
|
||||||
|
user.setPermission("prefix.100." + prefix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
suffix = ArgumentChecker.escapeCharacters(suffix);
|
||||||
|
try {
|
||||||
|
user.setPermission("suffix.100." + suffix, true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
plugin.getDatastore().saveUser(user);
|
plugin.getDatastore().saveUser(user);
|
||||||
}
|
}
|
||||||
|
@ -48,4 +48,12 @@ public class ArgumentChecker {
|
|||||||
return DateUtil.shouldExpire(l);
|
return DateUtil.shouldExpire(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String escapeCharacters(String s) {
|
||||||
|
s = s.replace(".", "{SEP}");
|
||||||
|
s = s.replace("/", "{FSEP}");
|
||||||
|
s = s.replace("$", "{DSEP}");
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user