From a1590d976937ee3f81d92b4202dd97bfcaae7675 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 4 Sep 2018 01:50:14 -0400
Subject: [PATCH] Fix yet another issue with concurrency with datafixers

---
 ...Fix-concurrency-issues-in-DataFixers.patch | 13 ++++++++
 scripts/importmcdev.sh                        | 31 +++++++++++++------
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/Spigot-Server-Patches/Fix-concurrency-issues-in-DataFixers.patch b/Spigot-Server-Patches/Fix-concurrency-issues-in-DataFixers.patch
index 77728be3c9..054de2a80a 100644
--- a/Spigot-Server-Patches/Fix-concurrency-issues-in-DataFixers.patch
+++ b/Spigot-Server-Patches/Fix-concurrency-issues-in-DataFixers.patch
@@ -44,6 +44,19 @@ index fb2c380f8a..c8e7a8aa10 100644
          return rules.get(key);
      }
  
+diff --git a/src/main/java/com/mojang/datafixers/functions/PointFree.java b/src/main/java/com/mojang/datafixers/functions/PointFree.java
+index 0d88490f77..028942b8ea 100644
+--- a/src/main/java/com/mojang/datafixers/functions/PointFree.java
++++ b/src/main/java/com/mojang/datafixers/functions/PointFree.java
+@@ -0,0 +0,0 @@ public abstract class PointFree<T> {
+     private Function<DynamicOps<?>, T> value;
+ 
+     @SuppressWarnings("ConstantConditions")
+-    public Function<DynamicOps<?>, T> evalCached() {
++    public synchronized Function<DynamicOps<?>, T> evalCached() { // Paper
+         if (!initialized) {
+             initialized = true;
+             value = eval();
 diff --git a/src/main/java/com/mojang/datafixers/schemas/Schema.java b/src/main/java/com/mojang/datafixers/schemas/Schema.java
 index 7c67d989e0..45f3ef5957 100644
 --- a/src/main/java/com/mojang/datafixers/schemas/Schema.java
diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh
index b509f268ce..156bf3893b 100755
--- a/scripts/importmcdev.sh
+++ b/scripts/importmcdev.sh
@@ -83,23 +83,36 @@ for f in $files; do
 	fi
 done
 
-# Import Libraries - these must always be mapped manually, no automatic stuff
-#             group       lib             prefix                    files
-importLibrary com.mojang datafixerupper com/mojang/datafixers \
-    schemas/Schema.java \
-    DataFixerUpper.java \
-    types/families/RecursiveTypeFamily.java
-
-
+########################################################
+########################################################
+########################################################
+#                   NMS IMPORTS
 # Temporarily add new NMS dev imports here before you run paper patch
 # but after you have paper rb'd your changes, remove the line from this file before committing.
-# we do not need any lines added to this file
+# we do not need any lines added to this file for NMS
 
 # import FileName
 
 
 
+########################################################
+########################################################
+########################################################
+#              LIBRARY IMPORTS
+# These must always be mapped manually, no automatic stuff
+#
+#             # group    # lib          # prefix               # many files
+importLibrary com.mojang datafixerupper com/mojang/datafixers \
+    schemas/Schema.java \
+    DataFixerUpper.java \
+    functions/PointFree.java \
+    types/families/RecursiveTypeFamily.java
 
+# dont forget \ at end of each line but last
+
+########################################################
+########################################################
+########################################################
 set -e
 cd "$workdir/Spigot/Spigot-Server/"
 rm -rf nms-patches applyPatches.sh makePatches.sh >/dev/null 2>&1