aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0063-Optimize-Spigot-s-Anti-X-Ray.patch
blob: f9a9f2f6632445b8bdb3b625511c63c4c7c84426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From 4222b417aed27fedcce9ca54c96f63fa17e504bb Mon Sep 17 00:00:00 2001
From: Iceee <andrew@opticgaming.tv>
Date: Thu, 23 Apr 2015 17:26:21 -0400
Subject: [PATCH] Optimize Spigot's Anti X-Ray


diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 06c70578..fb16a8ad 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -252,6 +252,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
         timings.doTickTiles.startTiming(); // Spigot
         this.h();
         timings.doTickTiles.stopTiming(); // Spigot
+        spigotConfig.antiXrayInstance.flushUpdates(this); // PaperSpigot
         this.methodProfiler.c("chunkMap");
         timings.doChunkMap.startTiming(); // Spigot
         this.manager.flush();
diff --git a/src/main/java/org/spigotmc/AntiXray.java b/src/main/java/org/spigotmc/AntiXray.java
index 7221b507..5466a61c 100644
--- a/src/main/java/org/spigotmc/AntiXray.java
+++ b/src/main/java/org/spigotmc/AntiXray.java
@@ -8,6 +8,11 @@ import net.minecraft.server.Blocks;
 import net.minecraft.server.World;
 import org.bukkit.craftbukkit.util.CraftMagicNumbers;
 
+// PaperSpigot start
+import java.util.HashSet;
+import java.util.Set;
+// PaperSpigot end
+
 public class AntiXray
 {
 
@@ -18,6 +23,10 @@ public class AntiXray
     private final boolean[] obfuscateBlocks = new boolean[ Short.MAX_VALUE ];
     // Used to select a random replacement ore
     private final byte[] replacementOres;
+    // PaperSpigot start
+    public boolean queueUpdates = true;
+    public final Set<BlockPosition> pendingUpdates = new HashSet<BlockPosition>();
+    // PaperSpigot end
 
     public AntiXray(SpigotWorldConfig config)
     {
@@ -43,6 +52,25 @@ public class AntiXray
         replacementOres = blocks.toArray();
     }
 
+    /**
+     * PaperSpigot - Flush queued block updates for world.
+     */
+    public void flushUpdates(World world)
+    {
+        if ( world.spigotConfig.antiXray && !pendingUpdates.isEmpty() )
+        {
+            queueUpdates = false;
+
+            for ( BlockPosition position : pendingUpdates )
+            {
+                updateNearbyBlocks( world, position );
+            }
+
+            pendingUpdates.clear();
+            queueUpdates = true;
+        }
+    }
+
     /**
      * Starts the timings handler, then updates all blocks within the set radius
      * of the given coordinate, revealing them if they are hidden ores.
@@ -51,6 +79,13 @@ public class AntiXray
     {
         if ( world.spigotConfig.antiXray )
         {
+            // PaperSpigot start
+            if ( queueUpdates )
+            {
+                pendingUpdates.add( position );
+                return;
+            }
+            // PaperSpigot end
             update.startTiming();
             updateNearbyBlocks( world, position, 2, false ); // 2 is the radius, we shouldn't change it as that would make it exponentially slower
             update.stopTiming();
-- 
2.34.0