rjng

Untitled

Dec 11th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.14 KB | None | 0 0
  1. package FFA;
  2.  
  3. import com.google.gson.Gson;
  4. import com.google.gson.JsonElement;
  5. import com.google.gson.JsonObject;
  6. import com.google.gson.JsonParser;
  7. import com.google.gson.stream.JsonWriter;
  8. import org.bukkit.*;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.enchantments.Enchantment;
  14. import org.bukkit.entity.Arrow;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.EventPriority;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.block.Action;
  20. import org.bukkit.event.block.BlockPlaceEvent;
  21. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  22. import org.bukkit.event.player.*;
  23. import org.bukkit.inventory.ItemStack;
  24. import org.bukkit.inventory.PlayerInventory;
  25. import org.bukkit.inventory.meta.ItemMeta;
  26. import org.bukkit.plugin.PluginManager;
  27. import org.bukkit.plugin.java.JavaPlugin;
  28. import org.bukkit.scheduler.BukkitRunnable;
  29. import org.bukkit.util.io.BukkitObjectInputStream;
  30. import org.bukkit.util.io.BukkitObjectOutputStream;
  31. import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
  32. import java.io.*;
  33. import java.text.DecimalFormat;
  34. import java.util.*;
  35. import java.util.concurrent.locks.ReadWriteLock;
  36. import java.util.concurrent.locks.ReentrantReadWriteLock;
  37.  
  38. public class Main
  39. extends JavaPlugin
  40. implements Listener, CommandExecutor
  41. {
  42. FileConfiguration config;
  43. File cfile;
  44.  
  45. File invSaves;
  46. ReadWriteLock lock;
  47.  
  48. Gson gson;
  49.  
  50. public Map<UUID, Map.Entry<ItemStack[], ItemStack[]>> inventories = new HashMap<>();
  51.  
  52. JsonParser parser;
  53.  
  54. public void onEnable()
  55. {
  56. getServer().getPluginManager().registerEvents(this, this);
  57. getServer().getPluginManager().registerEvents(new Events(), this);
  58. this.config = getConfig();
  59. this.config.options().copyDefaults(true);
  60. saveDefaultConfig();
  61. this.cfile = new File(getDataFolder(), "config.yml");
  62. invSaves = new File(getDataFolder(), "inventories.json");
  63. lock = new ReentrantReadWriteLock();
  64.  
  65. gson = new Gson();
  66.  
  67. parser = new JsonParser();
  68. lock.readLock().lock();
  69. try(FileReader fr = new FileReader(invSaves)) {
  70. JsonObject tree = parser.parse(fr).getAsJsonObject();
  71. for(Map.Entry<String, JsonElement> entry : tree.entrySet()) {
  72. UUID uuid = UUID.fromString(entry.getKey());
  73.  
  74. JsonObject data = entry.getValue().getAsJsonObject();
  75.  
  76. ItemStack[] contents = arrayFromBase64(data.get("inventory").getAsString());
  77. ItemStack[] armour = arrayFromBase64(data.get("armour").getAsString());
  78.  
  79. inventories.put(uuid, new AbstractMap.SimpleEntry<>(contents, armour));
  80. }
  81. }catch (IOException e) {
  82. e.printStackTrace();
  83. }finally {
  84. lock.readLock().unlock();
  85. }
  86. }
  87.  
  88. @EventHandler
  89. public void onPlayerJoin(PlayerJoinEvent event)
  90. {
  91. Player player = event.getPlayer();
  92. player.getInventory().clear();
  93. player.setGameMode(GameMode.SURVIVAL);
  94. teleportToSpawn(player);
  95. if(!inventories.containsKey(player.getUniqueId())) {
  96. ItemStack diamondsword = new ItemStack(Material.IRON_SWORD);
  97. diamondsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
  98. diamondsword.setAmount(1);
  99. ItemStack bow = new ItemStack(Material.BOW);
  100. bow.addEnchantment(Enchantment.ARROW_DAMAGE, 2);
  101. bow.setAmount(1);
  102. ItemStack frod = new ItemStack(Material.FISHING_ROD);
  103. frod.addEnchantment(Enchantment.DURABILITY, 3);
  104. frod.setAmount(1);
  105. ItemStack gapple1 = new ItemStack(Material.GOLDEN_APPLE);
  106. gapple1.setAmount(6);
  107. ItemStack arrow = new ItemStack(Material.ARROW);
  108. arrow.setAmount(64);
  109. ItemStack waterbucket = new ItemStack(Material.WATER_BUCKET);
  110. waterbucket.setAmount(1);
  111. ItemStack fns = new ItemStack(Material.FLINT_AND_STEEL);
  112. fns.setAmount(1);
  113. ItemStack madera = new ItemStack(Material.WOOD);
  114. madera.setAmount(64);
  115. ItemStack piedra = new ItemStack(Material.COBBLESTONE);
  116. piedra.setAmount(64);
  117. ItemStack helmet = new ItemStack(Material.IRON_HELMET);
  118. helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  119. helmet.setAmount(1);
  120. ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE);
  121. chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  122. chestplate.setAmount(1);
  123. ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS);
  124. leggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  125. leggings.setAmount(1);
  126. ItemStack boots = new ItemStack(Material.IRON_BOOTS);
  127. boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  128. boots.setAmount(1);
  129. player.getInventory().setItem(0, diamondsword);
  130. player.getInventory().setItem(1, frod);
  131. player.getInventory().setItem(2, bow);
  132. player.getInventory().setItem(4, gapple1);
  133. player.getInventory().setItem(11, arrow);
  134. player.getInventory().setItem(8, piedra);
  135. player.getInventory().setItem(5, waterbucket);
  136. player.getInventory().setItem(6, fns);
  137. player.getInventory().setHelmet(helmet);
  138. player.getInventory().setChestplate(chestplate);
  139. player.getInventory().setLeggings(leggings);
  140. player.getInventory().setBoots(boots);
  141. }else {
  142. Map.Entry<ItemStack[], ItemStack[]> inventory = inventories.get(player.getUniqueId());
  143. player.getInventory().setContents(inventory.getKey());
  144. player.getInventory().setArmorContents(inventory.getValue());
  145. }
  146. }
  147.  
  148. @EventHandler
  149. public void onRespawn(PlayerRespawnEvent e)
  150. {
  151. Player player = e.getPlayer();
  152. Player p = e.getPlayer();
  153. if (this.inventories.containsKey(e.getPlayer().getUniqueId())) {
  154. Map.Entry<ItemStack[], ItemStack[]> inventory = inventories.get(p.getUniqueId());
  155. p.getInventory().setContents(inventory.getKey());
  156. p.getInventory().setArmorContents(inventory.getValue());
  157. }else {
  158. ItemStack diamondsword = new ItemStack(Material.IRON_SWORD);
  159. diamondsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
  160. diamondsword.setAmount(1);
  161. ItemStack bow = new ItemStack(Material.BOW);
  162. bow.addEnchantment(Enchantment.ARROW_DAMAGE, 2);
  163. bow.setAmount(1);
  164. ItemStack frod = new ItemStack(Material.FISHING_ROD);
  165. frod.addEnchantment(Enchantment.DURABILITY, 3);
  166. frod.setAmount(1);
  167. ItemStack gapple1 = new ItemStack(Material.GOLDEN_APPLE);
  168. gapple1.setAmount(6);
  169. ItemStack arrow = new ItemStack(Material.ARROW);
  170. arrow.setAmount(64);
  171. ItemStack waterbucket = new ItemStack(Material.WATER_BUCKET);
  172. waterbucket.setAmount(1);
  173. ItemStack fns = new ItemStack(Material.FLINT_AND_STEEL);
  174. fns.setAmount(1);
  175. ItemStack madera = new ItemStack(Material.WOOD);
  176. madera.setAmount(64);
  177. ItemStack piedra = new ItemStack(Material.COBBLESTONE);
  178. piedra.setAmount(64);
  179. ItemStack helmet = new ItemStack(Material.IRON_HELMET);
  180. helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  181. helmet.setAmount(1);
  182. ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE);
  183. chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  184. chestplate.setAmount(1);
  185. ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS);
  186. leggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  187. leggings.setAmount(1);
  188. ItemStack boots = new ItemStack(Material.IRON_BOOTS);
  189. boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
  190. boots.setAmount(1);
  191. player.getInventory().setItem(0, diamondsword);
  192. player.getInventory().setItem(1, frod);
  193. player.getInventory().setItem(2, bow);
  194. player.getInventory().setItem(4, gapple1);
  195. player.getInventory().setItem(11, arrow);
  196. player.getInventory().setItem(8, piedra);
  197. player.getInventory().setItem(5, waterbucket);
  198. player.getInventory().setItem(6, fns);
  199. player.getInventory().setHelmet(helmet);
  200. player.getInventory().setChestplate(chestplate);
  201. player.getInventory().setLeggings(leggings);
  202. player.getInventory().setBoots(boots);
  203. }
  204. teleportToSpawn(player);
  205. }
  206.  
  207. public boolean isInt(String s)
  208. {
  209. try
  210. {
  211. Integer.parseInt(s);
  212. return true;
  213. }
  214. catch (Exception ex) {}
  215. return false;
  216. }
  217.  
  218. public String color(String s)
  219. {
  220. return ChatColor.translateAlternateColorCodes('&', s);
  221. }
  222.  
  223. @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=false)
  224. public void onJoin(PlayerJoinEvent e)
  225. {
  226. Player p = e.getPlayer();
  227. p.setHealth(20.0D);
  228. p.teleport(p.getWorld().getSpawnLocation());
  229. for (Player allp : Bukkit.getOnlinePlayers()) {
  230. allp.showPlayer(p);
  231. }
  232. }
  233.  
  234.  
  235. @EventHandler
  236. public void onPlace(final BlockPlaceEvent e)
  237. {
  238. if (e.getItemInHand().getType().equals(Material.WOOD)) {
  239. new BukkitRunnable()
  240. {
  241. public void run()
  242. {
  243. if (e.getBlock().getType().equals(Material.WOOD)){
  244. e.getBlock().setType(Material.AIR);
  245. }
  246. }
  247. }
  248. .runTaskLater(this, getConfig().getInt("times.wood"));
  249. }
  250. World w = Bukkit.getWorld("ffa");
  251. if ((e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)) && (e.getPlayer().getLocation().getBlockY() > e.getPlayer().getWorld().getHighestBlockYAt(e.getPlayer().getLocation().getBlockX() + 1, e.getPlayer().getLocation().getBlockZ()) + 10))
  252. {
  253. e.setCancelled(true);
  254. e.getPlayer().sendMessage(ChatColor.RED + "You have reached the Max Build Height!");
  255. }
  256. }
  257.  
  258.  
  259. @EventHandler
  260. public void onPlace2(final BlockPlaceEvent e)
  261. {
  262. if (e.getItemInHand().getType().equals(Material.COBBLESTONE)) {
  263. new BukkitRunnable()
  264. {
  265. public void run()
  266. {
  267. if (e.getBlock().getType().equals(Material.COBBLESTONE)) {
  268. e.getBlock().setType(Material.AIR);
  269. Player p = e.getPlayer();
  270. Player player = e.getPlayer();
  271. ItemStack cobblestone = new ItemStack(Material.COBBLESTONE);
  272. player.getInventory().addItem(cobblestone);
  273. }
  274. }
  275. }
  276. .runTaskLater(this, getConfig().getInt("times.cobblestone"));
  277. }
  278. }
  279.  
  280. @EventHandler
  281. public void onPlace3(final BlockPlaceEvent e)
  282. {
  283. if (e.getItemInHand().getType().equals(Material.FLINT_AND_STEEL)) {
  284. new BukkitRunnable()
  285. {
  286. public void run()
  287. {
  288. if (e.getBlock().getType().equals(Material.FIRE)) {
  289. e.getBlock().setType(Material.AIR);
  290. }
  291. }
  292. }
  293. .runTaskLater(this, getConfig().getInt("times.fire"));
  294. }
  295. }
  296.  
  297. @EventHandler
  298. public void onBucketEmpty(PlayerBucketEmptyEvent e) {
  299. e.getPlayer().getInventory().getItemInHand().setType(Material.WATER_BUCKET);
  300. e.setCancelled(true);
  301. if (e.getPlayer().getFireTicks() > 1) {
  302. e.getPlayer().setFireTicks(0);
  303. }
  304. }
  305.  
  306. public void onInteractEvent(PlayerInteractEvent e)
  307. {
  308. if ((e.getItem() != null) && (e.getPlayer().getItemInHand().getType().equals(Material.FLINT_AND_STEEL)) &&
  309. (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)))
  310. {
  311. Player player = e.getPlayer();
  312. ItemStack item = player.getItemInHand();
  313. if (item.getDurability() == 0) {
  314. item.setDurability((short)62);
  315. }
  316. }
  317.  
  318. }
  319.  
  320. private void registerEvents()
  321. {
  322. PluginManager plm = Bukkit.getPluginManager();
  323. }
  324.  
  325. public void teleportToSpawn(Player p)
  326. {
  327. double X = getConfig().getDouble("Storage.DoNotEdit.RespawnLocation.X");
  328. double Y = getConfig().getDouble("Storage.DoNotEdit.RespawnLocation.Y");
  329. double Z = getConfig().getDouble("Storage.DoNotEdit.RespawnLocation.Z");
  330. Float Pitch = Float.valueOf((float)getConfig().getDouble("Storage.DoNotEdit.RespawnLocation.Pitch"));
  331. Float Yaw = Float.valueOf((float)getConfig().getDouble("Storage.DoNotEdit.RespawnLocation.Yaw"));
  332. String WorldName = getConfig().getString("Storage.DoNotEdit.RespawnLocation.World");
  333. World World = Bukkit.getWorld(WorldName);
  334. Location loc = new Location(World, X, Y, Z, Pitch.floatValue(), Yaw.floatValue());
  335. p.teleport(loc);
  336. }
  337.  
  338. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args)
  339. {
  340. Player p = (Player)sender;
  341. if (cmd.getName().equalsIgnoreCase("ffasetspawn"))
  342. {
  343. if (p.hasPermission("ac.admin")) {
  344. Player player = (Player) sender;
  345. Location loc = player.getLocation();
  346. double X = loc.getX();
  347. double Y = loc.getY();
  348. double Z = loc.getZ();
  349. double Pitch = loc.getPitch();
  350. double Yaw = loc.getYaw();
  351. String World = loc.getWorld().getName();
  352. getConfig().set("Storage.DoNotEdit.RespawnLocation.X", Double.valueOf(X));
  353. getConfig().set("Storage.DoNotEdit.RespawnLocation.Y", Double.valueOf(Y));
  354. getConfig().set("Storage.DoNotEdit.RespawnLocation.Z", Double.valueOf(Z));
  355. getConfig().set("Storage.DoNotEdit.RespawnLocation.Pitch", Double.valueOf(Pitch));
  356. getConfig().set("Storage.DoNotEdit.RespawnLocation.Yaw", Double.valueOf(Yaw));
  357. getConfig().set("Storage.DoNotEdit.RespawnLocation.World", World);
  358. saveConfig();
  359. return true;
  360. }
  361. }
  362. else if (cmd.getName().equalsIgnoreCase("ffaspawn"))
  363. {
  364. if (p.hasPermission("ac.admin"))
  365. {
  366. p.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', getConfig().getString("tpspawn")));
  367. p.teleport(p.getWorld().getSpawnLocation());
  368. }
  369. else
  370. {
  371. p.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', getConfig().getString("cant")));
  372. }
  373. }
  374. else if (cmd.getName().equalsIgnoreCase("cc"))
  375. {
  376. if (p.hasPermission("ac.mod"))
  377. {
  378. int i = 0;
  379. while (i < 120)
  380. {
  381. Bukkit.broadcastMessage("");
  382. i++;
  383. }
  384. Bukkit.broadcastMessage(ChatColor.RED +"Chat was cleared by " + ChatColor.GREEN + p.getName() + "");
  385. }
  386. else
  387. {
  388. p.sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', getConfig().getString("cant")));
  389. }
  390. }
  391.  
  392. else if (cmd.getName().equalsIgnoreCase("save"))
  393. {
  394. Player pl = (Player)sender;
  395. //this.inventories.put(p.getUniqueId(), Arrays.stream(p.getInventory().getContents()).map(ItemStack::clone).toArray(ItemStack[]::new));
  396. //this.armor.put(p.getUniqueId(), Arrays.stream(p.getInventory().getArmorContents()).map(ItemStack::clone).toArray(ItemStack[]::new));
  397.  
  398. Map.Entry<ItemStack[], ItemStack[]> inventory = null;
  399. try {
  400. inventory = playerInventoryFromBase64(playerInventoryToBase64(pl.getInventory()));
  401. }catch (IOException ignored) {}
  402.  
  403. if(inventory != null) {
  404. inventories.put(p.getUniqueId(), inventory);
  405.  
  406. new BukkitRunnable() {
  407. @Override
  408. public void run() {
  409. lock.writeLock().lock();
  410. JsonWriter writer = null;
  411. try {
  412. writer = new JsonWriter(new FileWriter(invSaves));
  413. writer.setIndent(" ");
  414. writer.beginObject();
  415. for(Map.Entry<UUID, Map.Entry<ItemStack[], ItemStack[]>> entry : inventories.entrySet()) {
  416. writer.name(entry.getKey().toString()).beginObject().name("inventory").value(arrayToBase64(entry.getValue().getKey())).name("armour").value(arrayToBase64(entry.getValue().getValue())).endObject();
  417. }
  418. writer.endObject();
  419. }catch (IOException ignored) {
  420. }finally {
  421. lock.writeLock().unlock();
  422.  
  423. if(writer != null) try {
  424. writer.close();
  425. }catch (IOException e) {
  426. e.printStackTrace();
  427. }
  428. }
  429. }
  430. }.runTaskAsynchronously(this);
  431. }
  432. p.getPlayer().sendMessage(ChatColor.RED + "Your inventory has been saved.");
  433. }
  434. else if (cmd.getName().equalsIgnoreCase("?"))
  435. {
  436. if (p.hasPermission("ac.admin"))
  437. {
  438.  
  439. }
  440. }
  441. return false;
  442. }
  443.  
  444.  
  445.  
  446. public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
  447. if (((e.getDamager() instanceof Arrow)) && ((e.getEntity() instanceof Player)) && ((((Arrow) e.getDamager()).getShooter() instanceof Player)) &&
  448. ((e.getDamager() instanceof Arrow))) {
  449. Player victim = (Player) e.getEntity();
  450. Player killer = (Player) ((Arrow) e.getDamager()).getShooter();
  451. if (killer.getItemInHand().getType() == Material.BOW){
  452. double h = victim.getHealth() / 2.0D;
  453. DecimalFormat df = new DecimalFormat("#.#");
  454. killer.sendMessage(ChatColor.GREEN + victim.getName() + ChatColor.GRAY + " is now at " + ChatColor.GREEN + df.format(h) + ChatColor.DARK_RED + " ❤");
  455. }
  456. }
  457. }
  458.  
  459. public static boolean isPlayerInSpawnR(Player player, Location loc1, Location loc2)
  460. {
  461. double[] dim = new double[2];
  462.  
  463. dim[0] = loc1.getX();
  464. dim[1] = loc2.getX();
  465. Arrays.sort(dim);
  466. if ((player.getLocation().getX() > dim[1]) || (player.getLocation().getX() < dim[0])) {
  467. return false;
  468. }
  469. dim[0] = loc1.getZ();
  470. dim[1] = loc2.getZ();
  471. Arrays.sort(dim);
  472. if ((player.getLocation().getZ() > dim[1]) || (player.getLocation().getZ() < dim[0])) {
  473. return false;
  474. }
  475. return true;
  476. }
  477.  
  478. public static String playerInventoryToBase64(PlayerInventory inventory) {
  479. try {
  480. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  481. BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
  482.  
  483. // Write the size of the inventory
  484. dataOutput.writeInt(inventory.getSize());
  485.  
  486. // Save every element in the list
  487. for (int i = 0; i < inventory.getSize(); i++) {
  488. dataOutput.writeObject(inventory.getItem(i));
  489. }
  490.  
  491. for(int i = 0; i < 4; i++) {
  492. dataOutput.writeObject(inventory.getArmorContents()[i]);
  493. }
  494.  
  495. // Serialize that array
  496. dataOutput.close();
  497. return Base64Coder.encodeLines(outputStream.toByteArray());
  498. } catch (Exception e) {
  499. throw new IllegalStateException("Unable to save item stacks.", e);
  500. }
  501. }
  502.  
  503. public static Map.Entry<ItemStack[], ItemStack[]> playerInventoryFromBase64(String data) throws IOException {
  504. try {
  505. ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
  506. BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
  507. List<ItemStack> inventory = new ArrayList<>();
  508. List<ItemStack> armour = new ArrayList<>();
  509.  
  510. int size = dataInput.readInt();
  511.  
  512. for(int i = 0; i < size; i++) {
  513. inventory.add((ItemStack) dataInput.readObject());
  514. }
  515.  
  516. for(int i = 0; i < 4; i++) {
  517. armour.add((ItemStack) dataInput.readObject());
  518. }
  519.  
  520. dataInput.close();
  521. return new AbstractMap.SimpleEntry<>(inventory.toArray(new ItemStack[size]), armour.toArray(new ItemStack[4]));
  522. } catch (Exception e) {
  523. throw new IOException("Unable to decode class type.", e);
  524. }
  525. }
  526.  
  527. public static String arrayToBase64(ItemStack[] array) {
  528. try {
  529. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  530. BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
  531.  
  532. // Write the size of the inventory
  533. dataOutput.writeInt(array.length);
  534.  
  535. // Save every element in the list
  536. for (int i = 0; i < array.length; i++) {
  537. dataOutput.writeObject(array[i]);
  538. }
  539.  
  540. // Serialize that array
  541. dataOutput.close();
  542. return Base64Coder.encodeLines(outputStream.toByteArray());
  543. } catch (Exception e) {
  544. throw new IllegalStateException("Unable to save item stacks.", e);
  545. }
  546. }
  547.  
  548. public static ItemStack[] arrayFromBase64(String data) throws IOException {
  549. try {
  550. ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
  551. BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
  552. ItemStack[] array = new ItemStack[dataInput.readInt()];
  553.  
  554. // Read the serialized inventory
  555. for (int i = 0; i < array.length; i++) {
  556. array[i] = (ItemStack) dataInput.readObject();
  557. }
  558. dataInput.close();
  559. return array;
  560. } catch (ClassNotFoundException e) {
  561. throw new IOException("Unable to decode class type.", e);
  562. }
  563. }
  564. }
Advertisement
Add Comment
Please, Sign In to add comment