Is there a plugin that limits or prevents opening inventory?

Discussion in 'Spigot Plugin Help' started by jflory7, May 28, 2015.

  1. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    Hello Spigot forums,

    I have been looking for a plugin to perform a specific function on my server. I have a semi-vanilla survival server, and one of the things we offer is a PvP Arena. However, players have been complaining that a lot of the more powerful players enter the arena with an inventory full of armor, weapons, and potions to annihilate everyone else.

    In order to help level the playing field, my staff came up with the idea for a plugin that would essentially limit a player to only accessing the items in their inventory hotbar, and not to move items from the rest of their inventory into their hotbar. This would essentially prevent players from quickly resupplying their broken armor with another god set, using a plethora of potions against others, and try to give everyone a fair shot.

    I was curious if something like this existed, and if not, is this even something possible within the confines of the Spigot API? I wasn't sure, so I was hoping some of you might know a little more. Thanks!


    Cheers,
    - jflory7​
     
  2. Sounds like a custom plugin... but ill look into this for you, you may just need to disable inventory for players in combat, I don't think that should be hard but than again what do I know of coding? Im just a beginner XD.
     
  3. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    Well, the tricky part is that I'm not trying to disable this globally, but rather within the confines of a specific area.
     
  4. Sounds like a few minutes task:
    - Listen for InventoryDragEvent
    - Check for move to hotbar
    - Check if player is in area (WE/WG)
    - Cancel event

    Don't know, maybe something like this already exists?
     
  5. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    So the handling of the player's inventory isn't an action that is handled solely by the client (meaning it could definitely be blocked)?

    I tried searching for something that already existed and couldn't turn anything up.
     
  6. sothatsit

    Patron

    It's definitely possible.

    Region detection is really simple. If you wanted you could do it with WorldGuard but its just as easy to make a simple system to do it yourself. Blocking the use of the inventory is quite simple as well, just a lot of things you have to take into account. One thing is that blocking dropping items is a bit broken and the item, instead of going back to the same place it was before, goes to the first available slot. You could combat this by not allowing players to pickup items into their hotbars as well though. It will just be a lot of fiddling with different events. Some i can think of which might be useful are the InventoryClickEvent and the ItemDrop and ItemPickup events.
     
  7. Cldfire

    Cldfire Retired Moderator
    Retired

    I know for sure that there are servers that prevent items from being moved around in the inventory. As I have no knowledge of Java whatsoever, that's as much as I can say.
     
    • Informative Informative x 1
  8. @jflory7
    cant you use world edit and flag sertain wepons?
    and make them not allowed?

    use a world edit to make regions and then implement that in ur code i have seen peaple do it like making a mini-game create the region and it will work in there code they created!?
    something like that
    and then that solves ur globaly problem!
     
  9. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    I wouldn't be needing to block the dropping or picking up of items, so hopefully that would not be an issue – I would just need to make sure they can only use the items in slots 1-9.

    I'm not needing to block certain weapons or specific items, but rather just make sure they can only use what's on their hotbar.
     
  10. I may be able to do this for you if i can figure out the worldguard api pretty quickly.
    What is the regions name?
     
  11. joshwenke

    Wiki Team

    As far as I know, canceling an inventoryClickEvent shouldn't be too hard. And inventoryClicks only happen when the inventory GUI is open. So it wouldn't change any hotbar action.
     
    • Useful Useful x 1
  12. jflory7

    jflory7 Retired Moderator
    Retired Benefactor

    Certainly, that would be awesome! If you do make it, my only request would be that it would be open source. In this case, the region's name is simply 'pvp', but there a multitude of child regions with special configurations that would need for this to be configured separately than being tied to a singular region.

    Sweet. Well, that's definitely what I need. :) Looks like this is doable, then.
     
  13. Well i will work on it, but i think i will only be able to do the pvp part for now, and i can upload it to my github as well if you'd like.
     
    • Like Like x 1
  14. This should be really easy to do - just listen for
    • org.bukkit.event.inventory.InventoryOpenEvent,
    do some region checks and then cancel the event. That's all you need, as far as I understand? Maybe tenten8401 can use this in what they're making, if not I'm willing to try my hand at a quick plugin for you :)
     
    • Informative Informative x 1
  15. Go ahead and try, Java is being stupid and wont go above 6 (running mac os x)
     
  16. Alright, time to give it a shot x)

    jflory7: What're you using for the regions?

    Edit:
    Oops, I entirely forgot I have to sleep early today. I'm gonna be pretty busy the coming two days and probably won't be on the forums, but if you still want my help with this do please send me a PM - I'd love to! I've got some pretty neat ideas for expanding the plugin as well, that I could add later. I'll get back on this when I'm back :p
     
    #16 bo0tzz, May 29, 2015
    Last edited by a moderator: May 29, 2015
  17. clip

    Benefactor

    I can throw something together for this. Gimme a few.
     
  18. Has this been resolved? If not let me try sketching up something. xP
     
  19. clip

    Benefactor

    Testing now.
     
  20. clip

    Benefactor

    Try it out: RegionInventoryBlocker

    Code (Text):
    name: RegionInventoryBlocker
    main: me.clip.regioninventoryblocker.RegionInventoryBlocker
    version: 1.0
    author: [extended_clip]
    description: Stop players from opening inventories in certain regions
    softdepend: [WorldGuard, WorldEdit]
    permissions:
        regioninventoryblocker.bypass:
            description: allowed to open inventories anywhere
            default: op
        regioninventoryblocker.admin:
            description: allowed to use commands
            default: op
    commands:
       regioninventoryblocker:
         description: RegionInventoryBlocker admin command
         aliases: [rib]
    Config:
    Code (Text):
    # RegionInventoryBlocker  version1.0 configuration file
    # WorldGuard returns region names in lower case
    # Make sure all regions listed are lower case!
    message: '&cYou can''t open inventories in this region!'
    regions:
      world:
      - region1
      - region2
    Source: https://github.com/extendedclip/Reg...ree/master/src/me/clip/regioninventoryblocker

    I didn't attach any license to it. It is a basic plugin, feel free to do what you please with it.
     

    Attached Files:

    #20 clip, May 29, 2015
    Last edited: May 29, 2015
    • Like Like x 4
    • Friendly Friendly x 2
    • Useful Useful x 1