Vaults for players

Discussion in 'Archived: Plugin Requests' started by ThePluginMaker, Jul 3, 2014.

  1. Offline

    ThePluginMaker

    Plugin category: Fun

    Suggested name: Vaults

    What I want: I want a plugin where if you type /vault it will open a chest gui, but not a normal chest gui, i want it so it'll open only 1 slot, not 9 as a normal chest row will hold. I want it to hold 1, and you can configurable how many slots each rank can get. So for example, player gets 1, lowest donator gets 2, next donor gets 3, ETC. And it will save the players vault in a file.

    Ideas for commands: /vault (/v)

    Ideas for permissions: vault.1 (for 1 slot) vault.2 (for 2 slots) vault.3 (for 3 slots) vault.4 (for 4 slots) ETC

    When I'd like it by: Tomorrow if that's possible.
    With no permission when they type /vault
    81e0b8d2b4938b500ec3a463f11ead9b.gif
    With vault.1 (They have a free 1 slot and i so happened to put a stack of diamond blocks.
    bc2bc3c86a89216c72478b5fe8bf98b1.gif
     
  2. Offline

    Joshuak52

  3. Offline

    ThePluginMaker

    Joshuak52
    This plugin does rows, i don't want rows, i want slots....
     
  4. Offline

    EclipseHD

    ThePluginMaker I don't think minecraft itself supports individual slots. Maybe open not a chest GUI but a modified Brewing Stand GUI? IDK lol.
     
  5. Offline

    ThePluginMaker

    A server called Gontroller has it, but used for their enderchests

    If not then could you make it so it's 9 slots, but 8 of them back a unmoveable block in it?

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

    15987632

    Yes that would work I'm not saying I would do it though
     
  7. Offline

    ThePluginMaker

  8. Offline

    ThePluginMaker

    Edit: Heres example for the vault, have slots like this but in a chest type thing?

    2014-07-06_18.52.01.png
     

    Attached Files:

    Last edited by a moderator: Jul 1, 2016
  9. Online

    timtower Administrator Administrator Moderator

  10. Offline

    ThePluginMaker

    timtower
    It was an example..... i didn't have a 1 row chest with unused inventory slots in it, so i used his picture
     
  11. Offline

    Harrison015

    Lol. All I did was rename some items and crop a screenshot.
    Here's a better example for you :p
    [​IMG]
     
  12. Offline

    ThePluginMaker

    Harrison015
    Thanks, that would be perfect!

    Now we just need someone to make it :p

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

    Harrison015

    I will try to make this.. But if anyone else wants to, go ahead
     
  14. Offline

    Onlineids

    Harrison015 If you need help saving the inventory tahg me
     
  15. Offline

    Harrison015

    Onlineids
    I think I need help with the metadata and the enchantments..
    I am saving the players' data in the config.yml,
    Code:java
    1. private void saveItem(ConfigurationSection section, ItemStack itemStack) {
    2. section.set("type", itemStack.getType().name());
    3. section.set("amount", itemStack.getAmount());
    4. section.set("meta", itemStack.getItemMeta()); //How to save all the item's data properly?

    And then later loading it
    Code:java
    1. private ItemStack loadItem(ConfigurationSection section) {
    2. return new ItemStack(Material.valueOf(section.getString("type")), section.getInt("amount"));
    3. //Load more item data
     
  16. Offline

    Onlineids

    Harrison015 Inventory handling: http://hastebin.com/tuxufemogu.php
    Save and Load:
    Code:java
    1. public void saveInventory(Player p, ConfigurationSection cs){
    2. String inv = InventoryHandling.saveInventory(p);
    3. String armor = InventoryHandling.saveArmor(p);
    4. cs.set("inv", inv);
    5. cs.set("armor", armor);
    6. saveInv();
    7. }
    8. public void loadInventory(Player p, ConfigurationSection cs) throws IOException{
    9. String inv = cs.getString("inv");
    10. if(inv != null){
    11. Inventory playerInv = InventoryHandling.fromBase64(inv);
    12. p.getInventory().setContents(playerInv.getContents());
    13. }
    14. String armor = cs.getString("armor");
    15. if(armor != null){
    16. ItemStack[] playerArmor = InventoryHandling.itemStackArrayFromBase64(armor);
    17. p.getInventory().setArmorContents(playerArmor);
    18. }
    19.  
    20. }
     
  17. Offline

    Harrison015

    Onlineids But I am not saving their inventory, I am saving the contents of their "Vault".
    Here is the code I have so far:
    Code:java
    1. package me.harmar.vaults;
    2.  
    3.  
    4. import java.util.HashMap;
    5. import java.util.Map.Entry;
    6. import java.util.UUID;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Material;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.configuration.ConfigurationSection;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.inventory.InventoryType;
    18. import org.bukkit.event.player.PlayerJoinEvent;
    19. import org.bukkit.event.player.PlayerQuitEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24. public class VaultInv extends JavaPlugin implements Listener {
    25.  
    26. private HashMap<UUID, Inventory> vaults = new HashMap<UUID, Inventory>();
    27.  
    28. @EventHandler
    29. public void onPlayerJoin(PlayerJoinEvent e) {
    30. Inventory inv = Bukkit.getServer().createInventory(e.getPlayer(), 9, "Your Vault");
    31.  
    32. if (getConfig().contains("vaults." + e.getPlayer().getUniqueId())) {
    33. for (String item : getConfig().getConfigurationSection("vaults." + e.getPlayer().getUniqueId()).getKeys(false)) {
    34. inv.addItem(loadItem(getConfig().getConfigurationSection("vaults." + e.getPlayer().getUniqueId() + "." + item)));
    35. }
    36. }
    37.  
    38. vaults.put(e.getPlayer().getUniqueId(), inv);
    39. }
    40.  
    41. @EventHandler
    42. public void onPlayerLeave(PlayerQuitEvent e) {
    43. if (!getConfig().contains("vaults." + e.getPlayer().getUniqueId())) {
    44. getConfig().createSection("vaults." + e.getPlayer().getUniqueId());
    45. }
    46.  
    47. char c = 'a';
    48. for (ItemStack itemStack : vaults.get(e.getPlayer().getUniqueId())) {
    49. if (itemStack != null) {
    50. saveItem(getConfig().createSection("vaults." + e.getPlayer().getUniqueId() + "." + c++), itemStack);
    51. }
    52. }
    53.  
    54. saveConfig();
    55. }
    56.  
    57. public void onEnable() {
    58. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    59. }
    60.  
    61. public void onDisable() {
    62. for (Entry<UUID, Inventory> entry : vaults.entrySet()) {
    63. if (!getConfig().contains("vaults." + entry.getKey())) {
    64. getConfig().createSection("vaults." + entry.getKey());
    65. }
    66.  
    67. char c = 'a';
    68. for (ItemStack itemStack : entry.getValue()) {
    69. if (itemStack != null) {
    70. saveItem(getConfig().createSection("vaults." + entry.getKey() + "." + c++), itemStack);
    71. }
    72. }
    73.  
    74. saveConfig();
    75. }
    76. }
    77.  
    78. @Override
    79. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    80. if (!(sender instanceof Player)) {
    81. sender.sendMessage(ChatColor.RED + "The console cannot have a Vault.");
    82. return true;
    83. }
    84.  
    85. Player p = (Player) sender;
    86.  
    87. if (cmd.getName().equalsIgnoreCase("vault")) {
    88. p.openInventory(vaults.get(p.getUniqueId()));
    89. }
    90.  
    91. return true;
    92. }
    93.  
    94. private void saveItem(ConfigurationSection section, ItemStack itemStack) {
    95. section.set("type", itemStack.getType().name());
    96. section.set("amount", itemStack.getAmount());
    97. section.set("meta", itemStack.getItemMeta());
    98. //Save more info
    99. }
    100.  
    101. private ItemStack loadItem(ConfigurationSection section) {
    102. return new ItemStack(Material.valueOf(section.getString("type")), section.getInt("amount"));
    103. // Load more information.
    104. }
    105. }
    106.  

    ThePluginMaker Keep in mind, I haven't added the blocked slots feature yet.
     
  18. Offline

    Onlineids

  19. Offline

    ThePluginMaker

  20. Offline

    Harrison015

    ThePluginMaker Onlineids
    I'm doing the best I can.
    Vaults version 1.0

    So far all I have is the command /vault that brings up your vault.
    The items are saved except for their cusom names, enchantments, and lores. (I'm working on that).
    There also is no restricted slots yet. (Also working on that).

    This is my first plugin by the way! :D
    Expect Bugs and horrible coding.
     
    izarooni likes this.
  21. Offline

    Onlineids

    Harrison015 The code I gave you saves everything to do with the items including lore names ect
     
  22. Online

    timtower Administrator Administrator Moderator

    Harrison015 You really want to reconsider your way of storing the items. It is pretty much a free repair method.
     
  23. Offline

    Harrison015

    I am working on it, still implementing Onlineids code...
     
  24. Offline

    electro4fun

    Just use:
    Code:
    config.set("path.path", itemStack);
    Have it save items that are not the unused inventory itemstack.
     
  25. Offline

    ThePluginMaker

    Harrison015
    When do you think you'll add the blocked feature?
     
  26. Offline

    Harrison015

    I am not sure if I can anymore. It's turning out to be harder than I expected, and I have less time to do things now. Might be a good idea to get someone else to make this.
     
  27. Offline

    izarooni

    <Edit by Moderator: Redacted mediafire url>
    To some people who saw my deleted post, I forgot to change some things because I was testing for bugs and I wasn't sure if someone else was working on this.
    You're probably going to get some errors but idk. Just reload if you do. If it doesn't go away, just say with the error if there's one.

    Permissions
    * vaults.1 - Default, given to all players only the first row available
    * vaults.2 - Top row disabled
    * vaults.3 - All rows enabled

    Here's what I have done that didn't give me errors. No guarentees it wont give you errors though
    * Item data type (For colored wool, stained glass, logs, pistons, etc)
    * Item durability
    * Item lore with colors
    * Item displayname with color
    * Item amounts
    * Enchantments with levels
    * Material type
    * The item should be saved in the slot that it was placed in
    * Items that would get overlapped with the '&cNo Access' item would get dropped (Not tested but should work)
    * Config file to cusotmize the '&cNo access' item type, name (with color), and data value
    * Contents saved when that specific inventory is closed - Not sure if this is a good idea but I did it
    * The '&cNo Access' item can't be moved or dropped - hooorah!

    If something's not right just tell me. It's probably because I was testing things.
    the command to open the vault is /vault
     
    Last edited by a moderator: Nov 2, 2016
  28. Offline

    ThePluginMaker

    izarooni
    Hey your plugin has rows, is there a way you can change it to slots? like the pictures i have up there?
     
  29. Offline

    izarooni

  30. Offline

    ThePluginMaker

    izarooni sure thing

    izarooni
    could i have the source?

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

Share This Page