Skip to content

Commit

Permalink
added confirm purchase gui
Browse files Browse the repository at this point in the history
  • Loading branch information
benfiratkaya committed Dec 21, 2023
1 parent d0ff9ac commit f91b021
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static void showGui(Player player) {
category.getCategoryIcon(),
1,
click -> {
click.getEvent().setCancelled(true);
WebStoreGui.showGui(player, category);
return true;
})))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ private static void addProductsToGroup(List<Product> 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;
})))
);
}
Expand Down

0 comments on commit f91b021

Please sign in to comment.