Balance ItemCountdown for uneven Teams #12
@ -19,16 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars;
|
package de.steamwar.misslewars;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
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;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MWTeam {
|
public class MWTeam {
|
||||||
private static final ItemStack bow = new ItemStack(Material.BOW);
|
private static final ItemStack bow = new ItemStack(Material.BOW);
|
||||||
@ -49,11 +51,7 @@ public class MWTeam {
|
|||||||
private final Location spawn;
|
private final Location spawn;
|
||||||
private final int portalZ;
|
private final int portalZ;
|
||||||
|
|
||||||
private Set<Player> players = new HashSet<>();
|
private LinkedList<Player> players = new LinkedList<>();
|
||||||
|
|
||||||
public Set<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;
|
||||||
@ -69,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;
|
||||||
}
|
}
|
||||||
@ -77,20 +104,19 @@ public class MWTeam {
|
|||||||
return spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join (Player p) {
|
public void join(Player p) {
|
||||||
players.add(p);
|
players.add(p);
|
||||||
p.teleport(spawn);
|
p.teleport(spawn);
|
||||||
p.setGameMode(GameMode.SURVIVAL);
|
p.setGameMode(GameMode.SURVIVAL);
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leave (Player p) {
|
public void leave(Player p) {
|
||||||
if(!players.contains(p))
|
if (!players.contains(p)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
players.remove(p);
|
players.remove(p);
|
||||||
sbteam.removePlayer(p);
|
sbteam.removePlayer(p);
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars.countdowns;
|
package de.steamwar.misslewars.countdowns;
|
||||||
|
|
||||||
import de.steamwar.misslewars.*;
|
import de.steamwar.misslewars.Config;
|
||||||
|
import de.steamwar.misslewars.FightState;
|
||||||
|
import de.steamwar.misslewars.MissileWars;
|
||||||
|
import de.steamwar.misslewars.StateDependent;
|
||||||
import de.steamwar.misslewars.items.Missile;
|
import de.steamwar.misslewars.items.Missile;
|
||||||
import de.steamwar.misslewars.items.SpecialItem;
|
import de.steamwar.misslewars.items.SpecialItem;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -29,7 +32,10 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class ItemCountdown extends StateDependent {
|
public class ItemCountdown extends StateDependent {
|
||||||
|
|
||||||
@ -41,43 +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 itemCount = Math.max(MissileWars.getBlueTeam().size(), MissileWars.getRedTeam().size());
|
||||||
List<ItemStack> itemList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < items; i++) {
|
|
||||||
itemList.add(SpecialItem.getRandomItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
giveTeamItem(MissileWars.getBlueTeam(), itemList);
|
for (int i = 0; i < itemCount; i++) {
|
||||||
giveTeamItem(MissileWars.getRedTeam(), itemList);
|
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||||
}
|
|
||||||
|
|
||||||
private void giveTeamItem(MWTeam team, List<ItemStack> itemList) {
|
MissileWars.getBlueTeam().givePlayerItem(itemStack);
|
||||||
List<ItemStack> itemStackList = new ArrayList<>(itemList);
|
MissileWars.getRedTeam().givePlayerItem(itemStack);
|
||||||
for (Player p : team.getPlayers()) {
|
|
||||||
ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size()));
|
|
||||||
givePlayerItem(p, itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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