Skip to content

Commit

Permalink
added custom price format
Browse files Browse the repository at this point in the history
  • Loading branch information
benfiratkaya committed Dec 21, 2023
1 parent 21db974 commit cffea76
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,26 @@ public static class WebStoreGui extends OkaeriConfig {
*/
private String guiName = "&8WebStore";

/**
* Price format
*/
@Comment({
"Price format",
"{price} for original price (e.g. 10.00 USD)",
"{rawPrice} for raw price (e.g. 10.00)"
})
private String priceFormat = "{price}";

/**
* Discounted price format
*/
@Comment({
"Discounted price format",
"{price} for original price (e.g. 10.00 USD)",
"{rawPrice} for raw price (e.g. 10.00)",
"{discountedPrice} for discounted price (e.g. 5.00 USD)",
"{rawDiscountedPrice} for raw discounted price (e.g. 5.00)"
})
private String discountedPriceFormat = "&c&m{price}&r &a{discountedPrice}";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,26 @@ public static class WebStoreGui extends Language.Gui.WebStoreGui {
*/
private String guiName = "&8WebStore";

/**
* Price format
*/
@Comment({
"Price format",
"{price} for original price (e.g. 10.00 USD)",
"{rawPrice} for raw price (e.g. 10.00)"
})
private String priceFormat = "{price}";

/**
* Discounted price format
*/
@Comment({
"Discounted price format",
"{price} for original price (e.g. 10.00 USD)",
"{rawPrice} for raw price (e.g. 10.00)",
"{discountedPrice} for discounted price (e.g. 5.00 USD)",
"{rawDiscountedPrice} for raw discounted price (e.g. 5.00)"
})
private String discountedPriceFormat = "&c&m{price}&r &a{discountedPrice}";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,24 @@ public static class WebStoreGui extends Language.Gui.WebStoreGui {
*/
private String guiName = "&8Site Market";

/**
* Price format
*/
@Comment({
"Fiyat: {price} (örn. 10.00 TL)",
"Ham Fiyat: {rawPrice} (örn. 10.00)"
})
private String priceFormat = "{price}";

/**
* Discounted price format
*/
@Comment({
"İndirimsiz Fiyat: {price} (örn. 10.00 TL)",
"Ham İndirimsiz Fiyat: {rawPrice} (örn. 10.00)",
"İndirimli Fiyat: {discountedPrice} (örn. 5.00 TL)",
"Ham İndirimli Fiyat: {rawDiscountedPrice} (örn. 5.00)",
})
private String discountedPriceFormat = "&c&m{price}&r &a{discountedPrice}";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ public ItemStack getProductIcon() {
hasDiscount = true;

int discountAmount = (int) (((getPrice() - getDiscountedPrice()) / getPrice()) * 100);
// Formatters of price
String priceFormat = Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getPriceFormat()
.replace("{price}", String.valueOf(priceText))
.replace("{rawPrice}", String.valueOf(price));
// Formatters of discount
String discountedPriceFormat = Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getDiscountedPriceFormat()
.replace("{price}", String.valueOf(priceText))
.replace("{discountedPrice}", String.valueOf(discountedPriceText));
.replace("{rawPrice}", String.valueOf(price))
.replace("{discountedPrice}", String.valueOf(discountedPriceText))
.replace("{rawDiscountedPrice}", String.valueOf(discountedPrice));
String discountAmountFormat = Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getDiscountAmountFormat()
.replace("{discount}", String.valueOf(discountAmount));
String stockUnlimited = Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getStockUnlimited();
Expand All @@ -183,7 +189,7 @@ public ItemStack getProductIcon() {
else {
displayName = displayName.replace("%discount_amount%", "");
lore = getProductLore().stream().map(key -> key.replace("%discount_amount%" , "")
.replace("%price%", String.valueOf(priceText))).collect(Collectors.toList());
.replace("%price%", priceFormat)).collect(Collectors.toList());
}

// Stock calculation for gui item
Expand Down

0 comments on commit cffea76

Please sign in to comment.