Created
July 23, 2011 02:58
-
-
Save SpaceManiac/1100901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.platymuus.bukkit.mapapi; | |
import net.minecraft.server.EntityPlayer; | |
import net.minecraft.server.ItemStack; | |
import net.minecraft.server.Item; | |
import net.minecraft.server.Packet; | |
import net.minecraft.server.WorldMap; | |
import net.minecraft.server.Packet131; | |
import org.bukkit.Material; | |
import org.bukkit.World; | |
import org.bukkit.craftbukkit.CraftWorld; | |
import org.bukkit.craftbukkit.entity.CraftPlayer; | |
import org.bukkit.entity.Player; | |
/** | |
* Map API implementation for CraftBukkit. Do not use directly. | |
*/ | |
public final class CraftMapAPI extends MapAPI { | |
protected CraftMapAPI() {} | |
@Override | |
public void sendRawData(Player player, short mapId, byte[] data) { | |
Packet packet = new Packet131((short) Material.MAP.getId(), mapId, data); | |
EntityPlayer entity = ((CraftPlayer) player).getHandle(); | |
entity.netServerHandler.sendPacket(packet); | |
} | |
@Override | |
public void sendMap(Player player, short mapId, byte[] data) { | |
for (int col = 0; col < 128; ++col) { | |
byte[] raw = new byte[131]; | |
raw[0] = 0; | |
raw[1] = (byte) col; | |
raw[2] = 0; | |
for (int row = 0; row < 128; ++row) { | |
raw[3 + row] = data[row * 128 + col]; | |
} | |
sendRawData(player, mapId, raw); | |
} | |
} | |
@Override | |
public void saveMap(World world, short mapId, MapInfo info) { | |
WorldMap worldMap = getWorldMap(world, mapId); | |
worldMap.b = info.getX(); | |
worldMap.c = info.getZ(); | |
worldMap.e = info.getScale(); | |
worldMap.f = info.getData(); | |
worldMap.a(); | |
} | |
@Override | |
public MapInfo loadMap(World world, short mapId) { | |
WorldMap worldMap = getWorldMap(world, mapId); | |
return new MapInfo(worldMap.b, worldMap.c, worldMap.e, worldMap.f); | |
} | |
private WorldMap getWorldMap(World world, short mapId) { | |
ItemStack nmsStack = new ItemStack(Material.MAP.getId(), 1, mapId); | |
net.minecraft.server.World nmsWorld = ((CraftWorld) world).getHandle(); | |
return Item.MAP.a(nmsStack, nmsWorld); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment