org.bukkit.entity.Entity.getWorld()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中org.bukkit.entity.Entity.getWorld()方法的一些代码示例,展示了Entity.getWorld()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getWorld()方法的具体详情如下:
包路径:org.bukkit.entity.Entity
类名称:Entity
方法名:getWorld

Entity.getWorld介绍

[英]Gets the current world this entity resides in
[中]获取此实体所在的当前世界

代码示例

代码示例来源:origin: EngineHub/WorldEdit

@Override
public Extent getExtent() {
  org.bukkit.entity.Entity entity = entityRef.get();
  if (entity != null) {
    return BukkitAdapter.adapt(entity.getWorld());
  } else {
    return NullWorld.getInstance();
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Returns the world that the given command sender is referring to when not specifying one.
 *
 * @param sender a command sender
 * @return the command sender's world if the sender is a block or entity, or the default world
 *         otherwise
 */
public static GlowWorld getWorld(CommandSender sender) {
  if (sender instanceof ConsoleCommandSender) {
    return getDefaultWorld();
  } else if (sender instanceof Entity) {
    return (GlowWorld) ((Entity) sender).getWorld();
  } else if (sender instanceof BlockCommandSender) {
    return (GlowWorld) ((BlockCommandSender) sender).getBlock().getWorld();
  }
  return getDefaultWorld();
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Gets the world in which the entity moved
 * 
 * @return Last and current Entity World
 */
public World getWorld() {
  return this.entity.getWorld();
}

代码示例来源:origin: EngineHub/CommandHelper

@Override
public MCWorld getWorld() {
  if(e == null || e.getWorld() == null) {
    return null;
  }
  return new BukkitMCWorld(e.getWorld());
}

代码示例来源:origin: libraryaddict/LibsDisguises

public static Object getEntityTrackerEntry(Entity target) throws Exception {
  Object world = getWorldServer(target.getWorld());
  Object tracker = trackerField.get(world);
  Object trackedEntities = entitiesField.get(tracker);
  return ihmGet.invoke(trackedEntities, target.getEntityId());
}

代码示例来源:origin: elBukkit/MagicPlugin

public void watch(Entity entity)
{
  if (entity == null) return;
  if (worldName != null && !entity.getWorld().getName().equals(worldName)) return;
  if (worldName == null) worldName = entity.getWorld().getName();
  if (!entity.hasMetadata("MagicBlockList")) {
    setUndoList(plugin, entity, this);
  }
  modifiedTime = System.currentTimeMillis();
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Gets the tracker entry of the entity specified
 * 
 * @param entity to get it for
 * @return entity tracker entry, or null if none is set
 */
public static Object getTrackerEntry(org.bukkit.entity.Entity entity) {
  return getTracker(entity.getWorld()).getEntry(entity);
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Sets a new entity tracker entry for the entity specified
 * 
 * @param entity to set it for
 * @param entityTrackerEntry to set to (can be null to remove only)
 * @return the previous tracker entry for the entity, or null if there was none
 */
public static Object setTrackerEntry(org.bukkit.entity.Entity entity, Object entityTrackerEntry) {
  return getTracker(entity.getWorld()).setEntry(entity, entityTrackerEntry);
}

代码示例来源:origin: DRE2N/DungeonsXL

public static DMob getByEntity(Entity entity) {
  DGameWorld gameWorld = DGameWorld.getByWorld(entity.getWorld());
  for (DMob dMob : gameWorld.getDMobs()) {
    if (dMob.entity == entity) {
      return dMob;
    }
  }
  return null;
}

代码示例来源:origin: Multiverse/Multiverse-Core

private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
  if (world != null) {
    return world.getSpawnLocation();
  } else {
    // add 0.5 to x and z to center people
    // (spawn location is stored as int meaning that you would spawn in the corner of a block)
    return e.getWorld().getSpawnLocation().add(.5, 0, .5);
  }
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Gets all the entities nearby an entity
 * 
 * @param entity to get the nearby entities of
 * @param radX to look for entities
 * @param radY to look for entities
 * @param radZ to look for entities
 * @return A (referenced) list of entities nearby
 */
public static List<org.bukkit.entity.Entity> getNearbyEntities(org.bukkit.entity.Entity entity, double radX, double radY, double radZ) {
  return CommonNMS.getEntities(entity.getWorld(), entity, CommonNMS.getNative(entity).boundingBox.grow(radX, radY, radZ));
}

代码示例来源:origin: stackoverflow.com

Entity arrow = event.getEntity();
Vector velocity = arrow.getVelocity();
Item item = arrow.getWorld().dropItem(arrow.getLocation(), ItemStack);
item.setVelocity(velocity);

代码示例来源:origin: DRE2N/DungeonsXL

@EventHandler
public void onEntityCombust(EntityCombustEvent event) {
  DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld());
  if (gameWorld != null) {
    event.setCancelled(true);
  }
}

代码示例来源:origin: CitizensDev/CitizensAPI

@Override
  public Block apply(PathEntry input) {
    return npc.getEntity().getWorld().getBlockAt(input.vector.getBlockX(),
        input.vector.getBlockY(), input.vector.getBlockZ());
  }
});

代码示例来源:origin: DRE2N/DungeonsXL

@EventHandler
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
  DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld());
  if (gameWorld != null) {
    if (event.isCancelled()) {
      event.setCancelled(false);
    }
  }
}

代码示例来源:origin: elBukkit/MagicPlugin

public static void swingOffhand(Entity entity, int range) {
  int rangeSquared = range * range;
  String worldName = entity.getWorld().getName();
  Location center = entity.getLocation();
  for (Player player : Bukkit.getOnlinePlayers()) {
    if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > rangeSquared) {
      continue;
    }
    swingOffhand(player, entity);
  }
}

代码示例来源:origin: EngineHub/WorldGuard

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPotionEffect(EntityPotionEffectEvent event) {
  if (event.getCause() == EntityPotionEffectEvent.Cause.CONDUIT) {
    WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(event.getEntity().getWorld()));
    if (config.disableConduitEffects) {
      event.setCancelled(true);
    }
  }
}

代码示例来源:origin: EngineHub/WorldGuard

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
  Entity ent = event.getEntity();
  World world = ent.getWorld();
  ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
  WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
  if (wcfg.disableHealthRegain) {
    event.setCancelled(true);
    return;
  }
}

代码示例来源:origin: BentoBoxWorld/BentoBox

/**
 * Allows or prevents enderman griefing
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanGrief(final EntityChangeBlockEvent e) {
  if (!(e.getEntity() instanceof Enderman) || !getIWM().inWorld(e.getEntity().getLocation())) {
    return;
  }
  if (!Flags.ENDERMAN_GRIEFING.isSetForWorld(e.getEntity().getWorld())) {
    e.setCancelled(true);
  }
}

代码示例来源:origin: EngineHub/WorldGuard

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
  Entity entity = event.getEntity();
  Block block = event.getBlock();
  ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
  WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
  if (block.getType() == Material.FARMLAND) {
    if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */
      wcfg.disableCreatureCropTrampling) {
      event.setCancelled(true);
    }
  }
}

相关文章