2019-02-14 18:37:38 +01:00
|
|
|
package me.yaruma.fightsystem.fight;
|
|
|
|
|
|
|
|
import me.yaruma.fightsystem.FightSystem;
|
2019-02-16 00:43:08 +01:00
|
|
|
import me.yaruma.fightsystem.utils.ItemBuilder;
|
|
|
|
import me.yaruma.fightsystem.utils.WorldEdit;
|
|
|
|
import me.yaruma.fightsystem.utils.countdown.Countdown;
|
|
|
|
import me.yaruma.fightsystem.utils.countdown.FinishPreRunning;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2019-02-14 18:37:38 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class FightTeam {
|
|
|
|
|
|
|
|
private FightPlayer leader;
|
|
|
|
private ArrayList<FightPlayer> players;
|
|
|
|
private FightSystem plugin;
|
|
|
|
private boolean ready;
|
|
|
|
private ArrayList<Player> invited;
|
2019-02-23 13:17:44 +01:00
|
|
|
private String name;
|
|
|
|
private String prefix;
|
2019-02-14 18:37:38 +01:00
|
|
|
|
|
|
|
public FightTeam(Player leader, FightSystem plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
this.leader = new FightPlayer(leader, false);
|
2019-02-23 16:07:31 +01:00
|
|
|
players = new ArrayList<>();
|
|
|
|
invited = new ArrayList<>();
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public FightPlayer getFightPlayer(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
if(leader.getPlayer().equals(player))
|
|
|
|
return leader;
|
|
|
|
for(FightPlayer fightPlayer : players) {
|
|
|
|
if(fightPlayer.getPlayer().equals(player))
|
|
|
|
return fightPlayer;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPlayerOut(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
getFightPlayer(player).setOut(true);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean allPlayersOut() {
|
|
|
|
if(!this.leader.isOut()) {
|
2019-02-23 16:07:31 +01:00
|
|
|
return false;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
for(FightPlayer fightPlayer : this.players) {
|
2019-02-23 16:07:31 +01:00
|
|
|
if(!fightPlayer.isOut())
|
|
|
|
return false;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
2019-02-23 16:07:31 +01:00
|
|
|
return true;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPlayerInTeam(Player player) {
|
2019-02-23 13:33:50 +01:00
|
|
|
for(FightPlayer fightPlayer : this.players) {
|
2019-02-23 16:07:31 +01:00
|
|
|
if(fightPlayer.getPlayer().equals(player))
|
|
|
|
return true;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
2019-02-23 16:07:31 +01:00
|
|
|
return leader.getPlayer() != null && leader.getPlayer().equals(player);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPlayerLeader(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
return leader.getPlayer().equals(player);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPlayerMember(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
return isPlayerInTeam(player) && !isPlayerLeader(player);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void broadcast(String message) {
|
2019-02-23 16:07:31 +01:00
|
|
|
leader.sendMessage(message);
|
|
|
|
for(FightPlayer fightPlayer : players) {
|
2019-02-14 18:37:38 +01:00
|
|
|
fightPlayer.sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addMember(Player player) {
|
|
|
|
FightPlayer fightPlayer = new FightPlayer(player, false);
|
2019-02-23 16:07:31 +01:00
|
|
|
players.add(fightPlayer);
|
|
|
|
invited.remove(player);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removePlayer(Player player) {
|
|
|
|
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
|
2019-02-23 16:07:31 +01:00
|
|
|
players.remove(fightPlayer);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasTeamLeader() {
|
2019-02-23 16:07:31 +01:00
|
|
|
return leader.getPlayer() != null;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public FightPlayer getLeader() {
|
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLeader(FightPlayer leader) {
|
|
|
|
this.leader = leader;
|
2019-02-23 20:56:20 +01:00
|
|
|
if(!this.players.contains(leader)) this.players.add(leader);
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<FightPlayer> getPlayers() {
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FightSystem getPlugin() {
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPlugin(FightSystem plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isReady() {
|
|
|
|
return ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setReady(boolean ready) {
|
|
|
|
this.ready = ready;
|
2019-02-16 00:43:08 +01:00
|
|
|
|
|
|
|
FightTeam fightTeam = Fight.getPlayerTeam(this.leader.getPlayer());
|
|
|
|
|
2019-02-19 21:32:04 +01:00
|
|
|
FightSystem instance = FightSystem.getPlugin();
|
|
|
|
|
2019-02-16 00:43:08 +01:00
|
|
|
if(this.ready == true) {
|
|
|
|
|
|
|
|
fightTeam.getLeader().getPlayer().getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 8).removeAllAtributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build());
|
|
|
|
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!");
|
|
|
|
if(Fight.getOpposite(fightTeam).isReady()) {
|
2019-02-19 21:32:04 +01:00
|
|
|
instance.setPreRunningState();
|
2019-02-16 00:43:08 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fightTeam.getLeader().getPlayer().getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());
|
|
|
|
fightTeam.broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!");
|
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<Player> getInvited() {
|
|
|
|
return invited;
|
|
|
|
}
|
|
|
|
|
2019-02-23 13:17:44 +01:00
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix() {
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefix(String prefix) {
|
|
|
|
this.prefix = prefix;
|
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|