DungeonsXL/core/src/main/java/de/erethon/dungeonsxl/requirement/FeeMoneyRequirement.java

100 lines
2.8 KiB
Java
Raw Normal View History

2016-03-01 22:08:07 +01:00
/*
2022-01-08 23:02:57 +01:00
* Copyright (C) 2012-2022 Frank Baumann
2016-03-01 22:08:07 +01:00
*
* 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/>.
*/
2018-05-03 21:54:25 +02:00
package de.erethon.dungeonsxl.requirement;
2016-03-01 22:08:07 +01:00
2018-05-03 21:54:25 +02:00
import de.erethon.dungeonsxl.DungeonsXL;
2020-03-16 16:33:41 +01:00
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
2018-05-03 21:54:25 +02:00
import de.erethon.dungeonsxl.config.DMessage;
2022-04-03 18:09:12 +02:00
import de.erethon.bedrock.chat.MessageUtil;
2020-04-11 02:02:42 +02:00
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
2018-08-18 16:52:51 +02:00
import net.milkbowl.vault.economy.Economy;
2016-07-26 14:44:39 +02:00
import org.bukkit.configuration.ConfigurationSection;
2016-03-01 22:08:07 +01:00
import org.bukkit.entity.Player;
/**
* @author Daniel Saukel
*/
public class FeeMoneyRequirement implements Requirement {
2016-03-01 22:08:07 +01:00
2018-08-18 16:52:51 +02:00
private Economy econ;
2016-03-01 22:08:07 +01:00
private double fee;
2020-03-16 16:33:41 +01:00
public FeeMoneyRequirement(DungeonsAPI api) {
econ = ((DungeonsXL) api).getEconomyProvider();
2018-08-18 16:52:51 +02:00
}
2016-07-26 14:44:39 +02:00
/* Getters and setters */
2016-03-01 22:08:07 +01:00
/**
* @return the fee
*/
public double getFee() {
return fee;
}
/**
2018-07-28 21:15:58 +02:00
* @param fee the fee to set
2016-03-01 22:08:07 +01:00
*/
public void setFee(double fee) {
this.fee = fee;
}
2016-07-26 14:44:39 +02:00
/* Actions */
@Override
public void setup(ConfigurationSection config) {
fee = config.getDouble("feeMoney");
}
2016-03-01 22:08:07 +01:00
@Override
public boolean check(Player player) {
2018-08-18 16:52:51 +02:00
if (econ == null) {
2016-03-01 22:08:07 +01:00
return true;
}
2018-08-18 16:52:51 +02:00
return econ.getBalance(player) >= fee;
2016-03-01 22:08:07 +01:00
}
2020-04-11 02:02:42 +02:00
@Override
public BaseComponent[] getCheckMessage(Player player) {
double money = econ.getBalance(player);
ChatColor color = money >= fee ? ChatColor.GREEN : ChatColor.DARK_RED;
return new ComponentBuilder(DMessage.REQUIREMENT_FEE_MONEY.getMessage() + ": ").color(ChatColor.GOLD)
.append(String.valueOf(money)).color(color)
.append("/" + fee).color(ChatColor.WHITE)
.create();
}
2016-03-01 22:08:07 +01:00
@Override
public void demand(Player player) {
2018-08-18 16:52:51 +02:00
if (econ == null) {
2016-03-01 22:08:07 +01:00
return;
}
2018-08-18 16:52:51 +02:00
econ.withdrawPlayer(player, fee);
MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(econ.format(fee)));
2016-03-01 22:08:07 +01:00
}
2020-04-11 02:02:42 +02:00
@Override
public String toString() {
return "FeeMoneyRequirement{fee=" + fee + "}";
}
2016-03-01 22:08:07 +01:00
}