From 5bfee9f3d9212a879a1df10b722af001e8b27d0c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 27 Dec 2019 12:32:15 +0100 Subject: [PATCH] Adding pumpkin tech ko Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 + FightSystem_Main/src/config.yml | 2 + .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/utils/FightScoreboard.java | 8 +-- .../WinconditionPumpkinTechKO.java | 70 +++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 980ead4..18ab1cd 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -86,6 +86,7 @@ public class Config { public static final boolean Entern; public static final boolean TechKO; public static final boolean WaterTechKO; + public static final boolean PumpkinTechKO; //win condition parameters public static final int TimeoutTime; @@ -165,6 +166,7 @@ public class Config { Entern = config.getBoolean("WinConditions.Entern"); TechKO = config.getBoolean("WinConditions.TechKO"); WaterTechKO = config.getBoolean("WinConditions.WaterTechKO"); + PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin"); diff --git a/FightSystem_Main/src/config.yml b/FightSystem_Main/src/config.yml index 96ddc4f..850f9e5 100644 --- a/FightSystem_Main/src/config.yml +++ b/FightSystem_Main/src/config.yml @@ -45,6 +45,8 @@ WinConditions: Points: boolean Entern: boolean TechKO: boolean + WaterTechKO: boolean + PumpkinTechKO: boolean WinConditionParams: TimeoutTime: 0 EnterPhaseBegin: 0 diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index ac55a25..3fca9c5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -112,6 +112,7 @@ public class FightSystem extends JavaPlugin { new WinconditionAllDead(); new WinconditionCaptainDead(); + new WinconditionPumpkinTechKO(); new WinconditionWaterTechKO(); new WinconditionPercentSystem(); new WinconditionRelativePercent(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index fc02511..6cbe38b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -5,10 +5,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightState; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.winconditions.WinconditionPercentSystem; -import de.steamwar.fightsystem.winconditions.WinconditionPoints; -import de.steamwar.fightsystem.winconditions.WinconditionRelativePercent; -import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO; +import de.steamwar.fightsystem.winconditions.*; import org.bukkit.Bukkit; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; @@ -86,6 +83,9 @@ public class FightScoreboard { }else if(Config.Points){ objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1); objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0); + }else if(Config.PumpkinTechKO){ + objective.getScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins()).setScore(1); + objective.getScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins()).setScore(0); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java new file mode 100644 index 0000000..100bb9b --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -0,0 +1,70 @@ +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; + +public class WinconditionPumpkinTechKO { + + private static int teamRedPumpkins = -1; + private static int teamBluePumpkins = -1; + private static final World WORLD = Bukkit.getWorlds().get(0); + private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); + + public WinconditionPumpkinTechKO(){ + if(!Config.PumpkinTechKO) + return; + + Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200); + } + + public static int getTeamBluePumpkins() { + return teamBluePumpkins; + } + public static int getTeamRedPumpkins() { + return teamRedPumpkins; + } + + private static void recursiveCheck(){ + teamRedPumpkins = getPumpkins(Config.TeamRedCornerX, + Config.TeamRedCornerY, + Config.TeamRedCornerZ, + Config.TeamRedCornerX + Config.SchemsizeX, + Config.TeamRedCornerY + Config.SchemsizeY, + Config.TeamRedCornerZ + Config.SchemsizeZ); + teamBluePumpkins = getPumpkins(Config.TeamBlueCornerX, + Config.TeamBlueCornerY, + Config.TeamBlueCornerZ, + Config.TeamBlueCornerX + Config.SchemsizeX, + Config.TeamBlueCornerY + Config.SchemsizeY, + Config.TeamBlueCornerZ + Config.SchemsizeZ); + + checkKO(Fight.getRedTeam(), teamRedPumpkins); + checkKO(Fight.getBlueTeam(), teamBluePumpkins); + } + + private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ + int pumpkins = 0; + for(int x = minX; x <= maxX; x++) { + for(int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + if (WORLD.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) + pumpkins++; + } + } + } + return pumpkins; + } + + private static void checkKO(FightTeam team, int pumpkins){ + if(pumpkins == 0){ + Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + } + } +}