Cleanup powerfulperms migration & remove support for older PP versions
This commit is contained in:
parent
ddc881af11
commit
bb818c8942
@ -141,7 +141,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cheesesoftware</groupId>
|
<groupId>com.github.cheesesoftware</groupId>
|
||||||
<artifactId>PowerfulPermsAPI</artifactId>
|
<artifactId>PowerfulPermsAPI</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.4.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -22,106 +22,51 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.PermissionManager;
|
import com.github.cheesesoftware.PowerfulPermsAPI.PermissionManager;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin;
|
import com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
|
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.core.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.common.storage.StorageType;
|
||||||
|
import me.lucko.luckperms.common.utils.HikariSupplier;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.HashMap;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
// Only supports the latest versions of the PP API. (it seems to change randomly almost every release)
|
||||||
public class MigrationPowerfulPerms extends SubCommand<Object> {
|
public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||||
private static Method getPlayerPermissionsMethod = null;
|
|
||||||
private static Method getPlayerGroupsMethod = null;
|
|
||||||
private static Method getGroupMethod = null;
|
|
||||||
|
|
||||||
// lol, nice "api"
|
|
||||||
private static boolean superLegacy = false;
|
|
||||||
private static boolean legacy = false;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.ResponseRunnable");
|
|
||||||
legacy = true;
|
|
||||||
} catch (ClassNotFoundException ignored) {}
|
|
||||||
|
|
||||||
if (legacy) {
|
|
||||||
try {
|
|
||||||
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class, ResultRunnable.class);
|
|
||||||
getPlayerPermissionsMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException ignored) {}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class);
|
|
||||||
getPlayerPermissionsMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
getGroupMethod = CachedGroup.class.getMethod("getGroup");
|
|
||||||
getGroupMethod.setAccessible(true);
|
|
||||||
superLegacy = true;
|
|
||||||
} catch (NoSuchMethodException ignored) {}
|
|
||||||
|
|
||||||
if (!legacy) {
|
|
||||||
try {
|
|
||||||
getPlayerGroupsMethod = PermissionManager.class.getMethod("getPlayerOwnGroups", UUID.class);
|
|
||||||
getPlayerGroupsMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
getPlayerGroupsMethod = PermissionManager.class.getMethod("getPlayerOwnGroups", UUID.class, ResultRunnable.class);
|
|
||||||
getPlayerGroupsMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
try {
|
|
||||||
getPlayerGroupsMethod = PermissionManager.class.getMethod("getPlayerGroups", UUID.class, ResultRunnable.class);
|
|
||||||
getPlayerGroupsMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MigrationPowerfulPerms() {
|
public MigrationPowerfulPerms() {
|
||||||
super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5),
|
super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@ -136,44 +81,37 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
try {
|
|
||||||
return run(plugin, sender, args);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandResult run(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
|
||||||
ProgressLogger log = new ProgressLogger("PowerfulPerms");
|
ProgressLogger log = new ProgressLogger("PowerfulPerms");
|
||||||
log.addListener(plugin.getConsoleSender());
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.addListener(sender);
|
log.addListener(sender);
|
||||||
|
|
||||||
log.log("Starting.");
|
log.log("Starting.");
|
||||||
|
|
||||||
if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
|
if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
|
||||||
log.logErr("PowerfulPerms is not loaded.");
|
log.logErr("PowerfulPerms is not loaded.");
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String address = args.get(0);
|
String method = plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
|
||||||
final String database = args.get(1);
|
StorageType type = StorageType.parse(method);
|
||||||
final String username = args.get(2);
|
|
||||||
final String password = args.get(3);
|
if (type == null || type != StorageType.MYSQL) {
|
||||||
final String dbTable = args.get(4);
|
// We need to load the Hikari/MySQL stuff.
|
||||||
|
DependencyManager.loadDependencies(plugin, DependencyManager.STORAGE_DEPENDENCIES.get(StorageType.MYSQL));
|
||||||
|
}
|
||||||
|
|
||||||
|
String address = args.get(0);
|
||||||
|
String database = args.get(1);
|
||||||
|
String username = args.get(2);
|
||||||
|
String password = args.get(3);
|
||||||
|
String dbTable = args.get(4);
|
||||||
|
|
||||||
// Find a list of UUIDs
|
// Find a list of UUIDs
|
||||||
log.log("Getting a list of UUIDs to migrate.");
|
log.log("Getting a list of UUIDs to migrate.");
|
||||||
Set<UUID> uuids = new HashSet<>();
|
Set<UUID> uuids = new HashSet<>();
|
||||||
|
|
||||||
try (HikariDataSource hikari = new HikariDataSource()) {
|
try (HikariSupplier hikari = new HikariSupplier(address, database, username, password)) {
|
||||||
hikari.setMaximumPoolSize(2);
|
hikari.setup();
|
||||||
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
|
||||||
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
|
||||||
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
|
||||||
hikari.addDataSourceProperty("databaseName", database);
|
|
||||||
hikari.addDataSourceProperty("user", username);
|
|
||||||
hikari.addDataSourceProperty("password", password);
|
|
||||||
|
|
||||||
try (Connection c = hikari.getConnection()) {
|
try (Connection c = hikari.getConnection()) {
|
||||||
DatabaseMetaData meta = c.getMetaData();
|
DatabaseMetaData meta = c.getMetaData();
|
||||||
@ -220,23 +158,52 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) Bukkit.getPluginManager().getPlugin("PowerfulPerms");
|
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) Bukkit.getPluginManager().getPlugin("PowerfulPerms");
|
||||||
PermissionManager pm = ppPlugin.getPermissionManager();
|
PermissionManager pm = ppPlugin.getPermissionManager();
|
||||||
|
|
||||||
|
Collection<Group> groups = pm.getGroups().values();
|
||||||
|
|
||||||
|
int maxWeight = 0;
|
||||||
|
|
||||||
// Groups first.
|
// Groups first.
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
Map<Integer, Group> groups = pm.getGroups(); // All versions
|
for (Group g : groups) {
|
||||||
for (Group g : groups.values()) {
|
maxWeight = Math.max(maxWeight, g.getRank());
|
||||||
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
|
|
||||||
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
|
||||||
|
|
||||||
for (Permission p : g.getOwnPermissions()) { // All versions
|
final String name = g.getName().toLowerCase();
|
||||||
applyPerm(group, p, log);
|
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
|
||||||
|
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name);
|
||||||
|
|
||||||
|
for (Permission p : g.getOwnPermissions()) {
|
||||||
|
applyPerm(group, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Group parent : g.getParents()) { // All versions
|
for (Group parent : g.getParents()) {
|
||||||
try {
|
group.setPermissionUnchecked(NodeFactory.make("group." + parent.getName().toLowerCase(), true));
|
||||||
group.setPermission("group." + parent.getName().toLowerCase(), true);
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
// server --> prefix afaik
|
||||||
|
for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
|
||||||
|
String server = prefix.getKey().toLowerCase();
|
||||||
|
if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
|
||||||
|
server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
group.setPermissionUnchecked(NodeFactory.makePrefixNode(g.getRank(), prefix.getValue()).setServer(server).build());
|
||||||
|
} else {
|
||||||
|
group.setPermissionUnchecked(NodeFactory.makePrefixNode(g.getRank(), prefix.getValue()).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
|
||||||
|
String server = suffix.getKey().toLowerCase();
|
||||||
|
if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
|
||||||
|
server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
group.setPermissionUnchecked(NodeFactory.makeSuffixNode(g.getRank(), suffix.getValue()).setServer(server).build());
|
||||||
|
} else {
|
||||||
|
group.setPermissionUnchecked(NodeFactory.makeSuffixNode(g.getRank(), suffix.getValue()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,291 +212,134 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
log.log("Migrated " + groupCount.get() + " groups");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Now users.
|
// Migrate all users
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
final Map<UUID, CountDownLatch> progress = new HashMap<>();
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
|
maxWeight += 5;
|
||||||
|
|
||||||
// Migrate all users and their groups
|
// Migrate all users and their groups
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
progress.put(uuid, new CountDownLatch(2));
|
|
||||||
|
|
||||||
// Create a LuckPerms user for the UUID
|
// Create a LuckPerms user for the UUID
|
||||||
plugin.getStorage().loadUser(uuid, "null").join();
|
plugin.getStorage().loadUser(uuid, "null").join();
|
||||||
User user = plugin.getUserManager().get(uuid);
|
User user = plugin.getUserManager().get(uuid);
|
||||||
|
|
||||||
// Get a list of Permissions held by the user from the PP API.
|
List<Permission> permissions = joinFuture(pm.getPlayerOwnPermissions(uuid));
|
||||||
getPlayerPermissions(pm, uuid, perms -> { // Changes each version
|
|
||||||
perms.forEach(p -> applyPerm(user, p, log));
|
|
||||||
|
|
||||||
// Update the progress so the user can be saved and unloaded.
|
for (Permission p : permissions) {
|
||||||
synchronized (progress) {
|
applyPerm(user, p);
|
||||||
progress.get(uuid).countDown();
|
}
|
||||||
if (progress.get(uuid).getCount() == 0) {
|
|
||||||
plugin.getStorage().saveUser(user);
|
|
||||||
plugin.getUserManager().cleanup(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Migrate the user's groups to LuckPerms from PP.
|
// server --> list of groups
|
||||||
Consumer<Map<String, List<CachedGroup>>> callback = groups1 -> {
|
Map<String, List<CachedGroup>> parents = joinFuture(pm.getPlayerOwnGroups(uuid));
|
||||||
for (Map.Entry<String, List<CachedGroup>> e : groups1.entrySet()) {
|
for (Map.Entry<String, List<CachedGroup>> parent : parents.entrySet()) {
|
||||||
final String server;
|
String server = parent.getKey().toLowerCase();
|
||||||
if (e.getKey() != null && (e.getKey().equals("") || e.getKey().equalsIgnoreCase("all"))) {
|
if (parent.getKey().equals("*") || parent.getKey().equals("all")) {
|
||||||
server = null;
|
server = null;
|
||||||
} else {
|
|
||||||
server = e.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (superLegacy) {
|
|
||||||
e.getValue().stream()
|
|
||||||
.filter(cg -> !cg.isNegated())
|
|
||||||
.map(cg -> {
|
|
||||||
try {
|
|
||||||
return (Group) getGroupMethod.invoke(cg);
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.forEach(g -> {
|
|
||||||
if (g != null) {
|
|
||||||
if (server == null) {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true, server);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
e.getValue().stream()
|
|
||||||
.filter(g -> !g.hasExpired() && !g.isNegated())
|
|
||||||
.forEach(g -> {
|
|
||||||
final Group group = pm.getGroup(g.getGroupId());
|
|
||||||
if (g.willExpire()) {
|
|
||||||
if (server == null) {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, g.getExpirationDate().getTime() / 1000L);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server, g.getExpirationDate().getTime() / 1000L);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (server == null) {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the progress so the user can be saved and unloaded.
|
for (CachedGroup group : parent.getValue()) {
|
||||||
synchronized (progress) {
|
applyGroup(pm, user, group, server);
|
||||||
progress.get(uuid).countDown();
|
|
||||||
if (progress.get(uuid).getCount() == 0) {
|
|
||||||
plugin.getStorage().saveUser(user);
|
|
||||||
plugin.getUserManager().cleanup(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!legacy) {
|
|
||||||
try {
|
|
||||||
ListenableFuture<LinkedHashMap<String, List<CachedGroup>>> future = (ListenableFuture<LinkedHashMap<String, List<CachedGroup>>>) getPlayerGroupsMethod.invoke(pm, uuid);
|
|
||||||
try {
|
|
||||||
if (future.isDone()) {
|
|
||||||
callback.accept(future.get());
|
|
||||||
} else {
|
|
||||||
future.addListener(() -> {
|
|
||||||
try {
|
|
||||||
callback.accept(future.get());
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, Runnable::run);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
getPlayerGroupsMethod.invoke(pm, uuid, new LPResultRunnable<LinkedHashMap<String, List<CachedGroup>>>() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
callback.accept(getResult());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix = joinFuture(pm.getPlayerOwnPrefix(uuid));
|
||||||
|
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
|
||||||
|
|
||||||
|
if (prefix != null && !prefix.equals("")) {
|
||||||
|
user.setPermissionUnchecked(NodeFactory.makePrefixNode(maxWeight, prefix).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != null && !suffix.equals("")) {
|
||||||
|
user.setPermissionUnchecked(NodeFactory.makeSuffixNode(maxWeight, suffix).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
String primary = joinFuture(pm.getPlayerPrimaryGroup(uuid)).getName().toLowerCase();
|
||||||
|
if (!primary.equals("default")) {
|
||||||
|
user.setPermissionUnchecked(NodeFactory.make("group." + primary));
|
||||||
|
user.setPrimaryGroup(primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getUserManager().cleanup(user);
|
||||||
|
plugin.getStorage().saveUser(user);
|
||||||
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
// All groups are migrated, but there may still be some users being migrated.
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
// This block will wait for all users to be completed.
|
|
||||||
log.log("Waiting for user migration to complete. This may take some time");
|
|
||||||
boolean sleep = true;
|
|
||||||
while (sleep) {
|
|
||||||
sleep = false;
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, CountDownLatch> e : progress.entrySet()) {
|
|
||||||
if (e.getValue().getCount() != 0) {
|
|
||||||
sleep = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sleep) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// We done.
|
|
||||||
log.log("Success! Migration complete.");
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPerm(PermissionHolder holder, Permission p, ProgressLogger log) {
|
private void applyPerm(PermissionHolder holder, Permission p) {
|
||||||
String node = p.getPermissionString();
|
String node = p.getPermissionString();
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!") || node.startsWith("-")) {
|
||||||
node = node.substring(1);
|
node = node.substring(1);
|
||||||
value = false;
|
value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String server = p.getServer();
|
String server = p.getServer();
|
||||||
if (server != null && server.equalsIgnoreCase("all")) {
|
if (server != null && (server.equalsIgnoreCase("all") || server.equalsIgnoreCase("*"))) {
|
||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String world = p.getWorld();
|
String world = p.getWorld();
|
||||||
if (world != null && world.equalsIgnoreCase("all")) {
|
if (world != null && (world.equalsIgnoreCase("all") || world.equalsIgnoreCase("*"))) {
|
||||||
world = null;
|
world = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
long expireAt = 0L;
|
long expireAt = 0L;
|
||||||
if (!superLegacy) {
|
if (p.willExpire()) {
|
||||||
if (p.willExpire()) {
|
expireAt = p.getExpirationDate().getTime() / 1000L;
|
||||||
expireAt = p.getExpirationDate().getTime() / 1000L;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world != null && server == null) {
|
if (world != null && server == null) {
|
||||||
server = "global";
|
server = "global";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world != null) {
|
Node.Builder nb = NodeFactory.newBuilder(node).setValue(value);
|
||||||
if (expireAt == 0L) {
|
|
||||||
try {
|
|
||||||
holder.setPermission(node, value, server, world);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
holder.setPermission(node, value, server, world, expireAt);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (server != null) {
|
if (expireAt != 0) {
|
||||||
if (expireAt == 0L) {
|
nb.setExpiry(expireAt);
|
||||||
try {
|
|
||||||
holder.setPermission(node, value, server);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
holder.setPermission(node, value, server, expireAt);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (expireAt == 0L) {
|
|
||||||
try {
|
|
||||||
holder.setPermission(node, value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
holder.setPermission(node, value, expireAt);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
nb.setServer(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world != null) {
|
||||||
|
nb.setWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.setPermissionUnchecked(nb.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getPlayerPermissions(PermissionManager manager, UUID uuid, Consumer<List<Permission>> callback) {
|
private void applyGroup(PermissionManager pm, PermissionHolder holder, CachedGroup g, String server) {
|
||||||
if (legacy) {
|
Group group = pm.getGroup(g.getGroupId());
|
||||||
try {
|
String node = "group." + group.getName();
|
||||||
getPlayerPermissionsMethod.invoke(manager, uuid, new LPResultRunnable<List<Permission>>() {
|
|
||||||
@Override
|
long expireAt = 0L;
|
||||||
public void run() {
|
if (g.willExpire()) {
|
||||||
callback.accept(getResult());
|
expireAt = g.getExpirationDate().getTime() / 1000L;
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
ListenableFuture<List<Permission>> lf = (ListenableFuture<List<Permission>>) getPlayerPermissionsMethod.invoke(manager, uuid);
|
|
||||||
try {
|
|
||||||
if (lf.isDone()) {
|
|
||||||
callback.accept(lf.get());
|
|
||||||
} else {
|
|
||||||
lf.addListener(() -> {
|
|
||||||
try {
|
|
||||||
callback.accept(lf.get());
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, Runnable::run);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node.Builder nb = NodeFactory.newBuilder(node);
|
||||||
|
|
||||||
|
if (expireAt != 0) {
|
||||||
|
nb.setExpiry(expireAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
nb.setServer(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.setPermissionUnchecked(nb.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private static <T> T joinFuture(Future<T> future) {
|
||||||
|
return future.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.bukkit.migration.utils;
|
|
||||||
|
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides the default ResultRunnable, callbacks will always run in the same thread. (an async one, hopefully.)
|
|
||||||
*
|
|
||||||
* @param <T> type
|
|
||||||
*/
|
|
||||||
public abstract class LPResultRunnable<T> extends ResultRunnable<T> {
|
|
||||||
public LPResultRunnable() {
|
|
||||||
super();
|
|
||||||
super.sameThread = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getResult() {
|
|
||||||
return super.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -56,7 +56,7 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<StorageType, List<Dependency>> STORAGE_DEPENDENCIES = ImmutableMap.<StorageType, List<Dependency>>builder()
|
public static final Map<StorageType, List<Dependency>> STORAGE_DEPENDENCIES = ImmutableMap.<StorageType, List<Dependency>>builder()
|
||||||
.put(StorageType.JSON, ImmutableList.of())
|
.put(StorageType.JSON, ImmutableList.of())
|
||||||
.put(StorageType.YAML, ImmutableList.of())
|
.put(StorageType.YAML, ImmutableList.of())
|
||||||
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
||||||
@ -78,6 +78,10 @@ public class DependencyManager {
|
|||||||
dependencies.add(Dependency.JEDIS);
|
dependencies.add(Dependency.JEDIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadDependencies(plugin, dependencies);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadDependencies(LuckPermsPlugin plugin, List<Dependency> dependencies) {
|
||||||
plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
||||||
|
|
||||||
File data = new File(plugin.getDataDirectory(), "lib");
|
File data = new File(plugin.getDataDirectory(), "lib");
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class HikariSupplier implements AutoCloseable {
|
||||||
|
|
||||||
|
private final String address;
|
||||||
|
private final String database;
|
||||||
|
private final String username;
|
||||||
|
private final String password;
|
||||||
|
|
||||||
|
private HikariDataSource hikari;
|
||||||
|
|
||||||
|
public void setup() {
|
||||||
|
hikari = new HikariDataSource();
|
||||||
|
hikari.setPoolName("powerfulperms-migrator-pool");
|
||||||
|
hikari.setMaximumPoolSize(2);
|
||||||
|
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||||
|
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
||||||
|
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
||||||
|
hikari.addDataSourceProperty("databaseName", database);
|
||||||
|
hikari.addDataSourceProperty("user", username);
|
||||||
|
hikari.addDataSourceProperty("password", password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
hikari.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
return hikari.getConnection();
|
||||||
|
}
|
||||||
|
}
|
@ -84,6 +84,10 @@ public class ProgressLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleException(Exception ex) {
|
public void handleException(Exception ex) {
|
||||||
|
handleAndPrintException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleAndPrintException(Exception ex) {
|
||||||
if (ex instanceof ObjectAlreadyHasException || ex instanceof ObjectLacksException) {
|
if (ex instanceof ObjectAlreadyHasException || ex instanceof ObjectLacksException) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -106,7 +106,7 @@
|
|||||||
<url>http://repo.wea-ondara.net/repository/public/</url>
|
<url>http://repo.wea-ondara.net/repository/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>placeholderapi</id>
|
<id>placeholderapi-repo</id>
|
||||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
|
Loading…
Reference in New Issue
Block a user