Discussion in 'Spigot Plugin Development' started by Koekjeee, May 29, 2016.

  1. I made a command to do something. If i use this command it should remove all the players their potion effect, teleport and send a message. But he only do it with 1 player? I think the for loop goes 1 time(1 player) then remove all the players and then he don't run the second player? Because the first player teleports and gets a message but the second or third don't?

    Code (Text):

    package me.koekjeee.quizmeister.commands;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitRunnable;

    import me.koekjeee.quizmeister.Main;
    import me.koekjeee.quizmeister.listeners.IsStarted;

    public class StopQuiz implements CommandExecutor {

       IsStarted started = new IsStarted();
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if(!(sender instanceof Player)) { return true; }
         Player player = (Player) sender;
         if(cmd.getName().equalsIgnoreCase("stopquiz")) {
           if(!player.hasPermission("quizmeister.stopquiz")) { return true; }
           if(started.GetIsStarted() == false) { player.sendMessage(ChatColor.RED + "The game isn't started yet!"); return true; }
           player.sendMessage(ChatColor.RED + "Quiz ended.");
           for (Player pl : Main.getIngamePlayers()){
             pl.sendMessage(ChatColor.RED + "Quiz ended.");
         return false;
       private void teleport(Player player) {
      World world = Bukkit.getWorld(Main.getPlugin().getConfig().getString(""));
      double x = Main.getPlugin().getConfig().getInt("quiz.stand.x");
      double y = Main.getPlugin().getConfig().getInt("quiz.stand.y");
      double z = Main.getPlugin().getConfig().getInt("quiz.stand.z");
      player.teleport(new Location(world,x,y,z));
    getIngamePlayers is the arraylist with all the players.
  2. Main.getIngamePlayers() makes reference to a List<Player> or something similar?
  3. Code (Text):

    private static ArrayList<Player> ingame = new ArrayList<Player>();

      public static ArrayList<Player> getIngamePlayers() {
         return ingame;
  4. Test with:
    I use this in my plugins and it works 100% good

    Code (Text):
    private List<Player> ingame = new ArrayList();

    public List<Player> getIngamePlayers() {
    return ingame;

    for (Player player : getIngamePlayers()) {
  5. So you want to get all the players of the server or only a few of them that you store in inGame?