diff --git a/bukkit/src/main/java/net/leaderos/plugin/configuration/Language.java b/bukkit/src/main/java/net/leaderos/plugin/configuration/Language.java index 5024abc12..62750e8f9 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/configuration/Language.java +++ b/bukkit/src/main/java/net/leaderos/plugin/configuration/Language.java @@ -511,26 +511,19 @@ public static class Credit extends OkaeriConfig { public static class ConfirmPurchase extends OkaeriConfig { /** - * Default Title + * GUI Name */ - private String title = "&a&lBUY"; - } - - /** - * CancelPurchase attributes - */ - private CancelPurchase cancelPurchase = new CancelPurchase(); + private String guiName = "&8Confirm Purchase"; - /** - * AcceptPurchase arguments class - */ - @Getter @Setter - public static class CancelPurchase extends OkaeriConfig { + /** + * Confirm Title + */ + private String confirmTitle = "&a&lBUY"; /** - * Default Title + * Cancel Title */ - private String title = "&c&lCANCEL"; + private String cancelTitle = "&c&lCANCEL"; } } diff --git a/bukkit/src/main/java/net/leaderos/plugin/configuration/Modules.java b/bukkit/src/main/java/net/leaderos/plugin/configuration/Modules.java index b490519b9..9550f4750 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/configuration/Modules.java +++ b/bukkit/src/main/java/net/leaderos/plugin/configuration/Modules.java @@ -334,20 +334,20 @@ public static class Credit extends OkaeriConfig { } /** - * Check Purchase attributes + * Confirm Purchase attributes */ - private Gui.CheckPurchase checkPurchase = new Gui.CheckPurchase(); + private Gui.ConfirmPurchase confirmPurchase = new Gui.ConfirmPurchase(); /** - * CheckPurchase arguments class + * ConfirmPurchase arguments class */ @Getter @Setter - public static class CheckPurchase extends OkaeriConfig { + public static class ConfirmPurchase extends OkaeriConfig { /** * Confirm material */ - private String confirmMaterial = "GREEN_WOOL"; + private String confirmMaterial = "LIME_WOOL"; /** * Cancel material diff --git a/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/en.java b/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/en.java index 094fe6f04..efbc92871 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/en.java +++ b/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/en.java @@ -512,26 +512,19 @@ public static class Credit extends Language.Gui.WebStoreGui.Credit { public static class ConfirmPurchase extends Language.Gui.WebStoreGui.ConfirmPurchase { /** - * Default Title + * GUI Name */ - private String title = "&a&lBUY"; - } - - /** - * CancelPurchase attributes - */ - private CancelPurchase cancelPurchase = new CancelPurchase(); + private String guiName = "&8Confirm Purchase"; - /** - * AcceptPurchase arguments class - */ - @Getter @Setter - public static class CancelPurchase extends Language.Gui.WebStoreGui.CancelPurchase { + /** + * Confirm Title + */ + private String confirmTitle = "&a&lBUY"; /** - * Default Title + * Cancel Title */ - private String title = "&c&lCANCEL"; + private String cancelTitle = "&c&lCANCEL"; } } diff --git a/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/tr.java b/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/tr.java index 04c94f5e7..35d357fab 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/tr.java +++ b/bukkit/src/main/java/net/leaderos/plugin/configuration/lang/tr.java @@ -510,26 +510,19 @@ public static class Credit extends Language.Gui.WebStoreGui.Credit { public static class ConfirmPurchase extends Language.Gui.WebStoreGui.ConfirmPurchase { /** - * Default Title + * GUI Name */ - private String title = "&a&lSATIN AL"; - } - - /** - * CancelPurchase attributes - */ - private CancelPurchase cancelPurchase = new CancelPurchase(); + private String guiName = "&8Satın Alımı Onayla"; - /** - * AcceptPurchase arguments class - */ - @Getter @Setter - public static class CancelPurchase extends Language.Gui.WebStoreGui.CancelPurchase { + /** + * Confirm Title + */ + private String confirmTitle = "&a&lSATIN AL"; /** - * Default Title + * Cancel Title */ - private String title = "&c&lIPTAL ET"; + private String cancelTitle = "&c&lIPTAL ET"; } } diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/ConfirmPurchaseGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/ConfirmPurchaseGui.java new file mode 100644 index 000000000..131a85ff7 --- /dev/null +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/ConfirmPurchaseGui.java @@ -0,0 +1,109 @@ +package net.leaderos.plugin.modules.webstore.gui; + +import com.cryptomorin.xseries.XMaterial; +import de.themoep.inventorygui.DynamicGuiElement; +import de.themoep.inventorygui.GuiElementGroup; +import de.themoep.inventorygui.InventoryGui; +import de.themoep.inventorygui.StaticGuiElement; +import net.leaderos.plugin.Bukkit; +import net.leaderos.plugin.helpers.ChatUtil; +import net.leaderos.plugin.helpers.GuiHelper; +import net.leaderos.plugin.helpers.ItemUtil; +import net.leaderos.plugin.modules.cache.model.User; +import net.leaderos.plugin.modules.webstore.helpers.WebStoreHelper; +import net.leaderos.plugin.modules.webstore.model.Category; +import net.leaderos.plugin.modules.webstore.model.Product; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +/** + * ConfirmPurchase GUI + * @author firatkaya + * @since 1.0.4 + */ +public class ConfirmPurchaseGui { + + /** + * Constructor of gui + */ + public ConfirmPurchaseGui() {} + + /** + * Opens gui to player + * @param player to show gui + * @param product to buy + */ + public static void showGui(Player player, Product product) { + // Gui template as array + String[] layout = Bukkit.getInstance().getModulesFile().getWebStore().getGui().getConfirmPurchase().getLayout().toArray(new String[0]); + // Inventory object + String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getConfirmPurchase().getGuiName()); + InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout); + // Filler item for empty slots + gui.setFiller(GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().getMaterial())); + + // Add product icon + gui.addElement(productIcon(product)); + + // Add buttons + gui.addElement(confirmIcon(player, product, gui)); + gui.addElement(cancelIcon(gui)); + + gui.show(player); + } + + /** + * ConfirmPurchase GUI add product icon + * + * @return product icon + */ + public static StaticGuiElement productIcon(Product product) { + return new StaticGuiElement( + 'p', + product.getProductIcon(), + 1, + click -> true + ); + } + + /** + * ConfirmPurchase GUI add confirm button + * + * @return confirm icon + */ + public static StaticGuiElement confirmIcon(Player player, Product product, InventoryGui gui) { + String displayName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getConfirmPurchase().getConfirmTitle()); + XMaterial material = XMaterial.matchXMaterial(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getConfirmPurchase().getConfirmMaterial()).orElse(XMaterial.LIME_WOOL); + return new StaticGuiElement( + 'y', + ItemUtil.getItem(material, displayName), + 1, + click -> { + gui.close(); + WebStoreHelper.buyItem(player, product.getProductId()); + return true; + } + ); + } + + /** + * ConfirmPurchase GUI add cancel button + * + * @return cancel icon + */ + public static StaticGuiElement cancelIcon(InventoryGui gui) { + String displayName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getConfirmPurchase().getCancelTitle()); + XMaterial material = XMaterial.matchXMaterial(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getConfirmPurchase().getCancelMaterial()).orElse(XMaterial.RED_WOOL); + return new StaticGuiElement( + 'n', + ItemUtil.getItem(material, displayName), + 1, + click -> { + gui.close(); + return true; + } + ); + } +} diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java index 9bce0f25c..331c11107 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/MainWebStoreGui.java @@ -50,7 +50,6 @@ public static void showGui(Player player) { category.getCategoryIcon(), 1, click -> { - click.getEvent().setCancelled(true); WebStoreGui.showGui(player, category); return true; }))) diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java index 58533cc02..295943461 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/gui/WebStoreGui.java @@ -112,10 +112,8 @@ private static void addProductsToGroup(List productList, GuiElementGrou product.getProductIcon(), 1, click -> { - click.getEvent().setCancelled(true); - gui.close(); - WebStoreHelper.buyItem(player, product.getProductId()); - return false; + ConfirmPurchaseGui.showGui(player, product); + return true; }))) ); }