SPIGOT-4608: Improve quality of MapMeta APIs

This commit is contained in:
md_5 2019-02-05 21:29:03 +11:00
parent 2ced02339a
commit 3d19f011e9
3 changed files with 27 additions and 1 deletions

View File

@ -1244,7 +1244,7 @@ public final class CraftServer implements Server {
@Override
@Deprecated
public CraftMapView getMap(short id) {
public CraftMapView getMap(int id) {
PersistentCollection collection = console.getWorldServer(DimensionManager.OVERWORLD).worldMaps;
WorldMap worldmap = (WorldMap) collection.get(DimensionManager.OVERWORLD, WorldMap::new, "map_" + id);
if (worldmap == null) {

View File

@ -6,12 +6,15 @@ import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.NBTTagInt;
import net.minecraft.server.NBTTagString;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.map.MapView;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@ -147,6 +150,22 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
this.mapId = id;
}
@Override
public boolean hasMapView() {
return mapId != null;
}
@Override
public MapView getMapView() {
Preconditions.checkState(hasMapView(), "Item does not have map associated - check hasMapView() first!");
return Bukkit.getMap(mapId);
}
@Override
public void setMapView(MapView map) {
this.mapId = (map != null) ? map.getId() : null;
}
boolean hasScaling() {
return scaling != SCALING_EMPTY;
}

View File

@ -206,6 +206,13 @@ public class Commodore
super.visitMethodInsn( opcode, owner, name, "()I", itf );
return;
}
// SPIGOT-4608
if ( (owner.equals( "org/bukkit/Bukkit" ) || owner.equals( "org/bukkit/Server" ) ) && name.equals( "getMap" ) && desc.equals( "(Lorg/bukkit/map/MapView;)S" ) )
{
// Should be same size on stack so just call other method
super.visitMethodInsn( opcode, owner, name, "(Lorg/bukkit/map/MapView;)I", itf );
return;
}
if ( modern )
{