Implement Leash API. Adds BUKKIT-4459, BUKKIT-4583
This commit is contained in:
@@ -264,6 +264,7 @@ public abstract class EntityCreature extends EntityInsentient {
|
||||
|
||||
if (this instanceof EntityTameableAnimal && ((EntityTameableAnimal) this).isSitting()) {
|
||||
if (f > 10.0F) {
|
||||
this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
|
||||
this.a(true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,11 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
//CraftBukkit start
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.entity.EntityUnleashEvent;
|
||||
import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
|
||||
// CraftBukkit end
|
||||
|
||||
public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
@@ -769,6 +772,12 @@ public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
public final boolean c(EntityHuman entityhuman) {
|
||||
if (this.bH() && this.bI() == entityhuman) {
|
||||
// CraftBukkit start
|
||||
if (CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman).isCancelled()) {
|
||||
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
|
||||
return false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.a(true, !entityhuman.abilities.canInstantlyBuild);
|
||||
return true;
|
||||
} else {
|
||||
@@ -776,12 +785,24 @@ public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
if (itemstack != null && itemstack.id == Item.LEASH.id && this.bG()) {
|
||||
if (!(this instanceof EntityTameableAnimal) || !((EntityTameableAnimal) this).isTamed()) {
|
||||
// CraftBukkit start
|
||||
if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
|
||||
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
|
||||
return false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.b(entityhuman, true);
|
||||
--itemstack.count;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (entityhuman.getName().equalsIgnoreCase(((EntityTameableAnimal) this).getOwnerName())) {
|
||||
// CraftBukkit start
|
||||
if (CraftEventFactory.callPlayerLeashEntityEvent(this, entityhuman, entityhuman).isCancelled()) {
|
||||
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, this, this.bI()));
|
||||
return false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.b(entityhuman, true);
|
||||
--itemstack.count;
|
||||
return true;
|
||||
@@ -803,6 +824,7 @@ public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
if (this.bv) {
|
||||
if (this.bw == null || this.bw.dead) {
|
||||
this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.HOLDER_GONE)); // CraftBukkit
|
||||
this.a(true, true);
|
||||
}
|
||||
}
|
||||
@@ -869,6 +891,7 @@ public abstract class EntityInsentient extends EntityLiving {
|
||||
|
||||
this.bw = entityleash;
|
||||
} else {
|
||||
this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
|
||||
this.a(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.minecraft.server;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
||||
|
||||
public class EntityLeash extends EntityHanging {
|
||||
|
||||
public EntityLeash(World world) {
|
||||
@@ -55,6 +57,12 @@ public class EntityLeash extends EntityHanging {
|
||||
while (iterator.hasNext()) {
|
||||
entityinsentient = (EntityInsentient) iterator.next();
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
|
||||
// CraftBukkit start
|
||||
if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman).isCancelled()) {
|
||||
((EntityPlayer) entityhuman).playerConnection.sendPacket(new Packet39AttachEntity(1, entityinsentient, entityinsentient.bI()));
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
entityinsentient.b(this, true);
|
||||
flag = true;
|
||||
}
|
||||
@@ -63,8 +71,11 @@ public class EntityLeash extends EntityHanging {
|
||||
}
|
||||
|
||||
if (!this.world.isStatic && !flag) {
|
||||
this.die();
|
||||
if (entityhuman.abilities.canInstantlyBuild) {
|
||||
// CraftBukkit start - Move below
|
||||
// this.die();
|
||||
boolean die = true;
|
||||
// CraftBukkit end
|
||||
if (true || entityhuman.abilities.canInstantlyBuild) { // CraftBukkit - Process for non-creative as well
|
||||
d0 = 7.0D;
|
||||
list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
|
||||
if (list != null) {
|
||||
@@ -73,11 +84,22 @@ public class EntityLeash extends EntityHanging {
|
||||
while (iterator.hasNext()) {
|
||||
entityinsentient = (EntityInsentient) iterator.next();
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == this) {
|
||||
entityinsentient.a(true, false);
|
||||
// CraftBukkit start
|
||||
if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
|
||||
die = false;
|
||||
continue;
|
||||
}
|
||||
entityinsentient.a(true, !entityhuman.abilities.canInstantlyBuild); // false -> survival mode boolean
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// CraftBukkit start
|
||||
if (die) {
|
||||
this.die();
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.minecraft.server;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent; // CraftBukkit
|
||||
|
||||
public class ItemLeash extends Item {
|
||||
|
||||
public ItemLeash(int i) {
|
||||
@@ -40,8 +42,23 @@ public class ItemLeash extends Item {
|
||||
if (entityinsentient.bH() && entityinsentient.bI() == entityhuman) {
|
||||
if (entityleash == null) {
|
||||
entityleash = EntityLeash.a(world, i, j, k);
|
||||
|
||||
// CraftBukkit start
|
||||
HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
entityleash.die();
|
||||
return false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman).isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
entityinsentient.b(entityleash, true);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user