Balance ItemCountdown for uneven Teams #12
@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars;
|
package de.steamwar.misslewars;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars.countdowns;
|
package de.steamwar.misslewars.countdowns;
|
||||||
|
|
||||||
import de.steamwar.misslewars.*;
|
import de.steamwar.misslewars.Config;
|
||||||
import de.steamwar.misslewars.items.Missile;
|
import de.steamwar.misslewars.FightState;
|
||||||
|
import de.steamwar.misslewars.MissileWars;
|
||||||
|
import de.steamwar.misslewars.StateDependent;
|
||||||
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;
|
||||||
@ -29,7 +31,10 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class ItemCountdown extends StateDependent {
|
public class ItemCountdown extends StateDependent {
|
||||||
|
|
||||||
@ -41,21 +46,18 @@ public class ItemCountdown extends StateDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size());
|
List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
|
||||||
List<ItemStack> itemList = new ArrayList<>();
|
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++) {
|
||||||
itemList.add(SpecialItem.getRandomItem());
|
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||||
}
|
|
||||||
|
|
||||||
giveTeamItem(MissileWars.getBlueTeam(), itemList);
|
givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack);
|
||||||
giveTeamItem(MissileWars.getRedTeam(), itemList);
|
givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack);
|
||||||
}
|
|
||||||
|
|
||||||
private void giveTeamItem(MWTeam team, List<ItemStack> itemList) {
|
|
||||||
List<ItemStack> itemStackList = new ArrayList<>(itemList);
|
|
||||||
for (Player p : team.getPlayers()) {
|
|
||||||
ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size()));
|
|
||||||
givePlayerItem(p, itemStack);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren