From 0a9149eb69839ef2b0bac4805e2fcbe0ba18020c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 17 May 2016 19:13:53 +0200 Subject: [PATCH] Added group size requirement --- pom.xml | 2 +- .../dre2n/dungeonsxl/config/DMessages.java | 2 +- .../dre2n/dungeonsxl/config/WorldConfig.java | 5 ++ .../requirement/GroupSizeRequirement.java | 78 +++++++++++++++++++ .../requirement/RequirementTypeDefault.java | 3 +- 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java diff --git a/pom.xml b/pom.xml index 652bb27f..9c5f9398 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ io.github.dre2n commons - 0.7 + 1.0-SNAPSHOT io.github.dre2n 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 f7894dfe..12995638 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -84,7 +84,7 @@ public enum DMessages implements Messages { 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_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"), ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"), 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"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java index 78846829..df133832 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java @@ -23,6 +23,7 @@ import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.requirement.FeeLevelRequirement; import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement; +import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement; import io.github.dre2n.dungeonsxl.requirement.Requirement; import java.io.File; import java.io.IOException; @@ -189,6 +190,10 @@ public class WorldConfig extends GameRules { } else if (requirement instanceof FeeLevelRequirement) { ((FeeLevelRequirement) requirement).setFee(configFile.getInt("requirements.feeLevel")); + + } else if (requirement instanceof GroupSizeRequirement) { + ((GroupSizeRequirement) requirement).setMinimum(configFile.getInt("requirements.groupSize.minimum")); + ((GroupSizeRequirement) requirement).setMaximum(configFile.getInt("requirements.groupSize.maximum")); } requirements.add(requirement); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java b/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java new file mode 100644 index 00000000..dc49a700 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/requirement/GroupSizeRequirement.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.requirement; + +import io.github.dre2n.dungeonsxl.player.DGroup; +import org.bukkit.entity.Player; + +/** + * @author Daniel Saukel + */ +public class GroupSizeRequirement extends Requirement { + + private RequirementType type = RequirementTypeDefault.GROUP_SIZE; + + private int minimum; + private int maximum; + + /** + * @return the group minimum + */ + public int getMinimum() { + return minimum; + } + + /** + * @param minimum + * the minimal group size to set + */ + public void setMinimum(int minimum) { + this.minimum = minimum; + } + + /** + * @return the group size maximum + */ + public int getMaximum() { + return maximum; + } + + /** + * @param maximum + * the maximal group size to set + */ + public void setMaximum(int maximum) { + this.maximum = maximum; + } + + @Override + public boolean check(Player player) { + DGroup dGroup = DGroup.getByPlayer(player); + int size = dGroup.getPlayers().size(); + return size >= minimum && size <= maximum; + } + + @Override + public void demand(Player player) { + } + + @Override + public RequirementType getType() { + return type; + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java index 83ce9cf6..a22aa2d8 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/requirement/RequirementTypeDefault.java @@ -22,7 +22,8 @@ package io.github.dre2n.dungeonsxl.requirement; public enum RequirementTypeDefault implements RequirementType { FEE_LEVEL("feeLevel", FeeLevelRequirement.class), - FEE_MONEY("feeMoney", FeeMoneyRequirement.class); + FEE_MONEY("feeMoney", FeeMoneyRequirement.class), + GROUP_SIZE("groupSize", GroupSizeRequirement.class); private String identifier; private Class handler;