summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2011-08-12 22:47:47 -0400
committerEvilSeph <evilseph@gmail.com>2011-08-12 23:06:02 -0400
commit748a6288e418ea8d52a287d55cc591ac1f0a536a (patch)
treee4bc6d4090f58bcc2807278f63bd8d8da81d997c /src/main/java/net/minecraft/server
parente6876a97da07a7218c177f4ddf61c277929bc759 (diff)
downloadcraftbukkit-748a6288e418ea8d52a287d55cc591ac1f0a536a.tar
craftbukkit-748a6288e418ea8d52a287d55cc591ac1f0a536a.tar.gz
craftbukkit-748a6288e418ea8d52a287d55cc591ac1f0a536a.tar.lz
craftbukkit-748a6288e418ea8d52a287d55cc591ac1f0a536a.tar.xz
craftbukkit-748a6288e418ea8d52a287d55cc591ac1f0a536a.zip
Added API for manipulating map items. Thanks SpaceManiac, codename_B, sk89q and dested!
Diffstat (limited to 'src/main/java/net/minecraft/server')
-rw-r--r--src/main/java/net/minecraft/server/ItemWorldMap.java10
-rw-r--r--src/main/java/net/minecraft/server/WorldMap.java7
-rw-r--r--src/main/java/net/minecraft/server/WorldMapHumanTracker.java101
3 files changed, 117 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/ItemWorldMap.java b/src/main/java/net/minecraft/server/ItemWorldMap.java
index be54e2d7..9ec729c2 100644
--- a/src/main/java/net/minecraft/server/ItemWorldMap.java
+++ b/src/main/java/net/minecraft/server/ItemWorldMap.java
@@ -1,5 +1,10 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.server.MapInitializeEvent;
+// CraftBukkit end
+
public class ItemWorldMap extends ItemWorldMapBase {
protected ItemWorldMap(int i) {
@@ -22,6 +27,11 @@ public class ItemWorldMap extends ItemWorldMapBase {
worldmap.map = (byte) world.worldProvider.dimension;
worldmap.a();
world.a(s, (WorldMapBase) worldmap);
+
+ // CraftBukkit start
+ MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
}
return worldmap;
diff --git a/src/main/java/net/minecraft/server/WorldMap.java b/src/main/java/net/minecraft/server/WorldMap.java
index ab20cf9b..4e93ed3a 100644
--- a/src/main/java/net/minecraft/server/WorldMap.java
+++ b/src/main/java/net/minecraft/server/WorldMap.java
@@ -11,6 +11,7 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.map.CraftMapView;
// CraftBukkit end
public class WorldMap extends WorldMapBase {
@@ -26,13 +27,17 @@ public class WorldMap extends WorldMapBase {
public List i = new ArrayList();
// CraftBukkit start
+ public final CraftMapView mapView;
private CraftServer server;
private UUID uniqueId = null;
// CraftBukkit end
public WorldMap(String s) {
super(s);
- server = (CraftServer) Bukkit.getServer(); // CraftBukkit
+ // CraftBukkit start
+ mapView = new CraftMapView(this);
+ server = (CraftServer) Bukkit.getServer();
+ // CraftBukkit end
}
public void a(NBTTagCompound nbttagcompound) {
diff --git a/src/main/java/net/minecraft/server/WorldMapHumanTracker.java b/src/main/java/net/minecraft/server/WorldMapHumanTracker.java
new file mode 100644
index 00000000..dc330b81
--- /dev/null
+++ b/src/main/java/net/minecraft/server/WorldMapHumanTracker.java
@@ -0,0 +1,101 @@
+package net.minecraft.server;
+
+// CraftBukkit start
+import org.bukkit.map.MapCursor;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.map.RenderData;
+// CraftBukkit end
+
+public class WorldMapHumanTracker {
+
+ public final EntityHuman trackee;
+ public int[] b;
+ public int[] c;
+ private int e;
+ private int f;
+ private byte[] g;
+
+ final WorldMap d;
+
+ public WorldMapHumanTracker(WorldMap worldmap, EntityHuman entityhuman) {
+ this.d = worldmap;
+ this.b = new int[128];
+ this.c = new int[128];
+ this.e = 0;
+ this.f = 0;
+ this.trackee = entityhuman;
+
+ for (int i = 0; i < this.b.length; ++i) {
+ this.b[i] = 0;
+ this.c[i] = 127;
+ }
+ }
+
+ public byte[] a(ItemStack itemstack) {
+ int i;
+ int j;
+
+ RenderData render = this.d.mapView.render((CraftPlayer) trackee.getBukkitEntity()); // CraftBukkit
+
+ if (--this.f < 0) {
+ this.f = 4;
+ byte[] abyte = new byte[render.cursors.size() * 3 + 1]; // CraftBukkit
+
+ abyte[0] = 1;
+
+ // CraftBukkit start
+ for (i = 0; i < render.cursors.size(); ++i) {
+ MapCursor cursor = render.cursors.get(i);
+ if (!cursor.isVisible()) continue;
+
+ byte value = (byte) (((cursor.getRawType() == 0 || cursor.getDirection() < 8 ? cursor.getDirection() : cursor.getDirection() - 1) & 15) * 16);
+ abyte[i * 3 + 1] = (byte) (value | (cursor.getRawType() != 0 && value < 0 ? 16 - cursor.getRawType() : cursor.getRawType()));
+ abyte[i * 3 + 2] = (byte) cursor.getX();
+ abyte[i * 3 + 3] = (byte) cursor.getY();
+ }
+ // CraftBukkit end
+
+ boolean flag = true;
+
+ if (this.g != null && this.g.length == abyte.length) {
+ for (j = 0; j < abyte.length; ++j) {
+ if (abyte[j] != this.g[j]) {
+ flag = false;
+ break;
+ }
+ }
+ } else {
+ flag = false;
+ }
+
+ if (!flag) {
+ this.g = abyte;
+ return abyte;
+ }
+ }
+
+ for (int k = 0; k < 10; ++k) {
+ i = this.e * 11 % 128;
+ ++this.e;
+ if (this.b[i] >= 0) {
+ j = this.c[i] - this.b[i] + 1;
+ int l = this.b[i];
+ byte[] abyte1 = new byte[j + 3];
+
+ abyte1[0] = 0;
+ abyte1[1] = (byte) i;
+ abyte1[2] = (byte) l;
+
+ for (int i1 = 0; i1 < abyte1.length - 3; ++i1) {
+ abyte1[i1 + 3] = render.buffer[(i1 + l) * 128 + i]; // CraftBukkit
+ }
+
+ this.c[i] = -1;
+ this.b[i] = -1;
+ return abyte1;
+ }
+ }
+
+ return null;
+ }
+}