From 30d60e9ea23a3970aa2d10f73477e7a8da6aece9 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Tue, 31 May 2016 22:47:21 +0200 Subject: [PATCH] Added maxDungeons config option --- .../dre2n/dungeonsxl/config/MainConfig.java | 16 ++++++++++ .../dre2n/dungeonsxl/global/GameSign.java | 5 +++ .../dungeonsxl/listener/PlayerListener.java | 32 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 036f82d4..51e4e2e5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -39,6 +39,7 @@ public class MainConfig extends BRConfig { private String tutorialDungeon = "tutorial"; private String tutorialStartGroup = "default"; private String tutorialEndGroup = "player"; + private int maxDungeons = 10; /* Misc */ private boolean sendFloorTitle = true; @@ -98,6 +99,13 @@ public class MainConfig extends BRConfig { return tutorialStartGroup; } + /** + * @return the maxDungeons + */ + public int getMaxDungeons() { + return maxDungeons; + } + /** * @return if the floor title shall be sent */ @@ -188,6 +196,10 @@ public class MainConfig extends BRConfig { config.set("tutorial.endgroup", tutorialEndGroup); } + if (!config.contains("maxDungeons")) { + config.set("maxDungeons", maxDungeons); + } + if (!config.contains("sendFloorTitle")) { config.set("sendFloorTitle", sendFloorTitle); } @@ -251,6 +263,10 @@ public class MainConfig extends BRConfig { tutorialEndGroup = config.getString("tutorial.endgroup"); } + if (config.contains("maxDungeons")) { + maxDungeons = config.getInt("maxDungeons"); + } + if (config.contains("sendFloorTitle")) { sendFloorTitle = config.getBoolean("sendFloorTitle"); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index 7bb9a8d6..77bd6759 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -506,6 +506,11 @@ public class GameSign extends GlobalProtection { return true; } + if (plugin.getGameWorlds().size() >= plugin.getMainConfig().getMaxDungeons()) { + MessageUtil.sendMessage(player, "&cEs gibt bereits zu viele laufende Dungeons!"); + return true; + } + int sx1 = gameSign.startSign.getX(), sy1 = gameSign.startSign.getY(), sz1 = gameSign.startSign.getZ(); Block topBlock = block.getRelative(0, sy1 - y, 0); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index 841f3e54..5364a6b5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.listener; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.config.MainConfig; import io.github.dre2n.dungeonsxl.config.WorldConfig; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; @@ -68,6 +69,7 @@ import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; @@ -556,6 +558,36 @@ public class PlayerListener implements Listener { } new DGamePlayer(player, dGroup.getGameWorld()); + return; + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerLogin(PlayerLoginEvent event) { + Player player = event.getPlayer(); + + MainConfig config = plugin.getMainConfig(); + if (!config.isTutorialActivated()) { + return; + } + if (DGamePlayer.getByPlayer(player) != null) { + return; + } + if (plugin.getPermissionProvider() == null) { + return; + } + if ((config.getTutorialDungeon() == null || config.getTutorialStartGroup() == null || config.getTutorialEndGroup() == null)) { + return; + } + for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) { + if (!config.getTutorialStartGroup().equalsIgnoreCase(group)) { + continue; + } + if (plugin.getGameWorlds().size() >= config.getMaxDungeons()) { + event.setResult(PlayerLoginEvent.Result.KICK_FULL); + event.setKickMessage("Es laufen bereits zu viele Tutorials, bitte warte eine Weile!"); + } + return; } }