Signs, Why my PlayerListener No Work?

Discussion in 'Plugin Development' started by yewtree8, Feb 26, 2014.

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

    yewtree8

    My PlayerListener That Is NOT working
    Code:java
    1. public class PlayerListener implements Listener {
    2.  
    3. String Prefix = ChatColor.GREEN + "[" + ChatColor.AQUA + "EffectSigns" + ChatColor.GREEN + "]";
    4.  
    5.  
    6. @EventHandler
    7. public void interact(PlayerInteractEvent event) {
    8. Player player = event.getPlayer();
    9. Action action = event.getAction();
    10. Material block = event.getClickedBlock().getType();
    11. if(action == Action.RIGHT_CLICK_BLOCK) {
    12. if(block == Material.SIGN_POST || block == Material.WALL_SIGN) {
    13. Sign sign = (Sign)event.getClickedBlock().getState();
    14. String line1 = sign.getLine(0);
    15. String line2 = sign.getLine(1);
    16. if (line1.contains("[ES]") && line2.contains("Speed")) {
    17. if(player.hasPermission("effectsigns.speed")) {
    18.  
    19. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 120, 2));
    20.  
    21. player.sendMessage(Prefix + ChatColor.AQUA + "You Were Given Speed for 120 Seconds");
    22.  
    23.  
    24. } else {
    25. player.sendMessage(Prefix + ChatColor.RED + " You don't have permission to make a speed sign");
    26. }
    27. }
    28.  
    29.  
    30. } return;
    31. } return;
    32. }
    33.  
    34.  
    35. }



    My SignListener That Works?


    Code:java
    1. public class SignListener implements Listener {
    2.  
    3. @EventHandler
    4. public void Sign(SignChangeEvent event) {
    5. String line1= event.getLine(0);
    6. String line2 = event.getLine(1);
    7. Player player = event.getPlayer();
    8. String Prefix = ChatColor.GREEN + "[" + ChatColor.AQUA + "EffectSigns" + ChatColor.GREEN + "]";
    9. if(player.hasPermission("effectsigns.admin.speed")) {
    10. if(line1.equalsIgnoreCase("[ES]")) {
    11. if(line2.equalsIgnoreCase("Speed")) {
    12. event.setLine(0, ChatColor.DARK_AQUA + "[" + ChatColor.LIGHT_PURPLE + "Speed" + ChatColor.DARK_AQUA + "]");
    13. event.setLine(1, ChatColor.DARK_PURPLE + "120 Secs");
    14. player.sendMessage(Prefix + ChatColor.DARK_AQUA + " You Created A Speed Sign");
    15. } return;
    16. } return;
    17. } else {
    18. player.sendMessage(ChatColor.RED + "You Do Not Have The Permission " + ChatColor.GREEN + "effectsigns.admin.speed");
    19. }
    20.  
    21.  
    22. }
    23.  
    24.  
    25.  
    26.  
    27. }
    28.  




    When i right click the sign nothing happens? any idea why?
     
  2. Offline

    CaLxCyMru

    Are you registering your events?
     
  3. Offline

    Brendyn Todd

    yewtree8
    What does the stacktrace look like? If there is one.
     
  4. Offline

    yewtree8

  5. Offline

    CaLxCyMru

    yewtree8 A stack trace is your console error log.
     
  6. Offline

    Brendyn Todd

    yewtree8 Yeah what CaLxCyMru said. It would help us solve the problem at hand.
     
  7. Offline

    Blackveil

    My suggestion: send a message to your console of the action and clickedblocktype are. It could simply not work because you may have chosen the incorrect data.
     
  8. Offline

    diage

    You can also take my route of testing and just put a Bukkit.broadcastMessage("YOU CLICKED!!") in between every conditional check, usually in these strings it is important to figure out which conditional is returning a false.
     
Thread Status:
Not open for further replies.

Share This Page