From a38b9a85ec90679f8e5c5e4a7fea065bb141865e Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 3 Aug 2015 19:27:03 +0800 Subject: [PATCH] Handle plr teleporting when carrying armor stand --- .../plugins/ArmorStandTools/MainListener.java | 25 +++++++++++++++++-- .../ArmorStandTools/PlotSquaredHook.java | 1 - .../plugins/ArmorStandTools/Utils.java | 8 +++--- src/config.yml | 2 +- src/language.yml | 2 +- src/plugin.yml | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index 8d72e94..03da608 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -28,6 +28,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.metadata.FixedMetadataValue; @@ -187,11 +188,31 @@ public class MainListener implements Listener { Utils.actionBarMsg(p, Config.asDropped); return; } - as.teleport(Utils.getLocationFacingPlayer(p)); + as.teleport(Utils.getLocationFacing(event.getTo())); Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); } } + @EventHandler + public void onPlayerTeleport(PlayerTeleportEvent event) { + final Player p = event.getPlayer(); + if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) { + final ArmorStand as = plugin.carryingArmorStand.get(p.getUniqueId()); + if (as == null || as.isDead()) { + plugin.carryingArmorStand.remove(p.getUniqueId()); + Utils.actionBarMsg(p, Config.asDropped); + return; + } + new BukkitRunnable() { + @Override + public void run() { + as.teleport(Utils.getLocationFacing(p.getLocation())); + Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); + } + }.runTaskLater(plugin, 1L); + } + } + @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { final Player p = event.getEntity(); @@ -282,7 +303,7 @@ public class MainListener implements Listener { p.sendMessage(ChatColor.RED + Config.generalNoPerm); return; } - Location l = Utils.getLocationFacingPlayer(p); + Location l = Utils.getLocationFacing(p.getLocation()); plugin.pickUpArmorStand(spawnArmorStand(l), p, true); Utils.actionBarMsg(p, ChatColor.GREEN + Config.carrying); p.updateInventory(); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java index 404be45..409d419 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/PlotSquaredHook.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.intellectualcrafters.plot.api.PlotAPI; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.Permissions; @SuppressWarnings("deprecation") class PlotSquaredHook { diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java index 488b807..5335519 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java @@ -54,12 +54,12 @@ class Utils { return false; } - static Location getLocationFacingPlayer(Player p) { - Vector v = p.getLocation().getDirection(); + static Location getLocationFacing(Location l) { + Vector v = l.getDirection(); v.setY(0); v.multiply(3); - Location l = p.getLocation().add(v); - l.setYaw(p.getLocation().getYaw() + 180); + l.add(v); + l.setYaw(l.getYaw() + 180); int n; boolean ok = false; for (n = 0; n < 5; n++) { diff --git a/src/config.yml b/src/config.yml index 33572c4..4a137df 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,7 +4,7 @@ # # Main Config # -# File generated by: v2.03 +# File generated by: v2.04 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/language.yml b/src/language.yml index fcb1548..50d0cd4 100644 --- a/src/language.yml +++ b/src/language.yml @@ -4,7 +4,7 @@ # # Language Config # -# File generated by: v2.03 +# File generated by: v2.04 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/plugin.yml b/src/plugin.yml index b59a92c..8574696 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: com.gmail.St3venAU.plugins.ArmorStandTools.Main name: ArmorStandTools -version: 2.03 +version: 2.04 author: St3venAU description: Armor stand manipulation tools softdepend: [WorldGuard, PlotSquared]