From b46485cb0d8935d1ae157d64c42e5bfd33787314 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 11:44:38 +0200 Subject: [PATCH] Add semi Random Item for player --- .../misslewars/countdowns/ItemCountdown.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java index bc4bd7c..958b5a2 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -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 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 itemList) { + List itemStackList = new ArrayList<>(itemList); + for (Player p : team.getPlayers()) { + ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size())); + givePlayerItem(p, itemStack); } } -- 2.39.5