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);
}
}
}
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);
}
}
}
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;
}
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;
}
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);
}
Aggregations