From 4a0507a838fcc8fe18f93452728c68211c98fa95 Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Mon, 30 Nov 2015 19:51:22 +0000 Subject: [PATCH] Clone map of name->uuid when writing to file. Educated-guess for a fix for #213. --- .../src/com/earth2me/essentials/UUIDMap.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/UUIDMap.java b/Essentials/src/com/earth2me/essentials/UUIDMap.java index e0c645777..6cb735d25 100644 --- a/Essentials/src/com/earth2me/essentials/UUIDMap.java +++ b/Essentials/src/com/earth2me/essentials/UUIDMap.java @@ -5,6 +5,7 @@ import org.bukkit.Bukkit; import java.io.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.*; @@ -95,10 +96,15 @@ public class UUIDMap { } public Future _writeUUIDMap() { - final ConcurrentSkipListMap names = ess.getUserMap().getNames(); + Map names = ess.getUserMap().getNames(); if (names.size() < 1) { return null; } + // The _names_ Map is being shallowly cloned because of an issue that occurs during restarts/reloads that + // causes UserMap database to be cleared. The assumed culprit is names.clear() when loading in UserMap. + // + // For more information, please refer to #213. + names = new HashMap<>(names); pendingDiskWrites.incrementAndGet(); Future future = EXECUTOR_SERVICE.submit(new WriteRunner(ess.getDataFolder(), userList, names, pendingDiskWrites)); return future; @@ -108,10 +114,10 @@ public class UUIDMap { private static class WriteRunner implements Runnable { private final File location; private final File endFile; - private final ConcurrentSkipListMap names; + private final Map names; private final AtomicInteger pendingDiskWrites; - private WriteRunner(final File location, final File endFile, final ConcurrentSkipListMap names, final AtomicInteger pendingDiskWrites) { + private WriteRunner(final File location, final File endFile, final Map names, final AtomicInteger pendingDiskWrites) { this.location = location; this.endFile = endFile; this.names = names; @@ -154,4 +160,4 @@ public class UUIDMap { } } } -} \ No newline at end of file +}