InventoryClickEvent - Get the furnace

Discussion in 'Plugin Development' started by Randy Schouten, Mar 8, 2014.

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

    Randy Schouten

    I was trying to get the player who put something into a furnace for some time but I can't find a variable that doesn't change for the life of me. Is there any way I can get the block or location from the object you put something in?

    I have tried using the ItemStack as well, but that doesn't really work well.
     
  2. Offline

    IkBenHarm

    Randy Schouten
    Code:java
    1. InventoryType topType = event.getView().getTopInventory().getType();
    2.  
    3. if(event.getWhoClicked() instanceof Player){
    4. if(topType == InventoryType.BREWING || topType == InventoryType.CHEST || topType == InventoryType.DISPENSER || topType == InventoryType.WORKBENCH
    5. || topType == InventoryType.HOPPER || topType == InventoryType.ENDER_CHEST || topType == InventoryType.FURNACE){
    6.  
    7. event.setCancelled(true);
    8.  
    9. }
    10. }

    this is what i used
     
  3. Offline

    Scizzr

    Here's something I just came up with:
    Code:
    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        if (event.getInventory().getType() == InventoryType.FURNACE) {
            FurnaceInventory fi = (FurnaceInventory)event.getInventory();
            Location loc = fi.getHolder().getLocation();
            Block block = loc.getBlock();
            //do something with the location or the block
        }
    }
    
     
    Randy Schouten likes this.
  4. Offline

    Randy Schouten

    IkBenHarm
    If you read my question, that's not what I asked. But thanks anyway :).

    Scizzr
    Yeah that's sorta what I do up to now.
    What I have now is I have 2 events. The smelt event and the item drag event. Then I have one hashmap where I want to keep who put what in a furnace. The problem is that I can't find a "shared" variable that doesn't change in both events.

    Ideally I'd want to get the specific furnace, but the Click event doesn't allow me to get the furnace as a block (as far as I know), that means also the location.

    I've seen something you did a few edits ago with the hashmap, that's sort of what I have, but that only keeps track of a single furnace, that's where the problem comes in. I want to keep track of all the furnaces that somebody put something in.

    Sorry if it's a bit confusing to understand, but I hope you understand it haha :p

    Here's the code:

    Code:java
    1. public void onInventoryMoveItem(InventoryClickEvent event){
    2. if(event.getInventory().getType().equals(InventoryType.FURNACE) && event.getRawSlot() == 0){
    3.  
    4. Player player = (Player)event.getWhoClicked();
    5. EpicSystem.furnaceList.put(event.getCurrentItem(), EpicSystem.getEpicPlayer(player));
    6. }
    7. }


    Code:java
    1. public void OnFurnaceSmelt(FurnaceSmeltEvent event){
    2.  
    3. ItemStack oldStack = event.getSource();
    4.  
    5. System.out.print(EpicSystem.furnaceList.toString());
    6. System.out.print(oldStack);
    7.  
    8. EpicPlayer player = EpicSystem.furnaceList.get(oldStack);
    9. }


    I have "furnaceList" as a hashmap. I tried to use the ItemStack now, but it doesn't really work out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    IkBenHarm

  6. Offline

    Scizzr

    Read my modified post. :)
     
  7. Offline

    Randy Schouten

    Scizzr
    Welp. How did I miss that variable?!
     
Thread Status:
Not open for further replies.

Share This Page