我知道可以使用Bukkit.getServer().createMap(Bukkit.getWorld("world"));
创建地图,但这将创建具有第一个可用ID的地图。可以说我想创建一个ID为10000的地图。当我尝试使用Bukkit.getServer().getMap(10000);
时,它返回null,因为该地图不存在。
如何创建具有特定ID的MapView?
最佳答案
很难看,但是可以用:
import net.minecraft.server.v1_11_R1.WorldMap;
import net.minecraft.server.v1_11_R1.WorldServer;
public static MapView createMap(World world, int id) {
WorldServer ws = ((CraftWorld) world).getHandle();
String name = "map_" + id;
WorldMap map = new WorldMap(name);
map.scale = 3;
map.a(ws.getWorldData().b(), ws.getWorldData().d(), map.scale);
map.map = (byte) ws.dimension;
map.c();
ws.getServer().getServer().worlds.get(0).a(name, map);
MapInitializeEvent event = new MapInitializeEvent(map.mapView);
Bukkit.getServer().getPluginManager().callEvent(event);
return map.mapView;
}
仅在Spigot 1.11.2上进行了测试,但此方法应在其他版本上适用。我刚刚修改了NMS现有代码以使用自定义ID。
这是非常低级的NMS,因此如果此方法从现在起不再有效,我不会感到惊讶。