Skip to content

Commit 3b08518

Browse files
committed
fixed #8
1 parent 2bcebc8 commit 3b08518

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/main/java/ua/leonidius/trdinterface/sell/Sell.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public static void sellItem(Player player, String id, int amount) {
2222

2323
double price = Trading.sellCfg.getDouble(id.replace(":", "-"));
2424

25-
double cost = price*amount;
25+
double cost = price * amount;
26+
27+
if (!player.getInventory().contains(item)) {
28+
player.showFormWindow(new SellFailScreen());
29+
return;
30+
}
2631

2732
player.getInventory().removeItem(item);
2833
EconomyAPI.getInstance().addMoney(player, cost);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ua.leonidius.trdinterface.sell;
2+
3+
import cn.nukkit.event.player.PlayerFormRespondedEvent;
4+
import cn.nukkit.form.element.ElementButton;
5+
import cn.nukkit.form.window.FormWindowSimple;
6+
import ua.leonidius.trdinterface.Message;
7+
import ua.leonidius.trdinterface.screens.Screen;
8+
9+
public class SellFailScreen extends FormWindowSimple implements Screen {
10+
11+
public SellFailScreen() {
12+
super(Message.WDW_FAIL_TITLE.getText(), Message.WDW_SELL_NOTHING.getText());
13+
addButton(new ElementButton(Message.BTN_BACK.getText()));
14+
}
15+
16+
public void onResponse(PlayerFormRespondedEvent event) {
17+
event.getPlayer().showFormWindow(new SellItemSelectorScreen(event.getPlayer().getInventory()));
18+
}
19+
}

0 commit comments

Comments
 (0)