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.SchematicType; 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 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; 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; import java.util.List; 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); if(fightPlayer.isLeader()) this.leader = null; } 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 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); }else{ v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - 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; } public void sendPlayerSchematicList(boolean publicSchematics, int currentPage, int filesPerPage, Player player, SchematicType schematicType) { List preSchematicList; List schematicList = new ArrayList<>(); if(publicSchematics) { preSchematicList = Schematic.getSchemsOfType(0, schematicType); } else { preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); } 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())); schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schem " + schematic.getSchemName())); 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())); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist 1")); 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())); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage - 1))); 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())); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage - 1))); TextComponent nextPage = new TextComponent(">>"); nextPage.setColor(ChatColor.RED); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create())); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist " + (currPage + 1))); beforePage.addExtra(nextPage); player.spigot().sendMessage(beforePage); } } }