package de.steamwar.misslewars; import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scoreboard.Team; import java.util.HashSet; import java.util.Objects; import java.util.Set; public class MWTeam { private static final ItemStack bow = new ItemStack(Material.BOW); static { ItemMeta bowMeta = Objects.requireNonNull(bow.getItemMeta()); bowMeta.addEnchant(Enchantment.ARROW_FIRE, 1, false); bowMeta.setUnbreakable(true); bow.setItemMeta(bowMeta); } private final ChatColor color; private final String teamName; private final Team sbteam; //scoreboard-Team private final Location spawn; private final int portalZ; private Set players = new HashSet<>(); public Set getPlayers(){ return players; } MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) { this.teamName = teamName; this.color = color; this.spawn = spawn; this.portalZ = portalZ; if(FightScoreboard.getScoreboard().getTeam(teamName) == null) sbteam = FightScoreboard.getScoreboard().registerNewTeam(teamName); else sbteam = FightScoreboard.getScoreboard().getTeam(teamName); assert sbteam != null; sbteam.setAllowFriendlyFire(false); sbteam.setColor(color); } public int getPortalZ() { return portalZ; } public Location getSpawn(){ return spawn; } public void join (Player p) { players.add(p); p.teleport(spawn); Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> p.setGameMode(GameMode.SURVIVAL), 1); p.getInventory().setItem(0, bow); sbteam.addPlayer(p); p.setDisplayName(color + " " + p.getName()); if (MissileWars.getFightState() == FightState.WAITING && !enemy().getPlayers().isEmpty()) MissileWars.startRound(); } public void leave (Player p) { if(!players.contains(p)) return; players.remove(p); sbteam.removePlayer(p); if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING) MissileWars.end(WinReasons.NO_ENEMY, enemy()); } private MWTeam enemy() { if (this == MissileWars.getRedTeam()) return MissileWars.getBlueTeam(); return MissileWars.getRedTeam(); } public String getPrefix(){ return "ยง" + color.getChar(); } public boolean hasPlayer (Player p) { return players.contains(p); } public String getColoredName() { return color.toString() + teamName; } }