diff options
author | T00thpick1 <t00thpick1dirko@gmail.com> | 2013-07-31 17:35:16 -0400 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-08-03 15:03:41 -0500 |
commit | 54672a75f60a69802e7080b526fea737608a2530 (patch) | |
tree | f8b735ee83bab4bf81b7e979986ce32fe7373fff /src/main/java/org | |
parent | f7ca953ff1db983a99678f00584628d6e786a1dd (diff) | |
download | craftbukkit-54672a75f60a69802e7080b526fea737608a2530.tar craftbukkit-54672a75f60a69802e7080b526fea737608a2530.tar.gz craftbukkit-54672a75f60a69802e7080b526fea737608a2530.tar.lz craftbukkit-54672a75f60a69802e7080b526fea737608a2530.tar.xz craftbukkit-54672a75f60a69802e7080b526fea737608a2530.zip |
Implement Leash API. Adds BUKKIT-4459, BUKKIT-4583
Diffstat (limited to 'src/main/java/org')
5 files changed, 89 insertions, 10 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 75b1fb2e..e8315dd0 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -4,7 +4,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Random; import java.util.Set; @@ -994,6 +993,9 @@ public class CraftWorld implements World { entity = new EntityPainting(world, (int) x, (int) y, (int) z, dir); } else if (ItemFrame.class.isAssignableFrom(clazz)) { entity = new EntityItemFrame(world, (int) x, (int) y, (int) z, dir); + } else if (LeashHitch.class.isAssignableFrom(clazz)) { + entity = new EntityLeash(world, (int) x, (int) y, (int) z); + entity.p = true; } if (entity != null && !((EntityHanging) entity).survives()) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 8e2e5cda..d9659fb6 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -147,6 +147,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } else if (entity instanceof EntityHanging) { if (entity instanceof EntityPainting) { return new CraftPainting(server, (EntityPainting) entity); } else if (entity instanceof EntityItemFrame) { return new CraftItemFrame(server, (EntityItemFrame) entity); } + else if (entity instanceof EntityLeash) { return new CraftLeash(server, (EntityLeash) entity); } else { return new CraftHanging(server, (EntityHanging) entity); } } else if (entity instanceof EntityTNTPrimed) { return new CraftTNTPrimed(server, (EntityTNTPrimed) entity); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLeash.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLeash.java new file mode 100644 index 00000000..710ed7a6 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLeash.java @@ -0,0 +1,27 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.server.EntityLeash; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LeashHitch; + +public class CraftLeash extends CraftHanging implements LeashHitch { + public CraftLeash(CraftServer server, EntityLeash entity) { + super(server, entity); + } + + @Override + public EntityLeash getHandle() { + return (EntityLeash) entity; + } + + @Override + public String toString() { + return "CraftLeash"; + } + + public EntityType getType() { + return EntityType.LEASH_HITCH; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 443dde91..f20c664f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -14,18 +14,17 @@ import net.minecraft.server.EntityEnderPearl; import net.minecraft.server.EntityInsentient; import net.minecraft.server.EntityLargeFireball; import net.minecraft.server.EntityLiving; -import net.minecraft.server.EntitySmallFireball; -import net.minecraft.server.EntitySnowball; import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPotion; +import net.minecraft.server.EntitySmallFireball; +import net.minecraft.server.EntitySnowball; +import net.minecraft.server.EntityWither; import net.minecraft.server.EntityWitherSkull; import net.minecraft.server.GenericAttributes; import net.minecraft.server.MobEffect; import net.minecraft.server.MobEffectList; -import net.minecraft.server.Packet42RemoveMobEffect; import org.apache.commons.lang.Validate; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -35,11 +34,11 @@ import org.bukkit.craftbukkit.inventory.CraftEntityEquipment; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Arrow; import org.bukkit.entity.Egg; +import org.bukkit.entity.EnderPearl; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.EnderPearl; import org.bukkit.entity.Fireball; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -407,6 +406,46 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return getHandle() instanceof EntityInsentient && ((EntityInsentient) getHandle()).getCustomNameVisible(); } + public boolean isLeashed() { + if (!(getHandle() instanceof EntityInsentient)) { + return false; + } + return ((EntityInsentient) getHandle()).bI() != null; + } + + public Entity getLeashHolder() throws IllegalStateException { + if (!isLeashed()) { + throw new IllegalStateException("Entity not leashed"); + } + return ((EntityInsentient) getHandle()).bI().getBukkitEntity(); + } + + private boolean unleash() { + if (!isLeashed()) { + return false; + } + ((EntityInsentient) getHandle()).a(true, false); + return true; + } + + public boolean setLeashHolder(Entity holder) { + if ((getHandle() instanceof EntityWither) || !(getHandle() instanceof EntityInsentient)) { + return false; + } + + if (holder == null) { + return unleash(); + } + + if (holder.isDead()) { + return false; + } + + unleash(); + ((EntityInsentient) getHandle()).b(((CraftEntity) holder).getHandle(), true); + return true; + } + @Deprecated public int _INVALID_getLastDamage() { return NumberConversions.ceil(getLastDamage()); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 6db7b9ba..8dea190b 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -30,8 +30,8 @@ import net.minecraft.server.World; import net.minecraft.server.WorldServer; import org.bukkit.Bukkit; -import org.bukkit.Server; import org.bukkit.Material; +import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -44,10 +44,8 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftDamageSource; -import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creeper; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LivingEntity; @@ -706,4 +704,16 @@ public class CraftEventFactory { player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand)); } } + + public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(EntityInsentient entity, EntityHuman player) { + PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity()); + entity.world.getServer().getPluginManager().callEvent(event); + return event; + } + + public static PlayerLeashEntityEvent callPlayerLeashEntityEvent(EntityInsentient entity, Entity leashHolder, EntityHuman player) { + PlayerLeashEntityEvent event = new PlayerLeashEntityEvent(entity.getBukkitEntity(), leashHolder.getBukkitEntity(), (Player) player.getBukkitEntity()); + entity.world.getServer().getPluginManager().callEvent(event); + return event; + } } |