From 59418b80013d71ff76c6217e4b7331d46e365f0e Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 13 Apr 2019 17:39:07 +0200 Subject: [PATCH] added TechKO wincondition; reworked player quit and join; send team leader schematic list; Signed-off-by: Yaruma3341 --- src/config.yml | 1 + .../yaruma/fightsystem/fight/FightTeam.java | 85 +++++++++++++++++++ .../fightsystem/fight/WaterRemover.java | 2 + .../listener/PlayerJoinListener.java | 2 + .../listener/PlayerQuitListener.java | 36 +++++++- src/me/yaruma/fightsystem/utils/Config.java | 2 + .../yaruma/fightsystem/utils/WorldEdit.java | 75 ---------------- .../winconditions/WinconditionAllDead.java | 5 ++ .../WinconditionCaptainDead.java | 5 ++ .../winconditions/WinconditionTechKO.java | 52 ++++++++++++ 10 files changed, 188 insertions(+), 77 deletions(-) create mode 100644 src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java diff --git a/src/config.yml b/src/config.yml index fa5010c..ec01552 100644 --- a/src/config.yml +++ b/src/config.yml @@ -39,6 +39,7 @@ WinConditions: CaptainDead: boolean PercentSystem: boolean Entern: boolean + TechKO: boolean WinConditionParams: TimeoutTime: 0 EnterPhaseBegin: 0 diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index 7be2451..26e342c 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -6,11 +6,17 @@ 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; @@ -20,6 +26,7 @@ import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.List; public class FightTeam { @@ -94,6 +101,8 @@ public class FightTeam { public void removePlayer(Player player) { FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); players.remove(fightPlayer); + if(fightPlayer.isLeader()) + this.leader = null; } public boolean hasTeamLeader() { @@ -194,4 +203,80 @@ public class FightTeam { public String getPrefix() { return prefix; } + + + public void sendPlayerSchematicList(int currentPage, int filesPerPage, Player player, SchematicType schematicType) { + List preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); + List schematicList = new ArrayList<>(); + 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, "/schem info " + 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, "/schem list 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, "/schem list " + (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, "/schem list " + (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, "/schem list " + (currPage + 1))); + + beforePage.addExtra(nextPage); + player.spigot().sendMessage(beforePage); + } + } } diff --git a/src/me/yaruma/fightsystem/fight/WaterRemover.java b/src/me/yaruma/fightsystem/fight/WaterRemover.java index 06aef9d..37e59f9 100644 --- a/src/me/yaruma/fightsystem/fight/WaterRemover.java +++ b/src/me/yaruma/fightsystem/fight/WaterRemover.java @@ -1,6 +1,7 @@ package me.yaruma.fightsystem.fight; import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.winconditions.WinconditionTechKO; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -69,6 +70,7 @@ public class WaterRemover { Bukkit.getScheduler().runTask((Plugin)FightSystem.getPlugin(), () -> { for (Block block : blocksToRemove) { block.setType(Material.AIR); + WinconditionTechKO.removeWater(block.getLocation()); } }); } diff --git a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java index e9b98ba..ad4cccc 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java @@ -34,9 +34,11 @@ public class PlayerJoinListener implements Listener { if (Fight.getPlayerTeam(player) == null) { if(!Fight.getRedTeam().hasTeamLeader()) { Fight.getRedTeam().setLeader(new FightPlayer(player, false)); + Fight.getRedTeam().sendPlayerSchematicList(0, 15, player, Config.SchematicType); player.setGameMode(GameMode.ADVENTURE); } else if(!Fight.getBlueTeam().hasTeamLeader()) { Fight.getBlueTeam().setLeader(new FightPlayer(player, false)); + Fight.getBlueTeam().sendPlayerSchematicList(0, 15, player, Config.SchematicType); player.setGameMode(GameMode.ADVENTURE); } else { player.setGameMode(GameMode.SPECTATOR); diff --git a/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java b/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java index acfcba2..557a9be 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java @@ -2,8 +2,10 @@ package me.yaruma.fightsystem.listener; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.fight.Fight; +import me.yaruma.fightsystem.fight.FightPlayer; import me.yaruma.fightsystem.fight.FightState; import me.yaruma.fightsystem.fight.FightTeam; +import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline; import org.bukkit.Bukkit; @@ -21,8 +23,38 @@ public class PlayerQuitListener implements Listener { Player player = event.getPlayer(); if(Fight.getPlayerTeam(player) == null) return; FightTeam fightTeam = Fight.getPlayerTeam(player); - fightTeam.getFightPlayer(player).setOut(true); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §chat den Kampf verlassen!"); + + FightState fightState = FightSystem.getPlugin().getFightState(); + if(!fightTeam.getFightPlayer(player).isLeader()) { + if(fightState == FightState.PRE_RUNNING + || fightState == FightState.RUNNING) { + fightTeam.getFightPlayer(player).setOut(true); + } else if(fightState == FightState.SETUP) { + fightTeam.removePlayer(player); + } + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §chat den Kampf verlassen!"); + } else { + if(fightState == FightState.SETUP) { + fightTeam.removePlayer(player); + if(!fightTeam.getPlayers().isEmpty()) { + fightTeam.setLeader(fightTeam.getPlayers().get(0)); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightTeam.getPlayers().get(0).getPlayer().getDisplayName() + " §aist nun Leader von Team " + fightTeam.getName() == Fight.getRedTeam().getName() ? + Config.TeamRedPrefix + Config.TeamRedName : Config.TeamBluePrefix + Config.TeamBlueName + "§a!"); + } else { + for(Player players : Bukkit.getServer().getOnlinePlayers()) { + if(Fight.getPlayerTeam(players) != null) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Es gibt keine Spieler mehr die den Leader ersetzen können! \n Server stoppt..."); + Bukkit.shutdown(); + } else { + FightPlayer fightPlayer = new FightPlayer(players, false); + fightTeam.setLeader(fightPlayer); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + players.getDisplayName() + " §aist nun Leader von Team " + fightTeam.getName() == Fight.getRedTeam().getName() ? + Config.TeamRedPrefix + Config.TeamRedName : Config.TeamBluePrefix + Config.TeamBlueName + "§a!"); + } + } + } + } + } if(fightTeam.allPlayersOut() && FightSystem.getPlugin().getFightState() == FightState.SETUP) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team " + fightTeam.getName() + " §chaben den Kampf verlassen!"); diff --git a/src/me/yaruma/fightsystem/utils/Config.java b/src/me/yaruma/fightsystem/utils/Config.java index 84b67a2..5dbd0bd 100644 --- a/src/me/yaruma/fightsystem/utils/Config.java +++ b/src/me/yaruma/fightsystem/utils/Config.java @@ -49,6 +49,7 @@ public class Config { public static boolean CaptainDead; public static boolean PercentSystem; public static boolean Entern; + public static boolean TechKO; public static int TimeoutTime; public static int EnterPhaseBegin; @@ -127,6 +128,7 @@ public class Config { CaptainDead = config.getBoolean("WinConditions.CaptainDead"); PercentSystem = config.getBoolean("WinConditions.PercentSystem"); Entern = config.getBoolean("WinConditions.Entern"); + TechKO = config.getBoolean("WinConditions.TechKO"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin"); diff --git a/src/me/yaruma/fightsystem/utils/WorldEdit.java b/src/me/yaruma/fightsystem/utils/WorldEdit.java index 693e402..f3c8ae5 100644 --- a/src/me/yaruma/fightsystem/utils/WorldEdit.java +++ b/src/me/yaruma/fightsystem/utils/WorldEdit.java @@ -106,80 +106,5 @@ public class WorldEdit { } } - public static void sendPlayerSchematicList(int currentPage, int filesPerPage, Player player, SchematicType schematicType) { - List preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); - List schematicList = new ArrayList<>(); - 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, "/schem info " + 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, "/schem list 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, "/schem list " + (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, "/schem list " + (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, "/schem list " + (currPage + 1))); - - beforePage.addExtra(nextPage); - player.spigot().sendMessage(beforePage); - } - } - } diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionAllDead.java b/src/me/yaruma/fightsystem/winconditions/WinconditionAllDead.java index c78d5a2..c6c4cbe 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionAllDead.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionAllDead.java @@ -2,6 +2,7 @@ package me.yaruma.fightsystem.winconditions; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.fight.Fight; +import me.yaruma.fightsystem.fight.FightState; import me.yaruma.fightsystem.fight.FightTeam; import me.yaruma.fightsystem.utils.Config; import org.bukkit.Bukkit; @@ -18,9 +19,11 @@ public class WinconditionAllDead implements Listener { @EventHandler public void handlePlayerDeath(PlayerDeathEvent event) { if(!Config.AllDead) return; + if(instance.getFightState() != FightState.PRE_RUNNING && instance.getFightState() != FightState.RUNNING) return; Player player = event.getEntity().getPlayer(); if(Fight.getPlayerTeam(player) == null) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + fightTeam.getFightPlayer(player).setOut(true); if(fightTeam.allPlayersOut()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getPrefix() + fightTeam.getName() + " §cist gestorben!"); @@ -31,9 +34,11 @@ public class WinconditionAllDead implements Listener { @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { if(!Config.AllDead) return; + if(instance.getFightState() != FightState.PRE_RUNNING && instance.getFightState() != FightState.RUNNING) return; Player player = event.getPlayer(); if(Fight.getPlayerTeam(player) == null) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + fightTeam.getFightPlayer(player).setOut(true); if(fightTeam.allPlayersOut()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus §6" + fightTeam.getPrefix() + fightTeam.getName() + " §chat den Kampf verlassen!"); diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionCaptainDead.java b/src/me/yaruma/fightsystem/winconditions/WinconditionCaptainDead.java index 0084921..b216d37 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionCaptainDead.java @@ -2,6 +2,7 @@ package me.yaruma.fightsystem.winconditions; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.fight.Fight; +import me.yaruma.fightsystem.fight.FightState; import me.yaruma.fightsystem.fight.FightTeam; import me.yaruma.fightsystem.utils.Config; import org.bukkit.Bukkit; @@ -18,9 +19,11 @@ public class WinconditionCaptainDead implements Listener { @EventHandler public void handlePlayerDeath(PlayerDeathEvent event) { if(!Config.CaptainDead) return; + if(instance.getFightState() != FightState.PRE_RUNNING && instance.getFightState() != FightState.RUNNING) return; Player player = event.getEntity().getPlayer(); if(Fight.getPlayerTeam(player) == null) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + fightTeam.getFightPlayer(player).setOut(true); if(fightTeam.isPlayerLeader(player)) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getName() + " §cist gestorben!"); @@ -32,9 +35,11 @@ public class WinconditionCaptainDead implements Listener { @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { if(!Config.CaptainDead) return; + if(instance.getFightState() != FightState.PRE_RUNNING && instance.getFightState() != FightState.RUNNING) return; Player player = event.getPlayer(); if(Fight.getPlayerTeam(player) == null) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + fightTeam.getFightPlayer(player).setOut(true); if(fightTeam.isPlayerLeader(player)) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getName() + " §chat den Kampf verlassen!"); diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java new file mode 100644 index 0000000..8fa8249 --- /dev/null +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java @@ -0,0 +1,52 @@ +package me.yaruma.fightsystem.winconditions; + +import me.yaruma.fightsystem.utils.Config; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; + +import java.util.HashSet; + +public class WinconditionTechKO { + + public static HashSet teamRedWater = new HashSet<>(); + public static HashSet teamBlueWater = new HashSet<>(); + + public static void addWater() { + + //Team Red + for(int x = Config.TeamRedCornerX; x <= (x + Config.SchemsizeX); x++) { + for(int y = Config.TeamRedCornerY; y <= (y + Config.SchemsizeY); y++) { + for(int z = Config.TeamRedCornerZ; z <= (y + Config.SchemsizeZ); z++) { + Location location = new Location(Bukkit.getWorlds().get(0), x, y, z); + if(location.getBlock().getType() == Material.WATER + || location.getBlock().getType() == Material.STATIONARY_WATER) + teamRedWater.add(location); + } + } + } + + //Team Blue + for(int x = Config.TeamBlueCornerX; x <= (x + Config.SchemsizeX); x++) { + for(int y = Config.TeamBlueCornerY; y <= (y + Config.SchemsizeY); y++) { + for(int z = Config.TeamBlueCornerZ; z <= (y + Config.SchemsizeZ); z++) { + Location location = new Location(Bukkit.getWorlds().get(0), x, y, z); + if(location.getBlock().getType() == Material.WATER + || location.getBlock().getType() == Material.STATIONARY_WATER) + teamBlueWater.add(location); + } + } + } + } + + public static void removeWater(Location location) { + if(!Config.TechKO) + return; + + if(teamRedWater.contains(location)) + teamRedWater.remove(location); + if(teamBlueWater.contains(location)) + teamBlueWater.remove(location); + } + +}