SteamWar/MissileWars
Archiviert
13
0

Balance ItemCountdown for uneven Teams #12

Manuell gemergt
Lixfel hat 6 Commits von BalanceItems nach master 2020-09-26 20:46:30 +02:00 zusammengeführt
2 geänderte Dateien mit 34 neuen und 35 gelöschten Zeilen
Nur Änderungen aus Commit d1461b5e8c werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -25,6 +25,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scoreboard.Team;
@ -52,10 +53,6 @@ public class MWTeam {
private LinkedList<Player> players = new LinkedList<>();
public LinkedList<Player> getPlayers(){
return players;
}
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
this.teamName = teamName;
this.color = color;
@ -70,6 +67,35 @@ public class MWTeam {
sbteam.setColor(color);
}
public void givePlayerItem(ItemStack item){
Player p = players.removeFirst();
players.addLast(p);
Inventory inventory = p.getInventory();
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
inventory.setItem(i, itemStack);
p.updateInventory();
return;
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
inventory.setItem(i, item);
p.updateInventory();
return;
}
}
}
public int size() {
return players.size();
}
public int getPortalZ() {
return portalZ;
}
@ -85,7 +111,7 @@ public class MWTeam {
p.getInventory().setItem(0, bow);
sbteam.addPlayer(p);
p.setDisplayName(color + p.getName());
if (MissileWars.getFightState() == FightState.WAITING && !enemy().getPlayers().isEmpty())
if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty())
MissileWars.startRound();
}

Datei anzeigen

@ -47,40 +47,13 @@ public class ItemCountdown extends StateDependent {
}
private void run(){
int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size());
int items = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
for (int i = 0; i < items; i++) {
ItemStack itemStack = SpecialItem.getRandomItem();
Player blue = MissileWars.getBlueTeam().getPlayers().removeFirst();
givePlayerItem(blue, itemStack);
MissileWars.getBlueTeam().getPlayers().addLast(blue);
Player red = MissileWars.getRedTeam().getPlayers().removeFirst();
givePlayerItem(red, itemStack);
MissileWars.getBlueTeam().getPlayers().addLast(red);
}
}
private void givePlayerItem(Player p, ItemStack item){
Inventory inventory = p.getInventory();
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.isSimilar(item) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setAmount(itemStack.getAmount() + item.getAmount());
inventory.setItem(i, itemStack);
p.updateInventory();
return;
}
}
for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot
ItemStack itemStack = inventory.getItem(i);
if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
inventory.setItem(i, item);
p.updateInventory();
return;
}
MissileWars.getBlueTeam().givePlayerItem(itemStack);
MissileWars.getRedTeam().givePlayerItem(itemStack);
}
}