org.bukkit.entity.Entity#getType ( )源码实例Demo

下面列出了org.bukkit.entity.Entity#getType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: QuickShop-Reremake   文件: RealDisplayItem.java
@Override
public boolean removeDupe() {
    if (this.item == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }

    boolean removed = false;
    // Chunk chunk = shop.getLocation().getChunk();
    for (Entity entity : item.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.DROPPED_ITEM) {
            continue;
        }
        Item eItem = (Item) entity;
        UUID displayUUID = this.item.getUniqueId();
        if (!eItem.getUniqueId().equals(displayUUID)) {
            if (DisplayItem.checkIsTargetShopDisplay(eItem.getItemStack(), this.shop)) {
                Util.debugLog(
                        "Removing a duped ItemEntity " + eItem.getUniqueId() + " at " + eItem.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
源代码2 项目: Modern-LWC   文件: MagnetModule.java
public static boolean isDisplay(Entity entity) {
    try {
        if (entity.getType() == EntityType.DROPPED_ITEM) {
            ItemMeta itemMeta = ((Item) entity).getItemStack().getItemMeta();
            if (itemMeta != null && containsLocation(itemMeta.getDisplayName())) {
                return true;
            }
        } else if (entity.getType() == EntityType.ARMOR_STAND) {
            if (containsLocation(entity.getCustomName())) {
                return true;
            }
        }
    } catch (NoSuchFieldError error) {
        // do nothing
    }
    return false;
}
 
源代码3 项目: NBTEditor   文件: EntityRemoverTool.java
@Override
public void onRightClick(PlayerInteractEvent event, PlayerDetails details) {
	Player player = event.getPlayer();
	if (player.isSneaking()) {
		Location location = event.getPlayer().getLocation();
		int i = 0;
		for (Entity entity : location.getWorld().getNearbyEntities(location, _radius, _radius, _radius)) {
			if (entity.getType() != EntityType.PLAYER) {
				entity.remove();
				i++;
			}
		}
		if (i == 1) {
			player.sendMessage(ChatColor.GREEN + "Removed " + i + " entity.");
		} else if (i != 0) {
			player.sendMessage(ChatColor.GREEN + "Removed " + i + " entities.");
		} else {
			player.sendMessage(ChatColor.YELLOW + "No entities on a " + _radius + " block radius.");
		}
	}
}
 
源代码4 项目: ClaimChunk   文件: ChunkEventHelper.java
public static void handleEntityEvent(@Nonnull Player ply, @Nonnull Entity ent, @Nonnull Cancellable e) {
    if (e.isCancelled()) return;

    // If entities aren't protected, we don't need to check if this
    // one is -_-
    // If PvP is disabled, all entities (including players) are protected.
    // If PvP is enabled, all entities except players are protected.
    boolean protectEntities = config.getBool("protection", "protectEntities");
    boolean blockPvp = ent.getType() == EntityType.PLAYER && config.getBool("protection", "blockPvp");
    if (!protectEntities && !blockPvp) {
        return;
    }

    // Admins have permission to do anything in claimed chunks.
    if (Utils.hasAdmin(ply)) return;

    // Check if the player is able to edit in both the chunk they're in as
    // well as the chunk the animal is in.
    boolean canPlayerEditEntityChunk = getCanEdit(ent.getLocation().getChunk(), ply.getUniqueId());
    if (!blockPvp && canPlayerEditEntityChunk) {
        return;
    }

    // Cancel the event
    e.setCancelled(true);
}
 
源代码5 项目: AdditionsAPI   文件: EntityDamage.java
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
	if (event.isCancelled())
		return;

	DamageCause cause = event.getCause();
	Entity damagee = event.getEntity();
	EntityType damageeType = damagee.getType();
	// PlayerCustomArmorDamageEvent
	if (damageeType == EntityType.PLAYER) {
		Player player = (Player) damagee;
		PlayerInventory inv = player.getInventory();
		for (ItemStack armor : inv.getArmorContents())
			// TODO: Speed up
			if (armor != null && armor.getType() != Material.AIR && AdditionsAPI.isCustomItem(armor)
					&& new CustomItemStack(armor).getCustomItem() instanceof CustomArmor
					&& new CustomItemStack(armor).getCustomItem()
							.getDurabilityMechanics() instanceof ArmorDurability) {
				CustomArmor cArmor = (CustomArmor) new CustomItemStack(armor).getCustomItem();
				Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomArmorDamageEvent(player, armor,
						cArmor, cause, (float) event.getDamage(), armor.containsEnchantment(Enchantment.THORNS)));
			}
	}
}
 
源代码6 项目: AnnihilationPro   文件: Pyro.java
@Override
protected boolean performSpecialAction(Player player, AnniPlayer p)
{
	if(p.getTeam() != null)
	{
		for(Entity e : player.getNearbyEntities(5, 5, 5))
		{
			if(e.getType() == EntityType.PLAYER)
			{
				AnniPlayer d = AnniPlayer.getPlayer(e.getUniqueId());
				if(d != null && d.getTeam() != null && !d.getTeam().equals(p.getTeam()))
					e.setFireTicks(40);
			}
		}
		player.sendMessage(ChatColor.DARK_RED+ChatColor.stripColor(getSpecialItemName()).toUpperCase()+"!");
		return true;
	}
	else return false;
}
 
源代码7 项目: NovaGuilds   文件: RegionInteractListener.java
@EventHandler
public void onPlayerClickEntityEvent(PlayerInteractEntityEvent event) {
	Player player = event.getPlayer();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	Entity entity = event.getEntity();
	List<String> denyDamage = Config.REGION_DENYMOBDAMAGE.getStringList();

	if(entity instanceof Player ) {
		return;
	}

	if(RegionManager.get(entity) != null) {
		if(event.getAction() == EntityUseAction.ATTACK) {
			if(!plugin.getRegionManager().canInteract(player, entity) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.MOB_ATTACK))
					&& denyDamage.contains(entity.getType().name())) {
				event.setCancelled(true);
				Message.CHAT_REGION_DENY_ATTACKMOB.send(player);
			}
		}
		else if(!plugin.getRegionManager().canInteract(player, entity) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.MOB_RIDE))
				&& entity.getType() == EntityType.SHEEP
				&& CompatibilityUtils.getItemInMainHand(player).getType() == Material.SHEARS) {
			event.setCancelled(true);
			Message.CHAT_REGION_DENY_RIDEMOB.send(player);
		}
	}
}
 
源代码8 项目: GriefDefender   文件: GDClaim.java
public int countEntities(Entity spawnedEntity) {
    int count = 0;
    for (Chunk chunk : this.getChunks()) {
        for (Entity entity : chunk.getEntities()) {
            if (spawnedEntity.getType() == entity.getType()) {
                count++;
            }
        }
    }

    return count;
}
 
源代码9 项目: FastAsyncWorldedit   文件: ChunkListener.java
public void cleanup(Chunk chunk) {
    for (Entity entity : chunk.getEntities()) {
        if (entity.getType() == EntityType.DROPPED_ITEM) {
            entity.remove();
        }
    }

}
 
源代码10 项目: FastAsyncWorldedit   文件: ChunkListener.java
/**
 * Prevent FireWorks from loading chunks
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
    if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
        Chunk chunk = event.getChunk();
        Entity[] entities = chunk.getEntities();
        World world = chunk.getWorld();

        Exception e = new Exception();
        int start = 14;
        int end = 22;
        int depth = Math.min(end, getDepth(e));

        for (int frame = start; frame < depth; frame++) {
            StackTraceElement elem = getElement(e, frame);
            if (elem == null) return;
            String className = elem.getClassName();
            int len = className.length();
            if (className != null) {
                if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
                    for (Entity ent : world.getEntities()) {
                        if (ent.getType() == EntityType.FIREWORK) {
                            Vector velocity = ent.getVelocity();
                            double vertical = Math.abs(velocity.getY());
                            if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
                                Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
                                ent.remove();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
源代码11 项目: uSkyBlock   文件: EntityMatch.java
public boolean matches(Entity entity) {
    if (entity != null && entity.getType() == type) {
        for (String key : meta.keySet()) {
            if (!matchFieldGetter(entity, key, meta.get(key))) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
源代码12 项目: GriefDefender   文件: GDPermissionManager.java
public void addCustomEntityTypeContexts(Entity targetEntity, String id, Set<Context> contexts, GDEntityType type, boolean isSource) {
    if (isSource) {
        contexts.add(ContextGroups.SOURCE_ANY);
        contexts.add(new Context(ContextKeys.SOURCE, "#" + type.getModId().toLowerCase() + ":any"));
    } else {
        contexts.add(ContextGroups.TARGET_ANY);
        contexts.add(new Context(ContextKeys.TARGET, "#" + type.getModId().toLowerCase() + ":any"));
    }
    // check vehicle
    if (targetEntity instanceof Vehicle) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_VEHICLE);
        } else {
            contexts.add(ContextGroups.TARGET_VEHICLE);
        }
    }
    // pixelmon
    if (targetEntity.getType() != null && targetEntity.getType().name().equalsIgnoreCase("pixelmon_pixelmon") || targetEntity.getType().name().equalsIgnoreCase("pixelmon")) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_PIXELMON);
        } else {
            contexts.add(ContextGroups.TARGET_PIXELMON);
        }
    }
    final String creatureType = type.getEnumCreatureTypeId();
    if (creatureType == null) {
        return;
    }

    final String modId = type.getModId().toLowerCase();
    if (creatureType.contains("animal")) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_ANIMAL);
            contexts.add(new Context(ContextKeys.SOURCE, "#" + modId + ":animal"));
        } else {
            contexts.add(ContextGroups.TARGET_ANIMAL);
            contexts.add(new Context(ContextKeys.TARGET, "#" + modId + ":animal"));
        }
        this.checkPetContext(targetEntity, modId, contexts, isSource);
    } else if (creatureType.contains("aquatic")) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_AQUATIC);
            contexts.add(new Context(ContextKeys.SOURCE, "#" + modId + ":aquatic"));
        } else {
            contexts.add(ContextGroups.TARGET_AQUATIC);
            contexts.add(new Context(ContextKeys.TARGET, "#" + modId + ":aquatic"));
        }
        this.checkPetContext(targetEntity, modId, contexts, isSource);
    } else if (creatureType.contains("monster")) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_MONSTER);
            contexts.add(new Context(ContextKeys.SOURCE, "#" + modId + ":monster"));
        } else {
            contexts.add(ContextGroups.TARGET_MONSTER);
            contexts.add(new Context(ContextKeys.TARGET, "#" + modId + ":monster"));
        }
    }  else if (creatureType.contains("ambient")) {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_AMBIENT);
            contexts.add(new Context(ContextKeys.SOURCE, "#" + modId + ":ambient"));
        } else {
            contexts.add(ContextGroups.TARGET_AMBIENT);
            contexts.add(new Context(ContextKeys.TARGET, "#" + modId + ":ambient"));
        }
        this.checkPetContext(targetEntity, modId, contexts, isSource);
    } else {
        if (isSource) {
            contexts.add(ContextGroups.SOURCE_MISC);
            contexts.add(new Context(ContextKeys.SOURCE, "#" + modId + ":misc"));
        } else {
            contexts.add(ContextGroups.TARGET_MISC);
            contexts.add(new Context(ContextKeys.TARGET, "#" + modId + ":misc"));
        }
    }
}
 
源代码13 项目: PGM   文件: EntityInfo.java
public EntityInfo(Entity entity, @Nullable ParticipantState owner) {
  this(entity.getType(), entity.getCustomName(), owner);
}
 
源代码14 项目: Shopkeepers   文件: Utils.java
public static List<Entity> getNearbyEntities(Location location, double radius, EntityType... types) {
	List<Entity> entities = new ArrayList<Entity>();
	if (location == null) return entities;
	if (radius <= 0.0D) return entities;

	double radius2 = radius * radius;
	int chunkRadius = ((int) (radius / 16)) + 1;
	Chunk center = location.getChunk();
	int startX = center.getX() - chunkRadius;
	int endX = center.getX() + chunkRadius;
	int startZ = center.getZ() - chunkRadius;
	int endZ = center.getZ() + chunkRadius;
	World world = location.getWorld();
	for (int chunkX = startX; chunkX <= endX; chunkX++) {
		for (int chunkZ = startZ; chunkZ <= endZ; chunkZ++) {
			if (!world.isChunkLoaded(chunkX, chunkZ)) continue;
			Chunk chunk = world.getChunkAt(chunkX, chunkZ);
			for (Entity entity : chunk.getEntities()) {
				Location entityLoc = entity.getLocation();
				// TODO: this is a workaround: for some yet unknown reason entities sometimes report to be in a
				// different world..
				if (!entityLoc.getWorld().equals(world)) {
					Log.debug("Found an entity which reports to be in a different world than the chunk we got it from:");
					Log.debug("Location=" + location + ", Chunk=" + chunk + ", ChunkWorld=" + chunk.getWorld()
							+ ", entityType=" + entity.getType() + ", entityLocation=" + entityLoc);
					continue; // skip this entity
				}

				if (entityLoc.distanceSquared(location) <= radius2) {
					if (types == null) {
						entities.add(entity);
					} else {
						EntityType type = entity.getType();
						for (EntityType t : types) {
							if (type.equals(t)) {
								entities.add(entity);
								break;
							}
						}
					}
				}
			}
		}
	}
	return entities;
}
 
源代码15 项目: BetonQuest   文件: ClearEvent.java
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Location location = loc.getLocation(playerID);
    Collection<Entity> entities = location.getWorld().getEntities();
    loop:
    for (Entity entity : entities) {
        if (!(entity instanceof LivingEntity)) {
            continue;
        }
        if (name != null && (entity.getCustomName() == null || !entity.getCustomName().equals(name))) {
            continue;
        }
        if (marked != null) {
            if (!entity.hasMetadata("betonquest-marked")) {
                continue;
            }
            List<MetadataValue> meta = entity.getMetadata("betonquest-marked");
            for (MetadataValue m : meta) {
                if (!m.asString().equals(marked)) {
                    continue loop;
                }
            }
        }
        double r = range.getDouble(playerID);
        if (entity.getLocation().distanceSquared(location) < r * r) {
            EntityType entityType = entity.getType();
            for (EntityType allowedType : types) {
                if (entityType == allowedType) {
                    if (kill) {
                        LivingEntity living = (LivingEntity) entity;
                        living.damage(living.getHealth() + 10);
                    } else {
                        entity.remove();
                    }
                    break;
                }
            }
        }
    }
    return null;
}
 
源代码16 项目: StackMob-3   文件: BukkitCompat.java
@Override
public boolean checkFood(Entity entity, ItemStack food) {
    Material type = food.getType();
    switch (entity.getType()) {
        case COW:
        case SHEEP:
        case MUSHROOM_COW:
            return type == Material.WHEAT;
        case PIG:
            return (type == Material.CARROT || type == Material.BEETROOT || type == Material.POTATO);
        case CHICKEN:
            return type == Material.WHEAT_SEEDS
                    || type == Material.MELON_SEEDS
                    || type == Material.BEETROOT_SEEDS
                    || type == Material.PUMPKIN_SEEDS;
        case HORSE:
            return (type == Material.GOLDEN_APPLE || type == Material.GOLDEN_CARROT) && ((Horse)entity).isTamed();
        case WOLF:
            return (type == Material.BEEF
                    || type == Material.CHICKEN
                    || type == Material.COD
                    || type == Material.MUTTON
                    || type == Material.PORKCHOP
                    || type == Material.RABBIT
                    || type == Material.SALMON
                    || type == Material.COOKED_BEEF
                    || type == Material.COOKED_CHICKEN
                    || type == Material.COOKED_COD
                    || type == Material.COOKED_MUTTON
                    || type == Material.COOKED_PORKCHOP
                    || type == Material.COOKED_RABBIT
                    || type == Material.COOKED_SALMON)
                    && ((Wolf) entity).isTamed();
        case OCELOT:
            return (type == Material.SALMON
                    || type == Material.COD
                    || type == Material.PUFFERFISH
                    || type == Material.TROPICAL_FISH);
        case RABBIT:
            return type == Material.CARROT || type == Material.GOLDEN_CARROT || type == Material.DANDELION;
        case LLAMA:
            return type == Material.HAY_BLOCK;
        case TURTLE:
            return type == Material.SEAGRASS;
        case PANDA:
            return type == Material.BAMBOO;
        case FOX:
            return type == Material.SWEET_BERRIES;
        case CAT:
            return (type == Material.COD || type == Material.SALMON) && ((Cat) entity).isTamed();
    }
    return false;
}
 
源代码17 项目: ProtocolSupport   文件: HoverAction.java
public EntityInfo(Entity entity) {
	this(entity.getType(), entity.getUniqueId(), entity.getName());
}
 
源代码18 项目: BetonQuest   文件: VehicleCondition.java
@Override
protected Boolean execute(String playerID) {
    Entity entity = PlayerConverter.getPlayer(playerID).getVehicle();
    return entity != null && (any || entity.getType() == vehicle);
}
 
源代码19 项目: AnnihilationPro   文件: Scorpio.java
@Override
public void run()
{
	//maxTicks--;
	if(maxTicks <= 0 || !owner.getKit().getName().equals(scorpioName))
	{
		item.remove();
		return;
	}
	
	for(Entity entity : item.getNearbyEntities(1, 1, 1))
	{
		if(entity.getType() == EntityType.PLAYER)
		{
			Player target = (Player)entity;
			AnniPlayer p = AnniPlayer.getPlayer(target.getUniqueId());
			if(p != null && !p.equals(owner))
			{
				Player user = owner.getPlayer();
				if(user != null)
				{
					if(owner.getTeam() == p.getTeam())
					{			
						Location loc1 = user.getLocation();
						Location loc2 = target.getLocation();
						if(loc2.getY() >= loc1.getY())
						{
							target.getWorld().playSound(target.getLocation(), Sound.DOOR_OPEN, 1F, 0.1F);
							user.getWorld().playSound(user.getLocation(), Sound.DOOR_OPEN, 1F, 0.1F);
							loc2.setY(loc1.getY());
							Vector vec = loc2.toVector().subtract(loc1.toVector()).setY(.08D).multiply(7);
							user.setVelocity(vec);
						}
					}
					else
					{
						target.getWorld().playSound(target.getLocation(), Sound.DOOR_OPEN, 1F, 0.1F);
						user.getWorld().playSound(user.getLocation(), Sound.DOOR_OPEN, 1F, 0.1F);
						//plugin.getKits().stopNextFallDamage(target.getName());
						Location loc = user.getLocation();
						Location tele;
						Direction dec = Direction.getDirection(loc.getDirection());
						if(dec == Direction.North)
							tele = loc.getBlock().getRelative(BlockFace.NORTH).getLocation();
						else if(dec == Direction.South)
							tele = loc.getBlock().getRelative(BlockFace.SOUTH).getLocation();
						else if(dec == Direction.East)
							tele = loc.getBlock().getRelative(BlockFace.EAST).getLocation();
						else if(dec == Direction.West)
							tele = loc.getBlock().getRelative(BlockFace.WEST).getLocation();
						else if(dec == Direction.NorthWest)
							tele = loc.getBlock().getRelative(BlockFace.NORTH_WEST).getLocation();
						else if(dec == Direction.NorthEast)
							tele = loc.getBlock().getRelative(BlockFace.NORTH_EAST).getLocation();
						else if(dec == Direction.SouthEast)
							tele = loc.getBlock().getRelative(BlockFace.SOUTH_EAST).getLocation();
						else tele = loc.getBlock().getRelative(BlockFace.SOUTH_WEST).getLocation();
						tele.setPitch(0);
						tele.setYaw(loc.getYaw()+180);
						target.teleport(tele);
					}
				}
				item.remove();
				return;
			}
		}
	}
	
	Bukkit.getScheduler().scheduleSyncDelayedTask(AnnihilationMain.getInstance(), new HookTracer(item,owner,maxTicks-1,scorpioName), 1);
}
 
源代码20 项目: CombatLogX   文件: Reward.java
private boolean isMobAllowed(Entity entity) {
    EntityType type = entity.getType();
    return isMobAllowed(type);
}