PlayerInteractEvent Help!

Discussion in 'Plugin Development' started by ImImprobable, Jan 3, 2014.

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

    ImImprobable

    Please help.
    Here is my code
    Code:java
    1.  
    2.  
    3. @EventHandler
    4. public void onPlayerInteract1(PlayerInteractEvent e) {
    5. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block b = e.getClickedBlock();
    7. Player p = e.getPlayer();
    8. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    9. Sign sign = (Sign) b.getState();
    10. String[] lines = sign.getLines();
    11. if(lines[0].equalsIgnoreCase("[MobArena]")) {
    12. sign.setLine(0, ChatColor.GOLD + "[" + ChatColor.AQUA + "MobArena" + ChatColor.GOLD + "]");
    13. if(lines[1].equalsIgnoreCase("Join"))
    14. {
    15. sign.setLine(1, ChatColor.GREEN + "Join");
    16. if(lines[2].equalsIgnoreCase("Cage"))
    17. {
    18. sign.setLine(2, ChatColor.AQUA + "Cage");
    19. }
    20. else
    21. {
    22. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");
    23. }
    24. }
    25. }
    26. }
    27. }
    28. }
    29. @EventHandler
    30. public void onPlayerInteract2(PlayerInteractEvent e)
    31. {
    32. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)
    33. {
    34. Block b = e.getClickedBlock();
    35. Player p = e.getPlayer();
    36. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST)
    37. {
    38. Sign sign = (Sign) b.getState();
    39. String[] lines = sign.getLines();
    40. if(lines[0].equalsIgnoreCase(ChatColor.GOLD + "[" + ChatColor.AQUA + "MobArena" + ChatColor.GOLD + "]"))
    41. {
    42. p.sendMessage("Line 1 Working! Going onto line 2");
    43. if(lines[0].equalsIgnoreCase(ChatColor.GREEN + "Join"))
    44. {
    45. p.sendMessage("Line 2 Working! Going onto line 3");
    46. if(lines[0].equalsIgnoreCase(ChatColor.AQUA + "Cage"))
    47. {
    48. p.sendMessage("Plugin Works ready to be released after a few more touches!");
    49. p.chat("/ma join Cage");
    50.  
    51.  
    52. /*;
    53. * //Reserved
    54. */
    55. }
    56. }
    57. }
    58. }
    59. }
    60. }
    61. }


    Thx ImIm
     
  2. Offline

    Davesan

    hmm.. i don't know what's the problem. It does nothing? Then... first of all, did you registered the listener into the Bukkit? In the onEnable() method (usually). What I can say... I would use (b.getType().equals(Material.X)) instead of (b.getType() == Material.X). Try these stuff.
     
  3. Offline

    Bart

    It should be == not .equals().

    As Davesan said, make sure you register your listeners.
     
  4. Offline

    16davidjm6

    Make sure your plugin extends JavaPlugin and implements Listener and registers the events when it is enabled. Your code should look something like this:

    Code:java
    1. //imports
    2.  
    3. public class PluginName extends JavaPlugin implements Listener{
    4.  
    5. public void onEnable(){
    6. getServer().getPluginManager().registerEvents(this,this);
    7. }
    8.  
    9. //your @EventHandler stuff here
    10.  
    11. }
     
  5. Offline

    ImImprobable

    Im still a noob may someone explain what a listener is so i don't have to post more of these threads in the future ^^

    Code:java
    1. getServer().getPluginManager().registerEvents(this,this);


    Will that work?

    EDIT: Ok the first this is underlined and its giving me and error plz help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page