90 Zeilen
2.2 KiB
Java
90 Zeilen
2.2 KiB
Java
|
package de.steamwar.misslewars;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.bukkit.ChatColor;
|
||
|
import org.bukkit.Location;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.scoreboard.Team;
|
||
|
import org.bukkit.scoreboard.Team.Option;
|
||
|
import org.bukkit.scoreboard.Team.OptionStatus;
|
||
|
|
||
|
public class MWTeam {
|
||
|
private ChatColor color;
|
||
|
private String teamName;
|
||
|
private String prefix;
|
||
|
private Team sbteam; //scoreboard-Team
|
||
|
private ArrayList<MWPlayer> spieler = new ArrayList<MWPlayer>();
|
||
|
private Location spawn;
|
||
|
|
||
|
public List<MWPlayer> getPlayers(){
|
||
|
return spieler;
|
||
|
}
|
||
|
|
||
|
public MWTeam(ChatColor color, String teamName, String prefix) {
|
||
|
this.teamName = teamName;
|
||
|
this.prefix = prefix;
|
||
|
this.color = color;
|
||
|
if(FightScoreboard.getScoreboard().getTeam(teamName) == null)
|
||
|
sbteam = FightScoreboard.getScoreboard().registerNewTeam(teamName);
|
||
|
else
|
||
|
sbteam = FightScoreboard.getScoreboard().getTeam(teamName);
|
||
|
assert sbteam != null;
|
||
|
sbteam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
|
||
|
sbteam.setAllowFriendlyFire(false);
|
||
|
}
|
||
|
|
||
|
public void tpToSpawn(Player p) {
|
||
|
p.teleport(spawn);
|
||
|
}
|
||
|
|
||
|
public void join (Player p) {
|
||
|
spieler.add(new MWPlayer(p));
|
||
|
p.setDisplayName(color + "[" + teamName + "]" + p.getName());
|
||
|
if (MissleWars.getFightState() == FightState.WAITING) {
|
||
|
if (!enemy().getPlayers().isEmpty())
|
||
|
MissleWars.startRound();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void leave (Player p) {
|
||
|
for (MWPlayer pl : spieler) {
|
||
|
if (p == pl.getPlayer()) {
|
||
|
spieler.remove(pl);
|
||
|
break;
|
||
|
}
|
||
|
p.setDisplayName(p.getName());
|
||
|
}
|
||
|
if (spieler.isEmpty())
|
||
|
MissleWars.end(WinReasons.NOENEMY, enemy());
|
||
|
}
|
||
|
|
||
|
public MWTeam enemy() {
|
||
|
if (this == MissleWars.redTeam) return MissleWars.blueTeam;
|
||
|
return MissleWars.redTeam;
|
||
|
}
|
||
|
|
||
|
public String getPrefix(){
|
||
|
return prefix;
|
||
|
}
|
||
|
|
||
|
public boolean hasPlayer (Player p) {
|
||
|
for (MWPlayer pl : spieler)
|
||
|
if (p == pl.getPlayer())
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public MWPlayer getPlayer (Player p) {
|
||
|
for (MWPlayer pl : spieler)
|
||
|
if (p == pl.getPlayer())
|
||
|
return pl;
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public String getColoredName() {
|
||
|
return color.toString() + teamName;
|
||
|
}
|
||
|
}
|