2019-02-14 18:37:38 +01:00
|
|
|
package me.yaruma.fightsystem.fight;
|
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
import com.boydti.fawe.FaweAPI;
|
|
|
|
import com.sk89q.worldedit.Vector;
|
2019-04-12 12:57:49 +02:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
2019-04-05 19:32:59 +02:00
|
|
|
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;
|
2019-02-14 18:37:38 +01:00
|
|
|
import me.yaruma.fightsystem.FightSystem;
|
2019-04-13 16:30:25 +02:00
|
|
|
import me.yaruma.fightsystem.kit.KitManager;
|
2019-04-05 19:32:59 +02:00
|
|
|
import me.yaruma.fightsystem.utils.Config;
|
2019-02-16 00:43:08 +01:00
|
|
|
import me.yaruma.fightsystem.utils.ItemBuilder;
|
2019-04-05 19:32:59 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2019-04-12 12:57:49 +02:00
|
|
|
import org.bukkit.Location;
|
2019-02-16 00:43:08 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2019-02-14 18:37:38 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2019-02-14 18:37:38 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class FightTeam {
|
|
|
|
|
|
|
|
private FightPlayer leader;
|
2019-03-26 12:33:33 +01:00
|
|
|
private final ArrayList<FightPlayer> players;
|
2019-02-14 18:37:38 +01:00
|
|
|
private boolean ready;
|
2019-03-26 12:33:33 +01:00
|
|
|
private final ArrayList<Player> invited;
|
2019-04-12 12:57:49 +02:00
|
|
|
private final String name;
|
|
|
|
private final String prefix;
|
2019-04-05 19:32:59 +02:00
|
|
|
private Schematic schematic;
|
2019-04-12 12:57:49 +02:00
|
|
|
private final Location spawn;
|
|
|
|
private final Vector paste;
|
|
|
|
private final boolean rotate;
|
2019-02-14 18:37:38 +01:00
|
|
|
|
2019-04-12 12:57:49 +02:00
|
|
|
public FightTeam(String Name, String Prefix, Location Spawn, Vector Paste, boolean Rotate) {
|
2019-02-23 16:07:31 +01:00
|
|
|
players = new ArrayList<>();
|
|
|
|
invited = new ArrayList<>();
|
2019-04-12 12:57:49 +02:00
|
|
|
spawn = Spawn;
|
|
|
|
paste = Paste;
|
2019-04-05 19:32:59 +02:00
|
|
|
name = Name;
|
|
|
|
prefix = Prefix;
|
2019-04-05 20:13:42 +02:00
|
|
|
ready = false;
|
2019-04-12 12:57:49 +02:00
|
|
|
rotate = Rotate;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 16:30:25 +02:00
|
|
|
public void teleportToSpawn(){
|
|
|
|
for(FightPlayer player : players){
|
|
|
|
player.getPlayer().teleport(spawn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 18:37:38 +01:00
|
|
|
public FightPlayer getFightPlayer(Player player) {
|
2019-02-23 16:07:31 +01:00
|
|
|
for(FightPlayer fightPlayer : players) {
|
|
|
|
if(fightPlayer.getPlayer().equals(player))
|
|
|
|
return fightPlayer;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean allPlayersOut() {
|
|
|
|
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 21:07:47 +01:00
|
|
|
return false;
|
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 void broadcast(String message) {
|
2019-02-23 16:07:31 +01:00
|
|
|
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-04-05 19:32:59 +02:00
|
|
|
return leader != null;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public FightPlayer getLeader() {
|
|
|
|
return leader;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLeader(FightPlayer leader) {
|
|
|
|
this.leader = leader;
|
2019-04-13 16:30:25 +02:00
|
|
|
leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
|
2019-04-12 12:57:49 +02:00
|
|
|
if(!this.players.contains(leader)){
|
2019-02-23 21:07:47 +01:00
|
|
|
this.players.add(leader);
|
2019-04-12 12:57:49 +02:00
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<FightPlayer> getPlayers() {
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
public boolean isReady() {
|
|
|
|
return ready;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
private void pasteSchematic(){
|
2019-04-12 12:57:49 +02:00
|
|
|
File file = new File(Config.SchematicDirectory + WarkingUser.get(schematic.getSchemOwner()).getUUID().toString() + "/" + schematic.getSchemName() + ".schematic");
|
2019-04-05 19:32:59 +02:00
|
|
|
com.boydti.fawe.object.schematic.Schematic schem;
|
|
|
|
try {
|
|
|
|
schem = FaweAPI.load(file);
|
|
|
|
}catch(IOException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
2019-04-12 12:57:49 +02:00
|
|
|
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
|
|
|
Vector dimensions = schem.getClipboard().getDimensions();
|
2019-04-13 16:30:25 +02:00
|
|
|
Vector v;
|
|
|
|
Vector offset = new Vector(schem.getClipboard().getRegion().getMinimumPoint()).subtract(schem.getClipboard().getOrigin());
|
2019-04-05 19:32:59 +02:00
|
|
|
AffineTransform aT = new AffineTransform();
|
2019-04-12 12:57:49 +02:00
|
|
|
if(rotate){
|
2019-04-13 16:30:25 +02:00
|
|
|
aT = aT.rotateY(180);
|
|
|
|
v = paste.add(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset.multiply(-1, 1, -1));
|
|
|
|
}else{
|
|
|
|
v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset);
|
2019-04-12 12:57:49 +02:00
|
|
|
}
|
2019-04-05 19:32:59 +02:00
|
|
|
schem.paste(w, v, false, true, aT).flushQueue();
|
2019-04-13 16:30:25 +02:00
|
|
|
teleportToSpawn();
|
2019-04-05 19:32:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSchematic(Schematic schematic){
|
|
|
|
this.schematic = schematic;
|
|
|
|
if(Fight.getOpposite(this).hasSchematic()){
|
|
|
|
pasteSchematic();
|
|
|
|
Fight.getOpposite(this).pasteSchematic();
|
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
public boolean hasSchematic(){
|
|
|
|
return schematic != null;
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setReady(boolean ready) {
|
2019-04-05 19:32:59 +02:00
|
|
|
Player leader = getLeader().getPlayer();
|
2019-02-16 00:43:08 +01:00
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
if(schematic == null){
|
|
|
|
leader.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
|
|
|
|
return;
|
|
|
|
}
|
2019-02-16 00:43:08 +01:00
|
|
|
|
2019-04-05 19:32:59 +02:00
|
|
|
this.ready = ready;
|
|
|
|
if(ready) {
|
|
|
|
leader.getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 8).removeAllAtributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName("§aBereit").build());
|
2019-02-16 00:43:08 +01:00
|
|
|
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!");
|
2019-04-05 19:32:59 +02:00
|
|
|
if(Fight.getOpposite(this).isReady()) {
|
|
|
|
FightSystem.getPlugin().setPreRunningState();
|
2019-02-16 00:43:08 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-05 19:32:59 +02:00
|
|
|
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!");
|
2019-02-16 00:43:08 +01:00
|
|
|
}
|
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() {
|
2019-04-05 19:32:59 +02:00
|
|
|
return prefix + name;
|
2019-02-23 13:17:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix() {
|
|
|
|
return prefix;
|
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|