Re-add painting spawning code (Still broken in Bukkit, need to look into

the issue more), have entity spawns use World.spawn instead of World.spawnCreature.
This commit is contained in:
zml2008 2012-04-12 19:33:20 -07:00
parent af784c0ee2
commit 345cb5a690
3 changed files with 57 additions and 5 deletions

View File

@ -150,9 +150,9 @@ public class BukkitUtil {
switch (e.getType()) { switch (e.getType()) {
case EXPERIENCE_ORB: case EXPERIENCE_ORB:
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience()); return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
/*case PAINTING: // TODO: Figure out what celticminstrel broke case PAINTING:
Painting paint = (Painting) e; Painting paint = (Painting) e;
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());*/ return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
case DROPPED_ITEM: case DROPPED_ITEM:
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId()); return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
default: default:

View File

@ -45,6 +45,6 @@ public class BukkitEntity extends LocalEntity {
@Override @Override
public boolean spawn(Location weLoc) { public boolean spawn(Location weLoc) {
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc); org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
return loc.getWorld().spawnCreature(loc, type) != null; return loc.getWorld().spawn(loc, type.getEntityClass()) != null;
} }
} }

View File

@ -21,16 +21,51 @@ package com.sk89q.worldedit.bukkit.entity;
import com.sk89q.worldedit.Location; import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Painting; import org.bukkit.entity.Painting;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID; import java.util.UUID;
/** /**
* @author zml2008 * @author zml2008
*/ */
public class BukkitPainting extends BukkitEntity { public class BukkitPainting extends BukkitEntity {
private static int spawnTask = -1;
private static final Deque<QueuedPaintingSpawn> spawnQueue = new ArrayDeque<QueuedPaintingSpawn>();
private class QueuedPaintingSpawn {
private final Location weLoc;
public QueuedPaintingSpawn(Location weLoc) {
this.weLoc = weLoc;
}
public void spawn() {
spawnRaw(weLoc);
}
}
private static class PaintingSpawnRunnable implements Runnable {
@Override
public void run() {
synchronized (spawnQueue) {
QueuedPaintingSpawn spawn;
while ((spawn = spawnQueue.poll()) != null) {
try {
spawn.spawn();
} catch (Throwable t) {
t.printStackTrace();
continue;
}
}
spawnTask = -1;
}
}
}
private final Art art; private final Art art;
private final BlockFace facingDirection; private final BlockFace facingDirection;
public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) { public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) {
@ -39,12 +74,29 @@ public class BukkitPainting extends BukkitEntity {
this.facingDirection = facingDirection; this.facingDirection = facingDirection;
} }
/**
* Queue the painting to be spawned at the specified location.
* This operation is delayed so that the block changes that may be applied can be applied before the painting spawn is attempted.
*
* @param weLoc The WorldEdit location
* @return Whether the spawn as successful
*/
public boolean spawn(Location weLoc) { public boolean spawn(Location weLoc) {
synchronized (spawnQueue) {
spawnQueue.add(new QueuedPaintingSpawn(weLoc));
if (spawnTask == -1) {
spawnTask = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), new PaintingSpawnRunnable(), 1L);
}
}
return true;
}
public boolean spawnRaw(Location weLoc) {
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc); org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
Painting paint = loc.getWorld().spawn(loc, Painting.class); Painting paint = loc.getWorld().spawn(loc, Painting.class);
if (paint != null) { if (paint != null) {
paint.setFacingDirection(facingDirection); paint.setFacingDirection(facingDirection, true);
paint.setArt(art); paint.setArt(art, true);
return true; return true;
} }
return false; return false;