diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 5bf96064..b6f41141 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -83,10 +83,12 @@ public enum DMessages implements Messages { ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."), ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."), ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"), - ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"), ERROR_READY("Error_Ready", "&4Choose your class first!"), ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"), ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"), + ERROR_TOO_MANY_INSTANCES("Error_TooManyInstances", "&4There are currently too many maps instantiated. Try it again in a few minutes!"), + ERROR_TOO_MANY_TUTORIALS("Error_TooManyTutorials", "&4There are currently too many tutorials running. Try it again in a few minutes!"), + ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"), HELP_CMD_BREAK("Help_Cmd_Break", "/dxl break - Break a block protected by DungeonsXL"), HELP_CMD_CHAT("Help_Cmd_Chat", "/dxl chat - Change the chat mode"), HELP_CMD_CHATSPY("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode"), 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 87b25334..0d13f2c5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -30,7 +30,7 @@ import org.bukkit.configuration.ConfigurationSection; */ public class MainConfig extends BRConfig { - public static final int CONFIG_VERSION = 7; + public static final int CONFIG_VERSION = 8; private String language = "english"; private boolean enableEconomy = false; @@ -45,6 +45,7 @@ public class MainConfig extends BRConfig { private boolean sendFloorTitle = true; private Map externalMobProviders = new HashMap<>(); private List groupColorPriority = new ArrayList<>(Arrays.asList((short) 11, (short) 14, (short) 4, (short) 5, (short) 10, (short) 1, (short) 0, (short) 15)); + private int maxInstances = 10; /* Secure Mode */ private boolean secureModeEnabled = false; @@ -136,6 +137,8 @@ public class MainConfig extends BRConfig { } /** + * <<<<<<< HEAD + * * @param group * the group the player gets when he plays the tutorial */ @@ -195,6 +198,21 @@ public class MainConfig extends BRConfig { groupColorPriority = dataValues; } + /** + * @return the maximum amount of worlds to instantiate at once + */ + public int getMaxInstances() { + return maxInstances; + } + + /** + * @param maxInstances + * the maximum amount of worlds to instantiate at once + */ + public void setMaxInstances(int maxInstances) { + this.maxInstances = maxInstances; + } + /** * @return if the secure mode is enabled */ @@ -254,7 +272,7 @@ public class MainConfig extends BRConfig { public void setSecureModeCheckInterval(double interval) { secureModeCheckInterval = interval; } - + /** * @return the editCommandWhitelist */ @@ -315,6 +333,10 @@ public class MainConfig extends BRConfig { config.set("groupColorPriority", groupColorPriority); } + if (!config.contains("maxInstances")) { + config.set("maxInstances", maxInstances); + } + if (!config.contains("secureMode.enabled")) { config.set("secureMode.enabled", secureModeEnabled); } @@ -386,6 +408,10 @@ public class MainConfig extends BRConfig { groupColorPriority = config.getShortList("groupColorPriority"); } + if (config.contains("maxInstances")) { + maxInstances = config.getInt("maxInstances"); + } + if (config.contains("secureMode.enabled")) { secureModeEnabled = config.getBoolean("secureMode.enabled"); } 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 9a245c8d..27a3466c 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -469,6 +469,11 @@ public class GameSign extends GlobalProtection { return false; } + if (plugin.getGameWorlds().size() >= plugin.getMainConfig().getMaxInstances()) { + MessageUtil.sendMessage(player, DMessages.ERROR_TOO_MANY_INSTANCES.getMessage()); + return true; + } + DGroup dGroup = DGroup.getByPlayer(player); if (dGroup == null) { 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 e01b5965..924f0fbf 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.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent; @@ -65,6 +66,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -570,6 +572,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.getMaxInstances()) { + event.setResult(PlayerLoginEvent.Result.KICK_FULL); + event.setKickMessage(DMessages.ERROR_TOO_MANY_TUTORIALS.getMessage()); + } + return; } }