package me.yaruma.fightsystem.fight; import com.boydti.fawe.FaweAPI; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.world.World; import de.warking.hunjy.MySQL.Schematic; import de.warking.hunjy.MySQL.WarkingUser; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.ItemBuilder; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.util.ArrayList; public class FightTeam { private FightPlayer leader; private final ArrayList players; private boolean ready; private final ArrayList invited; private String name; private String prefix; private Schematic schematic; public FightTeam(String Name, String Prefix) { players = new ArrayList<>(); invited = new ArrayList<>(); name = Name; prefix = Prefix; ready = false; } public FightPlayer getFightPlayer(Player player) { for(FightPlayer fightPlayer : players) { if(fightPlayer.getPlayer().equals(player)) return fightPlayer; } return null; } public void setPlayerOut(Player player) { getFightPlayer(player).setOut(true); } public boolean allPlayersOut() { for(FightPlayer fightPlayer : this.players) { if(!fightPlayer.isOut()) return false; } return true; } public boolean isPlayerInTeam(Player player) { for(FightPlayer fightPlayer : this.players) { if(fightPlayer.getPlayer().equals(player)) return true; } return false; } public boolean isPlayerLeader(Player player) { return leader.getPlayer().equals(player); } public void broadcast(String message) { for(FightPlayer fightPlayer : players) { fightPlayer.sendMessage(message); } } public void addMember(Player player) { FightPlayer fightPlayer = new FightPlayer(player, false); players.add(fightPlayer); invited.remove(player); } public void removePlayer(Player player) { FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); players.remove(fightPlayer); } public boolean hasTeamLeader() { return leader != null; } public FightPlayer getLeader() { return leader; } public void setLeader(FightPlayer leader) { this.leader = leader; if(!this.players.contains(leader)) this.players.add(leader); } public ArrayList getPlayers() { return players; } public boolean isReady() { return ready; } private void pasteSchematic(){ File file = new File(Config.SchematicDirectory + WarkingUser.get(schematic.getSchemOwner()) + "/" + schematic.getSchemName() + ".schematic"); com.boydti.fawe.object.schematic.Schematic schem; try { schem = FaweAPI.load(file); }catch(IOException e){ e.printStackTrace(); return; } AffineTransform aT = new AffineTransform(); World w = (World) Bukkit.getWorlds().get(0); Vector v = schem.getClipboard().getDimensions().divide(-2); if(this == Fight.getBlueTeam()) v = v.add(Config.TeamBluePasteX, Config.TeamBluePasteY, Config.TeamBluePasteZ); else v = v.add(Config.TeamRedPasteX, Config.TeamRedPasteY, Config.TeamRedPasteZ); schem.paste(w, v, false, true, aT).flushQueue(); } public void setSchematic(Schematic schematic){ this.schematic = schematic; if(Fight.getOpposite(this).hasSchematic()){ pasteSchematic(); Fight.getOpposite(this).pasteSchematic(); } } public boolean hasSchematic(){ return schematic != null; } public void setReady(boolean ready) { Player leader = getLeader().getPlayer(); if(schematic == null){ leader.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!"); return; } this.ready = ready; if(ready) { leader.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(this).isReady()) { FightSystem.getPlugin().setPreRunningState(); } } else { leader.getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit!"); } } public ArrayList getInvited() { return invited; } public String getName() { return prefix + name; } public String getPrefix() { return prefix; } }