mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Added permission requirement
This commit is contained in:
parent
cea08e440d
commit
00df06e45e
@ -26,7 +26,9 @@ 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.PermissionRequirement;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
import io.github.dre2n.dungeonsxl.requirement.RequirementTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -190,15 +192,18 @@ public class WorldConfig extends GameRules {
|
||||
Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier));
|
||||
|
||||
// Check for built-in requirements
|
||||
if (requirement instanceof FeeMoneyRequirement) {
|
||||
if (requirement.getType() == RequirementTypeDefault.FEE_MONEY) {
|
||||
((FeeMoneyRequirement) requirement).setFee(configFile.getDouble("requirements.feeMoney"));
|
||||
|
||||
} else if (requirement instanceof FeeLevelRequirement) {
|
||||
} else if (requirement.getType() == RequirementTypeDefault.FEE_LEVEL) {
|
||||
((FeeLevelRequirement) requirement).setFee(configFile.getInt("requirements.feeLevel"));
|
||||
|
||||
} else if (requirement instanceof GroupSizeRequirement) {
|
||||
} else if (requirement.getType() == RequirementTypeDefault.GROUP_SIZE) {
|
||||
((GroupSizeRequirement) requirement).setMinimum(configFile.getInt("requirements.groupSize.minimum"));
|
||||
((GroupSizeRequirement) requirement).setMaximum(configFile.getInt("requirements.groupSize.maximum"));
|
||||
|
||||
} else if (requirement.getType() == RequirementTypeDefault.PERMISSION) {
|
||||
((PermissionRequirement) requirement).setPermissions(configFile.getStringList("requirements.permission"));
|
||||
}
|
||||
|
||||
requirements.add(requirement);
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.requirement;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class PermissionRequirement extends Requirement {
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.PERMISSION;
|
||||
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the permission the player must have to play the dungeon
|
||||
*/
|
||||
public List<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permissions
|
||||
* the permissions to set
|
||||
*/
|
||||
public void setPermissions(List<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public boolean check(Player player) {
|
||||
for (String permission : permissions) {
|
||||
if (!DPermissions.hasPermission(player, permission)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void demand(Player player) {
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,8 @@ public enum RequirementTypeDefault implements RequirementType {
|
||||
|
||||
FEE_LEVEL("feeLevel", FeeLevelRequirement.class),
|
||||
FEE_MONEY("feeMoney", FeeMoneyRequirement.class),
|
||||
GROUP_SIZE("groupSize", GroupSizeRequirement.class);
|
||||
GROUP_SIZE("groupSize", GroupSizeRequirement.class),
|
||||
PERMISSION("permission", PermissionRequirement.class);
|
||||
|
||||
private String identifier;
|
||||
private Class<? extends Requirement> handler;
|
||||
|
Loading…
Reference in New Issue
Block a user