Skip to content

Commit

Permalink
feat(migrator): Provide a luckperms migrator for outdated data
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Mar 4, 2024
1 parent 473af96 commit e38c4ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>

<project.package>${project.groupId}.plugin.${project.artifactId}</project.package>
<deps.core.version>1.1.0</deps.core.version>
<deps.core.version>1.1.1</deps.core.version>
</properties>
<groupId>com.artformgames</groupId>
<artifactId>usersuffix</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>

<name>UserSuffix</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cc.carm.lib.easysql.api.SQLQuery;
import com.artformgames.core.ArtCore;
import com.artformgames.core.user.UserKey;
import com.artformgames.plugin.usersuffix.user.SuffixAccount;
import com.artformgames.plugin.usersuffix.user.SuffixLoader;

import java.sql.ResultSet;
Expand All @@ -15,6 +14,10 @@

public class LuckPermsMigrator {

public record CachedRecord(UserKey user,
String content, String formatColor) {
}

// REGEX For suffix.<weight>.<content>
public static final Pattern PATTERN = Pattern.compile("^suffix\\.\\d+\\.(.*)$");

Expand All @@ -25,7 +28,7 @@ public class LuckPermsMigrator {

public static int importData(String sourceTable, String usersTable, boolean purge) {
Set<Integer> indexList = new HashSet<>();
Set<MigrateCache> data = new HashSet<>();
Set<CachedRecord> data = new HashSet<>();
try (SQLQuery query = ArtCore.getSQLManager().createQuery().inTable(sourceTable)
.selectColumns("id", "uuid", "permission")
.build().execute()) {
Expand All @@ -49,15 +52,18 @@ public static int importData(String sourceTable, String usersTable, boolean purg
String username = getUsername(usersTable, uuid);
if (username == null) continue;

UserKey key = importKey(uuid, username);
if (key == null) continue;

indexList.add(rs.getInt("id"));
data.add(new MigrateCache(importKey(uuid, username), content, formatColor));
data.add(new CachedRecord(key, content, formatColor));
}
} catch (Exception ex) {
ex.printStackTrace();
return -1;
}

for (MigrateCache cache : data) { // Insert data into the new table
for (CachedRecord cache : data) { // Insert data into the new table
SuffixLoader.TABLE.createReplace()
.setColumnNames("user", "content", "color")
.setParams(cache.user().id(), cache.content(), cache.content())
Expand Down Expand Up @@ -92,7 +98,11 @@ public static String getUsername(String playersTable, UUID uuid) {
}

public static UserKey importKey(UUID uuid, String username) {
return ArtCore.getUserManager().getKey(uuid);
try {
return ArtCore.getUserManager().upsertKey(uuid, username);
} catch (Exception e) {
return null;
}
}


Expand Down

This file was deleted.

0 comments on commit e38c4ac

Please sign in to comment.