summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemWrittenBook.patch
blob: e43dd9090a8be306c55ce842c11732045633c8c8 (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
--- a/net/minecraft/server/ItemWrittenBook.java
+++ b/net/minecraft/server/ItemWrittenBook.java
@@ -62,6 +62,23 @@
 
                     Object object;
 
+                    // CraftBukkit start
+                    // Some commands use the worldserver variable but we leave it full of null values,
+                    // so we must temporarily populate it with the world of the commandsender
+                    WorldServer[] prev = MinecraftServer.getServer().worldServer;
+                    MinecraftServer server = MinecraftServer.getServer();
+                    server.worldServer = new WorldServer[server.worlds.size()];
+                    server.worldServer[0] = (WorldServer) entityhuman.getWorld();
+                    int bpos = 0;
+                    for (int pos = 1; pos < server.worldServer.length; pos++) {
+                        WorldServer world = server.worlds.get(bpos++);
+                        if (server.worldServer[0] == world) {
+                            pos--;
+                            continue;
+                        }
+                        server.worldServer[pos] = world;
+                    }
+                    // CraftBukkit end
                     try {
                         IChatBaseComponent ichatbasecomponent = IChatBaseComponent.ChatSerializer.b(s);
 
@@ -69,6 +86,7 @@
                     } catch (Exception exception) {
                         object = new ChatComponentText(s);
                     }
+                    finally { MinecraftServer.getServer().worldServer = prev; } // CraftBukkit
 
                     nbttaglist.set(i, (NBTBase) (new NBTTagString(IChatBaseComponent.ChatSerializer.a((IChatBaseComponent) object))));
                 }