From bf3baed537ea8396eba115fe1d8e95929ba61fea Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 30 Apr 2020 16:09:24 +0200 Subject: [PATCH] Implementing check capability into TestArenas Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 8 ++++ .../de/steamwar/fightsystem/FightSystem.java | 8 +++- .../fightsystem/listener/CheckListener.java | 40 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 3150286..88bb7dc 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -116,6 +116,9 @@ public class Config { public static final boolean BothTeamsPublic; public static final int MaximumTeamMembers; + //check parameter + public static final int CheckSchemID; + static{ File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { @@ -336,6 +339,8 @@ public class Config { RedLeader = UUID.fromString(redLeader); else RedLeader = null; + + CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); } public static boolean event(){ @@ -344,4 +349,7 @@ public class Config { public static boolean test(){ return EventKampfID == -1; } + public static boolean check(){ + return CheckSchemID != 0; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index faf2816..fa6e642 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -13,6 +13,7 @@ import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; +import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -58,6 +59,7 @@ public class FightSystem extends JavaPlugin { new InFightDamageListener(); new FreezeWorldStateListener(); new EventJoinListener(); + new CheckListener(); new TestListener(); new NormalJoinListener(); if(Core.getVersion() > 8) @@ -95,7 +97,11 @@ public class FightSystem extends JavaPlugin { setPreSchemState(); }else if(Config.test()){ - Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0); + if(Config.check()){ + Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0); + }else{ + Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0); + } Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0); setPreSchemState(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java new file mode 100644 index 0000000..a792170 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java @@ -0,0 +1,40 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.Schematic; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserGroup; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.EnumSet; + +public class CheckListener extends BasicListener { + + public CheckListener() { + super(Config.check() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + } + + public void onJoin(PlayerJoinEvent e){ + Player player = e.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + if(allowedToCheck(user)) + return; + + Schematic schem = Schematic.getSchemFromDB(Config.CheckSchemID); + if(user.getId() == schem.getSchemOwner()) + return; + + player.sendMessage("§cAuf diesem Server wird momentan eine Schematic geprüft!"); + player.kickPlayer(""); + } + + public static boolean allowedToCheck(SteamwarUser user) { + return user.getUserGroup() == UserGroup.Supporter || + user.getUserGroup() == UserGroup.Developer || + user.getUserGroup() == UserGroup.Moderator || + user.getUserGroup() == UserGroup.Admin; + } +}