package me.yaruma.fightsystem.fight; import com.boydti.fawe.FaweAPI; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitWorld; 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.kit.KitManager; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.ItemBuilder; import org.bukkit.Bukkit; import org.bukkit.Location; 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 final String name; private final String prefix; private Schematic schematic; private final Location spawn; private final Vector paste; private final boolean rotate; public FightTeam(String Name, String Prefix, Location Spawn, Vector Paste, boolean Rotate) { players = new ArrayList<>(); invited = new ArrayList<>(); spawn = Spawn; paste = Paste; name = Name; prefix = Prefix; ready = false; rotate = Rotate; } public void teleportToSpawn(){ for(FightPlayer player : players){ player.getPlayer().teleport(spawn); } } public FightPlayer getFightPlayer(Player player) { for(FightPlayer fightPlayer : players) { if(fightPlayer.getPlayer().equals(player)) return fightPlayer; } return null; } 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; leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); 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()).getUUID().toString() + "/" + schematic.getSchemName() + ".schematic"); com.boydti.fawe.object.schematic.Schematic schem; try { schem = FaweAPI.load(file); }catch(IOException e){ e.printStackTrace(); return; } World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = schem.getClipboard().getDimensions(); Vector v; Vector offset = new Vector(schem.getClipboard().getRegion().getMinimumPoint()).subtract(schem.getClipboard().getOrigin()); AffineTransform aT = new AffineTransform(); if(rotate){ aT = aT.rotateY(180); v = paste.add(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset.multiply(-1, 1, -1)); if(Config.SchemsizeX % 2 == 0){ v = v.add(-1, 0, 0); } if(Config.SchemsizeZ % 2 == 0){ v = v.add(0, 0, -1); } }else{ v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset); } schem.paste(w, v, false, true, aT).flushQueue(); teleportToSpawn(); } 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; } }