From dafadb7573dda165d077047126448e2806cb7f29 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 11 Jul 2017 23:17:57 -0400
Subject: [PATCH] Fix Anvil Level sync to client

https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/763827668e6e5cddc111f3c93a0d718fec21ff51

Was done incorrectly and is now causing level desyncs to client.

Always send current level to the client, and instead make setWindowProperty set the level.

diff --git a/src/main/java/net/minecraft/server/ContainerAnvil.java b/src/main/java/net/minecraft/server/ContainerAnvil.java
index 229f4f8829..fb3413d81e 100644
--- a/src/main/java/net/minecraft/server/ContainerAnvil.java
+++ b/src/main/java/net/minecraft/server/ContainerAnvil.java
@@ -377,9 +377,9 @@ public class ContainerAnvil extends Container {
         for (int i = 0; i < this.listeners.size(); ++i) {
             ICrafting icrafting = (ICrafting) this.listeners.get(i);
 
-            if (this.lastLevelCost != this.levelCost) {
+            //if (this.lastLevelCost != this.levelCost) { // Paper - this was the wrong solution to this, fixing it correctly in CraftPlayer
                 icrafting.setContainerData(this, 0, this.levelCost);
-            }
+            //} // Paper
         }
 
         this.lastLevelCost = this.levelCost;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index a546f3118e..8686457e13 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1378,6 +1378,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
         if (container.getBukkitView().getType() != prop.getType()) {
             return false;
         }
+        // Paper start
+        if (prop == Property.REPAIR_COST && container instanceof net.minecraft.server.ContainerAnvil) {
+            ((net.minecraft.server.ContainerAnvil) container).levelCost = value;
+        }
+        // Paper end
         getHandle().setContainerData(container, prop.getId(), value);
         return true;
     }
-- 
2.18.0