}else{ dont work

Discussion in 'Plugin Development' started by ArthurHoeke, Apr 3, 2014.

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

    ArthurHoeke

    Hello!
    Im making a vote scoreboard for one of my plugins,
    And i got a problem, The problem is that when a player votes the scoreboard add his vote on the scoreboard that works, But it teleports the player if he votes, But it must teleport the player only if 2 players has voted... This is my code

    Under the code is the else, And the begin of the code is the if.

    Code:
    if (Voted.size() == 2){
                        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                            public void run() {
                                if(number != -1) {
                                    if (number!= 0) {
                                        objective.setDisplayName(ChatColor.GOLD + secToMin(number));
     
                                        Score Vote1 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GRAY + "Clay Spleef"));
                                        Score Vote2 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GRAY + "World's End"));
                                        Score Vote3 = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GRAY + "DvZ"));
                                        Vote1.setScore(ClaySpleef);
                                        Vote2.setScore(WorldsEnd);
                                        Vote3.setScore(DVZ);
                                            p2.setScoreboard(board);
                                        number--;
                                    } else {
                                        number--;
                                        if (Voted.size() == 0){
                                            Bukkit.broadcastMessage(ChatColor.RED + "Not enough players to start the game!");
                                        }else{
                                            if(ClaySpleef >= WorldsEnd){ //checking if one is equaled or higher than the two int
                                                Bukkit.broadcastMessage(ChatColor.RED + "The game " + ChatColor.BOLD + "Clay Spleef " + "is selected!");
                                                Location Glass1 = new Location(Bukkit.getWorld("world"), 1001.32560, 114.471, 49.70000);
                                                Location Glass2 = new Location(Bukkit.getWorld("world"), 1000.30000, 114.460, 49.70000);
                                                Location Glass3 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 49.70000);
                                                Location Glass4 = new Location(Bukkit.getWorld("world"), 1001.52180, 114.455, 50.70000);
                                                Location Glass5 = new Location(Bukkit.getWorld("world"), 1000.41621, 114.434, 50.70000);
                                                Location Glass6 = new Location(Bukkit.getWorld("world"), 999.50723, 114.434, 50.70000);
                                                Location Glass7 = new Location(Bukkit.getWorld("world"), 999.57063, 114.434, 51.70000);
                                                Location Glass8 = new Location(Bukkit.getWorld("world"), 1000.57155, 114.434, 51.70000);
                                                Location Glass9 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 51.7000);
                                                Location Glass10 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 52.7000);
                                                Location Glass11 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 53.7000);
                                                Location Glass12 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 54.7000);
                                                Location Glass13 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 55.7000);
                                                Location Glass14 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 56.7000);
                                                Location Glass15 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 57.7000);
                                                Location Glass16 = new Location(Bukkit.getWorld("world"), 1001.30000, 114.434, 58.7000);
                                                Location Glass17 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 49.69613);
                                                Location Glass18 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 50.69613);
                                                Location Glass19 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 51.69613);
                                                Location Glass20 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 52.69613);
                                                Location Glass21 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 53.69613);
                                                Location Glass22 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 54.69613);
                                                Location Glass23 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 55.69613);
                                                Location Glass24 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 56.69613);
                                                Location Glass25 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 57.69613);
                                                Location Glass26 = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 58.69613);
                                                Location Glass27 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 50.70000);
                                                Location Glass28 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 51.70000);
                                                Location Glass29 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 52.70000);
                                                Location Glass30 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 53.70000);
                                                Location Glass31 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 54.70000);
                                                Location Glass32 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 55.70000);
                                                Location Glass33 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 56.70000);
                                                Location Glass34 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 57.70000);
                                                Location Glass35 = new Location(Bukkit.getWorld("world"), 999.30000, 114.460, 58.70000);
                                                Location Glass36 = new Location(Bukkit.getWorld("world"), 1000.60761, 114.334, 52.70000);
                                                Location Glass37 = new Location(Bukkit.getWorld("world"), 1000.60146, 114.334, 53.70000);
                                                Location Glass38 = new Location(Bukkit.getWorld("world"), 1000.60083, 114.334, 54.70000);
                                                Location Glass39 = new Location(Bukkit.getWorld("world"), 1000.60083, 114.334, 55.70000);
                                                Location Glass40 = new Location(Bukkit.getWorld("world"), 1000.60083, 114.334, 56.70000);
                                                Location Glass41 = new Location(Bukkit.getWorld("world"), 1000.60083, 114.334, 57.70000);
                                                Location Glass42 = new Location(Bukkit.getWorld("world"), 1000.60083, 114.334, 58.70000);
                                                Location Heli = new Location(Bukkit.getWorld("world"), 1000.49980, 116, 53.69613);
                                                final Block Glas1 = Glass1.getBlock();
                                                final Block Glas2 = Glass2.getBlock();
                                                final Block Glas3 = Glass3.getBlock();
                                                final Block Glas4 = Glass4.getBlock();
                                                final Block Glas5 = Glass5.getBlock();
                                                final Block Glas6 = Glass6.getBlock();
                                                final Block Glas7 = Glass7.getBlock();
                                                final Block Glas8 = Glass8.getBlock();
                                                final Block Glas9 = Glass9.getBlock();
                                                final Block Glas10 = Glass10.getBlock();
                                                final Block Glas11 = Glass11.getBlock();
                                                final Block Glas12 = Glass12.getBlock();
                                                final Block Glas13 = Glass13.getBlock();
                                                final Block Glas14 = Glass14.getBlock();
                                                final Block Glas15 = Glass15.getBlock();
                                                final Block Glas16 = Glass16.getBlock();
                                                final Block Glas17 = Glass17.getBlock();
                                                final Block Glas18 = Glass18.getBlock();
                                                final Block Glas19 = Glass19.getBlock();
                                                final Block Glas20 = Glass20.getBlock();
                                                final Block Glas21 = Glass21.getBlock();
                                                final Block Glas22 = Glass22.getBlock();
                                                final Block Glas23 = Glass23.getBlock();
                                                final Block Glas24 = Glass24.getBlock();
                                                final Block Glas25 = Glass25.getBlock();
                                                final Block Glas26 = Glass26.getBlock();
                                                final Block Glas27 = Glass27.getBlock();
                                                final Block Glas28 = Glass28.getBlock();
                                                final Block Glas29 = Glass29.getBlock();
                                                final Block Glas30 = Glass30.getBlock();
                                                final Block Glas31 = Glass31.getBlock();
                                                final Block Glas32 = Glass32.getBlock();
                                                final Block Glas33 = Glass33.getBlock();
                                                final Block Glas34 = Glass34.getBlock();
                                                final Block Glas35 = Glass35.getBlock();
                                                final Block Glas36 = Glass36.getBlock();
                                                final Block Glas37 = Glass37.getBlock();
                                                final Block Glas38 = Glass38.getBlock();
                                                final Block Glas39 = Glass39.getBlock();
                                                final Block Glas40 = Glass40.getBlock();
                                                final Block Glas41 = Glass41.getBlock();
                                                final Block Glas42 = Glass42.getBlock();
                                                Player[] list = (Bukkit.getOnlinePlayers());
                                             
                                                for (Player p2 : list) {
                                                    Ingame.put(p2, null);
                                                    p2.getInventory().clear();
                                                    p2.teleport(Heli);
                                                    ItemStack Cookie = new ItemStack(Material.BLAZE_ROD, 1);
                                                      ArrayList Cookie1 = new ArrayList();
                                                      Cookie1.add("Right click to thow clay breaker!");
                                                      ItemMeta im = Cookie.getItemMeta();
                                                      im.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Clay Breaker");
                                                      im.setLore(Cookie1);
                                                      Cookie.setItemMeta(im);
                                                          p2.getInventory().addItem(Cookie);
                                                          p2.updateInventory();;
                                                          p2.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 2000000000, 5));
                                                          BarAPI.setMessage(p2, ChatColor.AQUA + "Deploy zone in", 10);
                                                              Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                                                                  public void run() {
                                                                      Glas1.setType(Material.AIR);
                                                                    Glas2.setType(Material.AIR);
                                                                    Glas3.setType(Material.AIR);
                                                                    Glas4.setType(Material.AIR);
                                                                    Glas5.setType(Material.AIR);
                                                                    Glas6.setType(Material.AIR);
                                                                    Glas7.setType(Material.AIR);
                                                                    Glas8.setType(Material.AIR);
                                                                    Glas9.setType(Material.AIR);
                                                                    Glas10.setType(Material.AIR);
                                                                    Glas11.setType(Material.AIR);
                                                                    Glas12.setType(Material.AIR);
                                                                    Glas13.setType(Material.AIR);
                                                                    Glas14.setType(Material.AIR);
                                                                    Glas15.setType(Material.AIR);
                                                                    Glas16.setType(Material.AIR);
                                                                    Glas27.setType(Material.AIR);
                                                                    Glas28.setType(Material.AIR);
                                                                    Glas29.setType(Material.AIR);
                                                                    Glas30.setType(Material.AIR);
                                                                    Glas31.setType(Material.AIR);
                                                                    Glas32.setType(Material.AIR);
                                                                    Glas33.setType(Material.AIR);
                                                                    Glas34.setType(Material.AIR);
                                                                    Glas35.setType(Material.AIR);
                                                                    Glas36.setType(Material.AIR);
                                                                    Glas37.setType(Material.AIR);
                                                                    Glas38.setType(Material.AIR);
                                                                    Glas39.setType(Material.AIR);
                                                                    Glas40.setType(Material.AIR);
                                                                    Glas41.setType(Material.AIR);
                                                                    Glas42.setType(Material.AIR);
                                                                  }
                                                                      }, 200);
                                                }
                                                  Bukkit.getScheduler().runTaskLater(Main.this, new Runnable() {
                                                      public void run() {
                                                              Glas1.setType(Material.GLASS);
                                                            Glas2.setType(Material.GLASS);
                                                            Glas3.setType(Material.GLASS);
                                                            Glas4.setType(Material.GLASS);
                                                            Glas5.setType(Material.GLASS);
                                                            Glas6.setType(Material.GLASS);
                                                            Glas7.setType(Material.GLASS);
                                                            Glas8.setType(Material.GLASS);
                                                            Glas9.setType(Material.GLASS);
                                                            Glas10.setType(Material.GLASS);
                                                            Glas11.setType(Material.GLASS);
                                                            Glas12.setType(Material.GLASS);
                                                            Glas13.setType(Material.GLASS);
                                                            Glas14.setType(Material.GLASS);
                                                            Glas15.setType(Material.GLASS);
                                                            Glas16.setType(Material.GLASS);
                                                            Glas27.setType(Material.GLASS);
                                                            Glas28.setType(Material.GLASS);
                                                            Glas29.setType(Material.GLASS);
                                                            Glas30.setType(Material.GLASS);
                                                            Glas31.setType(Material.GLASS);
                                                            Glas32.setType(Material.GLASS);
                                                            Glas33.setType(Material.GLASS);
                                                            Glas34.setType(Material.GLASS);
                                                            Glas35.setType(Material.GLASS);
                                                            Glas36.setType(Material.GLASS);
                                                            Glas37.setType(Material.GLASS);
                                                            Glas38.setType(Material.GLASS);
                                                            Glas39.setType(Material.GLASS);
                                                            Glas40.setType(Material.GLASS);
                                                            Glas41.setType(Material.GLASS);
                                                            Glas42.setType(Material.GLASS);
                                                      }
                                                          }, 300);
                                            }
                                        }
                                    }
                                }
                            }
                        }, 0L, 20l);
                    }else{
                        if(WorldsEnd >= ClaySpleef){ //checking if one is equaled or higher than the two int
                            Location WorldsEndSpawn = new Location(Bukkit.getWorld("world"), 1052.46630, 174, 393.44565);
                            p2.teleport(WorldsEndSpawn);
                        }
                    }
                }
            }
            }
        }
        }
     
  2. Offline

    amhokies

    ArthurHoeke
    A really great ability that every programmer should learn is debugging. Sprinkle statements that print out to the console throughout your code and see exactly what path it takes and where things are going wrong.
     
  3. Offline

    ArthurHoeke

  4. Offline

    Not2EXceL

    ArthurHoeke He literally just told you what you need to do. Also learn to efficiently write code and not that clusterfuck that no one's gonna read. Don't paste extra brackets that aren't part of the code in question. And learn to format
     
    MrSnare likes this.
  5. Offline

    ArthurHoeke

    amhokies The problem is, I get no error on the plugin..
     
  6. Offline

    MrSnare

    Try to understand what your own code is doing/supposed to do before you ask other people for help.
     
  7. Offline

    ArthurHoeke

    MrSnare Im watching the code good, But can't find the solution ;s Please help me :(
     
  8. Offline

    afistofirony


    Basically, debugging is adding console output statements at various points in the code:

    Code:
    if (condition) {
        System.out.println("Condition is true");
        // do stuff
    }
    Make sure the statements are distinct, run your code, and check the console to see what is happening.

    EDIT: I'm looking through your code, and having 40 glass variables is awfully inefficient. Try using a for loop:

    Code:
    for (int x = minX; x < maxX; ++x) {
        for (int y = minY; y < maxY; ++y) {
            for (int z = minZ; z < maxZ; ++z {
                Bukkit.getWorld("world").getBlockAt(x, y, z).setType(Material.AIR);
            }
        }
    }
     
  9. Offline

    Zethariel

    ArthurHoeke Don't take this the wrong way, but the way it's formatted - no wonder you can't find anything. Refactor it a bit and you'll probably manage to find the error
     
  10. Offline

    TheHandfish

    If it makes it easier, sometimes it's better to put the opened bracket one line below the "if" line. It doesn't effect the code and looks a little messier, but it's easier to work with.

    i.e.

    Code:
    if(something is something)
    {
    then do this
    }
    else
    {
    do this
    }
     
    // OR
     
    if(something is something)
    {
    do this
    }
    else if(something is something else)
    {
    do this, instead
    }
     
Thread Status:
Not open for further replies.

Share This Page