Solved Bukkit coding getting the players in a mini game lobby [HELP]

Discussion in 'Plugin Development' started by benzimmer123, Feb 1, 2014.

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

    benzimmer123

    I am using a piece of code which is working but it only executes the code for one player not all the players! Also it seems to be picking this player at complete random.
    Thanks in advance!:D

    CODE:

    Code:java
    1. public void online(Player p){
    2. final ItemStack gun = new ItemStack(Material.STONE_HOE);
    3. ItemMeta gunn = gun.getItemMeta();
    4. gunn.setDisplayName(ChatColor.GREEN + "Snow Gun");
    5. gun.setItemMeta(gunn);
    6. p.sendMessage(ChatColor.GREEN + "You have joined map A.");
    7. final double gunspleefx = plugin.getConfig().getDouble("warps." + "gunspleef" + "spawn" + ".x");
    8. final double gunspleefy = plugin.getConfig().getDouble("warps." + "gunspleef" + "spawn" + ".y");
    9. final double gunspleefz = plugin.getConfig().getDouble("warps." + "gunspleef" + "spawn" + ".z");
    10. final float gunspleefyaw = (float) plugin.getConfig().getDouble("warps." + "gunspleef" + "spawn" + ".yaw");
    11. final float gunspleefpitch = (float) plugin.getConfig().getDouble("warps." + "gunspleef" + "spawn" + ".pitch");
    12. int players1 = plugin.getConfig().getInt("Gunspleef." + "1" + ".players");
    13. for (final Player ol : Bukkit.getOnlinePlayers()) {
    14. if (gunspleef1.contains(ol)) {
    15. if (players1 >= 1) {
    16. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    17. public void run() {
    18. number--;
    19. if (number == 30) {
    20. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + ChatColor.YELLOW + "The game starts in 30 seconds.");
    21. } else if (number == 20) {
    22. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + ChatColor.YELLOW + "The game starts in 20 seconds.");
    23. } else if (number == 10) {
    24. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + ChatColor.YELLOW + "The game starts in 10 seconds.");
    25. } else if (number <= 5 && number > 0) {
    26. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + ChatColor.YELLOW + "The game starts in " + number + " seconds.");
    27. } else if (number == 0) {
    28. ol.getInventory().clear();
    29. ol.setGameMode(GameMode.SURVIVAL);
    30. ol.setAllowFlight(false);
    31. ol.getInventory().addItem(gun);
    32. ol.teleport(new Location(ol.getWorld(), gunspleefx, gunspleefy, gunspleefz, gunspleefyaw, gunspleefpitch));
    33. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + ChatColor.YELLOW + "The game is starting!");
    34. }
    35. }
    36. }, 0, 20);
    37. ol.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Gunspleef" + ChatColor.GRAY + "]: " + p.getName() + ChatColor.YELLOW + " joined the game (" + ChatColor.LIGHT_PURPLE + players1 + ChatColor.YELLOW + "/" + ChatColor.LIGHT_PURPLE + "16" + ChatColor.YELLOW + ")");
    38. }
    39. }
    40. }
    41. }


    50 Views, no replys?:'(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    Iaccidentally

    for (final Player ol : Bukkit.getOnlinePlayers()) {
    That would be what final would mean, as it can only be assigned once.
     
    benzimmer123 likes this.
  3. Offline

    benzimmer123

Thread Status:
Not open for further replies.

Share This Page