Java 类org.bukkit.event.enchantment.PrepareItemEnchantEvent 实例源码
项目:EnchantmentAPI
文件:EnchantListener.java
@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());
});
}
}
项目:PV-Star
文件:ArenaEventForwarder.java
@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);
}
}
}
项目:Skellett
文件:ExprEnchantmentOffers.java
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;
}
项目:Skellett
文件:ExprEnchantmentOffers.java
@Nullable
protected EnchantmentOffer[] get(Event e) {
if (((PrepareItemEnchantEvent)e).getOffers() != null) {
return ((PrepareItemEnchantEvent)e).getOffers();
}
return null;
}
项目:sensibletoolbox
文件:GeneralListener.java
@EventHandler
public void onPrepareItemEnchant(PrepareItemEnchantEvent event) {
BaseSTBItem item = SensibleToolbox.getItemRegistry().fromItemStack(event.getItem());
if (item != null && !item.isEnchantable()) {
event.setCancelled(true);
}
}
项目:SleepingPlus
文件:PlayerEvent.java
@EventHandler
public void onPlayerEnchantItem(PrepareItemEnchantEvent event)
{
if(plugin.isXpBar())
{
event.setCancelled(true);
}
}
项目:AbilityAPI
文件:SequenceListener.java
@EventHandler
public void onPrepareEnchantItem(PrepareItemEnchantEvent event) {
this.manager.invoke(event.getEnchanter(), event);
}
项目:RpgPlus
文件:ScriptEventManager.java
@EventHandler
public void onPlayerPrepareEnchant(PrepareItemEnchantEvent event) {
callHandlers("player.enchant.prepare", event);
}
项目:CraftBukkit
文件:ContainerEnchantTable.java
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;
}
}
}
}
项目:Almura-Server
文件:ContainerEnchantTable.java
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;
}
}
}
}
项目:Tweakkit-Server
文件:ContainerEnchantTable.java
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;
}
}
}
}
项目:Cauldron
文件:ContainerEnchantment.java
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;
}
}
}
}
项目:Craft-city
文件:ContainerEnchantTable.java
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;
}
}
}
}