Skip to content

Commit

Permalink
3.16.0
Browse files Browse the repository at this point in the history
Fixed an issue where items could not be added to the shop in MC versions prior to 1.20.2.
Modified so that the icon of the balance button can be changed.
Improved the ability to edit item quantity in the Trade UI.
Fixed an issue where new values were not displayed in config.yml even if the plugin was updated.
Change the version of placeholderapi to 2.11.5.
Update worth.yml file.
  • Loading branch information
7sat committed Dec 19, 2023
1 parent 71138bd commit 586dd3f
Show file tree
Hide file tree
Showing 8 changed files with 1,103 additions and 840 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.sat7</groupId>
<artifactId>DynamicShop</artifactId>
<version>3.15.3</version>
<version>3.16.0</version>
<packaging>jar</packaging>

<name>DynamicShop</name>
Expand Down Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/me/sat7/dynamicshop/events/OnChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.sat7.dynamicshop.DynamicShop;
import me.sat7.dynamicshop.DynaShopAPI;
import me.sat7.dynamicshop.files.CustomConfig;
import me.sat7.dynamicshop.guis.StartPage;
import me.sat7.dynamicshop.utilities.ShopUtil;

Expand Down Expand Up @@ -47,6 +48,10 @@ public static void WaitForInput(Player player)
UserUtil.userTempData.put(uuid, "");
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.INPUT_CANCELED"));
} else if (userData.equals("waitforPageDelete") || userData.equals("sellCmd") || userData.equals("buyCmd"))
{
UserUtil.userTempData.put(uuid, "");
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.INPUT_CANCELED"));
} else if (userData.contains("waitForTradeUI"))
{
UserUtil.userTempData.put(uuid, "");
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.INPUT_CANCELED"));
Expand Down Expand Up @@ -111,6 +116,33 @@ public void onPlayerChat(AsyncPlayerChatEvent e)
UserUtil.userTempData.put(uuid, "");
DynaShopAPI.openStartPage(p);
cancelRunnable(p);
} else if (userData.contains("waitForTradeUI"))
{
e.setCancelled(true);

String[] temp = UserUtil.userInteractItem.get(uuid).split("/");
String shopName = temp[0];
String tradeIdx = temp[1];

CustomConfig shopData = ShopUtil.shopConfigFiles.get(shopName);

if (tradeIdx.equals("-1"))
{
shopData.get().set("Options.tradeUI", e.getMessage());
shopData.save();

DynaShopAPI.openShopSettingGui(p, shopName);
}
else
{
shopData.get().set(tradeIdx + ".tradeUI", e.getMessage());
shopData.save();

DynaShopAPI.openItemTradeGui(p, shopName, tradeIdx);
}

UserUtil.userTempData.put(uuid, "");
cancelRunnable(p);
} else if (userData.contains("waitforPageDelete"))
{
e.setCancelled(true);
Expand Down
41 changes: 35 additions & 6 deletions src/main/java/me/sat7/dynamicshop/guis/ItemPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ private void ShowItems()
}
}

public ItemStack getPotionItemStack(Material potionMat, PotionType type, boolean extend, boolean upgraded){
public ItemStack getPotionItemStack_deprecated(Material potionMat, PotionType type, boolean extend, boolean upgraded){
ItemStack potion = new ItemStack(potionMat, 1);
PotionMeta meta = (PotionMeta) potion.getItemMeta();
meta.setBasePotionData(new PotionData(type, extend, upgraded));
potion.setItemMeta(meta);
return potion;
}

public ItemStack getPotionItemStack(Material potionMat, PotionType potionType){
public ItemStack getPotionItemStack_mc1_20_2_or_newer(Material potionMat, PotionType potionType){
ItemStack potion = new ItemStack(potionMat, 1);
PotionMeta meta = (PotionMeta) potion.getItemMeta();
meta.setBasePotionType(potionType);
Expand All @@ -240,12 +240,41 @@ private void SortAllItems()
allItems.add(new ItemStack(m));
}

Material[] potionMat = {Material.POTION, Material.LINGERING_POTION, Material.SPLASH_POTION};
for (Material mat : potionMat)
try
{
for (PotionType pt : PotionType.values())
// 1.20.2 or newer
Material[] potionMat = {Material.POTION, Material.LINGERING_POTION, Material.SPLASH_POTION};
for (Material mat : potionMat)
{
allItems.add(getPotionItemStack(mat, pt));
for (PotionType pt : PotionType.values())
{
allItems.add(getPotionItemStack_mc1_20_2_or_newer(mat, pt));
}
}
}
catch(NoSuchMethodError ignored)
{
Material[] potionMat = {Material.POTION, Material.LINGERING_POTION, Material.SPLASH_POTION};
for (Material mat : potionMat)
{
for (PotionType pt : PotionType.values())
{
if (pt.isExtendable() && pt.isUpgradeable())
{
allItems.add(getPotionItemStack_deprecated(mat, pt, true, false));
allItems.add(getPotionItemStack_deprecated(mat, pt, false, true));
}
else if (pt.isExtendable())
{
allItems.add(getPotionItemStack_deprecated(mat, pt, true, false));
}
else if (pt.isUpgradeable())
{
allItems.add(getPotionItemStack_deprecated(mat, pt, false, true));
}

allItems.add(getPotionItemStack_deprecated(mat, pt, false, false));
}
}
}

Expand Down
121 changes: 95 additions & 26 deletions src/main/java/me/sat7/dynamicshop/guis/ItemTrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.sat7.dynamicshop.DynaShopAPI;
import me.sat7.dynamicshop.constants.Constants;
import me.sat7.dynamicshop.economyhook.PlayerpointHook;
import me.sat7.dynamicshop.events.OnChat;
import me.sat7.dynamicshop.files.CustomConfig;
import me.sat7.dynamicshop.transactions.Buy;
import me.sat7.dynamicshop.transactions.Sell;
Expand Down Expand Up @@ -54,6 +55,8 @@ public ItemTrade()
private String material;
private ItemMeta itemMeta;

private int[] tradeUI_default;

public Inventory getGui(Player player, String shopName, String tradeIdx)
{
this.player = player;
Expand All @@ -71,6 +74,26 @@ public Inventory getGui(Player player, String shopName, String tradeIdx)
uiTitle += t(player, "TRADE_TITLE");
inventory = Bukkit.createInventory(player, 18, uiTitle);

if (shopData.contains("Options.tradeUI"))
{
tradeUI_default = new int[]{1, 2, 4, 8, 16, 32, 64};
try
{
String amountArrayData = shopData.getString("Options.tradeUI");
String[] strArray = amountArrayData.split(",");
int count = Math.min(strArray.length, 7);
for (int i = 0; i < count; i++)
{
tradeUI_default[i] = Integer.parseInt(strArray[i]);
}
}
catch (Exception e)
{
tradeUI_default = null;
DynamicShop.console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + "Data parsing error. ShopName: " + shopName + ", tradeIdx: " + tradeIdx);
}
}

CreateBalanceButton();
CreateSellBuyOnlyToggle();
CreateTradeButtons();
Expand Down Expand Up @@ -155,28 +178,41 @@ public void OnClickUpperInventory(InventoryClickEvent e)
}
} else
{
ItemStack tempIS = new ItemStack(e.getCurrentItem().getType(), e.getCurrentItem().getAmount());
tempIS.setItemMeta((ItemMeta) data.get().get(tradeIdx + ".itemStack"));
if (player.hasPermission(P_ADMIN_SHOP_EDIT) && e.isShiftClick() && e.isRightClick())
{
player.closeInventory();
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "TRADE.WAIT_FOR_INPUT"));

// 무한재고&고정가격
boolean infiniteStock = data.get().getInt(tradeIdx + ".stock") <= 0;
UserUtil.userInteractItem.put(player.getUniqueId(), shopName + "/" + tradeIdx);
UserUtil.userTempData.put(player.getUniqueId(), "waitForTradeUI");

// 배달비 계산
ConfigurationSection optionS = data.get().getConfigurationSection("Options");
if (optionS.contains("world") && optionS.contains("pos1") && optionS.contains("pos2") && optionS.contains("flag.deliverycharge"))
OnChat.WaitForInput(player);
}
else
{
deliveryCharge = ShopUtil.CalcShipping(shopName, player);
if (deliveryCharge == -1)
ItemStack tempIS = new ItemStack(e.getCurrentItem().getType(), e.getCurrentItem().getAmount());
tempIS.setItemMeta((ItemMeta) data.get().get(tradeIdx + ".itemStack"));

// 무한재고&고정가격
boolean infiniteStock = data.get().getInt(tradeIdx + ".stock") <= 0;

// 배달비 계산
ConfigurationSection optionS = data.get().getConfigurationSection("Options");
if (optionS.contains("world") && optionS.contains("pos1") && optionS.contains("pos2") && optionS.contains("flag.deliverycharge"))
{
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.DELIVERY_CHARGE_NA")); // 다른 월드로 배달 불가능
return;
deliveryCharge = ShopUtil.CalcShipping(shopName, player);
if (deliveryCharge == -1)
{
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "MESSAGE.DELIVERY_CHARGE_NA")); // 다른 월드로 배달 불가능
return;
}
}
}

if (e.getSlot() <= 10)
Sell(optionS, tempIS, deliveryCharge, infiniteStock);
else
Buy(optionS, tempIS, deliveryCharge, infiniteStock);
if (e.getSlot() <= 10)
Sell(optionS, tempIS, deliveryCharge, infiniteStock);
else
Buy(optionS, tempIS, deliveryCharge, infiniteStock);
}
}
}
}
Expand Down Expand Up @@ -277,10 +313,47 @@ private void CreateTradeButtons(boolean sell)
tradeLimitString = limitString.replace("{num}", String.valueOf(tradeLimitLeft)).replace("{time}", tradeLimitResetTime);
}

int amount = 1;
int[] amountArray;
Material mat = Material.getMaterial(material);
if (tradeUI_default != null)
{
amountArray = tradeUI_default;
}
else
{
if (mat.getMaxStackSize() <= 1)
{
amountArray = new int[]{1, 2, 3, 4, 5, 6, 7};
}
else
{
amountArray = new int[]{1, 2, 4, 8, 16, 32, 64};
}
}

if (shopData.contains(tradeIdx + ".tradeUI"))
{
try
{
String amountArrayData = shopData.getString(tradeIdx + ".tradeUI");
String[] strArray = amountArrayData.split(",");
int count = Math.min(strArray.length, 7);
for (int i = 0; i < count; i++)
{
amountArray[i] = Integer.parseInt(strArray[i]);
}
}
catch (Exception e)
{
//DynamicShop.console.sendMessage(Constants.DYNAMIC_SHOP_PREFIX + "Data parsing error. ShopName: " + shopName + ", tradeIdx: " + tradeIdx);
}
}

int idx = sell ? 2 : 11;
for (int i = 1; i < 8; i++)
{
int amount = Math.min(64, amountArray[i - 1]);

ItemStack itemStack = new ItemStack(Material.getMaterial(material), amount);
itemStack.setItemMeta((ItemMeta) shopData.get(tradeIdx + ".itemStack"));
ItemMeta meta = itemStack.getItemMeta();
Expand Down Expand Up @@ -400,6 +473,11 @@ else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP))
String tradeLoreText = sell ? t(player, "TRADE.CLICK_TO_SELL") : t(player, "TRADE.CLICK_TO_BUY");
tradeLoreText = tradeLoreText.replace("{amount}", n(amount));

if (player.hasPermission(P_ADMIN_SHOP_EDIT))
{
tradeLoreText += "\n" + t(player, "TRADE.QUANTITY_LORE");
}

lore = lore.replace("{\\nPrice}", priceText.isEmpty() ? "" : "\n" + priceText);
lore = lore.replace("{\\nStock}", stockText.isEmpty() ? "" : "\n" + stockText);
lore = lore.replace("{\\nDeliveryCharge}", deliveryChargeText.isEmpty() ? "" : "\n" + deliveryChargeText);
Expand All @@ -420,15 +498,6 @@ else if (ShopUtil.GetCurrency(shopData).equalsIgnoreCase(Constants.S_EXP))
inventory.setItem(idx, itemStack);

idx++;

if(itemStack.getMaxStackSize() <= 1)
{
amount++;
}
else
{
amount = amount * 2;
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/me/sat7/dynamicshop/guis/ShopSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public ShopSettings()
private final int LOG_PRINT_CONSOLE = 52;
private final int LOG_PRINT_ADMIN = 53;

private final int TRADE_UI_SETTING = 36;

private final int CLOSE = 45;

private String shopName;
Expand Down Expand Up @@ -366,6 +368,12 @@ public Inventory getGui(Player player, String shopName)
logLore_3.add("§e" + t(player, "LMB") + ": " + (printToAdminActive ? t(player, "OFF") : t(player, "ON")));
CreateButton(LOG_PRINT_ADMIN, printToAdminActive ? Material.GREEN_STAINED_GLASS_PANE : Material.BLACK_STAINED_GLASS_PANE, t(player, "SHOP_SETTING.LOG_PRINT_ADMIN"), logLore_3);

// 거래 UI 설정
ArrayList<String> tradeUILore = new ArrayList<>();
tradeUILore.add("§9" + t(null, "CUR_STATE") + ": " + (confSec_Options.contains("tradeUI") ? confSec_Options.get("tradeUI") : t(player,"NULL")));
tradeUILore.add(t(player, "SHOP_SETTING.TRADE_UI_LORE"));
CreateButton(TRADE_UI_SETTING, Material.EMERALD, t(player, "SHOP_SETTING.TRADE_UI"), tradeUILore);

return inventory;
}

Expand Down Expand Up @@ -908,6 +916,26 @@ else if (e.getSlot() == CURRENCY_PP)
}
DynaShopAPI.openShopSettingGui(player, shopName);
}
else if (e.getSlot() == TRADE_UI_SETTING)
{
if (e.isLeftClick())
{
player.closeInventory();
player.sendMessage(DynamicShop.dsPrefix(player) + t(player, "TRADE.WAIT_FOR_INPUT"));

UserUtil.userInteractItem.put(player.getUniqueId(), shopName + "/-1");
UserUtil.userTempData.put(player.getUniqueId(), "waitForTradeUI");

OnChat.WaitForInput(player);
}
if (e.isRightClick())
{
data.get().set("Options.tradeUI", null);
data.save();

DynaShopAPI.openShopSettingGui(player, shopName);
}
}
}

private void CreateFlagButton(int buttonPosition, boolean isEnable, String title, String lore)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/sat7/dynamicshop/utilities/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static void Load()
DynamicShop.plugin.reloadConfig();

config = DynamicShop.plugin.getConfig();
config.options().copyDefaults(true);

try
{
Expand All @@ -71,6 +72,7 @@ public static void Load()
ValidateAndApply();
SetConfigVersion(ConfigUtil.PluginConfigVersion);
Save();

}

public static void Save()
Expand Down
Loading

0 comments on commit 586dd3f

Please sign in to comment.