mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-11 03:53:33 +01:00
Fix Sponge PEX meta migration weightings
This commit is contained in:
parent
d804c4be2a
commit
f0b4040458
@ -107,12 +107,12 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) {
|
for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) {
|
||||||
String pmName = MigrationUtils.convertGroupName(pmGroup.getIdentifier().toLowerCase());
|
String pmName = MigrationUtils.convertName(pmGroup.getIdentifier());
|
||||||
|
|
||||||
// Make a LuckPerms group for the one being migrated
|
// Make a LuckPerms group for the one being migrated
|
||||||
plugin.getStorage().createAndLoadGroup(pmName).join();
|
plugin.getStorage().createAndLoadGroup(pmName).join();
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(pmName);
|
Group group = plugin.getGroupManager().getIfLoaded(pmName);
|
||||||
migrateSubject(pmGroup, group);
|
migrateSubject(pmGroup, group, 100);
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
@ -144,7 +144,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
if (user.getNodes().size() <= 1) {
|
if (user.getNodes().size() <= 1) {
|
||||||
user.clearNodes(false);
|
user.clearNodes(false);
|
||||||
}
|
}
|
||||||
migrateSubject(pmUser, user);
|
migrateSubject(pmUser, user, 100);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.OptionalInt;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -89,33 +90,55 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||||
|
|
||||||
|
log.log("Calculating group weightings.");
|
||||||
|
int maxWeight = 0;
|
||||||
|
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
||||||
|
Optional<String> pos = pexGroup.getOption("rank");
|
||||||
|
if (pos.isPresent()) {
|
||||||
|
try {
|
||||||
|
int i = Integer.parseInt(pos.get());
|
||||||
|
maxWeight = Math.max(maxWeight, i);
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxWeight += 5;
|
||||||
|
|
||||||
Map<String, TreeMap<Integer, String>> tracks = new HashMap<>();
|
Map<String, TreeMap<Integer, String>> tracks = new HashMap<>();
|
||||||
|
|
||||||
// Migrate groups
|
// Migrate groups
|
||||||
log.log("Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
AtomicInteger groupCount = new AtomicInteger(0);
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
||||||
String pexName = MigrationUtils.convertGroupName(pexGroup.getIdentifier().toLowerCase());
|
String pexName = MigrationUtils.convertName(pexGroup.getIdentifier());
|
||||||
|
|
||||||
|
Optional<String> rankString = pexGroup.getOption("rank");
|
||||||
|
OptionalInt rank = OptionalInt.empty();
|
||||||
|
if (rankString.isPresent()) {
|
||||||
|
try {
|
||||||
|
int r = Integer.parseInt(rankString.get());
|
||||||
|
rank = OptionalInt.of(r);
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
int weight = 100;
|
||||||
|
if (rank.isPresent()) {
|
||||||
|
weight = maxWeight - rank.getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
// Make a LuckPerms group for the one being migrated
|
// Make a LuckPerms group for the one being migrated
|
||||||
plugin.getStorage().createAndLoadGroup(pexName).join();
|
plugin.getStorage().createAndLoadGroup(pexName).join();
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(pexName);
|
Group group = plugin.getGroupManager().getIfLoaded(pexName);
|
||||||
migrateSubject(pexGroup, group);
|
migrateSubject(pexGroup, group, weight);
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
|
||||||
// Pull track data
|
// Pull track data
|
||||||
Optional<String> track = pexGroup.getOption("rank-ladder");
|
Optional<String> track = pexGroup.getOption("rank-ladder");
|
||||||
Optional<String> pos = pexGroup.getOption("rank");
|
if (track.isPresent() && rank.isPresent()) {
|
||||||
if (track.isPresent() && pos.isPresent()) {
|
String trackName = MigrationUtils.convertName(track.get());
|
||||||
String trackName = track.get().toLowerCase();
|
|
||||||
try {
|
|
||||||
int rank = Integer.parseInt(pos.get());
|
|
||||||
if (!tracks.containsKey(trackName)) {
|
if (!tracks.containsKey(trackName)) {
|
||||||
tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder()));
|
tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder()));
|
||||||
}
|
}
|
||||||
|
tracks.get(trackName).put(rank.getAsInt(), pexName);
|
||||||
tracks.get(trackName).put(rank, pexName);
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
@ -141,6 +164,10 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
// Migrate users
|
// Migrate users
|
||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
|
maxWeight += 5;
|
||||||
|
|
||||||
for (Subject pexUser : pexService.getUserSubjects().getAllSubjects()) {
|
for (Subject pexUser : pexService.getUserSubjects().getAllSubjects()) {
|
||||||
UUID uuid = Util.parseUuid(pexUser.getIdentifier());
|
UUID uuid = Util.parseUuid(pexUser.getIdentifier());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
@ -154,7 +181,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
if (user.getNodes().size() <= 1) {
|
if (user.getNodes().size() <= 1) {
|
||||||
user.clearNodes(false);
|
user.clearNodes(false);
|
||||||
}
|
}
|
||||||
migrateSubject(pexUser, user);
|
migrateSubject(pexUser, user, maxWeight);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ import java.util.Set;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class MigrationUtils {
|
public class MigrationUtils {
|
||||||
|
|
||||||
public static void migrateSubject(Subject subject, PermissionHolder holder) {
|
public static void migrateSubject(Subject subject, PermissionHolder holder, int priority) {
|
||||||
// Migrate permissions
|
// Migrate permissions
|
||||||
Map<Set<Context>, Map<String, Boolean>> perms = subject.getSubjectData().getAllPermissions();
|
Map<Set<Context>, Map<String, Boolean>> perms = subject.getSubjectData().getAllPermissions();
|
||||||
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
|
for (Map.Entry<Set<Context>, Map<String, Boolean>> e : perms.entrySet()) {
|
||||||
@ -77,11 +77,11 @@ public class MigrationUtils {
|
|||||||
for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
|
for (Map.Entry<String, String> opt : e.getValue().entrySet()) {
|
||||||
if (opt.getKey().equalsIgnoreCase("prefix")) {
|
if (opt.getKey().equalsIgnoreCase("prefix")) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(NodeFactory.makePrefixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
holder.setPermission(NodeFactory.makePrefixNode(priority, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
} else if (opt.getKey().equalsIgnoreCase("suffix")) {
|
} else if (opt.getKey().equalsIgnoreCase("suffix")) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(NodeFactory.makeSuffixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
holder.setPermission(NodeFactory.makeSuffixNode(priority, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -111,7 +111,7 @@ public class MigrationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setPermission(new NodeBuilder("group." + convertGroupName(s.getIdentifier().toLowerCase())).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
holder.setPermission(new NodeBuilder("group." + convertName(s.getIdentifier())).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {}
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,8 +137,8 @@ public class MigrationUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertGroupName(String s) {
|
public static String convertName(String s) {
|
||||||
return s.replace(' ', '_');
|
return s.replace(' ', '_').toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user