@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onInvOpen(InventoryClickEvent event) {
Bukkit.getScheduler().scheduleSyncDelayedTask(ProtocolSupportLegacySupport.getInstance(), () -> {
Inventory topinv = event.getWhoClicked().getOpenInventory().getTopInventory();
if (!(topinv instanceof EnchantingInventory)) {
return;
}
EnchantingInventory enchinv = (EnchantingInventory) topinv;
Player player = (Player) event.getWhoClicked();
int lapisEnchAmount = enchinv.getSecondary() != null ? enchinv.getSecondary().getAmount() : 0;
ItemStack[] contents = player.getInventory().getStorageContents();
for (int i = 0; i < contents.length; i++) {
ItemStack itemstack = contents[i];
if (lapis.isSimilar(itemstack)) {
int lapisPlayerAmount = Math.min(itemstack.getAmount(), Material.INK_SACK.getMaxStackSize() - lapisEnchAmount);
itemstack.setAmount(itemstack.getAmount() - lapisPlayerAmount);
if (itemstack.getAmount() == 0) {
contents[i] = null;
}
lapisEnchAmount += lapisPlayerAmount;
if (lapisEnchAmount == Material.INK_SACK.getMaxStackSize()) {
break;
}
}
}
player.getInventory().setStorageContents(contents);
if (lapisEnchAmount != 0) {
enchinv.setSecondary(new Dye(DyeColor.BLUE).toItemStack(lapisEnchAmount));
}
player.updateInventory();
});
}
java类org.bukkit.inventory.EnchantingInventory的实例源码
EnchantingTableHandler.java 文件源码
项目:ProtocolSupportLegacySupport
阅读 22
收藏 0
点赞 0
评论 0
EnchantingTableHandler.java 文件源码
项目:ProtocolSupportLegacySupport
阅读 31
收藏 0
点赞 0
评论 0
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onInvClose(InventoryCloseEvent event) {
Inventory topinv = event.getView().getTopInventory();
if (!(topinv instanceof EnchantingInventory)) {
return;
}
EnchantingInventory enchinv = (EnchantingInventory) topinv;
ItemStack lapisEnch = enchinv.getSecondary();
enchinv.setSecondary(null);
if (lapisEnch != null) {
Player player = (Player) event.getPlayer();
player.getInventory().addItem(lapisEnch).values().forEach(rem -> player.getWorld().dropItem(player.getLocation(), rem));
}
}
ModuleNoLapisEnchantments.java 文件源码
项目:BukkitOldCombatMechanics
阅读 20
收藏 0
点赞 0
评论 0
@EventHandler
public void onEnchant(EnchantItemEvent e) {
Block block = e.getEnchantBlock();
if(!isEnabled(block.getWorld())) return;
if(!hasPermission(e.getEnchanter())) return;
EnchantingInventory ei = (EnchantingInventory) e.getInventory(); //Not checking here because how else would event be fired?
ei.setSecondary(getLapis());
}
ModuleNoLapisEnchantments.java 文件源码
项目:BukkitOldCombatMechanics
阅读 20
收藏 0
点赞 0
评论 0
@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
if(!isEnabled(e.getPlayer().getWorld())) return;
Inventory inv = e.getInventory();
if(inv == null || inv.getType() != InventoryType.ENCHANTING || !hasPermission((Player) e.getPlayer())) return;
EnchantingInventory ei = (EnchantingInventory) inv;
ei.setSecondary(new ItemStack(Material.AIR));
}
ModuleNoLapisEnchantments.java 文件源码
项目:BukkitOldCombatMechanics
阅读 24
收藏 0
点赞 0
评论 0
@EventHandler
public void onInventoryOpen(InventoryOpenEvent e) {
if(!isEnabled(e.getPlayer().getWorld())) return;
Inventory inv = e.getInventory();
if(inv == null || inv.getType() != InventoryType.ENCHANTING || !hasPermission((Player) e.getPlayer())) return;
( (EnchantingInventory) inv).setSecondary(getLapis());
}