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 javafx.util.Pair; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.kit.KitManager; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.ItemBuilder; import me.yaruma.fightsystem.utils.TechHider; import me.yaruma.fightsystem.winconditions.WinconditionTechKO; 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.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class FightTeam { private FightPlayer leader; private final List players = new ArrayList<>(); private boolean ready; private final List invited = new ArrayList<>(); 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) { 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 : players) { if(!fightPlayer.isOut()) return false; } return true; } public boolean isPlayerInTeam(Player player) { for(FightPlayer fightPlayer : players) { if(fightPlayer.getPlayer().equals(player)) return true; } return false; } public boolean isPlayerLeader(Player player) { if(leader != null) return leader.getPlayer().equals(player); else return false; } public void broadcast(String message) { for(FightPlayer fightPlayer : players) { fightPlayer.sendMessage(message); } } public FightPlayer addMember(Player player) { final List> chunksToReload = TechHider.prepareChunkReload(player); FightPlayer fightPlayer = new FightPlayer(player, false); players.add(fightPlayer); invited.remove(player); player.setGameMode(GameMode.ADVENTURE); player.teleport(spawn); player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } public void removePlayer(Player player) { FightPlayer fightPlayer = getFightPlayer(player); if(fightPlayer == null) return; final List> chunksToReload = TechHider.prepareChunkReload(player); players.remove(fightPlayer); fightPlayer.getPlayer().getInventory().clear(); if(fightPlayer.equals(leader) && FightSystem.getFightState() == FightState.SETUP){ this.leader = null; if(!players.isEmpty()) { setLeader(players.get(0)); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + leader.getPlayer().getName() + " §aist nun Leader von Team " + getName() + "§a!"); }else{ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + getName() + " §chat keine Spieler mehr.\n Arena schließt..."); Bukkit.shutdown(); } } player.setGameMode(GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); TechHider.reloadChunks(player, chunksToReload); } 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)); Inventory inventory = leader.getPlayer().getInventory(); inventory.setItem(0, new ItemBuilder(Material.PAPER).removeAllAtributs().setDisplayName("§eSpieler einladen").build()); inventory.setItem(2, new ItemBuilder(Material.FIREWORK_CHARGE).removeAllAtributs().setDisplayName("§cSpieler rauswerfen").build()); inventory.setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); inventory.setItem(5, new ItemBuilder(Material.INK_SACK, (short) 1).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§4Abbrechen").build()); inventory.setItem(7, new ItemBuilder(Material.CAULDRON_ITEM).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); } public List 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; broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); leader.getPlayer().getInventory().clear(7); if(Fight.getOpposite(this).hasSchematic()){ pasteSchematic(); Fight.getOpposite(this).pasteSchematic(); Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), WinconditionTechKO::addWater, 20*10L); } } 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 List getInvited() { return invited; } public String getName() { return prefix + name; } public String getPrefix() { return prefix; } public Location getSpawn() { return spawn; } public void sendPlayerSchematicList(boolean publicSchematics, int currentPage, int filesPerPage, Player player, SchematicType schematicType) { List preSchematicList; List schematicList = new ArrayList<>(); if(publicSchematics) { preSchematicList = Schematic.getSchemsAccessibleByUser(0); } 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) schematicList.size() / (double) filesPerPage; int intPages = schematicList.size() / filesPerPage; if(schematicList.size() <= filesPerPage) { pages = 1; } else if(doublePages > intPages) { pages = (intPages + 1); } else pages = intPages; if(currentPage >= pages) return; player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======"); for(int i = currentPage * filesPerPage; i < (currentPage * 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() + (publicSchematics ? " public" : " private"))); player.spigot().sendMessage(schematics); } if(pages <= 1) return; if(currentPage == 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((currentPage + 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 " + (currentPage - 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 " + (currentPage - 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 " + (currentPage + 1))); beforePage.addExtra(nextPage); player.spigot().sendMessage(beforePage); } } }