Solved Get Target Block Not Working

Discussion in 'Plugin Development' started by The Fancy Whale, Mar 16, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    The Fancy Whale

    Here is the code where it is not working:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onUse(PlayerInteractEvent i){
    4.  
    5. Action action = i.getAction();
    6. Player player = i.getPlayer();
    7. Location loc = (Location) player.getTargetBlock(null, 100);
    8. //if (player.getLocation().getWorld().getName() == "BlocksVsZombies"){ add this later
    9. if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
    10. if (player.getInventory().getItemInHand().getType() == Material.STICK){
    11. if (map.containsKey(player.getName())) {
    12. player.sendMessage(ChatColor.RED
    13. + "You are still on cooldown for another "
    14. + getTimeLeft(player, map) + " seconds!");}
    15. else {
    16. player.getWorld().strikeLightning(loc);
    17. setCooldownLength(player, 5, map);
    18. startCooldown(player, map);
    19. }
    20. }
    21.  
    22. }
    23. }


    And here is the error:
    Code:
    [19:11:14] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KitAddon v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerInteractManager.interact(PlayerInteractManager.java:374) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:628) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile:9) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.block.CraftBlock cannot be cast to org.bukkit.Location
    at tfw.kits.Main.onUse(Main.java:66) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[?:1.6.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_45]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_45]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    ... 15 more
    [19:11:14] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KitAddon v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerInteractManager.interact(PlayerInteractManager.java:374) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:628) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile:9) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.block.CraftBlock cannot be cast to org.bukkit.Location
    at tfw.kits.Main.onUse(Main.java:66) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[?:1.6.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_45]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_45]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    ... 15 more
    [19:11:15] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to KitAddon v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerInteractManager.interact(PlayerInteractManager.java:374) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:628) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile:9) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.block.CraftBlock cannot be cast to org.bukkit.Location
    at tfw.kits.Main.onUse(Main.java:66) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[?:1.6.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_45]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_45]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425) ~[bukkit-dev-1.7.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    
    Player Interact event was working with previous items in hand, it just stopped working when I added the gettargetblock statement. Thanks!
     
  2. Offline

    FuZioN720

  3. Offline

    Mmarz11

    The Fancy Whale Change:
    Location loc = (Location) player.getTargetBlock(null, 100);
    to:
    Location loc = player.getTargetBlock(null, 100).getLocation();
     
    The Fancy Whale likes this.
  4. Offline

    The Fancy Whale


    Code:java
    1. Location loc = (Location) player.getTargetBlock(null, 100);


    Thanks. Also, do you know why I can hear the lightning but not see it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    FuZioN720

    @The Fancy Whale Try what Mmarz11 said
    or try
    Code:java
    1. Location loc = (Location) player.getLineOfSight(null, 100);
     
  6. Offline

    Mmarz11

    FuZioN720 That would cause the same error he was already having... The getLineOfSight method returns a List<Block> which is not something you can cast to a Location.
     
  7. Offline

    The Fancy Whale

    Mmarz11 Yeah it is now working, except the lightning is invisible :/
     
Thread Status:
Not open for further replies.

Share This Page