mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 20:46:31 +01:00
Fix PriceRestrictionModule
This commit is contained in:
parent
7f933cb1d0
commit
94e94e99a2
@ -0,0 +1,7 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyCheckEvent {
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class CurrencyTransferEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private BigDecimal amount;
|
||||
private World world;
|
||||
private String sender;
|
||||
private String receiver;
|
||||
|
||||
public CurrencyTransferEvent(BigDecimal amount, String sender, String receiver, World world) {
|
||||
this.amount = amount;
|
||||
this.world = world;
|
||||
|
||||
this.sender = sender;
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
public CurrencyTransferEvent(double amount, String sender, String receiver, World world) {
|
||||
this(BigDecimal.valueOf(amount), sender, receiver, world);
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public double getDoubleAmount() {
|
||||
return amount.doubleValue();
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount) {
|
||||
this.amount = BigDecimal.valueOf(amount);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public String getReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Events.Economy;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class TransferCurrencyEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
public TransferCurrencyEvent(BigDecimal amount, String fromWho, String toWho)
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -20,6 +21,7 @@ import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE;
|
||||
*/
|
||||
public class PriceRestrictionModule implements Listener {
|
||||
private YamlConfiguration configuration;
|
||||
private static final double INVALID_PATH = Double.MIN_VALUE;
|
||||
|
||||
public PriceRestrictionModule() {
|
||||
File file = new File(ChestShop.getFolder(), "priceLimits.yml");
|
||||
@ -47,16 +49,23 @@ public class PriceRestrictionModule implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPreShopCreation(PreShopCreationEvent event) {
|
||||
int itemID = MaterialUtil.getItem(event.getSignLine(ITEM_LINE)).getTypeId();
|
||||
ItemStack material = MaterialUtil.getItem(event.getSignLine(ITEM_LINE));
|
||||
|
||||
if (material == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int itemID = material.getTypeId();
|
||||
int amount = material.getAmount();
|
||||
|
||||
if (PriceUtil.hasBuyPrice(event.getSignLine(PRICE_LINE))) {
|
||||
double buyPrice = PriceUtil.getBuyPrice(event.getSignLine(PRICE_LINE));
|
||||
|
||||
if (configuration.isDouble("min.buy_price." + itemID) && buyPrice < configuration.getDouble("min.buy_price." + itemID)) {
|
||||
if (isValid("min.buy_price." + itemID) && buyPrice < (configuration.getDouble("min.buy_price." + itemID) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
|
||||
if (configuration.isDouble("max.buy_price." + itemID) && buyPrice > configuration.getDouble("max.buy_price." + itemID)) {
|
||||
if (isValid("max.buy_price." + itemID) && buyPrice > (configuration.getDouble("max.buy_price." + itemID) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
}
|
||||
@ -64,13 +73,17 @@ public class PriceRestrictionModule implements Listener {
|
||||
if (PriceUtil.hasSellPrice(event.getSignLine(PRICE_LINE))) {
|
||||
double sellPrice = PriceUtil.getSellPrice(event.getSignLine(PRICE_LINE));
|
||||
|
||||
if (configuration.isDouble("min.sell_price." + itemID) && sellPrice < configuration.getDouble("min.sell_price." + itemID)) {
|
||||
if (isValid("min.sell_price." + itemID) && sellPrice < (configuration.getDouble("min.sell_price." + itemID) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
|
||||
if (configuration.isDouble("max.sell_price." + itemID) && sellPrice > configuration.getDouble("max.sell_price." + itemID)) {
|
||||
if (isValid("max.sell_price." + itemID) && sellPrice > (configuration.getDouble("max.sell_price." + itemID) / amount)) {
|
||||
event.setOutcome(INVALID_PRICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(String path) {
|
||||
return configuration.getDouble(path, INVALID_PATH) != INVALID_PATH;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user