SteamWar/MissileWars
Archiviert
13
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
MissileWars/src/de/steamwar/misslewars/MWTeam.java

90 Zeilen
2.2 KiB
Java

2020-05-22 16:36:52 +02:00
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;
}
}