mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-08 09:27:38 +01:00
Fixes concurrency issue when loading blueprints and bundles
https://github.com/BentoBoxWorld/BentoBox/issues/868
This commit is contained in:
parent
ecca366fec
commit
fefa806852
@ -14,6 +14,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -81,8 +82,9 @@ public class BlueprintsManager {
|
|||||||
|
|
||||||
public BlueprintsManager(@NonNull BentoBox plugin) {
|
public BlueprintsManager(@NonNull BentoBox plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.blueprintBundles = new HashMap<>();
|
// Must use ConcurrentHashMap because the maps are loaded async and they need to be thread safe
|
||||||
this.blueprints = new HashMap<>();
|
this.blueprintBundles = new ConcurrentHashMap<>();
|
||||||
|
this.blueprints = new ConcurrentHashMap<>();
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
GsonBuilder builder = new GsonBuilder()
|
GsonBuilder builder = new GsonBuilder()
|
||||||
.excludeFieldsWithoutExposeAnnotation()
|
.excludeFieldsWithoutExposeAnnotation()
|
||||||
@ -162,7 +164,6 @@ public class BlueprintsManager {
|
|||||||
.runTaskAsynchronously(
|
.runTaskAsynchronously(
|
||||||
plugin, () -> {
|
plugin, () -> {
|
||||||
blueprintBundles.put(addon, new ArrayList<>());
|
blueprintBundles.put(addon, new ArrayList<>());
|
||||||
|
|
||||||
// See if there are any schems that need converting
|
// See if there are any schems that need converting
|
||||||
new SchemToBlueprint(plugin).convertSchems(addon);
|
new SchemToBlueprint(plugin).convertSchems(addon);
|
||||||
if (!loadBundles(addon)) {
|
if (!loadBundles(addon)) {
|
||||||
@ -189,7 +190,9 @@ public class BlueprintsManager {
|
|||||||
try {
|
try {
|
||||||
BlueprintBundle bb = gson.fromJson(new FileReader(file), BlueprintBundle.class);
|
BlueprintBundle bb = gson.fromJson(new FileReader(file), BlueprintBundle.class);
|
||||||
if (bb != null) {
|
if (bb != null) {
|
||||||
blueprintBundles.putIfAbsent(addon, new ArrayList<>()).add(bb);
|
blueprintBundles
|
||||||
|
.get(addon)
|
||||||
|
.add(bb);
|
||||||
plugin.log("Loaded Blueprint Bundle '" + bb.getUniqueId() + FOR + addon.getDescription().getName());
|
plugin.log("Loaded Blueprint Bundle '" + bb.getUniqueId() + FOR + addon.getDescription().getName());
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user