SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/src/me/yaruma/fightsystem/fight/FightTeam.java

292 Zeilen
10 KiB
Java

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.SchematicType;
2019-04-05 19:32:59 +02:00
import de.warking.hunjy.MySQL.WarkingUser;
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;
import me.yaruma.fightsystem.utils.ItemBuilder;
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;
2019-04-05 19:32:59 +02:00
import org.bukkit.Bukkit;
2019-04-12 12:57:49 +02:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
2019-04-05 19:32:59 +02:00
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<FightPlayer> players;
private boolean ready;
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-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-04-13 16:30:25 +02:00
public void teleportToSpawn(){
for(FightPlayer player : players){
player.getPlayer().teleport(spawn);
}
}
public FightPlayer getFightPlayer(Player player) {
2019-02-23 16:07:31 +01:00
for(FightPlayer fightPlayer : players) {
if(fightPlayer.getPlayer().equals(player))
return fightPlayer;
}
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-23 16:07:31 +01:00
return true;
}
public boolean isPlayerInTeam(Player player) {
for(FightPlayer fightPlayer : this.players) {
2019-02-23 16:07:31 +01:00
if(fightPlayer.getPlayer().equals(player))
return true;
}
return false;
}
public boolean isPlayerLeader(Player player) {
2019-02-23 16:07:31 +01:00
return leader.getPlayer().equals(player);
}
public void broadcast(String message) {
2019-02-23 16:07:31 +01:00
for(FightPlayer fightPlayer : players) {
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);
}
public void removePlayer(Player player) {
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
2019-02-23 16:07:31 +01:00
players.remove(fightPlayer);
if(fightPlayer.isLeader())
this.leader = null;
}
public boolean hasTeamLeader() {
2019-04-05 19:32:59 +02:00
return leader != null;
}
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)){
this.players.add(leader);
2019-04-12 12:57:49 +02:00
}
}
public ArrayList<FightPlayer> getPlayers() {
return players;
}
2019-04-05 19:32:59 +02:00
public boolean isReady() {
return ready;
}
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();
Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), new Runnable() {
@Override
public void run() {
Bukkit.broadcastMessage("ADD WATER");
WinconditionTechKO.addWater();
}
}, 20*10L);
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-05 19:32:59 +02:00
public boolean hasSchematic(){
return schematic != null;
}
public void setReady(boolean ready) {
2019-04-05 19:32:59 +02:00
Player leader = getLeader().getPlayer();
2019-04-05 19:32:59 +02:00
if(schematic == null){
leader.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!");
return;
}
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());
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!");
2019-04-05 19:32:59 +02:00
if(Fight.getOpposite(this).isReady()) {
FightSystem.getPlugin().setPreRunningState();
}
} 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!");
}
}
public ArrayList<Player> getInvited() {
return invited;
}
public String getName() {
2019-04-05 19:32:59 +02:00
return prefix + name;
}
public String getPrefix() {
return prefix;
}
public void sendPlayerSchematicList(boolean publicSchematics, int currentPage, int filesPerPage, Player player, SchematicType schematicType) {
List<Schematic> preSchematicList;
List<Schematic> schematicList = new ArrayList<>();
if(publicSchematics) {
2019-04-13 23:41:51 +02:00
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.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() + (publicSchematics ? " public" : " private")));
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);
}
}
}