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

The following examples show how to use org.bukkit.entity.LivingEntity#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: ReceivedDamageEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDamageReceived(EntityDamageEvent event) {
    if(event.getEntity() instanceof LivingEntity){
        if(StackTools.hasValidStackData(event.getEntity())){
            LivingEntity entity = (LivingEntity) event.getEntity();
            if(sm.getCustomConfig().getBoolean("kill-step-damage.enabled")){
                double healthAfter = entity.getHealth() - event.getFinalDamage();
                if(healthAfter <= 0){
                    entity.setMetadata(GlobalValues.LEFTOVER_DAMAGE, new FixedMetadataValue(sm, Math.abs(healthAfter)));
                }
            }

            if(!sm.getCustomConfig().getStringList("multiply-damage-received.cause-blacklist")
                    .contains(event.getCause().toString())) {
                if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){
                    return;
                }
                int stackSize = StackTools.getSize(entity);
                double extraDamage = event.getDamage() + ((event.getDamage() * (stackSize - 1) * 0.25));
                event.setDamage(extraDamage);
            }
        }
    }
}
 
Example 2
Source File: ControllableBaseEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public SpawnResult spawn(Location location) {
    if (isSpawned()) {
        return SpawnResult.ALREADY_SPAWNED;
    }

    this.handle = GameRegistry.get(IEntitySpawnHandler.class).createEntityHandle(this, location);

    LivingEntity entity = this.getBukkitEntity();
    if (entity != null) {
        entity.setMetadata(EntityAPI.ENTITY_METADATA_MARKER, new FixedMetadataValue(EntityAPI.getCore(), true)); // Perhaps make this a key somewhere
        entity.setRemoveWhenFarAway(false);
    }

    //return spawned;
    return isSpawned() ? SpawnResult.SUCCESS : SpawnResult.FAILED;
}
 
Example 3
Source File: LivingEntityShop.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
protected void assignShopkeeperMetadata(LivingEntity entity) {
	entity.setMetadata("shopkeeper", new FixedMetadataValue(ShopkeepersPlugin.getInstance(), true));
}