mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-12-01 06:53:26 +01:00
#367 Fix level requirements with keepInventoryOnEnter
This commit is contained in:
parent
89f1821d29
commit
154a6d2383
@ -1,80 +1,111 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2018 Frank Baumann
|
* Copyright (C) 2012-2018 Frank Baumann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package io.github.dre2n.dungeonsxl.requirement;
|
package io.github.dre2n.dungeonsxl.requirement;
|
||||||
|
|
||||||
import de.erethon.commons.chat.MessageUtil;
|
import de.erethon.commons.chat.MessageUtil;
|
||||||
import io.github.dre2n.dungeonsxl.config.DMessage;
|
import io.github.dre2n.dungeonsxl.config.DMessage;
|
||||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
import io.github.dre2n.dungeonsxl.game.Game;
|
||||||
import io.github.dre2n.dungeonsxl.player.DPlayerData;
|
import io.github.dre2n.dungeonsxl.game.GameRuleProvider;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import io.github.dre2n.dungeonsxl.player.DPlayerData;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
/**
|
import org.bukkit.entity.Player;
|
||||||
* @author Daniel Saukel
|
|
||||||
*/
|
/**
|
||||||
public class FeeLevelRequirement extends Requirement {
|
* @author Daniel Saukel
|
||||||
|
*/
|
||||||
private RequirementType type = RequirementTypeDefault.FEE_LEVEL;
|
public class FeeLevelRequirement extends Requirement {
|
||||||
|
|
||||||
private int fee;
|
private RequirementType type = RequirementTypeDefault.FEE_LEVEL;
|
||||||
|
|
||||||
/* Getters and setters */
|
private int fee;
|
||||||
/**
|
private Boolean keepInventory;
|
||||||
* @return the fee
|
|
||||||
*/
|
/* Getters and setters */
|
||||||
public int getFee() {
|
/**
|
||||||
return fee;
|
* @return the fee
|
||||||
}
|
*/
|
||||||
|
public int getFee() {
|
||||||
/**
|
return fee;
|
||||||
* @param fee
|
}
|
||||||
* the fee to set
|
|
||||||
*/
|
/**
|
||||||
public void setFee(int fee) {
|
* @param fee
|
||||||
this.fee = fee;
|
* the fee to set
|
||||||
}
|
*/
|
||||||
|
public void setFee(int fee) {
|
||||||
@Override
|
this.fee = fee;
|
||||||
public RequirementType getType() {
|
}
|
||||||
return type;
|
|
||||||
}
|
@Override
|
||||||
|
public RequirementType getType() {
|
||||||
/* Actions */
|
return type;
|
||||||
@Override
|
}
|
||||||
public void setup(ConfigurationSection config) {
|
|
||||||
fee = config.getInt("feeLevel");
|
/* Actions */
|
||||||
}
|
@Override
|
||||||
|
public void setup(ConfigurationSection config) {
|
||||||
@Override
|
fee = config.getInt("feeLevel");
|
||||||
public boolean check(Player player) {
|
}
|
||||||
return player.getLevel() >= fee;
|
|
||||||
}
|
@Override
|
||||||
|
public boolean check(Player player) {
|
||||||
@Override
|
if (isKeepInventory(player)) {
|
||||||
public void demand(Player player) {
|
return player.getLevel() >= fee;
|
||||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
}
|
||||||
if (dPlayer == null) {
|
|
||||||
return;
|
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||||
}
|
return dPlayer != null ? dPlayer.getData().getOldLevel() >= fee : true;
|
||||||
|
}
|
||||||
DPlayerData data = dPlayer.getData();
|
|
||||||
data.setOldLevel(data.getOldLevel() - fee);
|
@Override
|
||||||
|
public void demand(Player player) {
|
||||||
MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(fee + " levels"));
|
if (isKeepInventory(player)) {
|
||||||
}
|
player.setLevel(player.getLevel() - fee);
|
||||||
|
|
||||||
}
|
} else {
|
||||||
|
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||||
|
if (dPlayer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DPlayerData data = dPlayer.getData();
|
||||||
|
data.setOldLevel(data.getOldLevel() - fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(fee + " levels"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isKeepInventory(Player player) {
|
||||||
|
if (keepInventory != null) {
|
||||||
|
return keepInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = Game.getByPlayer(player);
|
||||||
|
GameRuleProvider rules = null;
|
||||||
|
if (game != null) {
|
||||||
|
rules = game.getRules();
|
||||||
|
}
|
||||||
|
if (rules != null) {
|
||||||
|
keepInventory = rules.getKeepInventoryOnEnter();
|
||||||
|
return keepInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
keepInventory = GameRuleProvider.DEFAULT_VALUES.getKeepInventoryOnEnter();
|
||||||
|
return keepInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user