From 0075684ee6d65309aa6c67b8f82b22c39aaea049 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Wed, 22 Mar 2023 19:06:55 +0100 Subject: [PATCH] Make party loading more resilient --- .../com/gmail/nossr50/party/PartyManager.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 16965629f..c723dbd50 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -28,6 +28,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; import java.util.UUID; +import java.util.logging.Level; public final class PartyManager { private static final String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml"; @@ -609,34 +610,38 @@ public final class PartyManager { ArrayList hasAlly = new ArrayList<>(); for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) { - Party party = new Party(partyName); + try { + Party party = new Party(partyName); - String[] leaderSplit = partiesFile.getString(partyName + ".Leader").split("[|]"); - party.setLeader(new PartyLeader(UUID.fromString(leaderSplit[0]), leaderSplit[1])); - party.setPassword(partiesFile.getString(partyName + ".Password")); - party.setLocked(partiesFile.getBoolean(partyName + ".Locked")); - party.setLevel(partiesFile.getInt(partyName + ".Level")); - party.setXp(partiesFile.getInt(partyName + ".Xp")); + String[] leaderSplit = partiesFile.getString(partyName + ".Leader").split("[|]"); + party.setLeader(new PartyLeader(UUID.fromString(leaderSplit[0]), leaderSplit[1])); + party.setPassword(partiesFile.getString(partyName + ".Password")); + party.setLocked(partiesFile.getBoolean(partyName + ".Locked")); + party.setLevel(partiesFile.getInt(partyName + ".Level")); + party.setXp(partiesFile.getInt(partyName + ".Xp")); - if (partiesFile.getString(partyName + ".Ally") != null) { - hasAlly.add(party); + if (partiesFile.getString(partyName + ".Ally") != null) { + hasAlly.add(party); + } + + party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE"))); + party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE"))); + + for (ItemShareType itemShareType : ItemShareType.values()) { + party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true)); + } + + LinkedHashMap members = party.getMembers(); + + for (String memberEntry : partiesFile.getStringList(partyName + ".Members")) { + String[] memberSplit = memberEntry.split("[|]"); + members.put(UUID.fromString(memberSplit[0]), memberSplit[1]); + } + + parties.add(party); + } catch (Exception e) { + mcMMO.p.getLogger().log(Level.WARNING, "An exception occurred while loading a party with name '" + partyName + "'. Skipped loading party.", e); } - - party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE"))); - party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE"))); - - for (ItemShareType itemShareType : ItemShareType.values()) { - party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true)); - } - - LinkedHashMap members = party.getMembers(); - - for (String memberEntry : partiesFile.getStringList(partyName + ".Members")) { - String[] memberSplit = memberEntry.split("[|]"); - members.put(UUID.fromString(memberSplit[0]), memberSplit[1]); - } - - parties.add(party); } mcMMO.p.debug("Loaded (" + parties.size() + ") Parties...");