From 3b085189b9975329ec2497eeea5e5d5180fb4b4c Mon Sep 17 00:00:00 2001 From: Leonidius20 <25536411+Leonidius20@users.noreply.github.com> Date: Tue, 18 Aug 2020 22:05:23 +0300 Subject: [PATCH] fixed #8 --- .../ua/leonidius/trdinterface/sell/Sell.java | 7 ++++++- .../trdinterface/sell/SellFailScreen.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ua/leonidius/trdinterface/sell/SellFailScreen.java diff --git a/src/main/java/ua/leonidius/trdinterface/sell/Sell.java b/src/main/java/ua/leonidius/trdinterface/sell/Sell.java index 99df651..a13b277 100644 --- a/src/main/java/ua/leonidius/trdinterface/sell/Sell.java +++ b/src/main/java/ua/leonidius/trdinterface/sell/Sell.java @@ -22,7 +22,12 @@ public static void sellItem(Player player, String id, int amount) { double price = Trading.sellCfg.getDouble(id.replace(":", "-")); - double cost = price*amount; + double cost = price * amount; + + if (!player.getInventory().contains(item)) { + player.showFormWindow(new SellFailScreen()); + return; + } player.getInventory().removeItem(item); EconomyAPI.getInstance().addMoney(player, cost); diff --git a/src/main/java/ua/leonidius/trdinterface/sell/SellFailScreen.java b/src/main/java/ua/leonidius/trdinterface/sell/SellFailScreen.java new file mode 100644 index 0000000..5ada64f --- /dev/null +++ b/src/main/java/ua/leonidius/trdinterface/sell/SellFailScreen.java @@ -0,0 +1,19 @@ +package ua.leonidius.trdinterface.sell; + +import cn.nukkit.event.player.PlayerFormRespondedEvent; +import cn.nukkit.form.element.ElementButton; +import cn.nukkit.form.window.FormWindowSimple; +import ua.leonidius.trdinterface.Message; +import ua.leonidius.trdinterface.screens.Screen; + +public class SellFailScreen extends FormWindowSimple implements Screen { + + public SellFailScreen() { + super(Message.WDW_FAIL_TITLE.getText(), Message.WDW_SELL_NOTHING.getText()); + addButton(new ElementButton(Message.BTN_BACK.getText())); + } + + public void onResponse(PlayerFormRespondedEvent event) { + event.getPlayer().showFormWindow(new SellItemSelectorScreen(event.getPlayer().getInventory())); + } +} \ No newline at end of file