Resetting a chest?

Discussion in 'Plugin Development' started by wptcraft, Aug 30, 2014.

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

    wptcraft

    okay so im making a chest regen plugin where the chest needs to reset everytime a player finishes using it, how can this be done? i have the contents of the chests and i can put it into the chests i just dont know how to reset it after its been used? or do i just create a loop and have it reset itself every couple of ticks? im not sure how to do either so Any help appreciated
     
  2. Offline

    lrdemolition

    you can delete the contents of the chest when a player interacts with it
    wptcraft
     
  3. Offline

    TheMintyMate

    But then the player would not be able to retrieve the items in the chest.

    Perhaps you could do something like this:
    Code:
    @EventHandler
    public void onInventoryClosed(InventoryCloseEvent event){
    if(event.getInventory().getType() == InventoryType.CHEST){
    //clear chest
    }
    }
    }
    
    Hope this helps,
    - Minty
     
    JustinsCool15 likes this.
  4. Offline

    lrdemolition

    public void cclick (PlayerInteractEvent e){

    Player p = (Player) e.getPlayer();


    Player p1 = (Player) e.getPlayer();
    String pi = (String) e.getPlayer().getName();


    BlockState state = e.getClickedBlock().getState();
    Chest s = (Chest) state;
    if(e.getClickedBlock().getWorld() != null){
    if((e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK)){
    if(e.getClickedBlock().getType() == Material.SIGN_POST || e.getClickedBlock().getType() == Material.CHEST ){
    p1.getWorld().playEffect(e.getPlayer().getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 100); //We will play a an effect at the clicker's location
    //figure it out from here

    TheMintyMate
    the code i posted above only fires when the player clicks a chest block.
    i found another thread:
    https://forums.bukkit.org/threads/get-a-chest-inventory-on-interact.74985/
    wptcraft

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

    wptcraft

    Tried TheMintyMate s first buy had no luck as i got erros on the onInventoryClosed part and could not resoulve this error lrdemolition s solution wont work as it fires before they finish with it :/ and the thread you sent me is about getting the chests invenotry etc. ive already got that working i just need to make it Reset after a player is done with it, by resseting i mean regening the items the player took out of it Btw. Any more ideas?
     
  6. Offline

    lrdemolition

    Last edited by a moderator: Jun 10, 2016
  7. Offline

    TheMintyMate

    Please post your current code, and the error produced
    - Minty
     
  8. Offline

    wptcraft

    I have figured it out im actualy going to use the interact event from @lrdemolitions solution i think it is and just reset it everytime before they enter it, it should work the same as reseting it after
     
  9. Offline

    hintss

    I did this a bit ago, what I did was on PlayerInteractEvent with a chest, I cancelled it (though cancelling InventoryOpen is probably better), and make a new inventory, then copy the items from the chest into the new inventory, and open the new inventory for the player
     
    TheMintyMate likes this.
  10. Offline

    TheMintyMate

    Please could you post the errors produced anyway? I would like to see what errors occur :)

    Also, hintss 's method seems rather reliable; lrdemolition 's version however will clear the chest before it is opened (though it is reset) thus this would make originally filling a chest pointless (and may not be classed as a regenerating chest, but rather as a chest that randomly fills every time you open it). I advise that you use hintss method - as his doesn't reset the chest before allowing a player to access whatever was inside said chest first.

    Note (if using hintss 's method): After opening the new inventory to the player, you could then reset the chest.

    Hope this helped (and please report the error messages shown using my code, thanks :) ) ,
    - Minty
     
  11. Offline

    hintss

    I should also add, I had a listener on inventory click event that kept players from putting items into the fake chest inventory, since they would be lost when you closed it.

    EDIT: re: that last part about resetting the chest, that isn't necesary since the actual chest is never opened. The player is actually opening an inventory holding a copy of the chest's inventory.
     
    TheMintyMate likes this.
Thread Status:
Not open for further replies.

Share This Page