Java Code Examples for org.bukkit.entity.Entity#getMetadata()
The following examples show how to use
org.bukkit.entity.Entity#getMetadata() .
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: ProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public static @Nullable ProjectileDefinition getProjectileDefinition(Entity entity) { MetadataValue metadataValue = entity.getMetadata("projectileDefinition", PGM.get()); if (metadataValue != null) { return (ProjectileDefinition) metadataValue.value(); } else if (launchingDefinition.get() != null) { return launchingDefinition.get(); } else { return null; } }
Example 2
Source File: MainListener.java From ArmorStandTools with MIT License | 5 votes |
private boolean noCooldown(Entity e) { for(MetadataValue meta : e.getMetadata("lastDrop")) { if(meta.getOwningPlugin() == plugin) { return System.currentTimeMillis() - meta.asFloat() > 100; } } return true; }
Example 3
Source File: Spawner.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
private boolean isTracked(Entity entity) { return entity.getMetadata(METADATA_KEY, PGM.get()) != null; }
Example 4
Source File: Projectiles.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
static @Nullable ProjectileDefinition getProjectileDefinition(Entity entity) { final MetadataValue metadataValue = entity.getMetadata(METADATA_KEY, PGM.get()); return metadataValue == null ? null : (ProjectileDefinition) metadataValue.value(); }
Example 5
Source File: MonstersCondition.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@Override protected Boolean execute(String playerID) throws QuestRuntimeException { Location location = loc.getLocation(playerID); int[] neededAmounts = new int[types.length]; for (int i = 0; i < neededAmounts.length; i++) { neededAmounts[i] = 0; } 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 theType = entity.getType(); for (int i = 0; i < types.length; i++) { if (theType == types[i]) { neededAmounts[i]++; break; } } } } for (int i = 0; i < amounts.length; i++) { if (neededAmounts[i] < amounts[i].getInt(playerID)) { return false; } } return true; }
Example 6
Source File: EntityInteractObjective.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
private boolean onInteract(Player player, Entity entity) { // check if it's the right entity type if (!entity.getType().equals(mobType)) { return false; } // if the entity should have a name and it does not match, return if (name != null && (entity.getCustomName() == null || !entity.getCustomName().equals(name))) { return false; } // check if the entity is correctly marked if (marked != null) { if (!entity.hasMetadata("betonquest-marked")) { return false; } List<MetadataValue> meta = entity.getMetadata("betonquest-marked"); for (MetadataValue m : meta) { if (!m.asString().equals(marked)) { return false; } } } // check if the player has this objective String playerID = PlayerConverter.getID(player); if (containsPlayer(playerID) && checkConditions(playerID)) { // Check location matches if (loc != null) { try { Location location = loc.getLocation(playerID); double r = range.getDouble(playerID); if (!entity.getWorld().equals(location.getWorld()) || entity.getLocation().distance(location) > r) { return false; } } catch (QuestRuntimeException e) { LogUtils.getLogger().log(Level.WARNING, "Error while handling '" + instruction.getID() + "' objective: " + e.getMessage()); LogUtils.logThrowable(e); } } // get data off the player EntityInteractData playerData = (EntityInteractData) dataMap.get(playerID); // check if player already interacted with entity if (playerData.containsEntity(entity)) return false; // right mob is interacted with, handle data update playerData.subtract(); playerData.addEntity(entity); if (playerData.isZero()) { completeObjective(playerID); } else if (notify && playerData.getAmount() % notifyInterval == 0) { // send a notification Config.sendNotify(playerID, "mobs_to_click", new String[]{String.valueOf(playerData.getAmount())}, "mobs_to_click,info"); } return true; } return false; }
Example 7
Source File: ClearEvent.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@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 8
Source File: EntityLimits.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks if new entities can be added to island * @param island * @param bypass - true if this is being done by a player with authorization to bypass limits * @param ent - the entity * @return true if at the limit, false if not */ private boolean atLimit(Island island, boolean bypass, Entity ent) { int count = 0; checkLimits: if (bypass || Settings.entityLimits.get(ent.getType()) > 0) { // If bypass, just tag the creature. If not, then we need to count creatures if (!bypass) { // Run through all the current entities on this world for (Entity entity: ent.getWorld().getEntities()) { // If it is the right one if (entity.getType().equals(ent.getType())) { if (DEBUG) plugin.getLogger().info("DEBUG: " + entity.getType() + " found"); // Check spawn location if (entity.hasMetadata("spawnLoc")) { if (DEBUG) plugin.getLogger().info("DEBUG: has meta"); // Get the meta data List<MetadataValue> values = entity.getMetadata("spawnLoc"); for (MetadataValue v : values) { // There is a chance another plugin also uses the meta data spawnLoc if (v.getOwningPlugin().equals(plugin)) { // Get the island spawn location Location spawnLoc = Util.getLocationString(v.asString()); if (DEBUG) plugin.getLogger().info("DEBUG: entity spawnLoc = " + spawnLoc); if (spawnLoc != null && spawnLoc.equals(island.getCenter())) { // Entity is on this island count++; if (DEBUG) plugin.getLogger().info("DEBUG: entity is on island. Number = " + count); if (count >= Settings.entityLimits.get(ent.getType())) { // No more allowed! if (DEBUG) plugin.getLogger().info("DEBUG: no more allowed! >=" + count); break checkLimits; } } } } } } } } // Okay to spawn, but tag it ent.setMetadata("spawnLoc", new FixedMetadataValue(plugin, Util.getStringLocation(island.getCenter()))); if (DEBUG) plugin.getLogger().info("DEBUG: spawn okay"); return false; } // Cancel - no spawning - tell nearby players if (DEBUG) plugin.getLogger().info("DEBUG: spawn cancelled"); return true; }