Skip to content

Commit b1374d9

Browse files
author
Leonidius20
committed
Fixed error when player responded to another plugin's form
1 parent 3c37b81 commit b1374d9

9 files changed

Lines changed: 37 additions & 17 deletions

File tree

src/main/java/ua/leonidius/trdinterface/Message.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public enum Message {
5656
// Buy item selector window
5757
WDW_BUY_EMPTY_CAT ("There are no items in this category."),
5858
BTN_ITEM_BUY ("%1% (%2%%3%)"),
59-
BTN_ITEM_BUY_SALE ("%1% (%2%%3%) %4%% off!"),
59+
BTN_ITEM_BUY_SALE ("%1% (%2%%3%) &c-%4%%!"),
6060

6161
// Buy window
6262
WDW_BUY_TITLE ("Buying %1%"),

src/main/java/ua/leonidius/trdinterface/Trading.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
public class Trading extends PluginBase implements Listener {
1717

1818
public static Config buyCfg, sellCfg, customNames;
19-
public static Trading plugin;
19+
private static Trading plugin;
2020
public static Settings settings;
21+
//public static File imageFolder;
2122

2223
@Override
2324
public void onEnable() {
@@ -33,6 +34,9 @@ public void onEnable() {
3334
getServer().getPluginManager().registerEvents(this, this);
3435

3536
getDataFolder().mkdirs();
37+
/*imageFolder = new File(getDataFolder(), "images");
38+
imageFolder.mkdirs();*/
39+
3640
saveResource("config.yml");
3741
saveResource("buyList.yml");
3842
saveResource("sellList.yml");
@@ -51,7 +55,7 @@ public static Trading getPlugin(){
5155
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
5256
public void onFormResponse(PlayerFormRespondedEvent event) {
5357
if (event.getResponse() == null) return;
54-
Screen screen = (Screen)event.getWindow();
55-
screen.onResponse(event);
58+
if (!(event.getWindow() instanceof Screen)) return;
59+
((Screen)event.getWindow()).onResponse(event);
5660
}
5761
}

src/main/java/ua/leonidius/trdinterface/buy/BuyNotEnoughWindow.java renamed to src/main/java/ua/leonidius/trdinterface/buy/BuyFailScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
/**
1010
* Created by Leonidius20 on 07.07.18.
1111
*/
12-
public class BuyNotEnoughWindow extends FormWindowSimple implements Screen {
12+
public class BuyFailScreen extends FormWindowSimple implements Screen {
1313

14-
String categoryId;
14+
private String categoryId;
1515

16-
public BuyNotEnoughWindow(int code, String categoryId) {
16+
public BuyFailScreen(int code, String categoryId) {
1717
super(Message.WDW_FAIL_TITLE.getText(), "");
1818
this.categoryId = categoryId;
1919
switch (code) {

src/main/java/ua/leonidius/trdinterface/buy/BuyItemSelectorScreen.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import cn.nukkit.item.Item;
88
import cn.nukkit.utils.ConfigSection;
99
import ua.leonidius.trdinterface.Message;
10-
import ua.leonidius.trdinterface.Trading;
1110
import ua.leonidius.trdinterface.elements.ItemButton;
1211
import ua.leonidius.trdinterface.screens.Screen;
1312

@@ -18,7 +17,7 @@
1817
*/
1918
public class BuyItemSelectorScreen extends FormWindowSimple implements Screen {
2019

21-
String categoryId;
20+
private String categoryId;
2221

2322
public BuyItemSelectorScreen(String categoryId) {
2423
super(buyCfg.getSection(categoryId).getString("name"), "");
@@ -65,11 +64,11 @@ public void onResponse(PlayerFormRespondedEvent event) {
6564
int maxByInventory = Buy.getMaxByInventory(player, item);
6665

6766
if (maxByMoney == 0 && maxByInventory == 0) {
68-
player.showFormWindow(new BuyNotEnoughWindow(0, categoryId));
67+
player.showFormWindow(new BuyFailScreen(0, categoryId));
6968
} else if (maxByMoney == 0){
70-
player.showFormWindow(new BuyNotEnoughWindow(1, categoryId));
69+
player.showFormWindow(new BuyFailScreen(1, categoryId));
7170
} else if (maxByInventory == 0) {
72-
player.showFormWindow(new BuyNotEnoughWindow(2, categoryId));
71+
player.showFormWindow(new BuyFailScreen(2, categoryId));
7372
} else {
7473
int maxAmount = Math.min(maxByInventory, maxByMoney);
7574
player.showFormWindow(new BuyScreen(categoryId, button.getStringId(), price, maxAmount));

src/main/java/ua/leonidius/trdinterface/elements/ItemButton.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
package ua.leonidius.trdinterface.elements;
88

99
import cn.nukkit.form.element.ElementButton;
10+
import cn.nukkit.form.element.ElementButtonImageData;
1011
import cn.nukkit.item.Item;
1112
import cn.nukkit.utils.TextFormat;
1213
import ua.leonidius.trdinterface.ItemName;
1314
import ua.leonidius.trdinterface.Message;
1415
import ua.leonidius.trdinterface.Trading;
1516

17+
import java.io.File;
18+
1619
public class ItemButton extends ElementButton {
1720

1821
private String id;
@@ -21,18 +24,28 @@ public class ItemButton extends ElementButton {
2124
public ItemButton(String id) {
2225
super(ItemName.get(id));
2326
this.id = id;
27+
//addItemIcon(id);
2428
}
2529

2630
public ItemButton(String id, double price) {
2731
super(Message.BTN_ITEM_BUY.getText(ItemName.get(id), price, Trading.settings.currency));
2832
this.id = id;
33+
//addItemIcon(id);
2934
}
3035

3136
public ItemButton(String id, double price, int discount) {
3237
super(Message.BTN_ITEM_BUY_SALE.getText(ItemName.get(id), price, Trading.settings.currency, discount));
3338
this.id = id;
39+
//addItemIcon(id);
3440
}
3541

42+
/*private void addItemIcon(String id) {
43+
File image = new File(Trading.imageFolder, id+".png");
44+
if (image.exists()) {
45+
addImage(new ElementButtonImageData(ElementButtonImageData.IMAGE_DATA_TYPE_PATH, image.getPath()));
46+
}
47+
}*/
48+
3649
public String getStringId() {
3750
return id;
3851
}

src/main/java/ua/leonidius/trdinterface/elements/SellItemButton.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package ua.leonidius.trdinterface.elements;
22

33
import cn.nukkit.form.element.ElementButton;
4+
import cn.nukkit.form.element.ElementButtonImageData;
45
import cn.nukkit.item.Item;
56
import ua.leonidius.trdinterface.ItemName;
67
import ua.leonidius.trdinterface.Message;
8+
import ua.leonidius.trdinterface.Trading;
9+
10+
import java.io.File;
711

812
/**
913
* Created by Leonidius20 on 07.07.18.
@@ -17,6 +21,10 @@ public SellItemButton(String id, int amount) {
1721
super(Message.BTN_ITEM_SELL.getText(ItemName.get(id), amount));
1822
this.id = id;
1923
this.amount = amount;
24+
/*File image = new File(Trading.imageFolder, id+".png");
25+
if (image.exists()) {
26+
addImage(new ElementButtonImageData(ElementButtonImageData.IMAGE_DATA_TYPE_PATH, image.getPath()));
27+
}*/
2028
}
2129

2230
public String getStringId() {

src/main/resources/lang/rus.lng

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ wdw_fail_title: Неудача
1919
wdw_buy_cat_title: Выберите категорию
2020
wdw_buy_no_categories: В магазине отсутствуют категории товаров. Для использования магазина необходимо наличие как минимум одной категории.
2121
wdw_buy_empty_cat: В этой категории нет товаров.
22-
btn_item_buy: '%1% (%2%%3%)'
23-
btn_item_buy_sale: '%1% (%2%%3%) скидка %4%%!'
2422
wdw_buy_title: Приобретение %1%
2523
wdw_buy_price: 'Цена: %1%%2% за штуку'
2624
wdw_buy_amount: Выберите количество

src/main/resources/lang/ukr.lng

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ wdw_fail_title: Невдача
1919
wdw_buy_cat_title: Виберіть категорію
2020
wdw_buy_no_categories: У магазині відсутні категорії товарів. Для використання магазина необхідно мати хоч одну категорію.
2121
wdw_buy_empty_cat: У цій категорії немає товарів.
22-
btn_item_buy: '%1% (%2%%3%)'
23-
btn_item_buy_sale: '%1% (%2%%3%) знижка %4%%!'
2422
wdw_buy_title: Придбання %1%
2523
wdw_buy_price: 'Ціна: %1%%2% за штуку'
2624
wdw_buy_amount: Виберіть кількість

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Trading Interface
22
main: ua.leonidius.trdinterface.Trading
3-
version: "1.0.0"
3+
version: "1.0.1"
44
author: Leonidius20
55
url: github.com/Leonidius20
66
api: ["1.0.0"]

0 commit comments

Comments
 (0)