ChestShop-3/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/PriceRatioChecker.java
Acrobot a5bfa86bca Mavenized the project
Switched the project to Maven - you're now able to easily build
ChestShop.
2013-03-08 20:31:15 +01:00

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);
}
}
}