Shop Developer Wiki

Nov 8, 2016
Shop Developer Wiki
  • (back to main page)
    [​IMG]

    Hooking into Shop:
    Add Shop as a soft depend in the plugin.yml of your plugin
    Code (yml):

    name: ExamplePlugin
    author: SnowGears
    softdepend: [Shop]
     

    Get an instance of the plugin
    Code (Java):

    private Shop getShop() {
        Plugin plugin = getServer().getPluginManager().getPlugin("Shop");
        // Shop may not be loaded
        if (plugin == null || !(plugin instanceof Shop)) {
            return null; // Maybe you want throw an exception instead
        }
        return (Shop) plugin;
    }
     


    Events you can listen for:

    PlayerCreateShopEvent - called when a player creates a shop

    PlayerInitializeShopEvent - called when a player initializes shop with an item
    PlayerDestroyShopEvent - called when a player destroys a shop
    PlayerExchangeShopEvent - called when a player performs a transaction with a shop
    PlayerResizeShopEvent - called when a player resizes a shop chest


    Examples:
    Code (Java):

    //set the shop items to meat if the player is too hungry
    @EventHandler
    public void onShopInitialize(PlayerInitializeShopEvent event){
        if(event.getPlayer().getFoodLevel() < 5){
            event.getShop().setItemStack(new ItemStack(Material.COOKED_BEEF));
            event.getPlayer().sendMessage("You are too hungry! The shop item has been set to meat!");
        }
    }
     
    Code (Java):

    //only allow players to break shops if they are holding an iron axe in their main hand
    @EventHandler
    public void onShopDestroy(PlayerDestroyShopEvent event){
        if(event.getPlayer().getItemInHand().getType() != Material.IRON_AXE){
            event.setCancelled(true);
            event.getPlayer().sendMessage("You must break shop signs with an Iron Axe!");
        }
    }
     
  • Loading...
  • Loading...