本文整理汇总了Java中org.bukkit.entity.Item.getNearbyEntities方法的典型用法代码示例。如果您正苦于以下问题:Java Item.getNearbyEntities方法的具体用法?Java Item.getNearbyEntities怎么用?Java Item.getNearbyEntities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Item
的用法示例。
在下文中一共展示了Item.getNearbyEntities方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.bukkit.entity.Item; //导入方法依赖的package包/类
@Override
public void run() {
for(Item item : Bukkit.getWorlds().get(0).getEntitiesByClass(Item.class)) {
if(item.getItemStack().getType() != Material.GHAST_TEAR) continue;
UUID skip = Gizmos.gunGizmo.items.get(item);
for(Entity entity : item.getNearbyEntities(0.5d, 0.5d, 0.5d)) {
if(entity instanceof Player && !entity.getUniqueId().equals(skip)) {
Player player = (Player) entity;
if(player.hasPermission("gizmo.immunity")) continue;
player.damage(0d, item);
Gizmos.gunGizmo.gifts.add(player.getUniqueId());
item.remove();
break;
}
}
if(item.getTicksLived() >= 6000) item.remove();
}
}
示例2: trigger
import org.bukkit.entity.Item; //导入方法依赖的package包/类
@Override
public void trigger(Player player, Item grenade) {
grenade.getWorld().createExplosion(grenade.getLocation(), 0);
List<Entity> entities = grenade.getNearbyEntities(radius, radius, radius);
for(Entity ent: entities){
if(ent instanceof Player){
Player pl = (Player) ent;
pl.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
}
}
grenade.remove();
}
示例3: onItemSpawn
import org.bukkit.entity.Item; //导入方法依赖的package包/类
/**
* Concentrate stacks
*
* @param event Event
*/
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
if (event.getEntityType() != EntityType.DROPPED_ITEM)
return;
Item newEntity = event.getEntity();
List<Entity> entityList = newEntity.getNearbyEntities(this.radius, 1, this.radius);
int maxSize = newEntity.getItemStack().getMaxStackSize();
for (Entity anEntityList : entityList)
{
if (anEntityList instanceof Item)
{
Item curEntity = (Item) anEntityList;
if (!curEntity.isDead()
&& curEntity.getItemStack().getType().equals(newEntity.getItemStack().getType())
&& curEntity.getItemStack().getData().getData() == newEntity.getItemStack().getData().getData()
&& curEntity.getItemStack().getDurability() == newEntity.getItemStack().getDurability()
&& Math.abs(curEntity.getLocation().getX() - newEntity.getLocation().getX()) <= this.radius
&& Math.abs(curEntity.getLocation().getY() - newEntity.getLocation().getY()) <= this.radius
&& Math.abs(curEntity.getLocation().getZ() - newEntity.getLocation().getZ()) <= this.radius)
{
int newAmount = newEntity.getItemStack().getAmount();
int curAmount = curEntity.getItemStack().getAmount();
int more = Math.min(newAmount, maxSize - curAmount);
curAmount += more;
newAmount -= more;
curEntity.getItemStack().setAmount(curAmount);
newEntity.getItemStack().setAmount(newAmount);
if (newAmount <= 0)
event.setCancelled(true);
return;
}
}
}
}