@EventHandler public void onClose(InventoryCloseEvent e) { if (Variables.enchanting.containsKey(e.getPlayer().getUniqueId())) Variables.enchanting.remove(e.getPlayer().getUniqueId()); if (Variables.backpack.containsKey(e.getPlayer().getUniqueId())) { ((Player) e.getPlayer()).playSound(e.getPlayer().getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Backpacks.saveBackpack(e.getInventory(), Variables.backpack.get(e.getPlayer().getUniqueId())); Variables.backpack.remove(e.getPlayer().getUniqueId()); } }
@EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { ItemStack item = e.getItem(); Player p = e.getPlayer(); if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_SMALL, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_SMALL, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 9))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_MEDIUM, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_MEDIUM, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 18))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_LARGE, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_LARGE, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.WOVEN_BACKPACK, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.WOVEN_BACKPACK, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GILDED_BACKPACK, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.GILDED_BACKPACK, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 45))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.BOUND_BACKPACK, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.COOLER, false)) { e.setCancelled(true); if (Slimefun.hasUnlocked(p, SlimefunItems.COOLER, true)) { if (item.getAmount() == 1) { for (int line = 0; line < item.getItemMeta().getLore().size(); line++) { if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) { ItemMeta im = item.getItemMeta(); List<String> lore = im.getLore(); lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27))); im.setLore(lore); item.setItemMeta(im); break; } } Backpacks.openBackpack(p, item); p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F); Variables.backpack.put(p.getUniqueId(), item); } else Messages.local.sendTranslation(p, "backpack.no-stack", true); } } } }