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

The following examples show how to use org.bukkit.entity.Entity#setMetadata() . 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: JobsHook.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setTrait(Entity entity) {
    if(getStackMob().getCustomConfig().getStringList("jobs-reborn.blacklist")
            .contains(entity.getType().toString())){
        return;
    }
    String metadata = Jobs.getPlayerManager().getMobSpawnerMetadata();
    entity.setMetadata(metadata, new FixedMetadataValue(getPlugin(), true));
}
 
Example 2
Source File: McmmoHook.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setTrait(Entity entity){
    if(!getStackMob().getCustomConfig().getStringList("mcmmo.no-experience.blacklist")
            .contains(entity.getType().toString())){
        entity.setMetadata(GlobalValues.MCMMO_META, new FixedMetadataValue(getPlugin(),false));
    }
}
 
Example 3
Source File: SpawnMobEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Location location = loc.getLocation(playerID);
    int a = amount.getInt(playerID);
    for (int i = 0; i < a; i++) {
        Entity entity = location.getWorld().spawnEntity(location, type);
        if (entity instanceof LivingEntity) {
            LivingEntity living = (LivingEntity) entity;
            EntityEquipment eq = living.getEquipment();
            eq.setHelmet(helmet == null ? null : helmet.generate(1));
            eq.setHelmetDropChance(0);
            eq.setChestplate(chestplate == null ? null : chestplate.generate(1));
            eq.setChestplateDropChance(0);
            eq.setLeggings(leggings == null ? null : leggings.generate(1));
            eq.setLeggingsDropChance(0);
            eq.setBoots(boots == null ? null : boots.generate(1));
            eq.setBootsDropChance(0);
            eq.setItemInMainHand(mainHand == null ? null : mainHand.generate(1));
            eq.setItemInMainHandDropChance(0);
            eq.setItemInOffHand(offHand == null ? null : offHand.generate(1));
            eq.setItemInOffHandDropChance(0);
        }
        int j = 0;
        for (Item item : drops) {
            entity.setMetadata("betonquest-drops-" + j,
                    new FixedMetadataValue(BetonQuest.getInstance(), item.getID().getFullID() + ":"
                            + item.getAmount().getInt(playerID)));
            j++;
        }
        if (name != null && entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            livingEntity.setCustomName(name);
        }
        if (marked != null) {
            entity.setMetadata("betonquest-marked", new FixedMetadataValue(BetonQuest.getInstance(), marked));
        }
    }
    return null;
}
 
Example 4
Source File: ModifyBowProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void changeBowProjectile(EntityShootBowEvent event) {
  Plugin plugin = PGM.get();
  Entity newProjectile;

  if (this.cls == Arrow.class && event.getProjectile() instanceof Arrow) {
    // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow
    newProjectile = event.getProjectile();
  } else {
    // Replace the projectile
    Projectile oldEntity = (Projectile) event.getProjectile();
    if (Projectile.class.isAssignableFrom(this.cls)) {
      newProjectile = event.getEntity().launchProjectile((Class<? extends Projectile>) this.cls);
    } else {
      World world = event.getEntity().getWorld();
      newProjectile = world.spawn(oldEntity.getLocation(), this.cls);
    }
    event.setProjectile(newProjectile);

    // Copy some things from the old projectile
    newProjectile.setVelocity(oldEntity.getVelocity());
    newProjectile.setFallDistance(oldEntity.getFallDistance());
    newProjectile.setFireTicks(oldEntity.getFireTicks());

    if (newProjectile instanceof Projectile) {
      ((Projectile) newProjectile).setShooter(oldEntity.getShooter());
      ((Projectile) newProjectile).setBounce(oldEntity.doesBounce());
    }

    // Save some special properties of Arrows
    if (oldEntity instanceof Arrow) {
      Arrow arrow = (Arrow) oldEntity;
      newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical()));
      newProjectile.setMetadata(
          "knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength()));
      newProjectile.setMetadata(
          "damage", new FixedMetadataValue(plugin, arrow.spigot().getDamage()));
    }
  }

  // Tag the projectile as custom
  newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true));

  match.callEvent(new EntityLaunchEvent(newProjectile, event.getEntity()));
}
 
Example 5
Source File: ModifyBowProjectileMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void changeBowProjectile(EntityShootBowEvent event) {
    Plugin plugin = this.getMatch().getPlugin();
    Entity newProjectile;

    if(this.projectile == Arrow.class && event.getProjectile() instanceof Arrow) {
        // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow
        newProjectile = event.getProjectile();
    } else {
        // Replace the projectile
        World world = event.getEntity().getWorld();
        Projectile oldEntity = (Projectile) event.getProjectile();

        if(Projectile.class.isAssignableFrom(projectile)) {
            // Ender Pearls need to be soawned this way, otherwise they will hit the shooter sometimes
            newProjectile = event.getEntity().launchProjectile(projectile.asSubclass(Projectile.class), oldEntity.getVelocity());
        } else {
            newProjectile = world.spawn(oldEntity.getLocation(), projectile);
            newProjectile.setVelocity(oldEntity.getVelocity());
        }

        event.setProjectile(newProjectile);

        // Copy some things from the old projectile
        newProjectile.setFallDistance(oldEntity.getFallDistance());
        newProjectile.setFireTicks(oldEntity.getFireTicks());

        if(newProjectile instanceof Projectile) {
            ((Projectile) newProjectile).setShooter(oldEntity.getShooter());
            ((Projectile) newProjectile).setBounce(oldEntity.doesBounce());
        }

        // Save some special properties of Arrows
        if(oldEntity instanceof Arrow) {
            Arrow arrow = (Arrow) oldEntity;
            newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical()));
            newProjectile.setMetadata("knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength()));
            newProjectile.setMetadata("damage", new FixedMetadataValue(plugin, arrow.getDamage()));
        }
    }

    // Tag the projectile as custom
    newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true));

    getMatch().callEvent(new EntityLaunchEvent(newProjectile, event.getEntity()));
}
 
Example 6
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}