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;
|
2019-04-13 17:39:07 +02:00
|
|
|
import de.warking.hunjy.MySQL.SchematicType;
|
2019-04-05 19:32:59 +02:00
|
|
|
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-14 01:07:38 +02:00
|
|
|
import me.yaruma.fightsystem.winconditions.WinconditionTechKO;
|
2019-04-13 17:39:07 +02:00
|
|
|
import net.md_5.bungee.api.ChatColor;
|
|
|
|
import net.md_5.bungee.api.chat.ClickEvent;
|
|
|
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
|
|
import net.md_5.bungee.api.chat.HoverEvent;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
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;
|
2019-04-13 17:39:07 +02:00
|
|
|
import java.util.List;
|
2019-02-14 18:37:38 +01:00
|
|
|
|
|
|
|
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) {
|
2019-04-14 15:07:40 +02:00
|
|
|
FightPlayer fightPlayer = getFightPlayer(player);
|
|
|
|
if(fightPlayer == null){
|
|
|
|
System.out.println("FightPlayer == null! : " + player.getName());
|
|
|
|
return;
|
|
|
|
}
|
2019-02-23 16:07:31 +01:00
|
|
|
players.remove(fightPlayer);
|
2019-04-13 17:39:07 +02:00
|
|
|
if(fightPlayer.isLeader())
|
|
|
|
this.leader = null;
|
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);
|
2019-04-13 22:04:08 +02:00
|
|
|
v = paste.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1);
|
2019-04-13 16:30:25 +02:00
|
|
|
}else{
|
2019-04-13 22:04:08 +02:00
|
|
|
v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - 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-04-14 15:07:40 +02:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> WinconditionTechKO.addWater(), 20*10L);
|
2019-04-05 19:32:59 +02:00
|
|
|
}
|
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-04-13 17:39:07 +02:00
|
|
|
|
|
|
|
|
2019-04-13 22:01:56 +02:00
|
|
|
public void sendPlayerSchematicList(boolean publicSchematics, int currentPage, int filesPerPage, Player player, SchematicType schematicType) {
|
|
|
|
|
|
|
|
List<Schematic> preSchematicList;
|
2019-04-13 17:39:07 +02:00
|
|
|
List<Schematic> schematicList = new ArrayList<>();
|
2019-04-13 22:01:56 +02:00
|
|
|
if(publicSchematics) {
|
2019-04-13 23:41:51 +02:00
|
|
|
preSchematicList = Schematic.getSchemsAccessibleByUser(0);
|
2019-04-13 22:01:56 +02:00
|
|
|
} else {
|
|
|
|
preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId());
|
|
|
|
}
|
|
|
|
|
2019-04-13 17:39:07 +02:00
|
|
|
for(Schematic s : preSchematicList) {
|
|
|
|
if(s.getSchemType() == schematicType)
|
|
|
|
schematicList.add(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(schematicList.isEmpty()) {
|
|
|
|
player.sendMessage(FightSystem.PREFIX + "§cDu hast noch keine Schematic(s)!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pages;
|
|
|
|
|
|
|
|
double doublePages = (Double.valueOf(schematicList.size()) / Double.valueOf(filesPerPage));
|
|
|
|
int intPages = schematicList.size() / filesPerPage;
|
|
|
|
|
|
|
|
if(schematicList.size() <= filesPerPage) {
|
|
|
|
pages = 1;
|
|
|
|
} else if(doublePages > intPages) {
|
|
|
|
pages = (intPages + 1);
|
|
|
|
} else
|
|
|
|
pages = intPages;
|
|
|
|
|
|
|
|
int currPage = currentPage;
|
|
|
|
|
|
|
|
if(currPage >= pages) return;
|
|
|
|
|
|
|
|
player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======");
|
|
|
|
|
|
|
|
for(int i = currPage * filesPerPage; i < (currPage * filesPerPage) + filesPerPage; i++) {
|
|
|
|
if(schematicList.size() <= i) break;
|
|
|
|
|
|
|
|
Schematic schematic = schematicList.get(i);
|
|
|
|
|
|
|
|
TextComponent schematics = new TextComponent("§b" + schematic.getSchemName());
|
|
|
|
schematics.setBold(true);
|
|
|
|
|
|
|
|
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic benutzen...").create()));
|
2019-04-15 18:30:39 +02:00
|
|
|
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schem " + schematic.getSchemName() + (publicSchematics ? " public" : " private")));
|
2019-04-13 17:39:07 +02:00
|
|
|
|
|
|
|
player.spigot().sendMessage(schematics);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pages <= 1) return;
|
|
|
|
|
|
|
|
if(currPage == 0) {
|
|
|
|
TextComponent nextPage = new TextComponent("Nächste Seite >>");
|
|
|
|
nextPage.setColor(ChatColor.RED);
|
|
|
|
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
|
2019-04-13 18:00:23 +02:00
|
|
|
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist 1"));
|
2019-04-13 17:39:07 +02:00
|
|
|
player.spigot().sendMessage(nextPage);
|
|
|
|
} else if((currPage + 1) == pages) {
|
|
|
|
TextComponent beforePage = new TextComponent("<< Vorherige Seite");
|
|
|
|
beforePage.setColor(ChatColor.RED);
|
|
|
|
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
|
2019-04-13 18:00:23 +02:00
|
|
|
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage - 1)));
|
2019-04-13 17:39:07 +02:00
|
|
|
player.spigot().sendMessage(beforePage);
|
|
|
|
} else {
|
|
|
|
TextComponent beforePage = new TextComponent("<< Seite ");
|
|
|
|
beforePage.setColor(ChatColor.RED);
|
|
|
|
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create()));
|
2019-04-13 18:00:23 +02:00
|
|
|
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage - 1)));
|
2019-04-13 17:39:07 +02:00
|
|
|
|
|
|
|
TextComponent nextPage = new TextComponent(">>");
|
|
|
|
nextPage.setColor(ChatColor.RED);
|
|
|
|
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create()));
|
2019-04-13 18:00:23 +02:00
|
|
|
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage + 1)));
|
2019-04-13 17:39:07 +02:00
|
|
|
|
|
|
|
beforePage.addExtra(nextPage);
|
|
|
|
player.spigot().sendMessage(beforePage);
|
|
|
|
}
|
|
|
|
}
|
2019-02-14 18:37:38 +01:00
|
|
|
}
|