Prevent players from closing a special inventory

Discussion in 'Plugin Development' started by superjesse07, Apr 22, 2014.

Thread Status:
Not open for further replies.
  1. so as the title say's i want to prevent player's from closing a specific inventory until they have clicked on the close item in the inventory
     
  2. Offline

    mickedplay

    You can open it again after he closed it :D
     
  3. Offline

    valon750

    superjesse07

    You could indeed do as mickedplay says, or perhaps there's a setCancelled() method for InventoryCloseEvent? Not sure though..
     
  4. Offline

    desht

    InventoryCloseEvent can't be cancelled, so the only way is to force a re-opening of the window following a close (which you'll probably want to delay a tick via the scheduler).
     
  5. Offline

    itzrobotix

    When they click an item add them to an ArrayList and remove them after like a few ticks.
    Code:java
    1. @EventHandler
    2. public void onIC(InventoryCloseEvent e){
    3. Inventory i = e.getInventory();
    4. if(i == *Special inventory variable?*){
    5. //Re-open?
    6. }
    7. }

    Then with something like this if they are not in the ArrayList re-open it?
     
  6. Offline

    RawCode

    player do report server about inventory close, but do not ask permission to perform it.

    also due to network latency this may fail
     
  7. Doesn't work the server crashes.

    here's the code
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onIC(final InventoryCloseEvent e){
    4. Inventory i = e.getInventory();
    5. if(i.getName().equalsIgnoreCase(Powerinv.getName()) || i.getName().equalsIgnoreCase(Powerinv.getName())){
    6. Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(main, new Runnable() {
    7.  
    8. @Override
    9. public void run() {
    10. show((Player)e.getPlayer(),1);
    11.  
    12. }
    13. }, 20);
    14. }
    15. }


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

    desht

    superjesse07 Do not use an async task for this. Use a sync task. Also, "the server crashes" is not a useful error report. And you haven't posted the show() method, so we have no idea what that does.
     
  9. It just show's the player the inventory by number 1 is the main inventory

    bumb

    the show method :
    Code:java
    1. public void show(Player p, int inv) {
    2. switch (inv) {
    3. case 1:
    4. p.openInventory(Powerinv);
    5. break;
    6.  
    7. case 2:
    8. p.openInventory(moveInv);
    9. break;
    10. default:
    11. p.openInventory(Powerinv);
    12. break;
    13. }
    14. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page