Added bed events and methods.

This commit is contained in:
sk89q 2011-04-07 11:26:51 -07:00
parent e2480e1347
commit 27d3396a35
2 changed files with 42 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
// CraftBukkit end // CraftBukkit end
@ -33,9 +35,13 @@ public abstract class EntityHuman extends EntityLiving {
public double w; public double w;
public double x; public double x;
public double y; public double y;
private boolean sleeping; // CraftBukkit start
public boolean sleeping;
// CraftBukkit end
private ChunkCoordinates b; private ChunkCoordinates b;
private int sleepTicks; // CraftBukkit start
public int sleepTicks;
// CraftBukkit end
public float z; public float z;
public float A; public float A;
private ChunkCoordinates d; private ChunkCoordinates d;
@ -547,6 +553,20 @@ public abstract class EntityHuman extends EntityLiving {
} else if (this.world.d()) { } else if (this.world.d()) {
return EnumBedError.NOT_POSSIBLE_NOW; return EnumBedError.NOT_POSSIBLE_NOW;
} else if (Math.abs(this.locX - (double) i) <= 3.0D && Math.abs(this.locY - (double) j) <= 2.0D && Math.abs(this.locZ - (double) k) <= 3.0D) { } else if (Math.abs(this.locX - (double) i) <= 3.0D && Math.abs(this.locY - (double) j) <= 2.0D && Math.abs(this.locZ - (double) k) <= 3.0D) {
// CraftBukkit start
if (this.getBukkitEntity() instanceof Player) {
Player player = (Player) this.getBukkitEntity();
CraftServer server = ((WorldServer) world).getServer();
org.bukkit.block.Block bed = ((WorldServer) world).getWorld().getBlockAt(i, j, k);
PlayerBedEnterEvent event = new PlayerBedEnterEvent(player, bed);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return EnumBedError.OTHER_PROBLEM;
}
}
// CraftBukkit end
this.b(0.2F, 0.2F); this.b(0.2F, 0.2F);
this.height = 0.2F; this.height = 0.2F;
if (this.world.f(i, j, k)) { if (this.world.f(i, j, k)) {
@ -637,6 +657,16 @@ public abstract class EntityHuman extends EntityLiving {
this.world.q(); this.world.q();
} }
// CraftBukkit start
if (this.getBukkitEntity() instanceof Player) {
Player player = (Player) this.getBukkitEntity();
CraftServer server = ((WorldServer) world).getServer();
org.bukkit.block.Block bed = ((WorldServer) world).getWorld().getBlockAt(this.b.a, this.b.b, this.b.c);
PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed);
server.getPluginManager().callEvent(event);
}
// CraftBukkit end
if (flag) { if (flag) {
this.sleepTicks = 0; this.sleepTicks = 0;
} else { } else {

View File

@ -47,4 +47,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
public String toString() { public String toString() {
return "CraftHumanEntity{" + "id=" + getEntityId() + "name=" + getName() + '}'; return "CraftHumanEntity{" + "id=" + getEntityId() + "name=" + getName() + '}';
} }
@Override
public boolean isSleeping() {
return getHandle().sleeping;
}
@Override
public int getSleepTicks() {
return getHandle().sleepTicks;
}
} }