aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0095-Improve-Maps-in-item-frames-performance-and-bug-fixe.patch
blob: 74f3c3fd2f0891708620d6e2a0d3c32565cbadaf (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 29 Apr 2016 20:02:00 -0400
Subject: [PATCH] Improve Maps (in item frames) performance and bug fixes

Maps used a modified version of rendering to support plugin controlled
imaging on maps. The Craft Map Renderer is much slower than Vanilla,
causing maps in item frames to cause a noticeable hit on server performance.

This updates the map system to not use the Craft system if we detect that no
custom renderers are in use, defaulting to the much simpler Vanilla system.

Additionally, numerous issues to player position tracking on maps has been fixed.

diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 94eab21f0defe90e7ad169c45de1fdd002f35f7a..d1cf7602a0c47723593be11c030d3c819426d4d4 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -595,6 +595,12 @@ public abstract class EntityHuman extends EntityLiving {
                 return null;
             }
             // CraftBukkit end
+            // Paper start - remove player from map on drop
+            if (itemstack.getItem() == Items.FILLED_MAP) {
+                WorldMap worldmap = ItemWorldMap.getSavedMap(itemstack, this.world);
+                worldmap.updateSeenPlayers(this, itemstack);
+            }
+            // Paper end
 
             return entityitem;
         }
diff --git a/src/main/java/net/minecraft/server/WorldMap.java b/src/main/java/net/minecraft/server/WorldMap.java
index e6d97e7ffae3eadac586bad078123cd4aaa69916..225353e072033d1e5aaf5604b8db255d9a154dc8 100644
--- a/src/main/java/net/minecraft/server/WorldMap.java
+++ b/src/main/java/net/minecraft/server/WorldMap.java
@@ -36,6 +36,7 @@ public class WorldMap extends PersistentBase {
     private final Map<String, MapIconBanner> m = Maps.newHashMap();
     public final Map<String, MapIcon> decorations = Maps.newLinkedHashMap();
     private final Map<String, WorldMapFrame> n = Maps.newHashMap();
+    private org.bukkit.craftbukkit.map.RenderData vanillaRender = new org.bukkit.craftbukkit.map.RenderData(); // Paper
 
     // CraftBukkit start
     public final CraftMapView mapView;
@@ -48,6 +49,7 @@ public class WorldMap extends PersistentBase {
         // CraftBukkit start
         mapView = new CraftMapView(this);
         server = (CraftServer) org.bukkit.Bukkit.getServer();
+        vanillaRender.buffer = colors; // Paper
         // CraftBukkit end
     }
 
@@ -115,6 +117,7 @@ public class WorldMap extends PersistentBase {
             this.m.put(mapiconbanner.f(), mapiconbanner);
             this.a(mapiconbanner.c(), (GeneratorAccess) null, mapiconbanner.f(), (double) mapiconbanner.a().getX(), (double) mapiconbanner.a().getZ(), 180.0D, mapiconbanner.d());
         }
+        this.vanillaRender.buffer = colors; // Paper
 
         NBTTagList nbttaglist1 = nbttagcompound.getList("frames", 10);
 
@@ -195,6 +198,7 @@ public class WorldMap extends PersistentBase {
         this.b();
     }
 
+    public void updateSeenPlayers(EntityHuman entityhuman, ItemStack itemstack) { this.a(entityhuman, itemstack); } // Paper - OBFHELPER
     public void a(EntityHuman entityhuman, ItemStack itemstack) {
         if (!this.humans.containsKey(entityhuman)) {
             WorldMap.WorldMapHumanTracker worldmap_worldmaphumantracker = new WorldMap.WorldMapHumanTracker(entityhuman);
@@ -430,6 +434,21 @@ public class WorldMap extends PersistentBase {
 
     public class WorldMapHumanTracker {
 
+        // Paper start
+        private void addSeenPlayers(java.util.Collection<MapIcon> icons) {
+            org.bukkit.entity.Player player = (org.bukkit.entity.Player) trackee.getBukkitEntity();
+            WorldMap.this.decorations.forEach((name, mapIcon) -> {
+                // If this cursor is for a player check visibility with vanish system
+                org.bukkit.entity.Player other = org.bukkit.Bukkit.getPlayerExact(name); // Spigot
+                if (other == null || player.canSee(other)) {
+                    icons.add(mapIcon);
+                }
+            });
+        }
+        private boolean shouldUseVanillaMap() {
+            return mapView.getRenderers().size() == 1 && mapView.getRenderers().get(0).getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class;
+        }
+        // Paper end
         public final EntityHuman trackee;
         private boolean d = true;
         private int e;
@@ -446,9 +465,12 @@ public class WorldMap extends PersistentBase {
         @Nullable
         public Packet<?> a(ItemStack itemstack) {
             // CraftBukkit start
-            org.bukkit.craftbukkit.map.RenderData render = WorldMap.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.trackee.getBukkitEntity()); // CraftBukkit
+            if (!this.d && this.i % 5 != 0) { this.i++; return null; } // Paper - this won't end up sending, so don't render it!
+            boolean vanillaMaps = shouldUseVanillaMap(); // Paper
+            org.bukkit.craftbukkit.map.RenderData render = !vanillaMaps ? WorldMap.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.trackee.getBukkitEntity()) : WorldMap.this.vanillaRender; // CraftBukkit // Paper
 
             java.util.Collection<MapIcon> icons = new java.util.ArrayList<MapIcon>();
+            if (vanillaMaps) addSeenPlayers(icons); // Paper
 
             for ( org.bukkit.map.MapCursor cursor : render.cursors) {
 
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 1525ea4666d67072f16a04647af238c82bcd3fbb..558093814d19bfc371ea03ea0233c11c04504709 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1011,6 +1011,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
                         {
                             if ( iter.next().trackee == entity )
                             {
+                                map.decorations.remove(entity.getDisplayName().getString()); // Paper
                                 iter.remove();
                             }
                         }
diff --git a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java b/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
index 256a131781721c86dd6cdbc329335964570cbe8c..5768cd512ec166f1e8d1f4a28792015347297c3f 100644
--- a/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
+++ b/src/main/java/org/bukkit/craftbukkit/map/RenderData.java
@@ -5,7 +5,7 @@ import org.bukkit.map.MapCursor;
 
 public class RenderData {
 
-    public final byte[] buffer;
+    public byte[] buffer; // Paper
     public final ArrayList<MapCursor> cursors;
 
     public RenderData() {