Issues with signs

Discussion in 'Plugin Development' started by Monkeyboystein, Jul 27, 2013.

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

    Monkeyboystein

    Hi im making like a lobby and i cant seem to get the play numbers right the sign starts with
    [ANN]
    0/10
    Blue

    and when i right click the sign it puts it to
    [ANN]
    10/10
    Blue

    so i cant use the lobby sign again,

    code:
    Code:
        @EventHandler
        public void playinteract(PlayerInteractEvent event){
           
            try{
            Player p = event.getPlayer();
            Bukkit.broadcastMessage("Interaction is happened");
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                if(event.getClickedBlock().getType() == Material.SIGN){
                    Location RedLocation = p.getWorld().getBlockAt(getConfig().getInt("RedX"), getConfig().getInt("RedY"), getConfig().getInt("RedZ")).getLocation();
                    Location BlueLocation = p.getWorld().getBlockAt(getConfig().getInt("BlueX"), getConfig().getInt("BlueY"), getConfig().getInt("BlueZ")).getLocation();
                    Location YellowLocation = p.getWorld().getBlockAt(getConfig().getInt("YellowX"), getConfig().getInt("YellowY"), getConfig().getInt("YellowZ")).getLocation();
                    Location GreenLocation = p.getWorld().getBlockAt(getConfig().getInt("GreenX"), getConfig().getInt("GreenY"), getConfig().getInt("GreenZ")).getLocation();
                    Block b = event.getClickedBlock();
                    Sign s = (Sign)b.getState();
                 
            Block b = event.getClickedBlock();
            if(b.getType() == Material.WALL_SIGN) {
            Sign s = (Sign)b.getState();
            Location RedLocation = p.getWorld().getBlockAt(getConfig().getInt("RedX"), getConfig().getInt("RedY"), getConfig().getInt("RedZ")).getLocation();
            Location BlueLocation = p.getWorld().getBlockAt(getConfig().getInt("BlueX"), getConfig().getInt("BlueY"), getConfig().getInt("BlueZ")).getLocation();
            Location YellowLocation = p.getWorld().getBlockAt(getConfig().getInt("YellowX"), getConfig().getInt("YellowY"), getConfig().getInt("YellowZ")).getLocation();
            Location GreenLocation = p.getWorld().getBlockAt(getConfig().getInt("GreenX"), getConfig().getInt("GreenY"), getConfig().getInt("GreenZ")).getLocation();
           
            if(s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[ANN]")){
                if(s.getLine(1).equalsIgnoreCase("0/10")) {
                    s.setLine(1, "1/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, (short) 9));
                       
                    }
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, (short) 14));
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, (short) 4));
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.getInventory().setHelmet(new ItemStack(Material.WOOL, 1, (short) 5));
                    }
                }
                if(s.getLine(1).equalsIgnoreCase("1/10")) {
                    s.setLine(1, "2/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                }
                if(s.getLine(1).equalsIgnoreCase("2/10")) {
                    s.setLine(1, "3/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("3/10")) {
                    s.setLine(1, "4/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("4/10")) {
                    s.setLine(1, "5/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("5/10")) {
                    s.setLine(1, "6/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("6/10")) {
                    s.setLine(1, "7/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("7/10")) {
                    s.setLine(1, "8/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("8/10")) {
                    s.setLine(1, "9/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("9/10")) {
                    s.setLine(1, "10/10");
                    s.update();
                    if(s.getLine(2).equalsIgnoreCase("Red")){
                        p.teleport(RedLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Blue")){
                        p.teleport(BlueLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Yellow")){
                        p.teleport(YellowLocation);
                    }
                    if(s.getLine(2).equalsIgnoreCase("Green")){
                        p.teleport(GreenLocation);
                    }
                   
                }
                if(s.getLine(1).equalsIgnoreCase("10/10")){
                   
                    p.sendMessage("Sorry this team is full.");
                   
                }
            }
        }
    }catch(Exception e){e.printStackTrace();}
        }
     
  2. Offline

    savagesun

    You are using if statements instead of if else statements. Since you update the value and then check what it is right after that, you're passing all the if statements which is why you are ending up at 10/10 right away.

    Edit: meant to say else if.
     
  3. Offline

    Monkeyboystein

    im sorry could you show me how to use if else's N00B question?

    nvm

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page