Search in sources :

Example 1 with EntityData

use of com.elmakers.mine.bukkit.entity.EntityData in project MagicPlugin by elBukkit.

the class MobController method load.

public void load(ConfigurationSection configuration) {
    Set<String> mobKeys = configuration.getKeys(false);
    for (String mobKey : mobKeys) {
        ConfigurationSection mobConfiguration = configuration.getConfigurationSection(mobKey);
        if (!mobConfiguration.getBoolean("enabled", true))
            continue;
        EntityData mob = new EntityData(controller, mobKey, mobConfiguration);
        mobs.put(mobKey, mob);
        // TODO Remove the name map
        String mobName = mob.getName();
        if (mobName != null && !mobName.isEmpty()) {
            mobsByName.put(mobName, mob);
        }
    }
}
Also used : EntityData(com.elmakers.mine.bukkit.entity.EntityData) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with EntityData

use of com.elmakers.mine.bukkit.entity.EntityData in project MagicPlugin by elBukkit.

the class MobController method onCreatureSpawn.

@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGHEST)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    Entity entity = event.getEntity();
    String customName = entity.getCustomName();
    if (customName != null) {
        EntityData customMob = mobsByName.get(customName);
        if (customMob != null) {
            customMob.modify(controller, entity);
            event.setCancelled(false);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) EntityData(com.elmakers.mine.bukkit.entity.EntityData) EventHandler(org.bukkit.event.EventHandler)

Example 3 with EntityData

use of com.elmakers.mine.bukkit.entity.EntityData in project MagicPlugin by elBukkit.

the class MaterialBrush method getEntities.

@Nullable
@Override
public Collection<com.elmakers.mine.bukkit.api.entity.EntityData> getEntities() {
    if (cloneTarget == null)
        return null;
    if ((mode == BrushMode.CLONE || mode == BrushMode.REPLICATE) && cloneSource != null) {
        List<com.elmakers.mine.bukkit.api.entity.EntityData> copyEntities = new ArrayList<>();
        World sourceWorld = cloneSource.getWorld();
        List<Entity> entities = sourceWorld.getEntities();
        for (Entity entity : entities) {
            if (!(entity instanceof Player || entity instanceof Item)) {
                Location entityLocation = entity.getLocation();
                Location translated = fromTargetLocation(cloneTarget.getWorld(), entityLocation);
                EntityData entityData = new EntityData(translated, entity);
                copyEntities.add(entityData);
            }
        }
        return copyEntities;
    } else if (mode == BrushMode.SCHEMATIC) {
        if (schematic != null) {
            return schematic.getEntities(cloneTarget);
        }
    }
    return null;
}
Also used : Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) EntityData(com.elmakers.mine.bukkit.entity.EntityData) ArrayList(java.util.ArrayList) World(org.bukkit.World) Location(org.bukkit.Location) Nullable(javax.annotation.Nullable)

Example 4 with EntityData

use of com.elmakers.mine.bukkit.entity.EntityData in project MagicPlugin by elBukkit.

the class UndoList method modify.

@Nullable
@Override
public EntityData modify(Entity entity) {
    EntityData entityData = null;
    if (entity == null || entity.hasMetadata("notarget"))
        return entityData;
    if (worldName != null && !entity.getWorld().getName().equals(worldName))
        return entityData;
    if (worldName == null)
        worldName = entity.getWorld().getName();
    // Check to see if this is something we spawned, and has now been destroyed
    if (entities != null && entities.contains(entity) && !entity.isValid()) {
        entities.remove(entity);
    } else if (entity.isValid()) {
        if (modifiedEntities == null)
            modifiedEntities = new HashMap<>();
        UUID entityId = entity.getUniqueId();
        entityData = modifiedEntities.get(entityId);
        if (entityData == null) {
            entityData = new EntityData(entity);
            modifiedEntities.put(entityId, entityData);
            watch(entity);
        }
    }
    modifiedTime = System.currentTimeMillis();
    return entityData;
}
Also used : EntityData(com.elmakers.mine.bukkit.entity.EntityData) UUID(java.util.UUID) Nullable(javax.annotation.Nullable)

Example 5 with EntityData

use of com.elmakers.mine.bukkit.entity.EntityData in project MagicPlugin by elBukkit.

the class MobController method onEntityDeath.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO: fix all of this, don't reference by names.
    Entity entity = event.getEntity();
    if (!(entity instanceof LivingEntity)) {
        return;
    }
    LivingEntity died = (LivingEntity) entity;
    String name = died.getCustomName();
    if (name == null || name.isEmpty()) {
        return;
    }
    // TODO Fix this
    EntityData mob = mobsByName.get(name);
    if (mob == null)
        return;
    MagicMobDeathEvent deathEvent = new MagicMobDeathEvent(controller, mob, event);
    Bukkit.getPluginManager().callEvent(deathEvent);
    if (!died.hasMetadata("nodrops")) {
        mob.modifyDrops(controller, event);
    }
    // Prevent double-deaths .. gg Mojang?
    // Kind of hacky to use this flag for it, but seemed easiest
    died.setCustomNameVisible(false);
    died.setCustomName(null);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) EntityData(com.elmakers.mine.bukkit.entity.EntityData) MagicMobDeathEvent(com.elmakers.mine.bukkit.api.event.MagicMobDeathEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EntityData (com.elmakers.mine.bukkit.entity.EntityData)5 Entity (org.bukkit.entity.Entity)3 Nullable (javax.annotation.Nullable)2 LivingEntity (org.bukkit.entity.LivingEntity)2 EventHandler (org.bukkit.event.EventHandler)2 MagicMobDeathEvent (com.elmakers.mine.bukkit.api.event.MagicMobDeathEvent)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Item (org.bukkit.entity.Item)1 Player (org.bukkit.entity.Player)1