use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project DragonsOnline by UniverseCraft.
the class SpellListeners method onInventoryClick.
@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
User user = UserLoader.fromPlayer(player);
if (e.getInventory().getType() == InventoryType.FURNACE) {
// 0 = smelting
// 1 = fuel
// 2 = result
CraftInventory cc = (CraftInventory) e.getInventory();
int i = 0;
for (ItemStack is : cc.getContents()) {
user.debug(i + ": " + is);
i++;
}
}
if (e.getView().getTitle().equals(SpellConstants.ENCHANTER_MENU_TITLE)) {
user.debug("Interacted with the Enchanter menu. SlotType=" + e.getSlotType());
CraftInventoryCustom cc = (CraftInventoryCustom) e.getInventory();
if (e.getSlotType() == SlotType.RESULT) {
user.debug("RESULT");
user.debug("curr=" + e.getCurrentItem());
user.debug("curs=" + e.getCursor());
Item current = ItemLoader.fromBukkit(e.getCurrentItem());
if (current == null)
return;
user.debug("receiving the updated item");
current.setItemStack(e.getCurrentItem().clone());
e.setCurrentItem(new ItemStack(Material.AIR));
e.setCursor(current.getItemStack());
cc.setItem(0, new ItemStack(Material.AIR));
cc.setItem(1, new ItemStack(Material.AIR));
cc.setItem(2, new ItemStack(Material.AIR));
e.setResult(Result.DENY);
e.setCancelled(false);
return;
}
ItemStack cursorCopy = e.getCursor().clone();
Item item = ItemLoader.fromBukkit(e.getCursor());
if (item == null)
return;
if (e.getSlotType() == SlotType.FUEL && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellScroll"))) {
user.debug("Using alternative fuel in furnace for enchanting");
user.debug("curr=" + e.getCurrentItem() + ", cursor=" + e.getCursor());
item.setItemStack(cursorCopy);
if (e.getInventory().getType() == InventoryType.FURNACE) {
int i = 0;
for (ItemStack is : cc.getContents()) {
user.debug(i + ": " + is);
i++;
}
e.setCurrentItem(cursorCopy);
e.setCursor(new ItemStack(Material.AIR));
e.setCancelled(true);
}
}
if (e.getSlotType() == SlotType.CRAFTING && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellCast"))) {
// No fuel
if (cc.getItem(1) == null)
return;
String spellDisplayName = ChatColor.stripColor(cc.getItem(1).getItemMeta().getDisplayName().replace("Scroll", "").trim());
user.debug("binding spell " + spellDisplayName);
Spell spell = registry.getSpellByDisplayName(spellDisplayName);
user.debug("spell=" + spell);
if (spell.bindStatus(item) == BindStatus.CAPABLE) {
double gold = user.getGold();
if (gold < 100.0) {
player.sendMessage(ChatColor.RED + "Binding spells costs 100 Gold. (Need " + (100 - gold) + " more)");
player.getInventory().addItem(cc.getItem(1) == null ? new ItemStack(Material.AIR) : cc.getItem(1));
player.getInventory().addItem(e.getCursor());
e.setCursor(new ItemStack(Material.AIR));
e.setCurrentItem(new ItemStack(Material.AIR));
e.setCancelled(true);
player.closeInventory();
return;
}
user.takeGold(100.0);
spell.bind(player, item);
cc.setItem(0, new ItemStack(Material.AIR));
cc.setItem(1, new ItemStack(Material.AIR));
cc.setItem(2, item.getItemStack());
e.setCursor(new ItemStack(Material.AIR));
e.setResult(Result.ALLOW);
e.setCancelled(true);
user.debug("bound spell and updated inventory");
player.sendMessage(ChatColor.DARK_PURPLE + "Bound spell " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName() + ChatColor.DARK_PURPLE + " to " + ChatColor.LIGHT_PURPLE + item.getName());
}
}
return;
}
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.
the class ContainerManager_v1_10_R1 method getLocation.
public Location getLocation(Inventory inventory) {
if (inventory == null) {
return null;
}
if (!(inventory instanceof CraftInventory)) {
return null;
}
try {
Field ic = CraftInventory.class.getDeclaredField("inventory");
ic.setAccessible(true);
Object crafting = ic.get(inventory);
if (crafting instanceof CustomInventoryCrafting) {
CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
return table.getLocation();
}
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.
the class ContainerManager_v1_15_R1 method getLocation.
public Location getLocation(Inventory inventory) {
if (inventory == null) {
return null;
}
if (!(inventory instanceof CraftInventory)) {
return null;
}
try {
Field ic = CraftInventory.class.getDeclaredField("inventory");
ic.setAccessible(true);
Object crafting = ic.get(inventory);
if (crafting instanceof CustomInventoryCrafting) {
CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
return table.getLocation();
}
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.
the class ContainerManager_v1_16_R2 method getLocation.
public Location getLocation(Inventory inventory) {
if (inventory == null) {
return null;
}
if (!(inventory instanceof CraftInventory)) {
return null;
}
try {
Field ic = CraftInventory.class.getDeclaredField("inventory");
ic.setAccessible(true);
Object crafting = ic.get(inventory);
if (crafting instanceof CustomInventoryCrafting) {
CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
return table.getLocation();
}
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.
the class ContainerManager_v1_16_R3 method getLocation.
public Location getLocation(Inventory inventory) {
if (inventory == null) {
return null;
}
if (!(inventory instanceof CraftInventory)) {
return null;
}
try {
Field ic = CraftInventory.class.getDeclaredField("inventory");
ic.setAccessible(true);
Object crafting = ic.get(inventory);
if (crafting instanceof CustomInventoryCrafting) {
CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
return table.getLocation();
}
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
Aggregations