mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-09-25 13:12:51 +02:00
a5bfa86bca
Switched the project to Maven - you're now able to easily build ChestShop.
31 lines
1.1 KiB
Java
31 lines
1.1 KiB
Java
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
|
|
|
import com.Acrobot.Breeze.Utils.PriceUtil;
|
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
|
|
import static com.Acrobot.Breeze.Utils.PriceUtil.hasBuyPrice;
|
|
import static com.Acrobot.Breeze.Utils.PriceUtil.hasSellPrice;
|
|
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SELL_PRICE_HIGHER_THAN_BUY_PRICE;
|
|
import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE;
|
|
import static org.bukkit.event.EventPriority.HIGH;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class PriceRatioChecker implements Listener {
|
|
|
|
@EventHandler(priority = HIGH)
|
|
public static void onPreShopCreation(PreShopCreationEvent event) {
|
|
String priceLine = event.getSignLine(PRICE_LINE);
|
|
|
|
double buyPrice = PriceUtil.getBuyPrice(priceLine);
|
|
double sellPrice = PriceUtil.getSellPrice(priceLine);
|
|
|
|
if (hasBuyPrice(priceLine) && hasSellPrice(priceLine) && sellPrice > buyPrice) {
|
|
event.setOutcome(SELL_PRICE_HIGHER_THAN_BUY_PRICE);
|
|
}
|
|
}
|
|
}
|