Solved Events not registering/working?

Discussion in 'Plugin Development' started by MCaeolus, Aug 31, 2014.

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

    MCaeolus

    Hi. I'm still (relatively) new to Java/Bukkit coding, and i've been working on a plugin lately.
    What the plugin does, is create a type of sign where when you click(right-click) on a sign where the first line is:

    [Name] (Lime color)
    and the second line has a name on it(whatever is written there, basically)

    It will(if you have correct permissions) set your name to whatever was written on the second line.

    It will correctly format the sign to have correct color, etc.
    if you have a correct permission and type in:

    [name] (not case sensitive)
    Some string

    However, when either creating the sign, or trying to use one, nothing happens. I have no errors in Java, and nothing shows up in the console. Can someone explain what I'm doing wrong?

    Code:
    Code:java
    1. public class Main
    2. extends JavaPlugin
    3. implements Listener
    4. {
    5. public void onEnable()
    6. {
    7. Bukkit.getPluginManager().registerEvents(this, this);
    8. getLogger().info("Plugin enabled. (Developed by: choas1010/Aeolus)");
    9. }
    10. public void onDisable()
    11. {
    12. getLogger().info("Plugin disabled.");
    13. }
    14.  
    15. @EventHandler
    16. public void onPlayerClick(PlayerInteractEvent e)
    17. {
    18. Player p = e.getPlayer();
    19. if(p.hasPermission("name.sign.use"))
    20. {
    21. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)
    22. {
    23. if(e.getClickedBlock().getType() == Material.SIGN_POST)
    24. {
    25. BlockState state = e.getClickedBlock().getState();
    26. Sign sign = (Sign) state;
    27.  
    28. if(sign.getLine(0).equals(ChatColor.GREEN + "[Name]"))
    29. {
    30. if(sign.getLine(1) != null)
    31. {
    32. String nick = sign.getLine(1);
    33. p.setDisplayName(nick);
    34. p.sendMessage(ChatColor.GREEN + "Name changed to: " + nick);
    35. }
    36. }
    37. }
    38. }
    39. }
    40. else
    41. {
    42. e.setCancelled(true);
    43. p.sendMessage(ChatColor.RED + "You aren't allowed to use that sign!");
    44. }
    45. }
    46.  
    47. @EventHandler
    48. public void createSign(SignChangeEvent e)
    49. {
    50. Player p = e.getPlayer();
    51.  
    52. BlockState state = e.getBlock().getState();
    53. Sign sign = (Sign) state;
    54. if(sign.getLine(0).equalsIgnoreCase("[name]"))
    55. {
    56. if(p.hasPermission("name.sign.create"))
    57. {
    58. if(sign.getLine(1) != null)
    59. {
    60. sign.setLine(1, ChatColor.GREEN + "[Name]");
    61. p.sendMessage("Nick sign for name: " + sign.getLine(1) + " successfully created.");
    62. }
    63. else
    64. {
    65. e.setCancelled(true);
    66. p.sendMessage(ChatColor.RED + "Nick sign does not contain a name. (Line 2)");
    67. }
    68. }
    69. else
    70. {
    71. e.setCancelled(true);
    72. p.sendMessage("You aren't allowed to do that!");
    73. }
    74. }
    75. }
    76. }


    Thanks in advance for taking your time to read/possibly replying. ;)
     
  2. Offline

    Gater12

    MCaeolus
    You did not register your events in your onEnable method.

    Such blind
     
  3. Offline

    MCaeolus

    I did? Look under onEnable event.

    (Bukkit.getPluginManager().registerEvents(this, this); )
     
  4. Offline

    Gater12

  5. Offline

    MCaeolus

    Doesn't seem to be it. Also, that wouldn't do anything towards actually CHANGING the sign (2nd event) which doesn't work either.

    ALSO: the plugin.yml is formatted like this:

    name: NameSigns
    main: com.choas1010.nameSigns.Main
    version: 1.0

    The plugin DOES load, and onEnable event occurs. (getLogger() shows up in console.)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  6. Have you tried any debug messages? Your events may be firing, but canceling at some point?
     
  7. Offline

    MCaeolus

    Did so, and it seems (for both) that it fires, (putting a log directly after the event) but doesnt get any farther in.

    Im not sure why... I also tried bumping up sign numberings (0 to 1, etc.) but that still doesn't do anything.
     
  8. Offline

    hintss

    This isn't the cause of your issue, but you should probably re-arrange your if statements...

    Anyway, what's not working about what you have now?
     
  9. Offline

    MCaeolus


    The events (right-click, signchange) fire, but seem to get cancelled soon after. I'm not really sure why. I don't believe it's the permissions message, either, as if it had to do with permissions, I'd still get the else message (You don't have this permission!)

    Also, the server uses no other plugins.
     
  10. Offline

    hintss

    For the sign writing, the event happens before the block is changed, so you'd want to use e.getLine(blah) rather than getting the sign's line
     
    MCaeolus likes this.
  11. Offline

    MCaeolus

    That fixed everything! Thanks so much ;D
     
Thread Status:
Not open for further replies.

Share This Page