Java Code Examples for org.bukkit.entity.Entity#getType()

The following examples show how to use org.bukkit.entity.Entity#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Pyro.java    From AnnihilationPro with MIT License 8 votes vote down vote up
@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;
}
 
Example 2
Source File: RealDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: MagnetModule.java    From Modern-LWC with MIT License 6 votes vote down vote up
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;
}
 
Example 4
Source File: EntityRemoverTool.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
@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.");
		}
	}
}
 
Example 5
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 6 votes vote down vote up
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);
}
 
Example 6
Source File: EntityDamage.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@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)));
			}
	}
}
 
Example 7
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@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);
		}
	}
}
 
Example 8
Source File: GDClaim.java    From GriefDefender with MIT License 5 votes vote down vote up
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;
}
 
Example 9
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void cleanup(Chunk chunk) {
    for (Entity entity : chunk.getEntities()) {
        if (entity.getType() == EntityType.DROPPED_ITEM) {
            entity.remove();
        }
    }

}
 
Example 10
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 11
Source File: EntityMatch.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: Reward.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
private boolean isMobAllowed(Entity entity) {
    EntityType type = entity.getType();
    return isMobAllowed(type);
}
 
Example 13
Source File: GDPermissionManager.java    From GriefDefender with MIT License 4 votes vote down vote up
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"));
        }
    }
}
 
Example 14
Source File: Scorpio.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@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);
}
 
Example 15
Source File: VehicleCondition.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Boolean execute(String playerID) {
    Entity entity = PlayerConverter.getPlayer(playerID).getVehicle();
    return entity != null && (any || entity.getType() == vehicle);
}
 
Example 16
Source File: HoverAction.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public EntityInfo(Entity entity) {
	this(entity.getType(), entity.getUniqueId(), entity.getName());
}
 
Example 17
Source File: BukkitCompat.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 18
Source File: ClearEvent.java    From BetonQuest with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 19
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: EntityInfo.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public EntityInfo(Entity entity, @Nullable ParticipantState owner) {
  this(entity.getType(), entity.getCustomName(), owner);
}