diff --git a/.gradle/8.8/checksums/checksums.lock b/.gradle/8.8/checksums/checksums.lock index 018a90c..4c7af81 100644 Binary files a/.gradle/8.8/checksums/checksums.lock and b/.gradle/8.8/checksums/checksums.lock differ diff --git a/.gradle/8.8/executionHistory/executionHistory.bin b/.gradle/8.8/executionHistory/executionHistory.bin index e2a4374..9e422a2 100644 Binary files a/.gradle/8.8/executionHistory/executionHistory.bin and b/.gradle/8.8/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.8/executionHistory/executionHistory.lock b/.gradle/8.8/executionHistory/executionHistory.lock index dec2951..7f63d3c 100644 Binary files a/.gradle/8.8/executionHistory/executionHistory.lock and b/.gradle/8.8/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.8/fileHashes/fileHashes.bin b/.gradle/8.8/fileHashes/fileHashes.bin index 985a532..fc795c5 100644 Binary files a/.gradle/8.8/fileHashes/fileHashes.bin and b/.gradle/8.8/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.8/fileHashes/fileHashes.lock b/.gradle/8.8/fileHashes/fileHashes.lock index 909d20a..e7eccfa 100644 Binary files a/.gradle/8.8/fileHashes/fileHashes.lock and b/.gradle/8.8/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.8/fileHashes/resourceHashesCache.bin b/.gradle/8.8/fileHashes/resourceHashesCache.bin index ebf5e33..89dd9d2 100644 Binary files a/.gradle/8.8/fileHashes/resourceHashesCache.bin and b/.gradle/8.8/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index ad0f248..76253d0 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/build/classes/java/main/CoswayUtil/BlockShop.class b/build/classes/java/main/CoswayUtil/BlockShop.class index 69c5447..2691484 100644 Binary files a/build/classes/java/main/CoswayUtil/BlockShop.class and b/build/classes/java/main/CoswayUtil/BlockShop.class differ diff --git a/build/resources/main/config.yml b/build/resources/main/config.yml index bb013c2..7339d20 100644 --- a/build/resources/main/config.yml +++ b/build/resources/main/config.yml @@ -12,5 +12,6 @@ shop: material: OAK_PLANKS price: 15 display_name: "Oak Planks" +poor: "you're poor..." pagination: max_items_per_page: 45 # Max items to display per page diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/BlockShop.class.uniqueId3 b/build/tmp/compileJava/compileTransaction/stash-dir/BlockShop.class.uniqueId3 index ae52114..f018027 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/BlockShop.class.uniqueId3 and b/build/tmp/compileJava/compileTransaction/stash-dir/BlockShop.class.uniqueId3 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 deleted file mode 100644 index aee7c6b..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 deleted file mode 100644 index 3f4018d..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 and /dev/null differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 063efea..304a6eb 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/CoswayUtil/BlockShop.java b/src/main/java/CoswayUtil/BlockShop.java index ef87a31..ed6f39e 100644 --- a/src/main/java/CoswayUtil/BlockShop.java +++ b/src/main/java/CoswayUtil/BlockShop.java @@ -164,27 +164,59 @@ public class BlockShop implements Listener { ItemStack clickedItem = event.getCurrentItem(); if (clickedItem != null && clickedItem.getType() != Material.AIR) { double price = getPrice(clickedItem); - if (economy.has(player, price)) { - economy.withdrawPlayer(player, price); - // Create a new ItemStack with the default meta - ItemStack sold = new ItemStack(clickedItem.getType(), clickedItem.getAmount()); - - // Reset item meta (default name, no lore) - ItemMeta defaultMeta = sold.getItemMeta(); - if (defaultMeta != null) { - defaultMeta.setDisplayName(null); // Reset to default name - defaultMeta.setLore(null); // Remove lore - sold.setItemMeta(defaultMeta); - } - player.getInventory().addItem(sold); - player.sendMessage(ChatColor.GREEN + "You bought " + sold.getType() + " for $" + price); - } else { - player.sendMessage(ChatColor.RED + "You don't have enough money to buy this."); + if (!economy.has(player, price)) { + player.sendMessage(ChatColor.RED + getConfigLine("poor", "You don't have enough money to buy this.")); + return; } + + // Create a new ItemStack with the default meta + ItemStack sold = new ItemStack(clickedItem.getType(), clickedItem.getAmount()); + + // Reset item meta (default name, no lore) + ItemMeta defaultMeta = sold.getItemMeta(); + if (defaultMeta != null) { + defaultMeta.setDisplayName(null); // Reset to default name + defaultMeta.setLore(null); // Remove lore + sold.setItemMeta(defaultMeta); + } + + // Check if player's inventory has space before proceeding + HashMap leftover = player.getInventory().addItem(sold); + if (!leftover.isEmpty()) { + // If there are leftover items, inventory is full + player.sendMessage(ChatColor.RED + getConfigLine("inventory_full", "Your inventory is full! Purchase failed.")); + return; + } + + // If inventory had space, finalize the purchase + economy.withdrawPlayer(player, price); + player.sendMessage(ColorKey("&aYou bought &b" + clickedItem.getAmount() + " &7" + + String.valueOf(sold.getType()).toLowerCase().replace("_", " ") + + "&a for &6$" + price)); } } } + public String ColorKey(String t) { + char searchChar = '&'; // Character to search for + char replacementChar = 'ยง'; // Character to replace with + StringBuilder sb = new StringBuilder(t); + // Search for the character in the StringBuilder + int index = sb.indexOf(String.valueOf(searchChar)); + + // Replace the character if found + for (int j = 0; j < sb.length(); j++) { + if (sb.charAt(j) == searchChar) { + sb.setCharAt(j, replacementChar); + } + } + return sb.toString(); + } + public String getConfigLine(String source, String dfault) { + plugin.reloadConfig(); + return config != null ? config.getString(source, dfault) : dfault; + } + // Helper method to retrieve the price of an item (can be customized to use a config file for prices) private double getPrice(ItemStack item) { for (String category : config.getConfigurationSection("shop.categories").getKeys(false)) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bb013c2..7339d20 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,5 +12,6 @@ shop: material: OAK_PLANKS price: 15 display_name: "Oak Planks" +poor: "you're poor..." pagination: max_items_per_page: 45 # Max items to display per page