Balance ItemCountdown for uneven Teams #12
@ -29,9 +29,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MWTeam {
|
public class MWTeam {
|
||||||
private static final ItemStack bow = new ItemStack(Material.BOW);
|
private static final ItemStack bow = new ItemStack(Material.BOW);
|
||||||
@ -52,9 +50,9 @@ public class MWTeam {
|
|||||||
private final Location spawn;
|
private final Location spawn;
|
||||||
private final int portalZ;
|
private final int portalZ;
|
||||||
|
|
||||||
private Set<Player> players = new HashSet<>();
|
private LinkedList<Player> players = new LinkedList<>();
|
||||||
|
|
||||||
public Set<Player> getPlayers(){
|
public LinkedList<Player> getPlayers(){
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.misslewars.Config;
|
|||||||
import de.steamwar.misslewars.FightState;
|
import de.steamwar.misslewars.FightState;
|
||||||
import de.steamwar.misslewars.MissileWars;
|
import de.steamwar.misslewars.MissileWars;
|
||||||
import de.steamwar.misslewars.StateDependent;
|
import de.steamwar.misslewars.StateDependent;
|
||||||
|
import de.steamwar.misslewars.items.Missile;
|
||||||
import de.steamwar.misslewars.items.SpecialItem;
|
import de.steamwar.misslewars.items.SpecialItem;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -46,18 +47,18 @@ public class ItemCountdown extends StateDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
|
int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size());
|
||||||
List<Player> 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());
|
|
||||||
|
|
||||||
for (int i = 0; i < items; i++) {
|
for (int i = 0; i < items; i++) {
|
||||||
ItemStack itemStack = SpecialItem.getRandomItem();
|
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||||
|
|
||||||
givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack);
|
Player blue = MissileWars.getBlueTeam().getPlayers().removeFirst();
|
||||||
givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack);
|
givePlayerItem(blue, itemStack);
|
||||||
|
MissileWars.getBlueTeam().getPlayers().addLast(blue);
|
||||||
|
|
||||||
|
Player red = MissileWars.getRedTeam().getPlayers().removeFirst();
|
||||||
|
givePlayerItem(red, itemStack);
|
||||||
|
MissileWars.getBlueTeam().getPlayers().addLast(red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.misslewars.data;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TapeSet<T> {
|
|
||||||
|
|
||||||
private Map<T, Node<T>> nodeMap = new HashMap<>();
|
|
||||||
private Node<T> last = null;
|
|
||||||
private Node<T> currentIterator = null;
|
|
||||||
|
|
||||||
private class Node<T> {
|
|
||||||
|
|
||||||
private Node<T> next = null;
|
|
||||||
private Node<T> 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<T> 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<T> 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<T> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren