SteamWar/MissileWars
Archiviert
13
0

Add semi Random Item for player

Dieser Commit ist enthalten in:
jojo 2020-09-05 11:44:38 +02:00
Ursprung 551eecd668
Commit b46485cb0d

Datei anzeigen

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