SteamWar/MissileWars
Archiviert
13
0

Add semi Random Item for player #4

Manuell gemergt
YoyoNow hat 1 Commits von ItemManagement nach master 2020-09-05 13:21:45 +02:00 zusammengeführt
Nur Änderungen aus Commit b46485cb0d werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,6 +1,7 @@
package de.steamwar.misslewars.countdowns; package de.steamwar.misslewars.countdowns;
import de.steamwar.misslewars.*; import de.steamwar.misslewars.*;
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;
@ -9,25 +10,33 @@ 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.EnumSet; import java.util.*;
public class ItemCountdown extends StateDependent { public class ItemCountdown extends StateDependent {
private BukkitTask task; private BukkitTask task;
private Random random = new Random();
public ItemCountdown() { public ItemCountdown() {
super(EnumSet.of(FightState.FIGHTING)); super(EnumSet.of(FightState.FIGHTING));
} }
private void run(){ private void run(){
ItemStack item = SpecialItem.getRandomItem(); int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size());
giveTeamItem(MissileWars.getBlueTeam(), item); List<ItemStack> itemList = new ArrayList<>();
giveTeamItem(MissileWars.getRedTeam(), item); for (int i = 0; i < items; i++) {
itemList.add(SpecialItem.getRandomItem());
}
giveTeamItem(MissileWars.getBlueTeam(), itemList);
giveTeamItem(MissileWars.getRedTeam(), itemList);
} }
private void giveTeamItem(MWTeam team, ItemStack item){ private void giveTeamItem(MWTeam team, List<ItemStack> itemList) {
for(Player p : team.getPlayers()){ List<ItemStack> itemStackList = new ArrayList<>(itemList);
givePlayerItem(p, item); for (Player p : team.getPlayers()) {
ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size()));
givePlayerItem(p, itemStack);
} }
} }