当前位置: 首页>>代码示例>>Java>>正文


Java Entity类代码示例

本文整理汇总了Java中org.bukkit.entity.Entity的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Entity类属于org.bukkit.entity包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInLineOfSight

import org.bukkit.entity.Entity; //导入依赖的package包/类
/**
 * @param check
 *            The entity to check whether
 * @param distance
 *            The difference in distance to allow for.
 * @return
 */
private boolean isInLineOfSight(Entity check, double distance) {
	final Location entityLocation = check.getLocation();
	final BlockIterator iterator = new BlockIterator(profile.getPlayer().getEyeLocation(), 0.0, 7);

	while (iterator.hasNext()) {
		final Location current = iterator.next().getLocation();

		if (getLocationDifference(current, entityLocation, "X") < distance
				&& getLocationDifference(current, entityLocation, "Y") < distance
				&& getLocationDifference(current, entityLocation, "Z") < distance) {
			return true;
		}
	}

	// The entity has not been found in the player's line of sight.
	return false;
}
 
开发者ID:davidm98,项目名称:Crescent,代码行数:25,代码来源:KillauraB.java

示例2: onEntityDamageByEntity

import org.bukkit.entity.Entity; //导入依赖的package包/类
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Player attacker = getDamageSource(event.getDamager());
    Entity eDefender = event.getEntity();
    if (!(eDefender instanceof Player)) {
        forbidIfInProtectedTerritory(attacker, eDefender, event, ATTACK);
        return;
    }
    Player defender = (Player) eDefender;
    Faction aFaction = plugin.getFactionCache().getByMember(attacker);
    Faction dFaction = plugin.getFactionCache().getByMember(defender);
    Faction rFaction = plugin.getFactionCache().getByLocation(defender.getLocation());
    if (aFaction.getRelation(dFaction).isProtected()) {
        ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_PLAYER.getMessage(), dFaction);
        event.setCancelled(true);
    } else if (rFaction != null && rFaction.getRelation(dFaction).isProtected()) {
        if (plugin.getFConfig().isTerritoryProtectionEnabled() && (!plugin.getFConfig().isCapitalProtectionEnabled()
                || rFaction.getCapital().equals(plugin.getBoard().getByLocation(eDefender.getLocation())))) {
            ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_FACTION.getMessage(), rFaction);
            event.setCancelled(true);
        } else if (plugin.getFConfig().getTerritoryShield() != 0) {
            event.setDamage(event.getDamage() * plugin.getFConfig().getTerritoryShield());
        }
    }
}
 
开发者ID:DRE2N,项目名称:FactionsXL,代码行数:26,代码来源:EntityProtectionListener.java

示例3: getEntities

import org.bukkit.entity.Entity; //导入依赖的package包/类
public static List<Entity> getEntities(Location location, double radius) {
    List<Entity> entities = new ArrayList<Entity>();
    World world = location.getWorld();

    // Find chunck by coordinates
    int smallX = MathHelper.floor((location.getX() - radius) / 16.0D);
    int bigX = MathHelper.floor((location.getX() + radius) / 16.0D);
    int smallZ = MathHelper.floor((location.getZ() - radius) / 16.0D);
    int bigZ = MathHelper.floor((location.getZ() + radius) / 16.0D);

    for (int x = smallX; x <= bigX; x++) 
    	for (int z = smallZ; z <= bigZ; z++) 
    		if (world.isChunkLoaded(x, z)) entities.addAll(Arrays.asList(world.getChunkAt(x, z).getEntities()));

    Iterator<Entity> entityIterator = entities.iterator();
    while (entityIterator.hasNext()) 
    	if (entityIterator.next().getLocation().distanceSquared(location) > radius * radius) entityIterator.remove(); 
    
    return entities;
}
 
开发者ID:EpticMC,项目名称:Mob-AI,代码行数:21,代码来源:CommandHandler.java

示例4: getNearbyEnemies

import org.bukkit.entity.Entity; //导入依赖的package包/类
/**
 * Gets the amount of enemies nearby a {@link Player}.
 *
 * @param player
 *            the {@link Player} to get for
 * @param distance
 *            the radius to get within
 * @return the amount of players within enemy distance
 */
public int getNearbyEnemies(Player player, int distance) {
    FactionManager factionManager = plugin.getFactionManager();
    Faction playerFaction = factionManager.getPlayerFaction(player.getUniqueId());
    int count = 0;

    Collection<Entity> nearby = player.getNearbyEntities(distance, distance, distance);
    for (Entity entity : nearby) {
        if (entity instanceof Player) {
            Player target = (Player) entity;

            // If the nearby player or sender cannot see each-other, continue.
            if (!target.canSee(player) || !player.canSee(target)) {
                continue;
            }

            if (playerFaction == null || factionManager.getPlayerFaction(target) != playerFaction) {
                count++;
            }
        }
    }

    return count;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:33,代码来源:TeleportTimer.java

示例5: ProjectileDefinitionImpl

import org.bukkit.entity.Entity; //导入依赖的package包/类
public ProjectileDefinitionImpl(@Nullable String name,
                                @Nullable Double damage,
                                double velocity,
                                ClickAction clickAction,
                                Class<? extends Entity> entity,
                                List<PotionEffect> potion,
                                Filter destroyFilter,
                                Duration coolDown,
                                boolean throwable) {
    this.name = name;
    this.damage = damage;
    this.velocity = velocity;
    this.clickAction = clickAction;
    this.projectile = entity;
    this.potion = potion;
    this.destroyFilter = destroyFilter;
    this.coolDown = coolDown;
    this.throwable = throwable;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:20,代码来源:ProjectileDefinition.java

示例6: pass

import org.bukkit.entity.Entity; //导入依赖的package包/类
/**
 * Passes the ball with the given strength parameters
 *
 * @param entity             entity
 * @param horizontalStrength horizontalStrength
 * @param verticalStrength   verticalStrength
 */
@Override
public void pass(Entity entity, double horizontalStrength, double verticalStrength) {
    BallKickEvent event = null;
    if (entity instanceof Player) {
        event = new BallKickEvent((Player) entity, this);
        Bukkit.getPluginManager().callEvent(new BallKickEvent((Player) entity, this));
    }
    if (event == null || !event.isCancelled()) {
        this.startVector = this.slime.getSpigotEntity().getLocation().toVector().subtract(entity.getLocation().toVector()).normalize().multiply(horizontalStrength * 0.8);
        this.startVector.setY(verticalStrength * 0.5);
        try {
            this.slime.getSpigotEntity().setVelocity(this.startVector.clone());
        } catch (final IllegalArgumentException ex) {

        }
        if (this.isRotating)
            this.getSpigotEntity().setHeadPose(new EulerAngle(1, this.getSpigotEntity().getHeadPose().getY(), this.getSpigotEntity().getHeadPose().getZ()));
        this.rvalue = this.random.nextInt(5) + 9;
        this.jumps = this.random.nextInt(5) + 5;
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:29,代码来源:CustomArmorstand.java

示例7: walkToPlayer

import org.bukkit.entity.Entity; //导入依赖的package包/类
public static void walkToPlayer(Entity e, Player p) {
    // Tamed animals already handle their own following
    if (e instanceof Tameable) {
        if (((Tameable) e).isTamed()) {
            return;
        }
    }
    if (e.getPassenger() instanceof Player) {
        return;
    }

    // Moving the dragon is too buggy
    if (e instanceof EnderDragon) {
        return;
    }
    // Once this is set we can't unset it.
    //((Creature)e).setTarget(p);

    // If the pet is too far just teleport instead of attempt navigation
    if (e.getLocation().distance(p.getLocation()) > 20) {
        e.teleport(p);
    } else {
        Navigation n = ((CraftLivingEntity) e).getHandle().getNavigation();
        n.a(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0.30f);
    }
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:27,代码来源:Control.java

示例8: removeBlock

import org.bukkit.entity.Entity; //导入依赖的package包/类
public void removeBlock(BlockBreakEvent e) {
		for (Entity en : e.getBlock().getWorld().getEntities()) {
			if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
				en.remove();
				en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
				
				ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);
				
				ItemMeta bmeta = block.getItemMeta();
				
				bmeta.setDisplayName(name);
				
				block.setItemMeta(bmeta);
				
				if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
					e.getPlayer().getInventory().addItem(block);
				} else {
					e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
				}
			}
		}
	//}
}
 
开发者ID:GigaGamma,项目名称:SuperiorCraft,代码行数:24,代码来源:CustomBlock.java

示例9: MatchEntityState

import org.bukkit.entity.Entity; //导入依赖的package包/类
protected MatchEntityState(Match match, Class<? extends Entity> entityClass, UUID uuid, EntityLocation location, @Nullable String customName) {
    this.uuid = checkNotNull(uuid);
    this.match = checkNotNull(match);
    this.entityClass = checkNotNull(entityClass);
    this.location = checkNotNull(location);
    this.customName = customName;

    EntityType type = null;
    for(EntityType t : EntityType.values()) {
        if(t.getEntityClass().isAssignableFrom(entityClass)) {
            type = t;
            break;
        }
    }
    checkArgument(type != null, "Unknown entity class " + entityClass);
    this.entityType = type;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:MatchEntityState.java

示例10: getPlayers

import org.bukkit.entity.Entity; //导入依赖的package包/类
public List<Player> getPlayers() {
    List<Player> list = new ArrayList<Player>();

    for (Object o : world.loadedEntityList) {
        if (o instanceof net.minecraft.entity.Entity) {
            net.minecraft.entity.Entity mcEnt = (net.minecraft.entity.Entity) o;
            Entity bukkitEntity = mcEnt.getBukkitEntity();

            if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
                list.add((Player) bukkitEntity);
            }
        }
    }

    return list;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:17,代码来源:CraftWorld.java

示例11: getEntity

import org.bukkit.entity.Entity; //导入依赖的package包/类
@Nullable
private static Entity getEntity(String input, @Nullable CommandSender sender) throws InputException {
    Entity target;
    if (sender instanceof Player) {
        if (input.equalsIgnoreCase("that")) {
            target = PlatformUtil.getEntityPlayerLookingAt((Player) sender, 25, 1.5D);

            if (target != null) {
                return target;
            }
        } else if (input.equalsIgnoreCase("me")) {
            return ((Player) sender);
        }
    }

    Location loc = getLocation(input, sender);
    return PlatformUtil.getEntityNearestTo(loc, 25, 1.5D);
}
 
开发者ID:zachbr,项目名称:Debuggery,代码行数:19,代码来源:InputFormatter.java

示例12: get

import org.bukkit.entity.Entity; //导入依赖的package包/类
/**
 * Gets a {@link MetadataMap} for the given object, if one already exists and has
 * been cached in this registry.
 *
 * A map will only be returned if the object is an instance of
 * {@link Player}, {@link UUID}, {@link Entity}, {@link Block} or {@link World}.
 *
 * @param obj the object
 * @return a metadata map
 */
@Nonnull
public static Optional<MetadataMap> get(@Nonnull Object obj) {
    Preconditions.checkNotNull(obj, "obj");
    if (obj instanceof Player) {
        return getForPlayer(((Player) obj));
    } else if (obj instanceof UUID) {
        return getForPlayer(((UUID) obj));
    } else if (obj instanceof Entity) {
        return getForEntity(((Entity) obj));
    } else if (obj instanceof Block) {
        return getForBlock(((Block) obj));
    } else if (obj instanceof World) {
        return getForWorld(((World) obj));
    } else {
        throw new IllegalArgumentException("Unknown object type: " + obj.getClass());
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:28,代码来源:Metadata.java

示例13: onPlayerMoveEvent

import org.bukkit.entity.Entity; //导入依赖的package包/类
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent e) {
	for (Entity en : e.getPlayer().getWorld().getEntities()) {
		if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().distance(e.getTo()) <= 1) {
			Location l = en.getLocation();
			//e.getPlayer().sendMessage(getPlayerDirection(e.getPlayer()));
			if (getPlayerDirection(e.getPlayer()).equals("north")) {
				l.add(-1.2, 0, 0);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("south")) {
				l.add(1.2, 0, 0);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("east")) {
				l.add(0, 0, -1.2);	
			}
			else if (getPlayerDirection(e.getPlayer()).equals("west")) {
				l.add(0, 0, 1.2);	
			}
			else {
				l = e.getPlayer().getLocation();
			}
			l.setDirection(e.getPlayer().getLocation().getDirection());
			e.setTo(l);
		}
	}
}
 
开发者ID:GigaGamma,项目名称:SuperiorCraft,代码行数:27,代码来源:GhostBlock.java

示例14: onEntityDeath

import org.bukkit.entity.Entity; //导入依赖的package包/类
/**
 * Utilizes a random chance to either spawn a skeleton with gold armor or resources.
 *
 * @param event The event
 */
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
  Entity entity = event.getEntity();
  if (entity instanceof Sheep) {
    double chance = Math.random();
    if (0.25 > chance) {
      Skeleton skeleton = entity.getWorld().spawn(entity.getLocation(), Skeleton.class);
      skeleton.getEquipment().setArmorContents(
          new ItemStack[]{
              new ItemStack(Material.GOLD_HELMET),
              new ItemStack(Material.GOLD_CHESTPLATE),
              new ItemStack(Material.GOLD_LEGGINGS),
              new ItemStack(Material.GOLD_BOOTS)
          }
      );
    } else if (0.5 > chance) {
      event.getDrops().add(new ItemStack(Material.IRON_INGOT));
    } else if (0.75 > chance) {
      event.getDrops().add(new ItemStack(Material.GOLD_INGOT));
    } else {
      event.getDrops().add(new ItemStack(Material.DIAMOND));
    }
  }
}
 
开发者ID:twizmwazin,项目名称:OpenUHC,代码行数:30,代码来源:GoldenFleece.java

示例15: handleSlowdown

import org.bukkit.entity.Entity; //导入依赖的package包/类
private void handleSlowdown(Player player, Rune rune) {
	new BukkitRunnable() {
		int iterations = 0;
		public void run() {
			if(!player.isOnline() || iterations / 2 >= rune.getDuration()) {
				finish(player, true);
				this.cancel();
				return;
			}
			
			for(Entity entity : player.getNearbyEntities(3D, 3D, 3D)) {
				if(!(entity instanceof Player)) {
					continue;
				}
				Player target = (Player) entity;
				
				if(Utility.canAttack(player, target)) {
					target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 0));
				}
			}
			iterations++;
		}
	}.runTaskTimer(plugin, 0L, 10L);
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:25,代码来源:RuneManager.java


注:本文中的org.bukkit.entity.Entity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。