3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 14:50:08 +01:00
Paper/nms-patches/WorldMap.patch

134 Zeilen
6.4 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldMap.java
+++ b/net/minecraft/server/WorldMap.java
2020-06-25 02:00:00 +02:00
@@ -11,6 +11,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.UUID;
+
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.map.CraftMapView;
2018-07-15 02:00:00 +02:00
+import org.bukkit.craftbukkit.util.CraftChatMessage;
+// CraftBukkit end
+
public class WorldMap extends PersistentBase {
2020-06-25 02:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
@@ -28,8 +37,18 @@
2019-04-23 04:00:00 +02:00
public final Map<String, MapIcon> decorations = Maps.newLinkedHashMap();
2020-06-25 02:00:00 +02:00
private final Map<String, WorldMapFrame> n = Maps.newHashMap();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ public final CraftMapView mapView;
+ private CraftServer server;
+ private UUID uniqueId = null;
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
public WorldMap(String s) {
super(s);
+ // CraftBukkit start
+ mapView = new CraftMapView(this);
+ server = (CraftServer) org.bukkit.Bukkit.getServer();
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
public void a(int i, int j, int k, boolean flag, boolean flag1, ResourceKey<World> resourcekey) {
@@ -52,12 +71,30 @@
2019-04-23 04:00:00 +02:00
@Override
public void a(NBTTagCompound nbttagcompound) {
2020-06-25 02:00:00 +02:00
- DataResult dataresult = DimensionManager.a(new Dynamic(DynamicOpsNBT.a, nbttagcompound.get("dimension")));
+ DataResult<ResourceKey<World>> dataresult = DimensionManager.a(new Dynamic(DynamicOpsNBT.a, nbttagcompound.get("dimension"))); // CraftBukkit - decompile error
Logger logger = WorldMap.LOGGER;
logger.getClass();
- this.map = (ResourceKey) dataresult.resultOrPartial(logger::error).orElseThrow(() -> {
- return new IllegalArgumentException("Invalid map dimension: " + nbttagcompound.get("dimension"));
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ this.map = (ResourceKey) dataresult.resultOrPartial(logger::error).orElseGet(() -> {
+ long least = nbttagcompound.getLong("UUIDLeast");
+ long most = nbttagcompound.getLong("UUIDMost");
+
+ if (least != 0L && most != 0L) {
+ this.uniqueId = new UUID(most, least);
+
+ CraftWorld world = (CraftWorld) server.getWorld(this.uniqueId);
+ // Check if the stored world details are correct.
+ if (world == null) {
+ /* All Maps which do not have their valid world loaded are set to a dimension which hopefully won't be reached.
+ This is to prevent them being corrupted with the wrong map data. */
2020-06-25 02:00:00 +02:00
+ // PAIL: Use Vanilla exception handling for now
+ } else {
2020-06-25 02:00:00 +02:00
+ return world.getHandle().getDimensionKey();
+ }
+ }
2020-06-25 02:00:00 +02:00
+ throw new IllegalArgumentException("Invalid map dimension: " + nbttagcompound.get("dimension"));
+ // CraftBukkit end
});
this.centerX = nbttagcompound.getInt("xCenter");
this.centerZ = nbttagcompound.getInt("zCenter");
@@ -92,13 +129,32 @@
2019-04-23 04:00:00 +02:00
@Override
2016-05-10 13:47:39 +02:00
public NBTTagCompound b(NBTTagCompound nbttagcompound) {
2020-06-25 02:00:00 +02:00
- DataResult dataresult = MinecraftKey.a.encodeStart(DynamicOpsNBT.a, this.map.a());
+ DataResult<NBTBase> dataresult = MinecraftKey.a.encodeStart(DynamicOpsNBT.a, this.map.a()); // CraftBukkit - decompile error
Logger logger = WorldMap.LOGGER;
logger.getClass();
dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
nbttagcompound.set("dimension", nbtbase);
});
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ if (true) {
+ if (this.uniqueId == null) {
+ for (org.bukkit.World world : server.getWorlds()) {
+ CraftWorld cWorld = (CraftWorld) world;
2020-06-25 02:00:00 +02:00
+ if (cWorld.getHandle().getDimensionKey() == this.map) {
+ this.uniqueId = cWorld.getUID();
+ break;
+ }
+ }
+ }
+ /* Perform a second check to see if a matching world was found, this is a necessary
+ change incase Maps are forcefully unlinked from a World and lack a UID.*/
+ if (this.uniqueId != null) {
+ nbttagcompound.setLong("UUIDLeast", this.uniqueId.getLeastSignificantBits());
+ nbttagcompound.setLong("UUIDMost", this.uniqueId.getMostSignificantBits());
+ }
+ }
+ // CraftBukkit end
nbttagcompound.setInt("xCenter", this.centerX);
nbttagcompound.setInt("zCenter", this.centerZ);
2020-06-25 02:00:00 +02:00
nbttagcompound.setByte("scale", this.scale);
@@ -389,12 +445,25 @@
2015-02-26 23:41:06 +01:00
2016-11-17 02:41:03 +01:00
@Nullable
2016-02-29 22:32:46 +01:00
public Packet<?> a(ItemStack itemstack) {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ org.bukkit.craftbukkit.map.RenderData render = WorldMap.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.trackee.getBukkitEntity()); // CraftBukkit
+
+ java.util.Collection<MapIcon> icons = new java.util.ArrayList<MapIcon>();
+
+ for ( org.bukkit.map.MapCursor cursor : render.cursors) {
+
+ if (cursor.isVisible()) {
2018-07-15 02:00:00 +02:00
+ icons.add(new MapIcon(MapIcon.Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
2015-02-26 23:41:06 +01:00
+ }
+ }
+
if (this.d) {
this.d = false;
2020-06-25 02:00:00 +02:00
- return new PacketPlayOutMap(ItemWorldMap.d(itemstack), WorldMap.this.scale, WorldMap.this.track, WorldMap.this.locked, WorldMap.this.decorations.values(), WorldMap.this.colors, this.e, this.f, this.g + 1 - this.e, this.h + 1 - this.f);
+ return new PacketPlayOutMap(ItemWorldMap.d(itemstack), WorldMap.this.scale, WorldMap.this.track, WorldMap.this.locked, icons, render.buffer, this.e, this.f, this.g + 1 - this.e, this.h + 1 - this.f);
2015-02-26 23:41:06 +01:00
} else {
2020-06-25 02:00:00 +02:00
- return this.i++ % 5 == 0 ? new PacketPlayOutMap(ItemWorldMap.d(itemstack), WorldMap.this.scale, WorldMap.this.track, WorldMap.this.locked, WorldMap.this.decorations.values(), WorldMap.this.colors, 0, 0, 0, 0) : null;
+ return this.i++ % 5 == 0 ? new PacketPlayOutMap(ItemWorldMap.d(itemstack), WorldMap.this.scale, WorldMap.this.track, WorldMap.this.locked, icons, render.buffer, 0, 0, 0, 0) : null;
2015-02-26 23:41:06 +01:00
}
+ // CraftBukkit end
}
public void a(int i, int j) {