[Unsolved] Help makeing something work after a Player Interact

Discussion in 'Plugin Development' started by legostarwarszach, Aug 23, 2013.

Thread Status:
Not open for further replies.
  1. So in my plugin I am tring to get if a person clicks on a sign it will do some stuff, but it doesn't work. To see if I could find the error, I put some checks, any help will be greatly appreciated!

    Code:
    Code:
        @EventHandler
        public void SignClick(PlayerInteractEvent inter){
            Player p = inter.getPlayer();
            if(p instanceof Player){
                p.sendMessage("Yes!");
                if(inter.getAction()==Action.RIGHT_CLICK_BLOCK || inter.getAction()==Action.LEFT_CLICK_BLOCK){
                    p.sendMessage("Yes! 1");
                    if(inter.getClickedBlock().getType() == Material.SIGN_POST || inter.getClickedBlock().getType() == Material.WALL_SIGN || inter.getClickedBlock().getType() == Material.SIGN) {
                        p.sendMessage("Yes! 2");
                        Block block = inter.getClickedBlock();
                        Sign s = (Sign) block.getState();
                        if(s.getLine(0).contains("Join")){
                            p.sendMessage("Yes! 3");
                            if(s.getLine(2).contains("Pies and")){
                                p.sendMessage("Yes! 4");
                                if(s.getLine(3).contains("Pirates")){
                                    p.sendMessage("Success!");
                                    //teleport the player
                                    info.pia1.put(p.getDisplayName(), null);
                                    p.sendMessage("Yes! 5");
                                    info.arena1p++;
                                    p.sendMessage("Yes! 6");
                                    s.setLine(0, state.getState());
                                    p.sendMessage("Yes! 7");
                                    s.setLine(1, info.arena1p + "/20");
                                    p.sendMessage("Yes! 8");
                                }
                            }
                        }
                    }
                }
            }
        }
     
  2. Offline

    Trevor1134

    .. Well, where is the error?

    Also don't do contains() do .EqualsIgnoreCase()
     

  3. I tried that, it won't work for some reason :/

    The error is that:
    Code:java
    1. info.pia1.put(p.getDisplayName(), null);
    2. p.sendMessage("Yes! 5");
    3. info.arena1p++;
    4. p.sendMessage("Yes! 6");
    5. s.setLine(0, state.getState());
    6. p.sendMessage("Yes! 7");
    7. s.setLine(1, info.arena1p + "/20");
    8. p.sendMessage("Yes! 8");

    Won't be triggered
     
  4. Offline

    Trevor1134


  5. HashMap
     
  6. Offline

    Trevor1134

  7. Integer
     
  8. Offline

    Trevor1134

    Do p.getName(), not DisplayName.
     
  9. Offline

    Dippoakabob

    BTW, to fix the caps just use:
    Code:
    if(s.getLine(0).toUpperCase().contains("JOIN")){
    That way it's not paying attention to caps and it will also recognize if someone put "[Join]" and stuff :)
     
    _Dashy likes this.
  10. Offline

    Dippoakabob

    Take a screenshot of the sign to see if it's an issue there
     
  11. Dippoakabob
    A screenshot?

    I captioned out the Hashmap part and it did the Yes! 5, but it didn't say Yes! 6-8

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

    Dippoakabob

    Check your console for errors. Also the server.log file. Make sure there's nothing that it caught that we couldn't see.
     
    _Dashy likes this.
  13. Offline

    Dippoakabob

    Just check line 53 and 63 and see what they are.
     
    _Dashy likes this.
  14. Dippoakabob
    That's weird, those two lines are:
    Code:java
    1. Sign s = (Sign) block.getState();

    and
    Code:java
    1. info.arena1p++;


    I wonder how those two are null.
     
  15. Offline

    Squid_Boss

    Here is what I use on my sign plugins:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    5. if (e.getClickedBlock().getState() instanceof Sign) {
    6. Sign s = (Sign)e.getClickedBlock().getState();
    7. if (s.getLine(0).equalsIgnoreCase("Top Line") {
    8. // Do stuff here
    9. }
    10. }
    11. return;
    12. }

    I can guarentee this works. If, after putting in your stuff, it still doesn't work, then the issue is with the hashmaps, or other bits of code you added.
     
  16. Offline

    NoChanceSD

  17. Offline

    Squid_Boss

  18. Offline

    NoChanceSD

    legostarwarszach
    Yes, did you make like arena1p = 0;
    arena1p is an int right?
     
  19. NoChance20
    Yes

    Squid_Boss
    Code:java
    1. info.arena1p++;


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

    Squid_Boss

    Then your error is with "info.arena1p++;", it's returning Null.
     
  21. Offline

    NoChanceSD

    Dippoakabob likes this.
  22. Last edited by a moderator: Jun 4, 2016
  23. Offline

    NoChanceSD

    legostarwarszach
    show us the method onPlayerInteract on your MakeLobbySign class, apparently the error is there in line 90.
     
  24. Offline

    NoChanceSD

    legostarwarszach
    On your MakeLobbySign class don't you have something like:
    public void onPlayerInteract(){
    //code
    }

    I wanted you to post that and tell which one is line 90.
     
  25. NoChance20
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    5. if (e.getClickedBlock().getState() instanceof Sign) {
    6. Sign s = (Sign)e.getClickedBlock().getState();
    7. if(s.getLine(0).contains("Join")){
    8. // p.sendMessage("Yes! 3");
    9. if(s.getLine(2).contains("Cops and")){
    10. //p.sendMessage("Yes! 4");
    11. if(s.getLine(3).contains("Robbers")){
    12. //teleport the player
    13. // info.pia1.put(p.getName(), null);
    14. // p.sendMessage("Yes! 5"); Line 90
    15. arena1p++;
    16. // p.sendMessage("Yes! 6");
    17. s.setLine(0, state.getState());
    18. // p.sendMessage("Yes! 7");
    19. s.setLine(1, arena1p + "/20");
    20. // p.sendMessage("Yes! 8");
    21. p.sendMessage("Success!");
    22. }
    23. }
    24. } return;
    25. }
    26. }


    Can anyone help please?

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

    Stoux

    Since it cannot break on a comment, I figure line 90 = "arena1p++;", right?
    If that is true:
    It throws a null pointer because arena1p is probably not defined. Make sure you define it somewhere. For example in the constructor:
    Code:java
    1. public void listener() {
    2. arena1p = 0;
    3. }
     
Thread Status:
Not open for further replies.

Share This Page