use of net.minecraft.server.v1_9_R2.PacketPlayOutAttachEntity in project MyPet by xXKeyleXx.
the class EntityMyPig method handlePlayerInteraction.
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
if (enumhand == EnumHand.OFF_HAND) {
if (itemStack != null) {
if (itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.OFF_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.OFF_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
}
return true;
}
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null || Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.MAIN_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.MAIN_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
getOwner().sendMessage("Unfortunately, pigs can not be ridden (Minecraft limitation)", 5000);
return true;
}
}
}
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
return true;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
return true;
} else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
entityitem.pickupDelay = 10;
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
this.world.addEntity(entityitem);
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setSaddle(null);
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
return true;
} else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
return false;
}
Aggregations