From d8020e77feb52b2c098f96071ad7e03915bbe776 Mon Sep 17 00:00:00 2001 From: Larry Date: Fri, 24 Jul 2020 11:43:49 +0100 Subject: [PATCH] Fix import with no users object (#2488, #2489) --- .../lucko/luckperms/common/backup/Importer.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java index 0fec4d633..efafe9cb9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java @@ -44,6 +44,7 @@ import net.luckperms.api.model.data.DataType; import net.luckperms.api.node.Node; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -122,6 +123,14 @@ public class Importer implements Runnable { this.plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); } + private Set> getDataSection(String id) { + if (this.data.has(id)) { + return this.data.get(id).getAsJsonObject().entrySet(); + } else { + return Collections.emptySet(); + } + } + @Override public void run() { long startTime = System.currentTimeMillis(); @@ -136,16 +145,16 @@ public class Importer implements Runnable { Map> tracks = new HashMap<>(); Map users = new HashMap<>(); - for (Map.Entry group : this.data.get("groups").getAsJsonObject().entrySet()) { + for (Map.Entry group : getDataSection("groups")) { groups.put(group.getKey(), NodeJsonSerializer.deserializeNodes(group.getValue().getAsJsonObject().get("nodes").getAsJsonArray())); } - for (Map.Entry track : this.data.get("tracks").getAsJsonObject().entrySet()) { + for (Map.Entry track : getDataSection("tracks")) { JsonArray trackGroups = track.getValue().getAsJsonObject().get("groups").getAsJsonArray(); List trackGroupsList = new ArrayList<>(); trackGroups.forEach(g -> trackGroupsList.add(g.getAsString())); tracks.put(track.getKey(), trackGroupsList); } - for (Map.Entry user : this.data.get("users").getAsJsonObject().entrySet()) { + for (Map.Entry user : getDataSection("users")) { JsonObject jsonData = user.getValue().getAsJsonObject(); UUID uuid = UUID.fromString(user.getKey());