### Hooking into ShopGUI+ using ShopGUIPlusPostEnableEvent (Java) Source: https://github.com/brcdev-minecraft/shopgui-api/blob/master/README.md This code snippet demonstrates the recommended way to hook into ShopGUI+ by listening for the ShopGUIPlusPostEnableEvent. This ensures that your custom item providers or other API integrations are registered after ShopGUI+ has fully initialized, preventing potential NullPointerExceptions. The example shows how to register an item provider, but the pattern can be adapted for other API functionalities. ```java import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import com.brcdev.shopguiplus.api.events.ShopGUIPlusPostEnableEvent; import com.brcdev.shopguiplus.api.ShopGuiPlusApi; public class YourPlugin extends JavaPlugin { @Override public void onEnable() { // Do not hook directly here } @EventHandler public void onShopGUIPlusPostEnable(ShopGUIPlusPostEnableEvent event) { // Safely register your API implementations here ShopGuiPlusApi.registerItemProvider(...); // Example:getLogger().info("ShopGUI+ has post-enabled. Registering custom items."); } } ``` -------------------------------- ### Open Main Shop Menu (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Opens the main shop GUI for a player. This functionality requires the ShopGUI+ plugin to be installed and requires player data to be loaded. It throws a PlayerDataNotLoadedException if the player's data is not yet ready. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; public class ShopMenuHandler implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); try { // Open the main shop menu ShopGuiPlusApi.openMainMenu(player); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cYour player data is not loaded yet. Please try again."); } } } ``` -------------------------------- ### Register Custom Economy Provider with ShopGUI+ (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt This snippet shows how to register a custom economy provider for ShopGUI+. It listens for the `ShopGUIPlusPostEnableEvent` and then registers an instance of `TokenEconomyProvider` using `ShopGuiPlusApi.registerEconomyProvider()`. The `TokenEconomyProvider` itself implements methods for getting balance, depositing, withdrawing, and checking if a player has sufficient funds. Dependencies include ShopGUI+ API and Bukkit API. The input is a `Player` object and a `double` amount, and the output is primarily UI feedback to the player and internal balance updates. This implementation assumes a `TokenDatabase` class exists for managing balances. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.event.ShopGUIPlusPostEnableEvent; import net.brcdev.shopgui.provider.economy.EconomyProvider; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; public class CustomEconomyPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onShopGUIPlusPostEnable(ShopGUIPlusPostEnableEvent event) { // Register economy provider when ShopGUI+ is ready ShopGuiPlusApi.registerEconomyProvider(new TokenEconomyProvider()); getLogger().info("Token economy provider registered with ShopGUI+"); } // Custom economy implementation public class TokenEconomyProvider extends EconomyProvider { public TokenEconomyProvider() { this.currencyPrefix = "§6"; this.currencySuffix = " Tokens"; } @Override public String getName() { return "TokenEconomy"; } @Override public double getBalance(Player player) { // Retrieve player's token balance from your system return getTokenDatabase().getBalance(player.getUniqueId()); } @Override public void deposit(Player player, double amount) { double currentBalance = getBalance(player); getTokenDatabase().setBalance(player.getUniqueId(), currentBalance + amount); player.sendMessage("§a+" + amount + " tokens!"); } @Override public void withdraw(Player player, double amount) { double currentBalance = getBalance(player); if (has(player, amount)) { getTokenDatabase().setBalance(player.getUniqueId(), currentBalance - amount); player.sendMessage("§c-" + amount + " tokens!"); } } @Override public boolean has(Player player, double amount) { return getBalance(player) >= amount; } private TokenDatabase getTokenDatabase() { // Return your token database instance return TokenDatabase.getInstance(); } } } ``` -------------------------------- ### Get Buy and Sell Prices for Items Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Retrieves the buy and sell prices for ItemStacks with player-specific price modifiers applied. ```APIDOC ## Get Buy and Sell Prices for Items ### Description Retrieves the buy and sell prices for ItemStacks with player-specific price modifiers applied. ### Method `public static double getItemStackPriceBuy(Player player, ItemStack itemStack)` `public static double getItemStackPriceSell(Player player, ItemStack itemStack)` `public static ShopItem getItemStackShopItem(Player player, ItemStack itemStack)` ### Endpoint N/A (Java method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.shop.item.ShopItem; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; // Assuming 'player' is an instance of org.bukkit.entity.Player ItemStack diamond = new ItemStack(Material.DIAMOND, 1); // Get buy price (includes player-specific modifiers) double buyPrice = ShopGuiPlusApi.getItemStackPriceBuy(player, diamond); // Get sell price (includes player-specific modifiers) double sellPrice = ShopGuiPlusApi.getItemStackPriceSell(player, diamond); if (buyPrice >= 0) { player.sendMessage("§aBuy price: $" + String.format("%.2f", buyPrice)); } else { player.sendMessage("§cThis item cannot be bought from the shop."); } if (sellPrice >= 0) { player.sendMessage("§aSell price: $" + String.format("%.2f", sellPrice)); } else { player.sendMessage("§cThis item cannot be sold to the shop."); } // Get the ShopItem details ShopItem shopItem = ShopGuiPlusApi.getItemStackShopItem(player, diamond); if (shopItem != null) { player.sendMessage("§7Found in shop: " + shopItem.getShop().getName()); player.sendMessage("§7Item ID: " + shopItem.getId()); } ``` ### Response #### Success Response (200) - **buyPrice** (double) - The buy price of the item, or -1 if it cannot be bought. - **sellPrice** (double) - The sell price of the item, or -1 if it cannot be sold. - **shopItem** (ShopItem) - Details about the item within the shop, or null if not found. #### Response Example ```json { "buyPrice": 100.50, "sellPrice": 80.25, "shopItem": { "shop": "ExampleShop", "id": "DiamondItem" } } ``` ``` -------------------------------- ### Get Item Buy/Sell Prices (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Retrieves the buy and sell prices for a given ItemStack for a specific player, including any applicable player-specific price modifiers. It also provides access to the ShopItem details if the item is found within a shop. Requires player data to be loaded. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.shop.item.ShopItem; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class PriceChecker { public void displayItemPrices(Player player, ItemStack itemStack) { // Get buy price (includes player-specific modifiers) double buyPrice = ShopGuiPlusApi.getItemStackPriceBuy(player, itemStack); // Get sell price (includes player-specific modifiers) double sellPrice = ShopGuiPlusApi.getItemStackPriceSell(player, itemStack); if (buyPrice >= 0) { player.sendMessage("§aBuy price: $" + String.format("%.2f", buyPrice)); } else { player.sendMessage("§cThis item cannot be bought from the shop."); } if (sellPrice >= 0) { player.sendMessage("§aSell price: $" + String.format("%.2f", sellPrice)); } else { player.sendMessage("§cThis item cannot be sold to the shop."); } // Get the ShopItem details ShopItem shopItem = ShopGuiPlusApi.getItemStackShopItem(player, itemStack); if (shopItem != null) { player.sendMessage("§7Found in shop: " + shopItem.getShop().getName()); player.sendMessage("§7Item ID: " + shopItem.getId()); } } public void checkDiamondPrice(Player player) { ItemStack diamond = new ItemStack(Material.DIAMOND, 1); displayItemPrices(player, diamond); } } ``` -------------------------------- ### Open Main Shop Menu Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Opens the main shop GUI to a specific player, displaying all available shops. ```APIDOC ## Open Main Shop Menu ### Description Opens the main shop GUI to a specific player, displaying all available shops. ### Method `public static void openMainMenu(Player player)` ### Endpoint N/A (Java method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import org.bukkit.entity.Player; // Assuming 'player' is an instance of org.bukkit.entity.Player try { ShopGuiPlusApi.openMainMenu(player); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cYour player data is not loaded yet. Please try again."); } ``` ### Response #### Success Response (200) N/A (void method) #### Response Example None ``` -------------------------------- ### Check Shop and Player Data Status in Java Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt This Java snippet demonstrates how to check if ShopGUI+ shops are loaded and if player data is ready before attempting to open a shop or display player-specific shop data. It ensures that essential ShopGUI+ components are initialized to prevent null pointer exceptions. ```java import net.brcdev.shopgui.ShopGuiPlugin; import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.player.PlayerData; import net.brcdev.shopgui.shop.Shop; import net.brcdev.shopgui.shop.ShopManager; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class ShopStatusChecker extends JavaPlugin { public void checkAndOpenShop(Player player, String shopId) { // Get ShopGUI+ instance ShopGuiPlugin shopGuiPlugin = ShopGuiPlusApi.getPlugin(); ShopManager shopManager = shopGuiPlugin.getShopManager(); // Check if shops are loaded if (!shopManager.areShopsLoaded()) { player.sendMessage("§cShops are still loading. Please wait..."); return; } // Check if player data is loaded if (!shopGuiPlugin.getPlayerManager().isPlayerLoaded(player)) { player.sendMessage("§cYour player data is still loading. Please wait..."); return; } // Get the shop Shop shop = ShopGuiPlusApi.getShop(shopId); if (shop == null) { player.sendMessage("§cShop not found: " + shopId); return; } // Open the shop try { ShopGuiPlusApi.openShop(player, shopId, 1); player.sendMessage("§aOpening " + shop.getName()); } catch (Exception e) { player.sendMessage("§cFailed to open shop: " + e.getMessage()); } } public void displayPlayerShopData(Player player) { ShopGuiPlugin plugin = ShopGuiPlusApi.getPlugin(); if (!plugin.getPlayerManager().isPlayerLoaded(player)) { player.sendMessage("§cYour data is not loaded yet."); return; } PlayerData playerData = plugin.getPlayerManager().getPlayerData(player); player.sendMessage("§7=== Your Shop Data ==="); player.sendMessage("§7UUID: " + playerData.getId()); player.sendMessage("§7Name: " + playerData.getName()); player.sendMessage("§7Has Open GUI: " + playerData.hasOpenGui()); } } ``` -------------------------------- ### Monitor Shop Transactions with Pre and Post Event Handlers (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt This Java code snippet demonstrates how to implement listeners for ShopGUI+'s pre and post transaction events. It allows for validation, logging, dynamic pricing adjustments, and handling of transaction outcomes. Requires the ShopGUI+ API and a Bukkit/Spigot server environment. ```java import net.brcdev.shopgui.event.ShopPreTransactionEvent; import net.brcdev.shopgui.event.ShopPostTransactionEvent; import net.brcdev.shopgui.shop.ShopTransactionResult; import net.brcdev.shopgui.shop.item.ShopItem; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; public class TransactionLogger extends JavaPlugin implements Listener { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler(priority = EventPriority.HIGH) public void onShopPreTransaction(ShopPreTransactionEvent event) { Player player = event.getPlayer(); ShopItem shopItem = event.getShopItem(); int amount = event.getAmount(); double price = event.getPrice(); // Log the attempted transaction getLogger().info(String.format( "Player %s attempting to %s %dx %s for $%.2f", player.getName(), event.getShopAction().toString().toLowerCase(), amount, shopItem.getId(), price )); // Example: Block purchases of specific items during events if (shopItem.getId().equals("rare_item") && isSpecialEventActive()) { event.setCancelled(true); player.sendMessage("§cThis item cannot be purchased during special events!"); return; } // Example: Apply dynamic pricing if (player.hasPermission("shop.premium")) { double discountedPrice = price * 0.9; event.setPrice(discountedPrice); player.sendMessage("§aPremium discount applied!"); } } @EventHandler(priority = EventPriority.MONITOR) public void onShopPostTransaction(ShopPostTransactionEvent event) { ShopTransactionResult result = event.getResult(); if (result.getResult() == ShopTransactionResult.ShopTransactionResultType.SUCCESS) { // Log successful transaction getLogger().info(String.format( "SUCCESS: %s %s %dx %s for $%.2f", result.getPlayer().getName(), result.getShopAction().toString().toLowerCase(), result.getAmount(), result.getShopItem().getId(), result.getPrice() )); // Award loyalty points awardLoyaltyPoints(result.getPlayer(), result.getPrice()); } else { // Log failed transaction getLogger().warning(String.format( "FAILED: %s attempted %s - Reason: %s", result.getPlayer().getName(), result.getShopAction().toString().toLowerCase(), result.getResult().toString() )); // Send appropriate error message handleTransactionFailure(result); } } private boolean isSpecialEventActive() { // Check if special event is running return false; } private void awardLoyaltyPoints(Player player, double transactionValue) { int points = (int) (transactionValue / 10); // Award points to player player.sendMessage("§e+§6" + points + " loyalty points!"); } private void handleTransactionFailure(ShopTransactionResult result) { Player player = result.getPlayer(); switch (result.getResult()) { case FAILURE_NO_MONEY: player.sendMessage("§cInsufficient funds! You need $" + result.getPrice()); break; case FAILURE_NO_ITEMS: player.sendMessage("§cYou don't have enough items to sell!"); break; case FAILURE_FULL_INVENTORY: player.sendMessage("§cYour inventory is full!"); break; default: player.sendMessage("§cTransaction failed: " + result.getResult().toString()); } } } ``` -------------------------------- ### Open Specific Shop by ID Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Opens a specific shop GUI to a player with pagination support. ```APIDOC ## Open Specific Shop by ID ### Description Opens a specific shop GUI to a player with pagination support. ### Method `public static void openShop(Player player, String shopId, int page)` ### Endpoint N/A (Java method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import org.bukkit.entity.Player; // Assuming 'player' is an instance of org.bukkit.entity.Player String shopId = "exampleShop"; int page = 1; try { ShopGuiPlusApi.openShop(player, shopId, page); player.sendMessage("§aOpening shop: " + shopId); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cYour data hasn't loaded yet. Please wait a moment."); } catch (NumberFormatException e) { player.sendMessage("§cInvalid page number!"); } ``` ### Response #### Success Response (200) N/A (void method) #### Response Example None ``` -------------------------------- ### Maven Dependency for shopgui-api Source: https://github.com/brcdev-minecraft/shopgui-api/blob/master/README.md This Maven snippet shows how to add the shopgui-api as a dependency to your Spigot plugin project. It includes configuration for the Jitpack repository and specifies the dependency with a 'provided' scope, indicating that the API will be supplied by the ShopGUI+ plugin itself at runtime. ```xml jitpack.io https://jitpack.io com.github.brcdev-minecraft shopgui-api latest provided ``` -------------------------------- ### Open Specific Shop by ID (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Opens a specific shop GUI to a player, identified by its ID. Supports pagination and requires player data to be loaded. Invalid shop IDs or page numbers will result in error messages. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class OpenShopCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("Only players can open shops!"); return true; } Player player = (Player) sender; if (args.length < 1) { player.sendMessage("§cUsage: /openshop [page]"); return true; } String shopId = args[0]; int page = args.length > 1 ? Integer.parseInt(args[1]) : 1; try { ShopGuiPlusApi.openShop(player, shopId, page); player.sendMessage("§aOpening shop: " + shopId); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cYour data hasn't loaded yet. Please wait a moment."); } catch (NumberFormatException e) { player.sendMessage("§cInvalid page number!"); } return true; } } ``` -------------------------------- ### Gradle Dependency for shopgui-api Source: https://github.com/brcdev-minecraft/shopgui-api/blob/master/README.md This Gradle snippet outlines how to include the shopgui-api in your Spigot plugin project. It configures the Jitpack repository and defines the dependency. The `compileOnly` configuration is used, similar to Maven's 'provided' scope, ensuring the API is available during compilation but not bundled with your plugin. ```gradle allprojects { repositories { // ... other repositories maven { url 'https://jitpack.io' } } } dependencies { compileOnly 'com.github.brcdev-minecraft:shopgui-api:latest' } ``` -------------------------------- ### Register Custom Spawner Provider with ShopGUI+ API (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt This Java code demonstrates how to register a custom spawner provider with the ShopGUI+ API. It listens for the ShopGUIPlusPostEnableEvent and registers an instance of CustomSpawnerProvider. It includes error handling for name conflicts. Dependencies include ShopGUI+ API and Bukkit API. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.event.ShopGUIPlusPostEnableEvent; import net.brcdev.shopgui.exception.api.ExternalSpawnerProviderNameConflictException; import net.brcdev.shopgui.spawner.external.provider.ExternalSpawnerProvider; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; public class CustomSpawnerPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onShopGUIPlusPostEnable(ShopGUIPlusPostEnableEvent event) { try { ShopGuiPlusApi.registerSpawnerProvider(new CustomSpawnerProvider()); getLogger().info("Custom spawner provider registered successfully"); } catch (ExternalSpawnerProviderNameConflictException e) { getLogger().severe("Failed to register spawner provider: " + e.getMessage()); } } public class CustomSpawnerProvider implements ExternalSpawnerProvider { @Override public String getName() { return "CustomSpawners"; } @Override public ItemStack getSpawnerItem(EntityType entityType) { ItemStack spawner = new ItemStack(Material.SPAWNER, 1); ItemMeta meta = spawner.getItemMeta(); meta.setDisplayName("§6" + formatEntityName(entityType) + " Spawner"); meta.setLore(java.util.Arrays.asList( "§7Type: §e" + formatEntityName(entityType), "§7Custom Spawner System", "§aPlace to spawn " + formatEntityName(entityType).toLowerCase() + "s" )); spawner.setItemMeta(meta); // Add custom NBT data to identify spawner type addSpawnerData(spawner, entityType); return spawner; } @Override public EntityType getSpawnerEntityType(ItemStack itemStack) { if (itemStack == null || itemStack.getType() != Material.SPAWNER) { return null; } // Extract entity type from custom NBT data return extractSpawnerEntityType(itemStack); } private String formatEntityName(EntityType type) { String name = type.name().replace("_", " "); return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); } private void addSpawnerData(ItemStack item, EntityType type) { // Add NBT data to store spawner type // Implementation depends on your NBT library } private EntityType extractSpawnerEntityType(ItemStack item) { // Extract entity type from NBT data // Return EntityType.PIG as fallback return EntityType.PIG; } } } ``` -------------------------------- ### Register Custom Item Provider in ShopGUI+ (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt This Java code demonstrates how to register a custom ItemProvider with ShopGUI+ to enable custom handling for specific item types. It includes methods for validating items, loading them from configuration, and comparing them based on custom criteria. This requires the ShopGUI+ API and Bukkit API. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.event.ShopGUIPlusPostEnableEvent; import net.brcdev.shopgui.provider.item.ItemProvider; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; public class CustomItemPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onShopGUIPlusPostEnable(ShopGUIPlusPostEnableEvent event) { // Register item provider when ShopGUI+ is ready ShopGuiPlusApi.registerItemProvider(new CustomWeaponItemProvider()); getLogger().info("Custom weapon item provider registered"); } public class CustomWeaponItemProvider extends ItemProvider { public CustomWeaponItemProvider() { super("CustomWeapons"); } @Override public boolean isValidItem(ItemStack itemStack) { if (itemStack == null || !itemStack.hasItemMeta()) { return false; } ItemMeta meta = itemStack.getItemMeta(); // Check if this is one of our custom weapons return meta.hasLore() && meta.getLore().stream().anyMatch(line -> line.contains("§6Custom Weapon")); } @Override public ItemStack loadItem(ConfigurationSection config) { // Load custom weapon from configuration String weaponType = config.getString("weapon-type"); int weaponLevel = config.getInt("weapon-level", 1); // Create and return the custom weapon ItemStack return createCustomWeapon(weaponType, weaponLevel); } @Override public boolean compare(ItemStack itemStack1, ItemStack itemStack2) { if (!isValidItem(itemStack1) || !isValidItem(itemStack2)) { return false; } // Compare custom weapons by their type and level String type1 = getWeaponType(itemStack1); String type2 = getWeaponType(itemStack2); int level1 = getWeaponLevel(itemStack1); int level2 = getWeaponLevel(itemStack2); return type1.equals(type2) && level1 == level2; } private ItemStack createCustomWeapon(String type, int level) { // Implementation to create weapon ItemStack return null; } private String getWeaponType(ItemStack item) { // Extract weapon type from NBT or meta return "sword"; } private int getWeaponLevel(ItemStack item) { // Extract weapon level from NBT or meta return 1; } } } ``` -------------------------------- ### Checking if ShopGUI+ Shops are Loaded (Java) Source: https://github.com/brcdev-minecraft/shopgui-api/blob/master/README.md This Java code snippet illustrates how to check if ShopGUI+'s shops have been loaded. This check is useful to ensure that shop-related operations or modifications are performed only after the shops are ready, preventing potential errors or unexpected behavior. It accesses the ShopManager from the ShopGuiPlugin instance provided by the API. ```java import com.brcdev.shopguiplus.ShopGuiPlugin; // ... inside an event handler or appropriate method if (ShopGuiPlugin.getInstance().getShopManager().areShopsLoaded()) { // Shops are loaded at this point // You can safely perform operations related to shops here. } else { // Shops are not yet loaded. } ``` -------------------------------- ### Price Modifier Management API Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Provides methods to apply, check, and reset price modifiers for players. ```APIDOC ## Price Modifier Management API This API allows for dynamic adjustment of item prices for players based on various conditions. ### Apply Global Price Modifier Applies a price modifier to all player purchases. - **Method**: `ShopGuiPlusApi.setPriceModifier(Player player, PriceModifierActionType actionType, double modifier)` - **Parameters**: - `player` (Player) - The player to apply the modifier to. - `actionType` (PriceModifierActionType) - Specifies whether the modifier applies to buying or selling (BUY, SELL, BOTH). - `modifier` (double) - The multiplier for the price. 1.0 is original price, 0.9 is 10% discount, 1.2 is 20% increase. - **Throws**: - `PlayerDataNotLoadedException` - If the player's data is not yet loaded. ### Apply Shop-Specific Price Modifier Applies a price modifier to all purchases within a specific shop for a player. - **Method**: `ShopGuiPlusApi.setPriceModifier(Player player, Shop shop, PriceModifierActionType actionType, double modifier)` - **Parameters**: - `player` (Player) - The player to apply the modifier to. - `shop` (Shop) - The specific shop to apply the modifier to. - `actionType` (PriceModifierActionType) - Specifies whether the modifier applies to buying or selling (BUY, SELL, BOTH). - `modifier` (double) - The multiplier for the price. - **Throws**: - `PlayerDataNotLoadedException` - If the player's data is not yet loaded. ### Apply Item-Specific Price Modifier Applies a price modifier to a specific item for a player. - **Method**: `ShopGuiPlusApi.setPriceModifier(Player player, ShopItem shopItem, PriceModifierActionType actionType, double modifier)` - **Parameters**: - `player` (Player) - The player to apply the modifier to. - `shopItem` (ShopItem) - The specific shop item to apply the modifier to. - `actionType` (PriceModifierActionType) - Specifies whether the modifier applies to buying or selling (BUY, SELL, BOTH). - `modifier` (double) - The multiplier for the price. - **Throws**: - `PlayerDataNotLoadedException` - If the player's data is not yet loaded. ### Get Player Price Modifier Retrieves the current price modifier for a player for a specific action type. - **Method**: `ShopGuiPlusApi.getPriceModifier(Player player, PriceModifierActionType actionType)` - **Parameters**: - `player` (Player) - The player whose modifier to retrieve. - `actionType` (PriceModifierActionType) - Specifies whether to get the BUY or SELL modifier. - **Returns**: - `PriceModifier` - An object containing the modifier details. - **Throws**: - `PlayerDataNotLoadedException` - If the player's data is not yet loaded. ### Reset Player Price Modifiers Resets all price modifiers for a player. - **Method**: `ShopGuiPlusApi.resetPriceModifier(Player player, PriceModifierActionType actionType)` - **Parameters**: - `player` (Player) - The player whose modifiers to reset. - `actionType` (PriceModifierActionType) - Specifies which modifiers to reset (BUY, SELL, BOTH). - **Throws**: - `PlayerDataNotLoadedException` - If the player's data is not yet loaded. ### Example Usage (Java) ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifierActionType; import org.bukkit.entity.Player; public class ExamplePriceModifier { public void applyDiscountAndCheck(Player player) { try { // Apply a global 10% discount on buying ShopGuiPlusApi.setPriceModifier(player, PriceModifierActionType.BUY, 0.9); player.sendMessage("§a10% discount applied!"); // Check the current buy modifier double currentModifier = ShopGuiPlusApi.getPriceModifier(player, PriceModifierActionType.BUY).getModifier(); player.sendMessage("§7Your current buy modifier is: " + currentModifier); // Reset all modifiers after a delay or event // ShopGuiPlusApi.resetPriceModifier(player, PriceModifierActionType.BOTH); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cError: Player data not loaded."); } } } ``` ``` -------------------------------- ### Apply Global Price Modifier (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Applies a global price modifier to a player for all purchases. This is useful for applying general discounts or surcharges. It requires the player object and the desired modifier value (e.g., 0.9 for a 10% discount). It handles PlayerDataNotLoadedException. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifierActionType; import org.bukkit.entity.Player; public class PriceModifierManager { public void applyVIPDiscount(Player player) { try { // Apply 10% discount on all purchases (0.9 = 90% of original price) ShopGuiPlusApi.setPriceModifier(player, PriceModifierActionType.BUY, 0.9); player.sendMessage("§aVIP discount applied! All purchases are 10% off."); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cCannot apply discount - data not loaded."); } } } ``` -------------------------------- ### Apply Shop-Specific Price Modifier (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Applies a price modifier to a player for a specific shop. This allows for tailored pricing within different shops. It requires the player, the shop ID, and the modifier value. It retrieves the shop object and handles PlayerDataNotLoadedException. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifierActionType; import net.brcdev.shopgui.shop.Shop; import org.bukkit.entity.Player; public class PriceModifierManager { public void applyShopDiscount(Player player, String shopId) { try { Shop shop = ShopGuiPlusApi.getShop(shopId); if (shop != null) { // Apply 25% discount on this specific shop (0.75 = 75% of original price) ShopGuiPlusApi.setPriceModifier(player, shop, PriceModifierActionType.BUY, 0.75); player.sendMessage("§a25% discount applied to " + shop.getName() + "!"); } } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cCannot apply shop discount."); } } } ``` -------------------------------- ### Apply Item-Specific Price Modifier (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Applies a price modifier to a player for a specific shop item, affecting either buying or selling prices. This is useful for special item pricing. It requires the player, the ShopItem object, the action type (BUY/SELL), and the modifier value. It handles PlayerDataNotLoadedException. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifierActionType; import net.brcdev.shopgui.shop.item.ShopItem; import org.bukkit.entity.Player; public class PriceModifierManager { public void applyItemPriceBoost(Player player, ShopItem shopItem) { try { // Increase sell price by 20% for this item (1.2 = 120% of original price) ShopGuiPlusApi.setPriceModifier(player, shopItem, PriceModifierActionType.SELL, 1.2); player.sendMessage("§a20% bonus on selling this item!"); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cCannot apply item boost."); } } } ``` -------------------------------- ### Check Player Price Modifiers (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Retrieves and displays the current buy and sell price modifiers active for a player. This is useful for debugging or informing players about active adjustments. It uses getPriceModifier and handles PlayerDataNotLoadedException. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifier; import net.brcdev.shopgui.modifier.PriceModifierActionType; import org.bukkit.entity.Player; public class PriceModifierManager { public void checkPlayerModifier(Player player) { try { PriceModifier buyModifier = ShopGuiPlusApi.getPriceModifier(player, PriceModifierActionType.BUY); PriceModifier sellModifier = ShopGuiPlusApi.getPriceModifier(player, PriceModifierActionType.SELL); player.sendMessage("§7Current buy modifier: " + buyModifier.getModifier()); player.sendMessage("§7Current sell modifier: " + sellModifier.getModifier()); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cCannot check modifiers."); } } } ``` -------------------------------- ### Reset All Player Price Modifiers (Java) Source: https://context7.com/brcdev-minecraft/shopgui-api/llms.txt Resets all active price modifiers (both buy and sell) for a given player, returning their prices to default. This is useful for clearing temporary discounts or boosts. It uses resetPriceModifier and handles PlayerDataNotLoadedException. ```java import net.brcdev.shopgui.ShopGuiPlusApi; import net.brcdev.shopgui.exception.player.PlayerDataNotLoadedException; import net.brcdev.shopgui.modifier.PriceModifierActionType; import org.bukkit.entity.Player; public class PriceModifierManager { public void resetAllModifiers(Player player) { try { ShopGuiPlusApi.resetPriceModifier(player, PriceModifierActionType.BOTH); player.sendMessage("§aAll price modifiers have been reset."); } catch (PlayerDataNotLoadedException e) { player.sendMessage("§cCannot reset modifiers."); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.