Balance ItemCountdown for uneven Teams #12
@ -25,6 +25,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
@ -52,10 +53,6 @@ public class MWTeam {
|
|||||||
|
|
||||||
private LinkedList<Player> players = new LinkedList<>();
|
private LinkedList<Player> players = new LinkedList<>();
|
||||||
|
|
||||||
public LinkedList<Player> getPlayers(){
|
|
||||||
return players;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
|
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
@ -70,6 +67,35 @@ public class MWTeam {
|
|||||||
sbteam.setColor(color);
|
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() {
|
public int getPortalZ() {
|
||||||
return portalZ;
|
return portalZ;
|
||||||
}
|
}
|
||||||
@ -85,7 +111,7 @@ public class MWTeam {
|
|||||||
p.getInventory().setItem(0, bow);
|
p.getInventory().setItem(0, bow);
|
||||||
sbteam.addPlayer(p);
|
sbteam.addPlayer(p);
|
||||||
p.setDisplayName(color + p.getName());
|
p.setDisplayName(color + p.getName());
|
||||||
if (MissileWars.getFightState() == FightState.WAITING && !enemy().getPlayers().isEmpty())
|
if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty())
|
||||||
MissileWars.startRound();
|
MissileWars.startRound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,40 +47,13 @@ public class ItemCountdown extends StateDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
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++) {
|
for (int i = 0; i < items; i++) {
|
||||||
ItemStack itemStack = SpecialItem.getRandomItem();
|
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||||
|
|
||||||
Player blue = MissileWars.getBlueTeam().getPlayers().removeFirst();
|
MissileWars.getBlueTeam().givePlayerItem(itemStack);
|
||||||
givePlayerItem(blue, itemStack);
|
MissileWars.getRedTeam().givePlayerItem(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren