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..cd52031 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java @@ -0,0 +1,56 @@ +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.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.EnumSet; +import java.util.logging.Level; + +public class CheckListener extends BasicListener { + + public CheckListener() { + super(Config.check() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + } + + @EventHandler + 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(""); + } + + @EventHandler + public void handlePlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + if(!event.getMessage().contains("copy") && !event.getMessage().contains("cut")) + return; + + event.setCancelled(true); + player.sendMessage("§cDieser Befehl ist beim Prüfen gesperrt! Admin wird benachrichtigt."); + Bukkit.getLogger().log(Level.SEVERE, player.getName() + " tried to use a copy command!"); + } + + private static boolean allowedToCheck(SteamwarUser user) { + return user.getUserGroup() == UserGroup.Supporter || + user.getUserGroup() == UserGroup.Developer || + user.getUserGroup() == UserGroup.Moderator || + user.getUserGroup() == UserGroup.Admin; + } +}