diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 449fff9..76d7920 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -1,10 +1,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; -import de.steamwar.bausystem.world.ArenaSection; -import de.steamwar.bausystem.world.BauScoreboard; -import de.steamwar.bausystem.world.RegionListener; -import de.steamwar.bausystem.world.TNTListener; +import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.sql.SteamwarUser; @@ -90,6 +87,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new TNTListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); + new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/AFKStopper.java b/BauSystem_Main/src/de/steamwar/bausystem/world/AFKStopper.java new file mode 100644 index 0000000..b3b7a22 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/AFKStopper.java @@ -0,0 +1,35 @@ +package de.steamwar.bausystem.world; + +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class AFKStopper implements Listener { + + private static final String afkWarning = BauSystem.PREFIX + "§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt"; + + private int minutesAfk; + + public AFKStopper(){ + minutesAfk = 0; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + switch(minutesAfk){ + case 5: + Bukkit.shutdown(); + break; + case 4: + Bukkit.broadcastMessage(afkWarning); + default: + minutesAfk++; + } + }, 1200, 1200); //every minute + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event){ + minutesAfk = 0; + } +}