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;
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());
}
private void giveTeamItem(MWTeam team, ItemStack item){
giveTeamItem(MissileWars.getBlueTeam(), itemList);
giveTeamItem(MissileWars.getRedTeam(), itemList);
}
private void giveTeamItem(MWTeam team, List<ItemStack> itemList) {
List<ItemStack> itemStackList = new ArrayList<>(itemList);
for (Player p : team.getPlayers()) {
givePlayerItem(p, item);
ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size()));
givePlayerItem(p, itemStack);
}
}