Problem with clicking signs

Discussion in 'Plugin Development' started by RoflFrankoc, Sep 26, 2015.

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

    RoflFrankoc

    i dont get it why isnt this working it somehow doesnt do anything when i click a sign with these stuff on it
    heres when a player clicks the sign
    Code:
    @EventHandler
        public void clicksign(PlayerInteractEvent e){
            if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
            if (e.getClickedBlock().getState() instanceof Sign){
                Sign s = (Sign) e.getClickedBlock().getState();
                Player ep = (Player) e.getPlayer();
                if (s.getLine(0).equalsIgnoreCase("§9[oCraft]")){
                    if (s.getLine(1).equalsIgnoreCase("leave")){
                            ep.teleport((Location) getConfig().get("spawn.Location", e.getPlayer().getLocation()));
                            Bukkit.getServer().dispatchCommand(ep, "lobby");
                            ep.sendMessage(ChatColor.GREEN+"teleported to spawn!");
                            return;
                    }
                }
            }
    }
    
    and the sign change:
    Code:
    @EventHandler
        public void signschange(SignChangeEvent e){
            if (e.getLine(0).equalsIgnoreCase("[leave]")){
                e.setLine(0, "§9[oCraft]");
                e.setLine(1, "leave");
            }
    }
    
    thanks
     
  2. Offline

    oceantheskatr

    Try changing this:
    if (s.getLine(0).equalsIgnoreCase("§9[oCraft]")){
    if (s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[oCraft]")){

    Do the same for signschange.

    Also, put in some debug messages to know what is and isn't working.

    And you don't need to cast to player, since it already is a player.
     
  3. Offline

    RoflFrankoc

    @oceantheskatr
    changing it didnt work
    and i have made a message to see whats not working its the part:
    Code:
    ep.sendMessage(ChatColor.GREEN+"teleported to spawn!");
    
    thats the test message i put in but it doesnt send
     
  4. Offline

    oceantheskatr

    Add checks after pretty much every line :p


    Code:
    @EventHandler
        public void clicksign(PlayerInteractEvent e){
            Player ep = (Player) e.getPlayer();
            if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
            ep.sendMessage("Right click");
            if (e.getClickedBlock().getState() instanceof Sign){
                ep.sendMessage("It's a sign");
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(0).equalsIgnoreCase("§9[oCraft]")){
                    ep.sendMessage("First line found");
                    if (s.getLine(1).equalsIgnoreCase("leave")){
                           ep.sendMessage("Leaving");
                            ep.teleport((Location) getConfig().get("spawn.Location", e.getPlayer().getLocation()));
                            Bukkit.getServer().dispatchCommand(ep, "lobby");
                            ep.sendMessage(ChatColor.GREEN+"teleported to spawn!");
                            return;
                    }
                }
            }
    }
    Something like that
     
    Last edited: Sep 26, 2015
  5. Offline

    RoflFrankoc

    i know what the problem is its that it doesnt run the codes in that part
     
  6. Offline

    Boomer

    As in "I have resolved this problem" or "I have isolated it to not even the first line of the method handler is running" which would imply that the class the listener event is in isn't registered.
     
  7. Offline

    RoflFrankoc

    no i didnt solve the problem i just know what isnt working but i dont know how to fix the plugin
     
  8. Offline

    Boomer

    well... is the class that the listener is in registered? Is it making it inside the event, before executing the first IF at all?
    Failure to execute ANY code inside the event is 99.99999% of the time due to non-registered listener class, or failing @EventHandler (which you have though)
     
  9. Offline

    RoflFrankoc

    no its just that part everything else in that event works and theres like about 5 of them that work and 1 that doesnt but i dont know why
     
  10. Offline

    Boomer

    5 samples signs that work and one that doesn;t? could it be due to color-coding for example?

    Try to put some output statements before your ifs that show the values of each thing
    That way if it fails an if that you are sure it should have passed, yhou can see why it isn't
     
Thread Status:
Not open for further replies.

Share This Page