public void die(DamageSource damagesource) {
    // CraftBukkit start
    if (this.dead) {
      return;
    }

    java.util.List<org.bukkit.inventory.ItemStack> loot =
        new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
    boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory");

    if (!keepInventory) {
      for (int i = 0; i < this.inventory.items.length; ++i) {
        if (this.inventory.items[i] != null) {
          loot.add(CraftItemStack.asCraftMirror(this.inventory.items[i]));
        }
      }

      for (int i = 0; i < this.inventory.armor.length; ++i) {
        if (this.inventory.armor[i] != null) {
          loot.add(CraftItemStack.asCraftMirror(this.inventory.armor[i]));
        }
      }
    }

    org.bukkit.event.entity.PlayerDeathEvent event =
        CraftEventFactory.callPlayerDeathEvent(
            this, loot, damagesource.getLocalizedDeathMessage(this));

    String deathMessage = event.getDeathMessage();

    if (deathMessage != null && deathMessage.length() > 0) {
      this.server.getPlayerList().k(event.getDeathMessage());
    }

    // CraftBukkit - we clean the player's inventory after the EntityDeathEvent is called so plugins
    // can get the exact state of the inventory.
    if (!keepInventory) {
      for (int i = 0; i < this.inventory.items.length; ++i) {
        this.inventory.items[i] = null;
      }

      for (int i = 0; i < this.inventory.armor.length; ++i) {
        this.inventory.armor[i] = null;
      }
    }

    this.closeInventory();

    // Update effects on player death
    this.updateEffects = true;
    // CraftBukkit end
  }
Beispiel #2
0
  private static boolean tryTakeInItemFromSlot(
      IHopper ihopper, IInventory iinventory, int i, int j) {
    ItemStack itemstack = iinventory.getItem(i);

    if (itemstack != null && canTakeItemFromInventory(iinventory, itemstack, i, j)) {
      ItemStack itemstack1 = itemstack.cloneItemStack();
      // CraftBukkit start - Call event on collection of items from inventories into the hopper
      CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1));

      Inventory sourceInventory;
      // Have to special case large chests as they work oddly
      if (iinventory instanceof InventoryLargeChest) {
        sourceInventory =
            new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(
                (InventoryLargeChest) iinventory);
      } else if (isIronChest) {
        sourceInventory = null;
      } else {
        sourceInventory = iinventory.getOwner().getInventory();
      }

      InventoryMoveItemEvent event =
          new InventoryMoveItemEvent(
              sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false);

      ihopper.getWorld().getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        iinventory.setItem(i, itemstack1);

        if (ihopper instanceof TileEntityHopper) {
          ((TileEntityHopper) ihopper).c(ihopper.getWorld().spigotConfig.hopperTransfer); // Spigot
        } else if (ihopper instanceof EntityMinecartHopper) {
          ((EntityMinecartHopper) ihopper)
              .l(ihopper.getWorld().spigotConfig.hopperTransfer / 2); // Spigot
        }

        return false;
      }
      ItemStack itemstack2 = addItem(ihopper, CraftItemStack.asNMSCopy(event.getItem()), -1);

      if (itemstack2 == null || itemstack2.count == 0) {
        if (event.getItem().equals(oitemstack)) {
          iinventory.update();
        } else {
          iinventory.setItem(i, itemstack1);
        }
        // CraftBukkit end

        return true;
      }

      iinventory.setItem(i, itemstack1);
    }

    return false;
  }
Beispiel #3
0
  // alkazia
  private boolean k() {
    IInventory iinventory = this.l();

    if (iinventory == null) {
      return false;
    } else {
      for (int i = 0; i < this.getSize(); ++i) {
        if (this.getItem(i) != null) {
          ItemStack itemstack = this.getItem(i).cloneItemStack();
          // CraftBukkit start - Call event when pushing items into other inventories
          CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.splitStack(i, 1));

          Inventory destinationInventory;
          // Have to special case large chests as they work oddly
          if (iinventory instanceof InventoryLargeChest) {
            destinationInventory =
                new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest(
                    (InventoryLargeChest) iinventory);
          } else if (isIronChest) {
            destinationInventory = null;
          } else {
            destinationInventory = iinventory.getOwner().getInventory();
          }

          InventoryMoveItemEvent event =
              new InventoryMoveItemEvent(
                  this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
          this.getWorld().getServer().getPluginManager().callEvent(event);
          if (event.isCancelled()) {
            this.setItem(i, itemstack);
            this.c(world.spigotConfig.hopperTransfer); // Spigot
            return false;
          }
          ItemStack itemstack1 =
              addItem(
                  iinventory,
                  CraftItemStack.asNMSCopy(event.getItem()),
                  Facing.OPPOSITE_FACING[BlockHopper.b(this.p())]);

          if (itemstack1 == null || itemstack1.count == 0) {
            if (event.getItem().equals(oitemstack)) {
              iinventory.update();
            } else {
              this.setItem(i, itemstack);
            }
            // CraftBukkit end
            return true;
          }

          this.setItem(i, itemstack);
        }
      }

      return false;
    }
  }
Beispiel #4
0
 // CraftBukkit start
 public org.bukkit.inventory.ShapedRecipe toBukkitRecipe() {
   CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
   CraftShapedRecipe recipe = new CraftShapedRecipe(result, this);
   switch (this.height) {
     case 1:
       switch (this.width) {
         case 1:
           recipe.shape("a");
           break;
         case 2:
           recipe.shape("ab");
           break;
         case 3:
           recipe.shape("abc");
           break;
       }
       break;
     case 2:
       switch (this.width) {
         case 1:
           recipe.shape("a", "b");
           break;
         case 2:
           recipe.shape("ab", "cd");
           break;
         case 3:
           recipe.shape("abc", "def");
           break;
       }
       break;
     case 3:
       switch (this.width) {
         case 1:
           recipe.shape("a", "b", "c");
           break;
         case 2:
           recipe.shape("ab", "cd", "ef");
           break;
         case 3:
           recipe.shape("abc", "def", "ghi");
           break;
       }
       break;
   }
   char c = 'a';
   for (ItemStack stack : this.items) {
     if (stack != null) {
       recipe.setIngredient(
           c,
           org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(stack.getItem()),
           stack.getData());
     }
     c++;
   }
   return recipe;
 }
  public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    EnumFacing enumfacing = BlockDispenser.b(isourceblock.h());
    double d0 = isourceblock.getX() + (double) enumfacing.c();
    double d1 = (double) ((float) isourceblock.getBlockY() + 0.2F);
    double d2 = isourceblock.getZ() + (double) enumfacing.e();

    // CraftBukkit start
    World world = isourceblock.k();
    ItemStack itemstack1 = itemstack.a(1);
    org.bukkit.block.Block block =
        world
            .getWorld()
            .getBlockAt(
                isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
    CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

    BlockDispenseEvent event =
        new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d0, d1, d2));
    if (!BlockDispenser.eventFired) {
      world.getServer().getPluginManager().callEvent(event);
    }

    if (event.isCancelled()) {
      itemstack.count++;
      return itemstack;
    }

    if (!event.getItem().equals(craftItem)) {
      itemstack.count++;
      // Chain to handler for new item
      ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
      IDispenseBehavior idispensebehavior =
          (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
      if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
        idispensebehavior.a(isourceblock, eventStack);
        return itemstack;
      }
    }

    itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
    EntityFireworks entityfireworks =
        new EntityFireworks(
            isourceblock.k(),
            event.getVelocity().getX(),
            event.getVelocity().getY(),
            event.getVelocity().getZ(),
            itemstack1);

    isourceblock.k().addEntity(entityfireworks);
    // itemstack.a(1); // Handled during event processing
    // CraftBukkit end

    return itemstack;
  }
  public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    ItemBucket itembucket = (ItemBucket) itemstack.getItem();
    BlockPosition blockposition =
        isourceblock.getBlockPosition().shift(BlockDispenser.b(isourceblock.f()));

    // CraftBukkit start
    World world = isourceblock.i();
    int x = blockposition.getX();
    int y = blockposition.getY();
    int z = blockposition.getZ();
    if (world.isEmpty(blockposition)
        || !world.getType(blockposition).getBlock().getMaterial().isBuildable()) {
      org.bukkit.block.Block block =
          world
              .getWorld()
              .getBlockAt(
                  isourceblock.getBlockPosition().getX(),
                  isourceblock.getBlockPosition().getY(),
                  isourceblock.getBlockPosition().getZ());
      CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);

      BlockDispenseEvent event =
          new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(x, y, z));
      if (!BlockDispenser.eventFired) {
        world.getServer().getPluginManager().callEvent(event);
      }

      if (event.isCancelled()) {
        return itemstack;
      }

      if (!event.getItem().equals(craftItem)) {
        // Chain to handler for new item
        ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
        IDispenseBehavior idispensebehavior =
            (IDispenseBehavior) BlockDispenser.M.get(eventStack.getItem());
        if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
          idispensebehavior.a(isourceblock, eventStack);
          return itemstack;
        }
      }

      itembucket = (ItemBucket) CraftItemStack.asNMSCopy(event.getItem()).getItem();
    }
    // CraftBukkit end

    if (itembucket.a(isourceblock.i(), blockposition)) {
      // CraftBukkit start - Handle stacked buckets
      Item item = Items.BUCKET;
      if (--itemstack.count == 0) {
        itemstack.setItem(Items.BUCKET);
        itemstack.count = 1;
      } else if (((TileEntityDispenser) isourceblock.getTileEntity()).addItem(new ItemStack(item))
          < 0) {
        this.b.a(isourceblock, new ItemStack(item));
      }
      // CraftBukkit end
      return itemstack;
    } else {
      return this.b.a(isourceblock, itemstack);
    }
  }
 public ItemStack getItemOnCursor() {
   return CraftItemStack.asCraftMirror(getHandle().inventory.getCarried());
 }
  public ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
    World world = isourceblock.i();
    IPosition iposition = BlockDispenser.a(isourceblock);
    EnumDirection enumdirection = BlockDispenser.b(isourceblock.f());
    IProjectile iprojectile = this.a(world, iposition);

    // iprojectile.shoot((double) enumdirection.getAdjacentX(), (double) ((float)
    // enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ(), this.b(),
    // this.a());
    // CraftBukkit start
    ItemStack itemstack1 = itemstack.a(1);
    org.bukkit.block.Block block =
        world
            .getWorld()
            .getBlockAt(
                isourceblock.getBlockPosition().getX(),
                isourceblock.getBlockPosition().getY(),
                isourceblock.getBlockPosition().getZ());
    CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

    BlockDispenseEvent event =
        new BlockDispenseEvent(
            block,
            craftItem.clone(),
            new org.bukkit.util.Vector(
                (double) enumdirection.getAdjacentX(),
                (double) ((float) enumdirection.getAdjacentY() + 0.1F),
                (double) enumdirection.getAdjacentZ()));
    if (!BlockDispenser.eventFired) {
      world.getServer().getPluginManager().callEvent(event);
    }

    if (event.isCancelled()) {
      itemstack.count++;
      return itemstack;
    }

    if (!event.getItem().equals(craftItem)) {
      itemstack.count++;
      // Chain to handler for new item
      ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
      IDispenseBehavior idispensebehavior =
          (IDispenseBehavior) BlockDispenser.N.get(eventStack.getItem());
      if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
        idispensebehavior.a(isourceblock, eventStack);
        return itemstack;
      }
    }

    iprojectile.shoot(
        event.getVelocity().getX(),
        event.getVelocity().getY(),
        event.getVelocity().getZ(),
        this.b(),
        this.a());
    ((Entity) iprojectile).projectileSource =
        new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(
            (TileEntityDispenser) isourceblock.getTileEntity());
    // CraftBukkit end
    world.addEntity((Entity) iprojectile);
    // itemstack.a(1); // CraftBukkit - Handled during event processing
    return itemstack;
  }