本文整理匯總了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;
}
}
}
}