From 4e0169f5a0116bab9536ed1bff47c07481762a7c Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 23 Aug 2014 12:24:30 +0800 Subject: [PATCH] Sitting animation sticks to EntityPlayer --- .../citizensnpcs/util/PlayerAnimation.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java index 7d76d6b10..d912eee7c 100644 --- a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java +++ b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java @@ -2,14 +2,18 @@ package net.citizensnpcs.util; import java.util.Arrays; +import net.citizensnpcs.api.CitizensAPI; import net.minecraft.server.v1_7_R4.EntityPlayer; import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutAnimation; import net.minecraft.server.v1_7_R4.PacketPlayOutBed; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.scheduler.BukkitRunnable; public enum PlayerAnimation { ARM_SWING { @@ -44,8 +48,19 @@ public enum PlayerAnimation { }, SIT { @Override - protected void playAnimation(EntityPlayer player, int radius) { - player.mount(player); + protected void playAnimation(final EntityPlayer player, int radius) { + player.getBukkitEntity().setMetadata("citizens.sitting", + new FixedMetadataValue(CitizensAPI.getPlugin(), true)); + Bukkit.getScheduler().runTaskTimer(CitizensAPI.getPlugin(), new BukkitRunnable() { + @Override + public void run() { + if (player.dead || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) { + cancel(); + return; + } + player.mount(player); + } + }, 0, 1); } }, SLEEP { @@ -75,6 +90,8 @@ public enum PlayerAnimation { STOP_SITTING { @Override protected void playAnimation(EntityPlayer player, int radius) { + player.getBukkitEntity().setMetadata("citizens.sitting", + new FixedMetadataValue(CitizensAPI.getPlugin(), false)); player.mount(null); } },