public static void showFakeItems(Plugin plugin, Player viewer, Location location, org.bukkit.inventory.ItemStack item, int count, Duration duration) { if(count <= 0) return; final EntityPlayer nmsPlayer = ((CraftPlayer) viewer).getHandle(); final int[] entityIds = new int[count]; for(int i = 0; i < count; i++) { final EntityItem entity = new EntityItem(nmsPlayer.getWorld(), location.getX(), location.getY(), location.getZ(), CraftItemStack.asNMSCopy(item)); entity.motX = randomEntityVelocity(); entity.motY = randomEntityVelocity(); entity.motZ = randomEntityVelocity(); sendPacket(viewer, new PacketPlayOutSpawnEntity(entity, ENTITY_TYPE_IDS.get(org.bukkit.entity.Item.class))); sendPacket(viewer, new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true)); entityIds[i] = entity.getId(); } scheduleEntityDestroy(plugin, viewer.getUniqueId(), duration, entityIds); }
/** * Gets the range an entity should be 'tracked' by players and visible in * the client. * * @param entity * @param defaultRange Default range defined by Mojang * @return */ public static int getEntityTrackingRange(Entity entity, int defaultRange) { SpigotWorldConfig config = entity.world.spigotConfig; int range = defaultRange; if ( entity instanceof EntityPlayer ) { range = config.playerTrackingRange; } else if ( entity.defaultActivationState || entity instanceof EntityGhast ) { range = defaultRange; } else if ( entity.activationType == 1 ) { range = config.monsterTrackingRange; } else if ( entity.activationType == 2 ) { range = config.animalTrackingRange; } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb ) { range = config.miscTrackingRange; } return Math.min( config.maxTrackingRange, range ); }
/** * ItemSpawnEvent */ public static ItemSpawnEvent callItemSpawnEvent(EntityItem entityitem) { org.bukkit.entity.Item entity = (org.bukkit.entity.Item) entityitem.getBukkitEntity(); CraftServer craftServer = (CraftServer) entity.getServer(); ItemSpawnEvent event = new ItemSpawnEvent(entity, entity.getLocation()); craftServer.getPluginManager().callEvent(event); return event; }
/** * ItemDespawnEvent */ public static ItemDespawnEvent callItemDespawnEvent(EntityItem entityitem) { org.bukkit.entity.Item entity = (org.bukkit.entity.Item) entityitem.getBukkitEntity(); ItemDespawnEvent event = new ItemDespawnEvent(entity, entity.getLocation()); entity.getServer().getPluginManager().callEvent(event); return event; }
/** * Gets the range an entity should be 'tracked' by players and visible in * the client. * * @param entity * @param defaultRange Default range defined by Mojang * @return */ public static int getEntityTrackingRange(Entity entity, int defaultRange) { SpigotWorldConfig config = entity.world.spigotConfig; if ( entity instanceof EntityPlayer ) { return config.playerTrackingRange; } else if ( entity.activationType == 1 ) { return config.monsterTrackingRange; } else if ( entity instanceof EntityGhast ) { if ( config.monsterTrackingRange > config.monsterActivationRange ) { return config.monsterTrackingRange; } else { return config.monsterActivationRange; } } else if ( entity.activationType == 2 ) { return config.animalTrackingRange; } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityExperienceOrb ) { return config.miscTrackingRange; } else { return config.otherTrackingRange; } }
public CraftItem(CraftServer server, Entity entity, EntityItem item) { super(server, entity); this.item = item; }
public CraftItem(CraftServer server, EntityItem entity) { this(server, entity, entity); }