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

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

源代码1 项目: StackMob-3   文件: JobsHook.java
@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));
}
 
源代码2 项目: StackMob-3   文件: McmmoHook.java
@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));
    }
}
 
源代码3 项目: BetonQuest   文件: SpawnMobEvent.java
@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;
}
 
源代码4 项目: PGM   文件: ModifyBowProjectileMatchModule.java
@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()));
}
 
@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()));
}
 
源代码6 项目: askyblock   文件: EntityLimits.java
/**
 * 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;
}