2020-05-27 17:52:55 +02:00
|
|
|
package de.steamwar.misslewars;
|
|
|
|
|
2020-06-24 18:24:00 +02:00
|
|
|
import org.bukkit.*;
|
2020-05-27 17:52:55 +02:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2020-06-24 15:26:10 +02:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2020-05-27 17:52:55 +02:00
|
|
|
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 {
|
2020-06-24 15:26:10 +02:00
|
|
|
ItemMeta bowMeta = Objects.requireNonNull(bow.getItemMeta());
|
2020-06-27 20:38:50 +02:00
|
|
|
bowMeta.addEnchant(Enchantment.ARROW_FIRE, 1, true);
|
|
|
|
bowMeta.addEnchant(Enchantment.ARROW_KNOCKBACK, 1, true);
|
|
|
|
bowMeta.addEnchant(Enchantment.KNOCKBACK, 1, true);
|
|
|
|
bowMeta.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
|
2020-06-24 15:26:10 +02:00
|
|
|
bowMeta.setUnbreakable(true);
|
|
|
|
bow.setItemMeta(bowMeta);
|
2020-05-27 17:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private final ChatColor color;
|
|
|
|
private final String teamName;
|
|
|
|
private final Team sbteam; //scoreboard-Team
|
|
|
|
private final Location spawn;
|
|
|
|
private final int portalZ;
|
|
|
|
|
|
|
|
private Set<Player> players = new HashSet<>();
|
|
|
|
|
|
|
|
public Set<Player> getPlayers(){
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2020-06-24 15:26:10 +02:00
|
|
|
MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) {
|
2020-05-27 17:52:55 +02:00
|
|
|
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);
|
2020-06-27 20:38:50 +02:00
|
|
|
p.setGameMode(GameMode.SURVIVAL);
|
2020-06-24 15:26:10 +02:00
|
|
|
p.getInventory().setItem(0, bow);
|
2020-05-27 17:52:55 +02:00
|
|
|
sbteam.addPlayer(p);
|
2020-06-24 20:36:43 +02:00
|
|
|
p.setDisplayName(color + p.getName());
|
2020-05-27 17:52:55 +02:00
|
|
|
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);
|
2020-06-24 15:26:10 +02:00
|
|
|
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
|
2020-05-27 17:52:55 +02:00
|
|
|
MissileWars.end(WinReasons.NO_ENEMY, enemy());
|
|
|
|
}
|
|
|
|
|
2020-06-24 15:26:10 +02:00
|
|
|
private MWTeam enemy() {
|
2020-05-27 17:52:55 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-08-30 21:37:10 +02:00
|
|
|
|
2020-05-27 17:52:55 +02:00
|
|
|
}
|