Fix MapInitializeEvent firing every tick

This commit is contained in:
md_5 2018-07-16 12:45:01 +10:00
parent 8fbc72b714
commit 84676f363c

View file

@ -30,7 +30,7 @@
} }
return worldmap; return worldmap;
@@ -33,26 +38,40 @@ @@ -33,26 +38,42 @@
public static int e(ItemStack itemstack) { public static int e(ItemStack itemstack) {
NBTTagCompound nbttagcompound = itemstack.getTag(); NBTTagCompound nbttagcompound = itemstack.getTag();
@ -59,12 +59,14 @@
@Nullable @Nullable
public static WorldMap a(GeneratorAccess generatoraccess, String s) { public static WorldMap a(GeneratorAccess generatoraccess, String s) {
- return (WorldMap) generatoraccess.a(WorldMap::new, s); - return (WorldMap) generatoraccess.a(WorldMap::new, s);
+ // CraftBukkit start + // CraftBukkit start - use primary world for maps and call event
+ WorldMap worldmap = (WorldMap) MinecraftServer.getServer().worlds.get(0).a(WorldMap::new, s); // CraftBukkit - use primary world for maps + WorldMap worldmap = (WorldMap) MinecraftServer.getServer().worlds.get(0).a((id) -> {
+ if (worldmap != null) { + // We only get here when the data file exists, but is not a valid map
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView); + WorldMap newMap = new WorldMap(id);
+ MapInitializeEvent event = new MapInitializeEvent(newMap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event); + Bukkit.getServer().getPluginManager().callEvent(event);
+ } + return newMap;
+ }, s);
+ return worldmap; + return worldmap;
+ // CraftBukkit end + // CraftBukkit end
} }
@ -76,7 +78,7 @@
int i = 1 << worldmap.scale; int i = 1 << worldmap.scale;
int j = worldmap.centerX; int j = worldmap.centerX;
int k = worldmap.centerZ; int k = worldmap.centerZ;
@@ -199,7 +218,8 @@ @@ -199,7 +220,8 @@
WorldMap worldmap = getSavedMap(itemstack, world); WorldMap worldmap = getSavedMap(itemstack, world);
if (worldmap != null) { if (worldmap != null) {