Join Sign not working?

Discussion in 'Plugin Development' started by Blingdaddy1, Dec 8, 2013.

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

    Blingdaddy1

    Please note, I am making a customized version of the Double0Negative SG plugin, to fit my servers needs.

    So, my problem is, Right-clicking a sign does nothing, but doing the sg join command works, what's going wrong? I've tried deleting the "!" and the e.setCancelled(true);, but nothing works! Also, no stacktraces aswell.

    SignClick class:
    Code:
    package org.mcsg.survivalgames.events;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.mcsg.survivalgames.GameManager;
     
     
     
    public class SignClickEvent implements Listener{
     
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void clickHandler(PlayerInteractEvent e){
     
            if(!(e.getAction()==Action.RIGHT_CLICK_BLOCK || e.getAction()==Action.LEFT_CLICK_BLOCK)) return;
           
     
            Block clickedBlock = e.getClickedBlock();
            if(!(clickedBlock.getType()==Material.SIGN || clickedBlock.getType()==Material.SIGN_POST || clickedBlock.getType()==Material.WALL_SIGN)) return;
            Sign thisSign = (Sign) clickedBlock.getState();
            //System.out.println("Clicked sign");
            String[] lines = thisSign.getLines();
            if(lines.length<3) return;
            if(lines[0].equalsIgnoreCase("[NexodusSG]")) {
                e.setCancelled(true);
                try{
                    if(lines[2].equalsIgnoreCase("Auto Assign")){
                        GameManager.getInstance().autoAddPlayer(e.getPlayer());
                    }
                    else{
                        String game = lines[2].replace("SG", "");
                        int gameno  = Integer.parseInt(game);
                        GameManager.getInstance().addPlayer(e.getPlayer(), gameno);
                    }
     
                }catch(Exception ek){}
            }
     
        }
     
    }
     
    
    And yes, the signs DO look the same!
     
  2. if(!(clickedBlock.getType()==Material.SIGN || clickedBlock.getType()==Material.SIGN_POST || clickedBlock.getType()==Material.WALL_SIGN))

    use if(clickedBlock.geType().equals(Material.WALL_SIGN){
     
    ImImprobable likes this.
  3. for a faster approach use

    if(clickedBlock.getState() instanceof Sign)
     
  4. Offline

    Blingdaddy1

    Neither of those work.
     
  5. 1. Make sure your signs doesnt have any colours
    2. Make sure you have registered the listener
     
  6. Offline

    Blingdaddy1

    No colors and its registered.
     
  7. Offline

    DCDJ

    Your logic is a little strange.

    Code:
    if(!(e.getAction()==Action.RIGHT_CLICK_BLOCK || e.getAction()==Action.LEFT_CLICK_BLOCK)) return;
    Should be

    Code:
    if(e.getAction()!=Action.RIGHT_CLICK_BLOCK && e.getAction()!=Action.LEFT_CLICK_BLOCK) return;


    And

    Code:
    if(!(clickedBlock.getType()==Material.SIGN || clickedBlock.getType()==Material.SIGN_POST || clickedBlock.getType()==Material.WALL_SIGN)) return;


    Should be

    Code:
    if(clickedBlock.getType()!=Material.SIGN && clickedBlock.getType()!=Material.SIGN_POST && clickedBlock.getType()!=Material.WALL_SIGN) return;
     
  8. Offline

    Blingdaddy1

    DCDJ doesn't work. :\ I wonder, if i could make it where they click on the sign and it makes them do the command? That should work right?
     
  9. Offline

    L33m4n123

    Just out of curiosity. You sure you got the correct text on the sign in the correct lines?
     
  10. Offline

    ImImprobable

    DCDJ
    || & && Work exactly the same ;)
     
  11. Offline

    L33m4n123


    Uhm.. No?

    • a || b
    that statement is true if EITHER a OR b is true OR BOTH are true
    • a && b
    That statement is ONLY true if BOTH are true
     
  12. Offline

    ImImprobable

    oh well in that case DCDJ If he used && then he would have to preform three clicks at once :?
     
  13. Offline

    Blingdaddy1

    Yes

    L33m4n123 Yes. they are the same
     
  14. Offline

    L33m4n123


    What do you mean?
     
  15. Offline

    Blingdaddy1

    Accidental double post on my part :p On the D0N SG plugin, you use a WE selection on signs to make a sign wall to join games, and it automatically puts what is define in the the SignClick class. For some reason, this doesn't work.
     
  16. Offline

    DCDJ


    No. Not at all.

    L33m4n123 made a very valid post above explaining the differences between && and ||. They are NOT the same. The logic is completely different.

    != || != { return; } says that if at least one of the statements is false, then the code will not execute at all.
    != && != { return; } says that at least one of the statements has to be true for the code to execute.

    I suggest you read up on AND/OR logical statements before tackling this problem.
     
  17. Offline

    ImImprobable

    Oh yes,
    Misread meh lines.
    Will double check next time :)
     
Thread Status:
Not open for further replies.

Share This Page