SPIGOT-7535: Fix maps not having an ID and also call MapInitializeEvent in more places

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2023-12-08 19:20:05 +11:00
parent e3eb82a356
commit aacf3bd308
2 changed files with 26 additions and 33 deletions

View File

@ -504,15 +504,31 @@
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey);
@@ -1277,6 +1471,7 @@
@@ -1272,11 +1466,22 @@
@Nullable
@Override
public WorldMap getMapData(String s) {
- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), s);
+ // CraftBukkit start
+ WorldMap worldmap = (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), s);
+ if (worldmap != null) {
+ worldmap.id = s;
+ }
+ return worldmap;
+ // CraftBukkit end
}
@Override
public void setMapData(String s, WorldMap worldmap) {
+ worldmap.id = s; // CraftBukkit
+ // CraftBukkit start
+ worldmap.id = s;
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
this.getServer().overworld().getDataStorage().set(s, worldmap);
}
@@ -1574,6 +1769,11 @@
@@ -1574,6 +1779,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
@ -524,7 +540,7 @@
this.updateNeighborsAt(blockposition, block);
}
@@ -1593,12 +1793,12 @@
@@ -1593,12 +1803,12 @@
}
public boolean isFlat() {
@ -539,7 +555,7 @@
}
@Nullable
@@ -1621,7 +1821,7 @@
@@ -1621,7 +1831,7 @@
private static <T> String getTypeCount(Iterable<T> iterable, Function<T, String> function) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@ -548,7 +564,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1630,7 +1830,7 @@
@@ -1630,7 +1840,7 @@
object2intopenhashmap.addTo(s, 1);
}
@ -557,7 +573,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1641,17 +1841,33 @@
@@ -1641,17 +1851,33 @@
}
public static void makeObsidianPlatform(WorldServer worldserver) {
@ -593,7 +609,7 @@
}
@Override
@@ -1785,6 +2001,8 @@
@@ -1785,6 +2011,8 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@ -602,7 +618,7 @@
}
public void onTrackingEnd(Entity entity) {
@@ -1821,6 +2039,14 @@
@@ -1821,6 +2049,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);

View File

@ -1,18 +1,6 @@
--- a/net/minecraft/world/item/ItemWorldMap.java
+++ b/net/minecraft/world/item/ItemWorldMap.java
@@ -33,6 +33,11 @@
import net.minecraft.world.level.material.MaterialMapColor;
import net.minecraft.world.level.saveddata.maps.WorldMap;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.server.MapInitializeEvent;
+// CraftBukkit end
+
public class ItemWorldMap extends ItemWorldMapBase {
public static final int IMAGE_WIDTH = 128;
@@ -69,7 +74,7 @@
@@ -69,7 +69,7 @@
public static Integer getMapId(ItemStack itemstack) {
NBTTagCompound nbttagcompound = itemstack.getTag();
@ -21,14 +9,3 @@
}
public static int createNewSavedData(World world, int i, int j, int k, boolean flag, boolean flag1, ResourceKey<World> resourcekey) {
@@ -77,6 +82,10 @@
int l = world.getFreeMapId();
world.setMapData(makeKey(l), worldmap);
+ // CraftBukkit start
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
return l;
}