Cleanup migration commands

This commit is contained in:
Luck
2017-03-13 19:10:36 +00:00
Unverified
parent 11465a4ce9
commit dbc909a317
15 changed files with 295 additions and 443 deletions
@@ -22,6 +22,8 @@
package me.lucko.luckperms.common.commands.migration;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.commands.Command;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@@ -35,60 +37,31 @@ import me.lucko.luckperms.common.utils.Predicates;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
public class MigrationMainCommand extends MainCommand<Object> {
private static final Map<String, String> PLUGINS = ImmutableMap.<String, String>builder()
.put("org.anjocaido.groupmanager.GroupManager", "me.lucko.luckperms.bukkit.migration.MigrationGroupManager")
.put("ru.tehkode.permissions.bukkit.PermissionsEx", "me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx")
.put("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin", "me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms")
.put("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService", "me.lucko.luckperms.bukkit.migration.MigrationZPermissions")
.put("net.alpenblock.bungeeperms.BungeePerms", "me.lucko.luckperms.bungee.migration.MigrationBungeePerms")
.put("de.bananaco.bpermissions.api.WorldManager", "me.lucko.luckperms.bukkit.migration.MigrationBPermissions")
.put("ninja.leaping.permissionsex.sponge.PermissionsExPlugin", "me.lucko.luckperms.sponge.migration.MigrationPermissionsEx")
.put("io.github.djxy.permissionmanager.PermissionManager", "me.lucko.luckperms.sponge.migration.MigrationPermissionManager")
.build();
@SuppressWarnings("unchecked")
private static List<Command<Object, ?>> getAvailableCommands() {
List<SubCommand<Object>> l = new ArrayList<>();
try {
Class.forName("org.anjocaido.groupmanager.GroupManager");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationGroupManager").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationZPermissions").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("net.alpenblock.bungeeperms.BungeePerms");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bungee.migration.MigrationBungeePerms").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("de.bananaco.bpermissions.api.WorldManager");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationBPermissions").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("ninja.leaping.permissionsex.sponge.PermissionsExPlugin");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx").newInstance());
} catch (Throwable ignored) {
}
try {
Class.forName("io.github.djxy.permissionmanager.PermissionManager");
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionManager").newInstance());
} catch (Throwable ignored) {
for (Map.Entry<String, String> plugin : PLUGINS.entrySet()) {
try {
Class.forName(plugin.getKey());
l.add((SubCommand<Object>) Class.forName(plugin.getValue()).newInstance());
} catch (Throwable ignored) {}
}
return l.stream().collect(Collectors.toList());
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.commands.migration;
import lombok.experimental.UtilityClass;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.Group;
@UtilityClass
public class MigrationUtils {
public static Node.Builder parseNode(String permission, boolean value) {
if (permission.startsWith("-") || permission.startsWith("!")) {
permission = permission.substring(1);
value = false;
} else if (permission.startsWith("+")) {
permission = permission.substring(1);
value = true;
}
return NodeFactory.newBuilder(permission).setValue(value);
}
public static void setGroupWeight(Group group, int weight) {
group.removeIf(n -> n.getPermission().startsWith("weight."));
group.setPermissionUnchecked(NodeFactory.make("weight." + weight));
}
public static String standardizeName(String string) {
return string.trim().replace(':', '-').replace(' ', '-').replace('.', '-').toLowerCase();
}
}
@@ -61,8 +61,8 @@ public class Patterns {
});
public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]");
public static final Pattern NON_ALPHA_NUMERIC_SPACE = Pattern.compile("[\\/\\$\\.\\-]");
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\. ]");
public static final Pattern NON_ALPHA_NUMERIC_SPACE = Pattern.compile("[\\/\\$\\.]");
public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]");
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");
@@ -195,11 +195,18 @@ public class ImmutableNode implements Node {
throw new IllegalArgumentException("Empty permission");
}
if (server != null && (server.equalsIgnoreCase("global") || server.equals(""))) {
if (server != null) {
server = server.toLowerCase();
}
if (world != null) {
world = world.toLowerCase();
}
if (server != null && (server.equals("global") || server.equals(""))) {
server = null;
}
if (world != null && (world.equalsIgnoreCase("global") || world.equals(""))) {
if (world != null && (world.equals("global") || world.equals(""))) {
world = null;
}