mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
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:
parent
af784c0ee2
commit
345cb5a690
@ -150,9 +150,9 @@ public class BukkitUtil {
|
||||
switch (e.getType()) {
|
||||
case EXPERIENCE_ORB:
|
||||
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;
|
||||
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:
|
||||
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
|
||||
default:
|
||||
|
@ -45,6 +45,6 @@ public class BukkitEntity extends LocalEntity {
|
||||
@Override
|
||||
public boolean spawn(Location weLoc) {
|
||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||
return loc.getWorld().spawnCreature(loc, type) != null;
|
||||
return loc.getWorld().spawn(loc, type.getEntityClass()) != null;
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,51 @@ package com.sk89q.worldedit.bukkit.entity;
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Painting;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
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 BlockFace facingDirection;
|
||||
public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) {
|
||||
@ -39,12 +74,29 @@ public class BukkitPainting extends BukkitEntity {
|
||||
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) {
|
||||
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);
|
||||
Painting paint = loc.getWorld().spawn(loc, Painting.class);
|
||||
if (paint != null) {
|
||||
paint.setFacingDirection(facingDirection);
|
||||
paint.setArt(art);
|
||||
paint.setFacingDirection(facingDirection, true);
|
||||
paint.setArt(art, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user