diff --git a/.gradle/8.8/executionHistory/executionHistory.bin b/.gradle/8.8/executionHistory/executionHistory.bin index b7831c2..e2a4374 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 f69b781..dec2951 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 ebdba6e..985a532 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 a2991c4..909d20a 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 5074027..ebf5e33 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 d4db409..ad0f248 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/build/classes/java/main/CoswayUtil/BlockShop$1.class b/build/classes/java/main/CoswayUtil/BlockShop$1.class deleted file mode 100644 index 2cc3373..0000000 Binary files a/build/classes/java/main/CoswayUtil/BlockShop$1.class and /dev/null differ diff --git a/build/classes/java/main/CoswayUtil/BlockShop.class b/build/classes/java/main/CoswayUtil/BlockShop.class index 40758bb..69c5447 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 e835f72..bb013c2 100644 --- a/build/resources/main/config.yml +++ b/build/resources/main/config.yml @@ -1,34 +1,16 @@ -# config.yml - shop: categories: - - name: "Building Blocks" + stone_blocks: items: - - material: "STONE" - price: 1 - display_name: "Stone" - - material: "WOOD" - price: 2 - display_name: "Wood" - - material: "BRICK" - price: 3 - display_name: "Brick" - - name: "Decorative Blocks" - items: - - material: "LANTERN" - price: 5 - display_name: "Lantern" - - material: "PAINTING" + stone: + material: STONE price: 10 - display_name: "Painting" - - name: "Tools" + display_name: "Stone Block" + wood_blocks: items: - - material: "WOODEN_SWORD" - price: 10 - display_name: "Wooden Sword" - - material: "IRON_SWORD" - price: 20 - display_name: "Iron Sword" - + oak_planks: + material: OAK_PLANKS + price: 15 + display_name: "Oak Planks" 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 new file mode 100644 index 0000000..ae52114 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/BlockShop.class.uniqueId3 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId8 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId0 similarity index 93% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId8 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId0 index 06db858..371af4c 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId8 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$1.class.uniqueId0 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId19 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 similarity index 91% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId19 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 index 3673042..aee7c6b 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId19 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$1.class.uniqueId8 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId10 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId2 similarity index 93% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId10 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId2 index 8ff578a..f38429d 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId10 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$2.class.uniqueId2 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$3.class.uniqueId5 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$3.class.uniqueId5 index 672e6d8..30408e1 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$3.class.uniqueId5 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$3.class.uniqueId5 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId3 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId4 similarity index 92% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId3 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId4 index 009949e..ed4b3e7 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId3 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield$4.class.uniqueId4 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId14 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 similarity index 88% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId14 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 index 6fd1018..3f4018d 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId14 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil$AnchorShield.class.uniqueId7 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId9 b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId1 similarity index 56% rename from build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId9 rename to build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId1 index 220d6ea..a5dc176 100644 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId9 and b/build/tmp/compileJava/compileTransaction/stash-dir/CoswayUtil.class.uniqueId1 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/GiveWandCommand.class.uniqueId15 b/build/tmp/compileJava/compileTransaction/stash-dir/GiveWandCommand.class.uniqueId15 deleted file mode 100644 index 5746ceb..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/GiveWandCommand.class.uniqueId15 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/GravityGauntlet.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/GravityGauntlet.class.uniqueId0 deleted file mode 100644 index d11403e..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/GravityGauntlet.class.uniqueId0 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand$1.class.uniqueId2 b/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand$1.class.uniqueId2 deleted file mode 100644 index b7b9dbf..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand$1.class.uniqueId2 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand.class.uniqueId11 b/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand.class.uniqueId11 deleted file mode 100644 index af0dcbb..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/MobLevitationWand.class.uniqueId11 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge$1.class.uniqueId16 b/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge$1.class.uniqueId16 deleted file mode 100644 index b8ab886..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge$1.class.uniqueId16 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge.class.uniqueId17 b/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge.class.uniqueId17 deleted file mode 100644 index eff2eda..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/PhantomDodge.class.uniqueId17 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/ShadowStep.class.uniqueId12 b/build/tmp/compileJava/compileTransaction/stash-dir/ShadowStep.class.uniqueId12 deleted file mode 100644 index b63243a..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/ShadowStep.class.uniqueId12 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$1.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$1.class.uniqueId1 deleted file mode 100644 index 1d9a4fa..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$1.class.uniqueId1 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$2.class.uniqueId4 b/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$2.class.uniqueId4 deleted file mode 100644 index ef78745..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract$2.class.uniqueId4 and /dev/null differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract.class.uniqueId18 b/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract.class.uniqueId18 deleted file mode 100644 index 6ce948a..0000000 Binary files a/build/tmp/compileJava/compileTransaction/stash-dir/WitherContract.class.uniqueId18 and /dev/null differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 02bb6ab..063efea 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 15f18fd..ef87a31 100644 --- a/src/main/java/CoswayUtil/BlockShop.java +++ b/src/main/java/CoswayUtil/BlockShop.java @@ -2,6 +2,7 @@ package CoswayUtil; import net.milkbowl.vault.economy.Economy; import org.bukkit.*; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.*; @@ -17,7 +18,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; public class BlockShop implements Listener { - private JavaPlugin plugin; + private static JavaPlugin plugin; private final Economy economy; private static FileConfiguration config; @@ -26,6 +27,7 @@ public class BlockShop implements Listener { public BlockShop(JavaPlugin plugin, Economy economy) { this.plugin = plugin; this.economy = economy; + config = plugin.getConfig(); // Fix: Initialize config properly } // Method to create the special book (or other item) to open the shop @@ -39,18 +41,25 @@ public class BlockShop implements Listener { return item; } - - - public void ShopGUI(JavaPlugin plugin) { - this.plugin = plugin; - config = plugin.getConfig(); - } - public static void openShop(Player player, int page) { - Inventory shopInventory = Bukkit.createInventory(null, 54, "Shop"); + reloadShopConfig(); + Inventory shopInventory = Bukkit.createInventory(null, 54, ChatColor.GREEN+"Block Shop"); // Get the categories from the config - List categories = config.getStringList("shop.categories"); + if (config == null) { + player.sendMessage(ChatColor.RED + "Shop configuration is missing."); + return; + } + + ConfigurationSection categoriesSection = config.getConfigurationSection("shop.categories"); + ConfigurationSection Conf = config.getConfigurationSection("shop"); + if (categoriesSection == null) { + player.sendMessage(ChatColor.RED + "No categories found in the shop."); + player.sendMessage(ChatColor.AQUA + "" + Conf); + return; + } + + Set categories = categoriesSection.getKeys(false); int maxItemsPerPage = config.getInt("pagination.max_items_per_page"); int startIndex = (page - 1) * maxItemsPerPage; int endIndex = startIndex + maxItemsPerPage; @@ -62,8 +71,18 @@ public class BlockShop implements Listener { // Calculate the correct number of items for pagination for (int i = startIndex; i < endIndex && i < items.size(); i++) { ItemStack item = items.get(i); + + // Get the item key from config based on index + String itemKey = new ArrayList<>(config.getConfigurationSection("shop.categories." + categoryName + ".items").getKeys(false)).get(i); + + // Retrieve the quantity from the config + int quantity = config.getInt("shop.categories." + categoryName + ".items." + itemKey + ".quantity", 64); // Default 64 if missing + + // Set the correct stack size + item.setAmount(quantity); shopInventory.addItem(item); } + } // Show inventory to the player @@ -71,27 +90,32 @@ public class BlockShop implements Listener { } private static List loadItemsFromCategory(String category) { - List items = new ArrayList<>(); + List items = new ArrayList<>(); // Correct variable name // Load items for the category from the config - List itemList = config.getStringList("shop.categories." + category + ".items"); + ConfigurationSection itemSection = config.getConfigurationSection("shop.categories." + category + ".items"); + if (itemSection == null) { + return items; + } - for (String item : itemList) { - String materialName = config.getString("shop.categories." + category + ".items." + item + ".material"); - Material material = Material.getMaterial(materialName.toUpperCase()); - int price = config.getInt("shop.categories." + category + ".items." + item + ".price"); - String displayName = config.getString("shop.categories." + category + ".items." + item + ".display_name"); + for (String itemKey : itemSection.getKeys(false)) { + String materialName = config.getString("shop.categories." + category + ".items." + itemKey + ".material"); + int price = config.getInt("shop.categories." + category + ".items." + itemKey + ".price"); + String displayName = config.getString("shop.categories." + category + ".items." + itemKey + ".display_name"); - if (material != null) { - ItemStack itemStack = new ItemStack(material); - ItemMeta meta = itemStack.getItemMeta(); - if (meta != null) { - meta.setDisplayName(displayName); - List lore = new ArrayList<>(); - lore.add(ChatColor.GOLD + "Price: " + price + " coins"); - meta.setLore(lore); - itemStack.setItemMeta(meta); - items.add(itemStack); + if (materialName != null) { + Material material = Material.matchMaterial(materialName.toUpperCase()); + if (material != null) { + ItemStack itemStack = new ItemStack(material); + ItemMeta meta = itemStack.getItemMeta(); + if (meta != null) { + meta.setDisplayName(ChatColor.GREEN + (displayName != null ? displayName : "Unnamed Item")); + List lore = new ArrayList<>(); + lore.add(ChatColor.GOLD + "Price: $" + price); + meta.setLore(lore); + itemStack.setItemMeta(meta); + items.add(itemStack); + } } } } @@ -99,6 +123,11 @@ public class BlockShop implements Listener { return items; } + public static void reloadShopConfig() { + plugin.reloadConfig(); // Reloads config from disk + config = plugin.getConfig(); // Reassign the updated config + } + // Helper method to add items to the shop private void addItemToShop(Inventory shop, Material material, String displayName, double price) { ItemStack item = new ItemStack(material); @@ -129,7 +158,7 @@ public class BlockShop implements Listener { Player player = (Player) event.getWhoClicked(); InventoryView clickedInventory = event.getWhoClicked().getOpenInventory(); - if (clickedInventory.getTitle().equals(ChatColor.DARK_GREEN + "Block Shop")) { + if (clickedInventory.getTitle().equals(ChatColor.GREEN + "Block Shop")) { event.setCancelled(true); // Prevent item from being moved ItemStack clickedItem = event.getCurrentItem(); @@ -137,10 +166,20 @@ public class BlockShop implements Listener { double price = getPrice(clickedItem); if (economy.has(player, price)) { economy.withdrawPlayer(player, price); - player.getInventory().addItem(clickedItem); - player.sendMessage(ChatColor.GREEN + "You bought " + clickedItem.getType() + " for " + price + " currency."); + // 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 currency to buy this."); + player.sendMessage(ChatColor.RED + "You don't have enough money to buy this."); } } } @@ -148,16 +187,21 @@ public class BlockShop implements Listener { // 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 simplicity, we assign prices based on material name, you can use a config file for more flexibility - switch (item.getType()) { - case STONE: return 10; - case DIRT: return 5; - case OAK_PLANKS: return 15; - case BRICKS: return 20; - default: return 0; + for (String category : config.getConfigurationSection("shop.categories").getKeys(false)) { + ConfigurationSection itemsSection = config.getConfigurationSection("shop.categories." + category + ".items"); + if (itemsSection != null) { + for (String itemKey : itemsSection.getKeys(false)) { + String materialName = config.getString("shop.categories." + category + ".items." + itemKey + ".material"); + if (materialName != null && item.getType() == Material.matchMaterial(materialName.toUpperCase())) { + return config.getDouble("shop.categories." + category + ".items." + itemKey + ".price", 0); + } + } + } } + return 0; // Default to 0 if no price is found } + // Register the block shop commands and events public void register() { plugin.getServer().getPluginManager().registerEvents(this, plugin); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e835f72..bb013c2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,34 +1,16 @@ -# config.yml - shop: categories: - - name: "Building Blocks" + stone_blocks: items: - - material: "STONE" - price: 1 - display_name: "Stone" - - material: "WOOD" - price: 2 - display_name: "Wood" - - material: "BRICK" - price: 3 - display_name: "Brick" - - name: "Decorative Blocks" - items: - - material: "LANTERN" - price: 5 - display_name: "Lantern" - - material: "PAINTING" + stone: + material: STONE price: 10 - display_name: "Painting" - - name: "Tools" + display_name: "Stone Block" + wood_blocks: items: - - material: "WOODEN_SWORD" - price: 10 - display_name: "Wooden Sword" - - material: "IRON_SWORD" - price: 20 - display_name: "Iron Sword" - + oak_planks: + material: OAK_PLANKS + price: 15 + display_name: "Oak Planks" pagination: max_items_per_page: 45 # Max items to display per page