Sign EventException

Discussion in 'Plugin Development' started by SoS_Dylan, Sep 13, 2013.

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

    SoS_Dylan

    Code:java
    1. Sign sign = (Sign) block.getState();

    Throws a Event Exception
    Full error:
    Code:
    [SEVERE] Could not pass event PlayerMoveEvent to Jump v1.2
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    at us.Myles.PWP.FakePluginManager.fireEvent(FakePluginManager.java:101)
    at us.Myles.PWP.FakePluginManager.callEvent(FakePluginManager.java:87)
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:227)
    at net.minecraft.server.v1_6_R2.Packet10Flying.handle(SourceFile:136)
    at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:230)
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:125)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:592)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
    at me.SoSDylan.Jump.Main.onPlayerMove(Main.java:224)
    at sun.reflect.GeneratedMethodAccessor387.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 15 more
    And the block is defiantly a Wall Sign / Sign Post.

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

    WauloK

    what is block defined as?
     
  3. Offline

    SoS_Dylan

  4. Offline

    WauloK

    Like this?

    Code:java
    1. Block block = event.getClickedBlock();


    There's not much code to go on.
     
  5. Offline

    SoS_Dylan

    WauloK
    Yeah, but I did a check to see if the block was a sign.
    Code:java
    1. if (event.getClickedBlock().getType().equals(Material.WALL_SIGN) || event.getClickedBlock().getType().equals(Material.SIGN_POST)) {
    2. // CODE
    3. }
     
  6. Offline

    Loogeh

  7. Offline

    SoS_Dylan

    Code:java
    1. Location standBlock = player.getWorld()
    2. .getBlockAt(player.getLocation().add(0.0D, -0.01D, 0.0D))
    3. .getLocation();
    4. if (standBlock.add(0, -1, 0).getBlock().getType()
    5. .equals(Material.WALL_SIGN)
    6. || standBlock.add(0, -1, 0).getBlock().getType()
    7. .equals(Material.SIGN_POST)) {
    8. Bukkit.broadcastMessage("0");
    9. Block block = standBlock.add(0, -1, 0).getBlock();
    10. Bukkit.broadcastMessage("2");
    11. Sign sign = (Sign) block.getState();
    12. Bukkit.broadcastMessage("3");
    13. String signline1 = sign.getLine(0);
    14. String signline2 = sign.getLine(1);
    15. String signline3 = sign.getLine(2);
    16. String signline4 = sign.getLine(3);
    17. Bukkit.broadcastMessage("4");
    18.  
    19. if (signline1
    20. .equalsIgnoreCase(ChatColor.DARK_PURPLE + "[Jump]")
    21. || signline1.equalsIgnoreCase(ChatColor.DARK_PURPLE
    22. + "[SpongeJump]")) {
    23. Bukkit.broadcastMessage("5");
    24. xvel = Double.parseDouble(signline2);
    25. yvel = Double.parseDouble(signline3);
    26. zvel = Double.parseDouble(signline4);
    27. Bukkit.broadcastMessage("6");
    28. }
    29. }
     
  8. Offline

    Loogeh

    SoS_Dylan Not sure why your getting a class cast exception yet but why are you add -0.01 to the player's y coordinate?
     
  9. Offline

    SoS_Dylan

    Loogeh
    So I can get the block the player is standing on, If they jump they will not be on the block.
     
  10. Offline

    Loogeh

    SoS_Dylan Okay, I can't figure out why you're getting this exception so i'm going to go try it for myself.
     
  11. Offline

    SoS_Dylan

    Loogeh
    Ok, thanks for all the help your giving me and other users that might have this problem.
    :)
     
  12. Offline

    Loogeh

    SoS_Dylan Sorry but I've tried a few things and I just get the same issue. It could be Bukkit problem, maybe update to the latest build. You could also try looking at the source of another plugin which uses signs e.g SignShop
     
  13. Offline

    SoS_Dylan

    Loogeh
    Ok, thanks

    Loogeh
    Hmm... I looked at a plugin called SignChanger and I saw the code was close to the same, it works but not mine?
    Code:java
    1. package com.conectedpvp.signchanger;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.block.BlockState;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class SignChanger extends JavaPlugin
    14. {
    15. public void sendMessage(String text, CommandSender player)
    16. {
    17. player.sendMessage(ChatColor.GREEN + "[SignChanger] " + ChatColor.GOLD + text);
    18. }
    19. public static String colorize(String s) {
    20. if (s == null) return null;
    21. return s.replaceAll("&([0-9a-f])", "ยง$1");
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    25. if (cmd.getName().equalsIgnoreCase("changeline")) {
    26. if (args.length >= 2) {
    27. if ((sender instanceof Player)) {
    28. Player player = (Player)sender;
    29. if (player.hasPermission("SignChanger.changeline"))
    30. {
    31. Block block = player.getTargetBlock(null, 200);
    32. if ((block.getType().equals(Material.WALL_SIGN)) || (block.getType().equals(Material.SIGN_POST))) {
    33. StringBuilder buffer = new StringBuilder();
    34. for (int i = 1; i < args.length; i++) {
    35. buffer.append(' ').append(args[i]);
    36. }
    37. String newb = colorize(buffer.toString());
    38. if (newb.length() <= 15) {
    39. int line = Integer.parseInt(args[0]);
    40. if ((line >= 1) && (line <= 4)) {
    41. BlockState state = block.getState();
    42. Sign sign = (Sign)state;
    43. line--;
    44. sign.setLine(line, newb);
    45. sign.update(true); } else {
    46. sendMessage("There are only 4 lines per sign!", sender);
    47. } } else { sendMessage("There are only 15 character spots one line!", sender); }
    48. } else { sendMessage("Please look at a sign to run this command!", sender); }
    49. } else { return false; }
    50. } else { sendMessage("You must be a player to run this command!", sender); }
    51. } else sendMessage("You must input a line number and the text", sender);
    52. }
    53. return true;
    54. }
    55. }[I][/I][/i]


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

    Loogeh

    SoS_Dylan Possibly could be because of the Bukkit build you're using. Try the latest recommended build here
     
  15. Offline

    SoS_Dylan

    Loogeh
    I downloaded it just before and nothing different, except for getTypeId() and setTypeId() is now depreciated.
     
  16. Offline

    Loogeh

    SoS_Dylan Yes the stuff to do with numeric ids are all deprecated now because of something which Mojang did. I have no idea why it didn't work though, sorry.
     
  17. Offline

    SoS_Dylan

    Loogeh
    Ok... more searching then...
     
Thread Status:
Not open for further replies.

Share This Page