diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index cd447dd..e850435 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -29,9 +29,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scoreboard.Team; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; +import java.util.*; public class MWTeam { private static final ItemStack bow = new ItemStack(Material.BOW); @@ -52,9 +50,9 @@ public class MWTeam { private final Location spawn; private final int portalZ; - private Set players = new HashSet<>(); + private LinkedList players = new LinkedList<>(); - public Set getPlayers(){ + public LinkedList getPlayers(){ return players; } diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java index 909aea8..1abb4a8 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -23,6 +23,7 @@ import de.steamwar.misslewars.Config; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.StateDependent; +import de.steamwar.misslewars.items.Missile; import de.steamwar.misslewars.items.SpecialItem; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -46,18 +47,18 @@ public class ItemCountdown extends StateDependent { } private void run(){ - List blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); - List red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); - - int items = Math.max(blue.size(), red.size()); - int randomOffsetBlue = random.nextInt(blue.size()); - int randomOffsetRed = random.nextInt(red.size()); + int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size()); for (int i = 0; i < items; i++) { ItemStack itemStack = SpecialItem.getRandomItem(); - givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack); - givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack); + Player blue = MissileWars.getBlueTeam().getPlayers().removeFirst(); + givePlayerItem(blue, itemStack); + MissileWars.getBlueTeam().getPlayers().addLast(blue); + + Player red = MissileWars.getRedTeam().getPlayers().removeFirst(); + givePlayerItem(red, itemStack); + MissileWars.getBlueTeam().getPlayers().addLast(red); } } diff --git a/src/de/steamwar/misslewars/data/TapeSet.java b/src/de/steamwar/misslewars/data/TapeSet.java deleted file mode 100644 index eb7e7eb..0000000 --- a/src/de/steamwar/misslewars/data/TapeSet.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.misslewars.data; - -import java.util.HashMap; -import java.util.Map; - -public class TapeSet { - - private Map> nodeMap = new HashMap<>(); - private Node last = null; - private Node currentIterator = null; - - private class Node { - - private Node next = null; - private Node prev = null; - private T value; - - public Node(T value) { - this.value = value; - } - - private void unlink() { - if (!itself()) { - next.prev = prev; - prev.next = next; - } - next = null; - prev = null; - } - - private void link(Node prev) { - this.prev = prev; - next = prev.next; - next.prev = this; - prev.next = this; - } - - private boolean itself() { - return next == prev && next == this; - } - - } - - public int size() { - return nodeMap.size(); - } - - public boolean isEmpty() { - return nodeMap.isEmpty(); - } - - public boolean contains(T t) { - return nodeMap.containsKey(t); - } - - public void add(T t) { - if (nodeMap.containsKey(t)) return; - Node node = new Node<>(t); - nodeMap.put(t, node); - if (last == null) { - last = node; - currentIterator = node; - } else { - node.link(last); - } - } - - public void remove(T t) { - if (!nodeMap.containsKey(t)) return; - Node node = nodeMap.get(t); - if (node.itself()) { - last = null; - currentIterator = null; - } - if (node == currentIterator) { - currentIterator = node.next; - } - node.unlink(); - nodeMap.remove(t); - } - - public T next() { - if (currentIterator == null) return null; - T value = currentIterator.value; - currentIterator = currentIterator.next; - return value; - } - -}