Guest User

Loadouts Class

a guest
May 28th, 2018
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.uba;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.inventory.Inventory;
  7. import org.bukkit.inventory.ItemStack;
  8.  
  9. public class loadouts {
  10.  
  11. private loadouts() { }
  12.  
  13. static loadouts instance = new loadouts();
  14.  
  15. public static loadouts getInstance() {
  16. return instance;
  17. }
  18.  
  19. loadouts plugin = this;
  20.  
  21. private HashMap<String, ItemStack[]> loadout = new HashMap<String, ItemStack[]>();
  22.  
  23. public void saveLoadout(Player player)
  24. {
  25. this.loadout.put(player.getName(), copyLoadout(player.getInventory()));
  26. }
  27.  
  28. /**
  29. * This removes the saved inventory from our HashMap, and restores it to the player if it existed.
  30. * @return true if success
  31. */
  32. public boolean restoreLoadout(Player player)
  33. {
  34. ItemStack[] savedLoadout = this.loadout.remove(player.getName());
  35. if(savedLoadout == null)
  36. return false;
  37. restoreLoadout(player, savedLoadout);
  38. return true;
  39. }
  40.  
  41. private ItemStack[] copyLoadout(Inventory inv)
  42. {
  43. ItemStack[] original = inv.getContents();
  44. ItemStack[] copy = new ItemStack[original.length];
  45. for(int i = 0; i < original.length; ++i)
  46. if(original != null)
  47. copy = (original);
  48. return copy;
  49. }
  50.  
  51. private void restoreLoadout(Player p, ItemStack[] inventory)
  52. {
  53. p.getInventory().setContents(inventory);
  54. }
  55. }
RAW Paste Data