Store inventory in world file

Discussion in 'Spigot Plugin Development' started by WiHrBr, May 24, 2015.

  1. Is there any way to store a inventory in a world file? I want that when you right click a specific Zombie, it will open a inventory but I dont want to save the inv in a separated file or mysql.
     
  2. Depends on the type of inventory.. If its a custom inventory you made in your plugin you don't need to store it anywhere, just call your inventory object.
     
  3. But if I restart my server? I will lose my inventory?
     
  4. Yet again, what type of an inventory is this? Did you create the inventory in your plugin?
     
  5. 27 slots. Yes.
     
  6. If the inventory was created in your plugin, and I assume that since you'd be clicking on a zombie to open it it has preset options? And when you click the option it will run a command or something? If so then it's perfectly fine, your plugin will create a new inventory for a player whenever they click the zombie.
     
  7. I want they having, for example, a player inventory, whenever zombie is nearly a dropped item (zombie kills player and get his items), izombie will pick up the items and whenever another player kills the same zombie, zombie will drop the items. Zombie inventory can be acessed by right click also.
     
  8. Let me see if I undestand this, you want to create a zombie invetory to be just like an enderchest for the player but you don't want save it and lose it when reloading the server.

    I'm not totally sure but It is not possible without saving the inventory in a file

    Edit: At least is not possible saving it on the world file
     

  9. One inv per zombie. Can I attach a inventory to zombie like horse ( maybe using NMS)?
     
  10. Just listen for a PlayerInteractEvent and open the correct inventory..
     
  11. Attach like, save the inventory with the entity.
     
  12. I don't think that you are thinking of the lag this will cause if this is for every zombie. I know a very easy way of doing what you want but it causes a lot of lag, like any other way you might do this. So, a very useful thing about any entity in the world is that it has a specific UUID. Simply create a Map with the UUID of the zombie as the key and the I inventory as the value. Remember, this will be likely VERY laggy, and so I suggest not to add this to whatever you are making.
     
  13. How would it be laggy when the inventory is stored in a file and is only called when a player clicks on a zombie? Same exact concept on when you log in to a server or ern single player. Your inventory is stored somewhere and only called when needed.
     
  14. Are you saying saving the inventory in a config file or something and accessing it when a player kills a zombie?
     
  15. Pretty much.. Just set the file name as the zombies UUID or custom name. Then store the item contents in a HashMap and save it to the file.
     
  16. Well the question is how many people on average will your server have cause if there is only a few players then you only really need to check when a player kills a zombie or a zombie kills a player but if there's a lot of players it still might me laggy
     
  17. Same exact concept of when a player dies and their inventory drops..
     
  18. Yeah except apply that concept to all the zombies that continuously spawn Im only guessing that it will be laggy with all that
     
  19. Unless all of those zombies die at exactly the same time why would it be more laggy than spawning in a zombie that doesn't have an invnetory? The plugin shouldn't even check a zombie to have an inventory before it spawns in, that would cause lag. Instead it should check when a player kills the zombie. When it does this that is the only time any part of the plugin would execute and run the code. Any other time it is normal Vanilla behavior.