summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemWorldMap.patch
blob: 42baeba5950bef69eb9c597457f7f6e6fd3f6b57 (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
--- a/net/minecraft/server/ItemWorldMap.java
+++ b/net/minecraft/server/ItemWorldMap.java
@@ -5,6 +5,11 @@
 import com.google.common.collect.Multisets;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.server.MapInitializeEvent;
+// CraftBukkit end
+
 public class ItemWorldMap extends ItemWorldMapBase {
 
     protected ItemWorldMap() {
@@ -12,41 +17,50 @@
     }
 
     public static ItemStack a(World world, double d0, double d1, byte b0, boolean flag, boolean flag1) {
-        ItemStack itemstack = new ItemStack(Items.FILLED_MAP, 1, world.b("map"));
+        World worldMain = world.getServer().getServer().worlds.get(0); // CraftBukkit - store reference to primary world
+        ItemStack itemstack = new ItemStack(Items.FILLED_MAP, 1, worldMain.b("map")); // CraftBukkit - use primary world for maps
         String s = "map_" + itemstack.getData();
         WorldMap worldmap = new WorldMap(s);
 
-        world.a(s, (PersistentBase) worldmap);
+        worldMain.a(s, (PersistentBase) worldmap); // CraftBukkit
         worldmap.scale = b0;
         worldmap.a(d0, d1, worldmap.scale);
-        worldmap.map = (byte) world.worldProvider.getDimensionManager().getDimensionID();
+        worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit - use bukkit dimension
         worldmap.track = flag;
         worldmap.unlimitedTracking = flag1;
         worldmap.c();
+        org.bukkit.craftbukkit.event.CraftEventFactory.callEvent(new org.bukkit.event.server.MapInitializeEvent(worldmap.mapView)); // CraftBukkit
         return itemstack;
     }
 
     @Nullable
     public WorldMap getSavedMap(ItemStack itemstack, World world) {
+        World worldMain = world.getServer().getServer().worlds.get(0); // CraftBukkit - store reference to primary world
         String s = "map_" + itemstack.getData();
-        WorldMap worldmap = (WorldMap) world.a(WorldMap.class, s);
+        WorldMap worldmap = (WorldMap) worldMain.a(WorldMap.class, s); // CraftBukkit - use primary world for maps
 
         if (worldmap == null && !world.isClientSide) {
-            itemstack.setData(world.b("map"));
+            itemstack.setData(worldMain.b("map")); // CraftBukkit - use primary world for maps
             s = "map_" + itemstack.getData();
             worldmap = new WorldMap(s);
             worldmap.scale = 3;
             worldmap.a((double) world.getWorldData().b(), (double) world.getWorldData().d(), worldmap.scale);
-            worldmap.map = (byte) world.worldProvider.getDimensionManager().getDimensionID();
+            worldmap.map = (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps
             worldmap.c();
-            world.a(s, (PersistentBase) worldmap);
+            worldMain.a(s, (PersistentBase) worldmap); // CraftBukkit - use primary world for maps
+
+            // CraftBukkit start
+            MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+            Bukkit.getServer().getPluginManager().callEvent(event);
+            // CraftBukkit end
         }
 
         return worldmap;
     }
 
     public void a(World world, Entity entity, WorldMap worldmap) {
-        if (world.worldProvider.getDimensionManager().getDimensionID() == worldmap.map && entity instanceof EntityHuman) {
+        // CraftBukkit - world.worldProvider -> ((WorldServer) world)
+        if (((WorldServer) world).dimension == worldmap.map && entity instanceof EntityHuman) {
             int i = 1 << worldmap.scale;
             int j = worldmap.centerX;
             int k = worldmap.centerZ;
@@ -308,6 +322,7 @@
     protected static void a(ItemStack itemstack, World world, int i) {
         WorldMap worldmap = Items.FILLED_MAP.getSavedMap(itemstack, world);
 
+        world = world.getServer().getServer().worlds.get(0); // CraftBukkit - use primary world for maps
         itemstack.setData(world.b("map"));
         WorldMap worldmap1 = new WorldMap("map_" + itemstack.getData());
 
@@ -318,6 +333,10 @@
             worldmap1.map = worldmap.map;
             worldmap1.c();
             world.a("map_" + itemstack.getData(), (PersistentBase) worldmap1);
+            // CraftBukkit start
+            MapInitializeEvent event = new MapInitializeEvent(worldmap1.mapView);
+            Bukkit.getServer().getPluginManager().callEvent(event);
+            // CraftBukkit end
         }
 
     }
@@ -325,6 +344,7 @@
     protected static void b(ItemStack itemstack, World world) {
         WorldMap worldmap = Items.FILLED_MAP.getSavedMap(itemstack, world);
 
+        world = world.getServer().getServer().worlds.get(0); // CraftBukkit - use primary world for maps
         itemstack.setData(world.b("map"));
         WorldMap worldmap1 = new WorldMap("map_" + itemstack.getData());
 
@@ -336,6 +356,10 @@
             worldmap1.map = worldmap.map;
             worldmap1.c();
             world.a("map_" + itemstack.getData(), (PersistentBase) worldmap1);
+            // CraftBukkit start
+            MapInitializeEvent event = new MapInitializeEvent(worldmap1.mapView);
+            Bukkit.getServer().getPluginManager().callEvent(event);
+            // CraftBukkit end
         }
 
     }