SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/src/me/yaruma/fightsystem/fight/FightTeam.java

172 Zeilen
5.6 KiB
Java

package me.yaruma.fightsystem.fight;
import me.yaruma.fightsystem.FightSystem;
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;
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;
public FightTeam(Player leader, FightSystem plugin) {
this.plugin = plugin;
this.leader = new FightPlayer(leader, false);
this.players = new ArrayList<>();
this.invited = new ArrayList<>();
}
public FightPlayer getFightPlayer(Player player) {
if(this.leader.getPlayer().equals(player)) {
return this.leader;
}
for(FightPlayer fightPlayer : this.players) {
if(!fightPlayer.getPlayer().equals(player)) continue;
return fightPlayer;
}
return null;
}
public void setPlayerOut(Player player) {
this.getFightPlayer(player).setOut(true);
}
public boolean allPlayersOut() {
boolean allout = true;
if(!this.leader.isOut()) {
allout = false;
}
for(FightPlayer fightPlayer : this.players) {
if(fightPlayer.isOut()) continue;
allout = false;
}
return allout;
}
public boolean isPlayerInTeam(Player player) {
if(this.leader.getPlayer().equals(player)) {
return true;
}
for(FightPlayer fightPlayer : this.players) {
if(!fightPlayer.getPlayer().equals(player)) continue;
return true;
}
return false;
}
public boolean isPlayerLeader(Player player) {
if(this.leader.getPlayer().equals(player)) {
return true;
}
return false;
}
public boolean isPlayerMember(Player player) {
for(FightPlayer fightPlayer : this.players) {
if(!fightPlayer.getPlayer().equals(player)) continue;
return true;
}
return false;
}
public void broadcast(String message) {
this.leader.sendMessage(message);
for(FightPlayer fightPlayer : this.players) {
fightPlayer.sendMessage(message);
}
}
public void addMember(Player player) {
FightPlayer fightPlayer = new FightPlayer(player, false);
this.players.add(fightPlayer);
this.invited.remove(player);
}
public void removePlayer(Player player) {
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
this.players.remove(fightPlayer);
}
public boolean hasTeamLeader() {
if(this.leader != null) {
return true;
} else
return false;
}
public FightPlayer getLeader() {
return leader;
}
public void setLeader(FightPlayer leader) {
this.leader = leader;
}
public ArrayList<FightPlayer> getPlayers() {
return players;
}
public void setPlayers(ArrayList<FightPlayer> players) {
this.players = 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;
FightTeam fightTeam = Fight.getPlayerTeam(this.leader.getPlayer());
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()) {
FightSystem.getPlugin().setPreRunningState();
int time = FightSystem.getPlugin().getFileManager().getIntegerFromConfig("Times.PreFightDuration");
Countdown countdown = new Countdown(time, new FinishPreRunning());
countdown.startTimer(FightSystem.getPlugin());
for(FightPlayer allFightPlayers : fightTeam.getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
for(FightPlayer allFightPlayers : Fight.getOpposite(fightTeam).getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
FightSystem.getPlugin().getFightManager().teleportAllToFightSpawn();
WorldEdit.replace(fightTeam.getLeader().getPlayer(), FightSystem.getPlugin().getTeam1cornerX(), FightSystem.getPlugin().getTeam1cornerY(), FightSystem.getPlugin().getTeam1cornerZ(), FightSystem.getPlugin().getSchemsizeX(), FightSystem.getPlugin().getSchemsizeY(), FightSystem.getPlugin().getSchemsizeZ());
}
} 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!");
}
}
public ArrayList<Player> getInvited() {
return invited;
}
public void setInvited(ArrayList<Player> invited) {
this.invited = invited;
}
}