@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPrepareEnchant(final PrepareItemEnchantEvent event) { final ItemStack item = getItem(event.getItem(), event.getEnchanter()); final long seed = enchantSeeds.get(event.getEnchanter().getUniqueId()); offers.put(event.getEnchanter().getUniqueId(), new int[] { event.getOffers()[0].getCost(), 1, event.getOffers()[1].getCost(), 2, event.getOffers()[2].getCost(), 3 }); for (final EnchantmentOffer offer : event.getOffers()) { final EnchantResult result = mechanics.generateEnchantments( event.getEnchanter(), item, offer.getCost(), true, seed); result.getFirstVanillaEnchantment().ifPresent(enchant -> { offer.setEnchantment(enchant.getEnchantment()); offer.setEnchantmentLevel(result.getFirstVanillaLevel()); }); } }
@Override protected void onInventoryEvent(InventoryEvent event) { if (event instanceof EnchantItemEvent) { callEvent(((EnchantItemEvent) event).getEnchanter(), event); } else if (event instanceof PrepareItemEnchantEvent) { callEvent(((PrepareItemEnchantEvent) event).getEnchanter(), event); } else { InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof Player) { callEvent((Player)holder, event); } } }
public boolean init(Expression<?>[] args, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) { if (!ScriptLoader.isCurrentEvent(PrepareItemEnchantEvent.class)) { Skript.error("You can not use enchantment offers expression in any event but on enchant prepare!"); return false; } return true; }
@Nullable protected EnchantmentOffer[] get(Event e) { if (((PrepareItemEnchantEvent)e).getOffers() != null) { return ((PrepareItemEnchantEvent)e).getOffers(); } return null; }
@EventHandler public void onPrepareItemEnchant(PrepareItemEnchantEvent event) { BaseSTBItem item = SensibleToolbox.getItemRegistry().fromItemStack(event.getItem()); if (item != null && !item.isEnchantable()) { event.setCancelled(true); } }
@EventHandler public void onPlayerEnchantItem(PrepareItemEnchantEvent event) { if(plugin.isXpBar()) { event.setCancelled(true); } }
@EventHandler public void onPrepareEnchantItem(PrepareItemEnchantEvent event) { this.manager.invoke(event.getEnchanter(), event); }
@EventHandler public void onPlayerPrepareEnchant(PrepareItemEnchantEvent event) { callHandlers("player.enchant.prepare", event); }
public void a(IInventory iinventory) { if (iinventory == this.enchantSlots) { ItemStack itemstack = iinventory.getItem(0); int i; if (itemstack != null) { // CraftBukkit - relax condition this.f = this.l.nextLong(); if (!this.world.isStatic) { i = 0; int j; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { if ((j != 0 || k != 0) && this.world.isEmpty(this.x + k, this.y, this.z + j) && this.world.isEmpty(this.x + k, this.y + 1, this.z + j)) { if (this.world.getType(this.x + k * 2, this.y, this.z + j * 2) == Blocks.BOOKSHELF) { ++i; } if (this.world.getType(this.x + k * 2, this.y + 1, this.z + j * 2) == Blocks.BOOKSHELF) { ++i; } if (k != 0 && j != 0) { if (this.world.getType(this.x + k * 2, this.y, this.z + j) == Blocks.BOOKSHELF) { ++i; } if (this.world.getType(this.x + k * 2, this.y + 1, this.z + j) == Blocks.BOOKSHELF) { ++i; } if (this.world.getType(this.x + k, this.y, this.z + j * 2) == Blocks.BOOKSHELF) { ++i; } if (this.world.getType(this.x + k, this.y + 1, this.z + j * 2) == Blocks.BOOKSHELF) { ++i; } } } } } for (j = 0; j < 3; ++j) { this.costs[j] = EnchantmentManager.a(this.l, j, i, itemstack); } // CraftBukkit start CraftItemStack item = CraftItemStack.asCraftMirror(itemstack); PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.world.getWorld().getBlockAt(this.x, this.y, this.z), item, this.costs, i); event.setCancelled(!itemstack.x()); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } return; } // CraftBukkit end this.b(); } } else { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } } } }
public void a(IInventory iinventory) { if (iinventory == this.enchantSlots) { ItemStack itemstack = iinventory.getItem(0); int i; if (itemstack != null) { // CraftBukkit - relax condition this.f = this.l.nextLong(); if (!this.world.isStatic) { i = 0; int j; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { if ((j != 0 || k != 0) && this.world.isEmpty(this.x + k, this.y, this.z + j) && this.world.isEmpty(this.x + k, this.y + 1, this.z + j)) { if (this.world.getTypeId(this.x + k * 2, this.y, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k * 2, this.y + 1, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (k != 0 && j != 0) { if (this.world.getTypeId(this.x + k * 2, this.y, this.z + j) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k * 2, this.y + 1, this.z + j) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k, this.y, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k, this.y + 1, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } } } } } for (j = 0; j < 3; ++j) { this.costs[j] = EnchantmentManager.a(this.l, j, i, itemstack); } // CraftBukkit start CraftItemStack item = CraftItemStack.asCraftMirror(itemstack); PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.world.getWorld().getBlockAt(this.x, this.y, this.z), item, this.costs, i); event.setCancelled(!itemstack.x()); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } return; } // CraftBukkit end this.b(); } } else { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } } } }
public void onCraftMatrixChanged(IInventory p_75130_1_) { if (p_75130_1_ == this.tableInventory) { ItemStack itemstack = p_75130_1_.getStackInSlot(0); int i; if (itemstack != null) // CraftBukkit - relax condition { this.nameSeed = this.rand.nextLong(); if (!this.worldPointer.isRemote) { i = 0; int j; float power = 0; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { if ((j != 0 || k != 0) && this.worldPointer.isAirBlock(this.posX + k, this.posY, this.posZ + j) && this.worldPointer.isAirBlock(this.posX + k, this.posY + 1, this.posZ + j)) { power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY, posZ + j * 2); power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY + 1, posZ + j * 2); if (k != 0 && j != 0) { power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY, posZ + j ); power += ForgeHooks.getEnchantPower(worldPointer, posX + k * 2, posY + 1, posZ + j ); power += ForgeHooks.getEnchantPower(worldPointer, posX + k, posY, posZ + j * 2); power += ForgeHooks.getEnchantPower(worldPointer, posX + k, posY + 1, posZ + j * 2); } } } } for (j = 0; j < 3; ++j) { this.enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(this.rand, j, (int)power, itemstack); } // CraftBukkit start CraftItemStack item = CraftItemStack.asCraftMirror(itemstack); PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.worldPointer.getWorld().getBlockAt(this.posX, this.posY, this.posZ), item, this.enchantLevels, i); event.setCancelled(!itemstack.isItemEnchantable()); if (this.getBukkitView() != null) this.worldPointer.getServer().getPluginManager().callEvent(event); // Cauldron - allow vanilla mods to byp if (event.isCancelled()) { for (i = 0; i < 3; ++i) { this.enchantLevels[i] = 0; } return; } // CraftBukkit end this.detectAndSendChanges(); } } else { for (i = 0; i < 3; ++i) { this.enchantLevels[i] = 0; } } } }
public void a(IInventory iinventory) { if (iinventory == this.enchantSlots) { ItemStack itemstack = iinventory.getItem(0); int i; if (itemstack != null) { // CraftBukkit - relax condition this.f = this.l.nextLong(); if (!this.world.isStatic) { i = 0; int j; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { if ((j != 0 || k != 0) && this.world.isEmpty(this.x + k, this.y, this.z + j) && this.world.isEmpty(this.x + k, this.y + 1, this.z + j)) { if (this.world.getTypeId(this.x + k * 2, this.y, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k * 2, this.y + 1, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (k != 0 && j != 0) { if (this.world.getTypeId(this.x + k * 2, this.y, this.z + j) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k * 2, this.y + 1, this.z + j) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k, this.y, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } if (this.world.getTypeId(this.x + k, this.y + 1, this.z + j * 2) == Block.BOOKSHELF.id) { ++i; } } } } } for (j = 0; j < 3; ++j) { this.costs[j] = EnchantmentManager.a(this.l, j, i, itemstack); } // CraftBukkit start CraftItemStack item = CraftItemStack.asCraftMirror(itemstack); PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.world.getWorld().getBlockAt(this.x, this.y, this.z), item, this.costs, i); event.setCancelled(!itemstack.w()); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } return; } // CraftBukkit end this.b(); } } else { for (i = 0; i < 3; ++i) { this.costs[i] = 0; } } } }