Skip to content

Commit

Permalink
Merge branch 'maxDungeons' of git://github.com/Sn0wStorm/DungeonsXL i…
Browse files Browse the repository at this point in the history
…nto 0.12
  • Loading branch information
Sataniel98 committed Jun 8, 2016
2 parents f1892aa + 30d60e9 commit df56276
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
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;
Expand All @@ -45,6 +45,7 @@ public class MainConfig extends BRConfig {
private boolean sendFloorTitle = true;
private Map<String, Object> externalMobProviders = new HashMap<>();
private List<Short> 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;
Expand Down Expand Up @@ -136,6 +137,8 @@ public String getTutorialStartGroup() {
}

/**
* <<<<<<< HEAD
*
* @param group
* the group the player gets when he plays the tutorial
*/
Expand Down Expand Up @@ -195,6 +198,21 @@ public void setGroupColorPriority(List<Short> dataValues) {
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
*/
Expand Down Expand Up @@ -254,7 +272,7 @@ public long getSecureModeCheckInterval() {
public void setSecureModeCheckInterval(double interval) {
secureModeCheckInterval = interval;
}

/**
* @return the editCommandWhitelist
*/
Expand Down Expand Up @@ -315,6 +333,10 @@ public void initialize() {
config.set("groupColorPriority", groupColorPriority);
}

if (!config.contains("maxInstances")) {
config.set("maxInstances", maxInstances);
}

if (!config.contains("secureMode.enabled")) {
config.set("secureMode.enabled", secureModeEnabled);
}
Expand Down Expand Up @@ -386,6 +408,10 @@ public void load() {
groupColorPriority = config.getShortList("groupColorPriority");
}

if (config.contains("maxInstances")) {
maxInstances = config.getInt("maxInstances");
}

if (config.contains("secureMode.enabled")) {
secureModeEnabled = config.getBoolean("secureMode.enabled");
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ public static boolean playerInteract(Block block, Player player) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -65,6 +66,7 @@
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;
Expand Down Expand Up @@ -570,6 +572,36 @@ public void onJoin(PlayerJoinEvent event) {
}

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;
}
}

Expand Down

0 comments on commit df56276

Please sign in to comment.