Solved Sign event not working...

Discussion in 'Plugin Development' started by vhbob, Apr 25, 2015.

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

    vhbob

    so i have this code
    Code:
        @EventHandler
        public void signClick(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if (e.getClickedBlock().equals(Material.SIGN)){
                Sign s = (Sign)e.getClickedBlock().getState();
                if (s.getLine(1).contains("Spleef")){
                    if (s.getLine(2).contains("Join")){
                        p.teleport(ValueSaver.locationFromString(getConfig().getString("SomeRandom.Location")));
                    }
                }
            }
        }
        
    and p.teleport(blah blah blah) is a custom method, but none of it works when i click a sign with the first line as "Spleef" and the 2nd as "Join"
     
  2. Offline

    Konato_K

    @vhbob A block will never be equals to a material
     
    vhbob likes this.
  3. Offline

    vhbob

    @Konato_K But Block.Sign isnt a thing....
     
  4. Offline

    mythbusterma

    @vhbob

    And the sign will not be Material.SIGN, it will be Material.SIGN_POST or Material.WALL_SIGN.

    But Block#getType() is a thing.
     
    vhbob likes this.
  5. Offline

    vhbob

  6. Offline

    meguy26

    @vhbob
    2 things:
    1. the first line is actually 0, so s.getLine(1) returns the second line on the sign, use s.getLine(0) to get the first line and so on.
    2.
    check if its a sign:
    Code:
                    Block b = ev.getClickedBlock();
                    BlockState bls = b.getState();
                    if (bls instanceof Sign) {
    }
     
  7. Offline

    LetsTalkTnTHere

    I dont think this will make a difference, however try replacing .equals(); by. '==' @vhbob
     
  8. Offline

    vhbob

    @CodePlaysMinecraft @meguy26 @LetsTalkTnTHere updated code still doesnt work:
    Code:
        @EventHandler
        public void signClick(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getClickedBlock().equals(Material.SIGN_POST)
                    || e.getClickedBlock().equals(Material.WALL_SIGN)) {
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(0).contentEquals("spleef")) {
                    if (s.getLine(1).contentEquals("join")) {
                        p.teleport(ValueSaver.locationFromString(getConfig()
                                .getString("Spleef Location")));
                    }
                }
            }
        }
     
  9. @vhbob What doesn't work, where does it get to, throw any errors?
     
  10. Offline

    vhbob

    it does absolutly nothing when i click a sign that has the text...
     
  11. Online

    timtower Administrator Administrator Moderator

    @vhbob Tried to add logger messages to see to which if statement you are getting?
     
  12. Offline

    vhbob

  13. Online

    timtower Administrator Administrator Moderator

    @vhbob Code with the messages?
    And did you register the event then?
     
  14. Offline

    vhbob

    Code:
        @EventHandler
        public void signClick(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getClickedBlock().equals(Material.SIGN_POST)
                    || e.getClickedBlock().equals(Material.WALL_SIGN)) {
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(0) == ("spleef")) {
                    p.sendMessage("test");
                    if (s.getLine(1) == ("join")) {
                        p.sendMessage("test");
                        p.teleport(ValueSaver.locationFromString(getConfig()
                                .getString("Spleef Location")));
                    }
                }
            }
        }
    and
    Code:
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    @timtower
     
  15. Online

    timtower Administrator Administrator Moderator

    @vhbob Same class?
    And you have 1 debug line, is the clicked block a sign?
    if (s.getLine(0) == ("spleef")) {
    Will always return false, you check strings with string1.equals(string2)
     
  16. Offline

    vhbob

    @timtower sso this???
    Code:
    String L1 = s.getLine(0);
                String L2 = s.getLine(1);
                if (L1 == ("spleef")) {
                    p.sendMessage("test");
                    if (L2 == ("join")) {
                        p.sendMessage("test");
                        p.teleport(ValueSaver.locationFromString(getConfig()
                                .getString("Spleef Location")));
                    }
     
  17. @vhbob No as he said, #equals not ==
     
  18. Offline

    vhbob

    @bwfcwalshy
    Code:
                String L1 = s.getLine(0);
                String L2 = s.getLine(1);
                if (L1.equalsIgnoreCase("spleef")) {
                    p.sendMessage("test");
                    if (L2.equalsIgnoreCase("join")) {
                        p.sendMessage("test");
                        p.teleport(ValueSaver.locationFromString(getConfig()
                                .getString("Spleef Location")));
                    }
    ??
     
  19. Online

    timtower Administrator Administrator Moderator

    @vhbob Better, till where does it run?
     
  20. Offline

    vhbob

    @timtower nvm i fixed it!!

    The error starts here
    Code:
            if (e.getClickedBlock().equals(Material.SIGN_POST)
                    || e.getClickedBlock().equals(Material.WALL_SIGN)) {
                p.sendMessage("test");
    it just doesnt work whatsoever

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Apr 26, 2015
  21. @vhbob Well print what they click.
     
  22. Offline

    vhbob

    @bwfcwalshy i fixed it, i needed to use e.getclickedblock.getType not just e.getclickedblock because block never = material...
     
Thread Status:
Not open for further replies.

Share This Page