From open Inventory to Block?

Discussion in 'Plugin Development' started by Mariusmak, Apr 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Mariusmak

    Hey guys,
    How can I get from an open inventory to the block holding the inventory?
    I have an open brewingstand inventory and i want to have the brewingstand block holding the inventory.
    Does anyone know how to do that?
    Hope you can help me :D
     
  2. Offline

    CookCreeperz

    Uhhhh maybe Block.getInventory??
     
  3. Show your current code where you need to get the inventory.
     
  4. Offline

    Mariusmak

    I am writing on a jobs plugin and I wanted to pay people for taking out potions of the brewing stand. So I wanted to save the location of the brewing stand and the newly brewed potions (after the BrewEvent got fired) with the slotnumber. If anybody takes out a potion (with the InventoryClickEvent) I wanted to get the location of the brewing stand, he took out the items, and then check if he took out one of the newly brewed items to pay him.
    But now I found another solution:
    When the BrewEvent is fired, all the itemstacks are put into an ArrayList and if someone takes out an item of the brewing stand, the plugin checks if the item he takes out is contained in the ArrayList. If the list contains the item, the item is removed from the list and the player gets his money. The only problem is, that for example if I brew 3 potions of harming they are put into the list. But the list is global, so if another player takes out 3 potions of harming out of a brewing stand he did not brew (he put them into the brewing stand before) the 3 items get removed from the list and the wrong player gets the money.
    Does anyone know a solution for this?
    Hope you understand my bad english :D

    Here is the part of the code where I put the itemstacks in the list and check if someone takes those items out of a brewing stand.
    Code:
    @EventHandler
        public void onBrewEvent(BrewEvent event){
            BrewerInventory inv = event.getContents();
            for(int i = 0;i<=2;i++)
            {
                if(inv.getItem(i)!=null)
                {
                    brauListe.add(inv.getItem(i));
                }
            }
        }
        @EventHandler
        public void onBrewingStandItemTakeEvent(InventoryClickEvent event){
            ItemStack voritem = new ItemStack(Material.AIR);
            try{
                voritem = event.getCurrentItem();
            }
            catch(NullPointerException e){}
            ItemStack item = voritem;
            if(!(voritem.equals(Material.AIR)))
            {
                if(event.getInventory().getType().equals(InventoryType.BREWING))
                {
                    if((item.getType().equals(Material.POTION)))
                    {
                        Player player = (Player) event.getWhoClicked();
                        String type = "Brew";
                        if(brauListe.contains(item))
                        {
                            //pay the player
                            Bukkit.broadcastMessage("money");
                        }
                        else
                            Bukkit.broadcastMessage("No money");
                    }
                }
            }
        }
     
  5. Whoa long text, I'm just going to reply to your initial questions:

    To get inventory: check if event.getInventory() is instanceof BrewerInventory then cast it to that.
    To get the block: use event.getInventory().getHolder() and check if that's instanceof BrewingStand I belive (see what is the org.bukkit.block implementation for brewing stand).
     
  6. Offline

    jayfella

    I just actually published a plugin for databases: http://dev.bukkit.org/server-mods/c3p0-extension/ - I wont bother repeating what is already said on the main page of the plugin.

    But back on track, preparedStatements are actually quite important in a minecraft plugin. Preparedstatements escape the scary characters, so you could effectively overcome something, such as give yourself loadsa money, unjail yourself, etc, etc..
     
Thread Status:
Not open for further replies.

Share This Page