Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public static void setInventory(OfflinePlayer player, Inventory inventory) {
  2.  
  3. NBTTagList list = new NBTTagList();
  4.  
  5. for (int x = 0; x < inventory.getSize(); x++) {
  6.  
  7. ItemStack item = inventory.getItem(x);
  8.  
  9. if ((item != null) && (item.getType() != Material.AIR)) {
  10.  
  11. NBTTagCompound compound = new NBTTagCompound();
  12. CraftItemStack.asNMSCopy(item).save(compound);
  13.  
  14. if (method(x) != -1) {
  15.  
  16. compound.setByte("Slot", (byte) method(x));
  17. list.add(compound);
  18. }
  19. }
  20. }
  21. try {
  22.  
  23. System.out.println("Debug");
  24. File file = new File(Bukkit.getWorlds().get(0).getName() + File.separator + "playerdata", player.getUniqueId().toString() + ".dat");
  25. System.out.println("Debug0");
  26. System.out.println(list);
  27. NBTTagCompound compound = NBTCompressedStreamTools.a(new FileInputStream(file));
  28. System.out.println("Debug1");
  29. compound.set("Inventory", list);
  30. System.out.println("Debug2");
  31. FileOutputStream fileOutputStream = new FileOutputStream(file);
  32. System.out.println("Debug3");
  33. NBTCompressedStreamTools.a(compound, fileOutputStream);
  34. System.out.println("Debug4");
  35. fileOutputStream.close();
  36. System.out.println("Debug5");
  37.  
  38. } catch (Exception e) {
  39.  
  40. e.printStackTrace();
  41. }
  42.  
  43. }
  44.  
  45. private static int method(int i) {
  46.  
  47. if (i > -1 && i < 27) {
  48.  
  49. return i -= 9;
  50.  
  51. } else if (i > 26 && i < 36) {
  52.  
  53. return i = -27;
  54.  
  55. } else {
  56.  
  57. switch (i) {
  58.  
  59. case 0 :
  60. return i = 103;
  61.  
  62. case 1 :
  63. return i = 102;
  64.  
  65. case 2 :
  66. return i = 101;
  67.  
  68. case 3 :
  69. return i = 100;
  70.  
  71. case 40 :
  72. return i = 150;
  73. }
  74. }
  75. return -1;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement