Add a SpawnReason to CraftWorld.dropItem

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      Hey,

      to my knowledge there is currently no (normaly accessible) method to spawn a item with a SpawnReason. This would be quite helpful for developers, as it would allow them to disallow item-spawning except there is a valid spawnreason.

      I´d propose following change. The method would need to be added to org.bukkit.World
      ( addEntity in CraftWorld has this functionality but is not accessible without a CraftBukkit reference)

          public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
              return dropItem(loc, item, SpawnReason.DEFAULT);
          }
      	
      	public org.bukkit.entity.Item dropItem(Location loc, ItemStack item, SpawnReason reason) {
              Validate.notNull(item, "Cannot drop a Null item.");
              Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR.");
              EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
              entity.pickupDelay = 10;
              world.addEntity(entity, reason);
              // TODO this is inconsistent with how Entity.getBukkitEntity() works.
              // However, this entity is not at the moment backed by a server entity class so it may be left.
              return new CraftItem(world.getServer(), entity);
          }
      
      
      

            Assignee:
            md_5
            Reporter:
            Kademlia
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: