From edbf8e6fda7d2e7a1defe105b7b96e0c1e857584 Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Fri, 31 Oct 2014 16:27:19 -0700 Subject: [PATCH] Fix the sit animation, fixes #96 The task would fail to cancel properly, and sometimes fail to recognize NPC removal. In addition, gitignore maven and IntelliJ artifacts to give contributors an easier time. --- .gitignore | 2 ++ src/main/java/net/citizensnpcs/util/PlayerAnimation.java | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5de6666ab..d477b3413 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ Citizens.jar *.lnk *.iml +/.idea +dependency-reduced-pom.xml diff --git a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java index 4ce738884..0261866ec 100644 --- a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java +++ b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java @@ -52,10 +52,11 @@ public enum PlayerAnimation { 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() { + new BukkitRunnable() { @Override public void run() { - if (player.dead || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) { + if (player.dead || !player.valid || + !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) { cancel(); return; } @@ -67,7 +68,7 @@ public enum PlayerAnimation { player.mount(player); } } - }, 0, 1); + }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1); } }, SLEEP {