Skip to content

Commit

Permalink
Add powered creepers and endermen holding blocks to dEntity.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 30, 2013
1 parent 1f6dbc1 commit c518821
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -14,6 +14,8 @@
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_5_R3.CraftWorld;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
Expand Down Expand Up @@ -293,7 +295,7 @@ public void spawnAt(Location location) {

Material material = null;

if (data != null) {
if (data != null && dMaterial.matches(data)) {

material = dMaterial.valueOf(data).getMaterial();

Expand All @@ -309,8 +311,7 @@ public void spawnAt(Location location) {
}
}

// If material is null, not a block, a portal section or air,
// default to SAND
// If material is null or not a block, default to SAND
if (material == null || material.isBlock() == false) {

material = Material.SAND;
Expand All @@ -326,14 +327,26 @@ public void spawnAt(Location location) {
ent = location.getWorld().spawnEntity(location, entity_type);
entity = ent;

// If there is some special data associated with this dEntity,
// If there is some special subtype data associated with this dEntity,
// use the setSubtype method to set it in a clean, object-oriented
// way that uses reflection
//
// Otherwise, just use entity-specific methods manually
if (data != null) {

try {

if (ent instanceof Ocelot) {
// Allow creepers to be powered
if (ent instanceof Creeper && data.equalsIgnoreCase("POWERED")) {
((Creeper) entity).setPowered(true);
}
else if (ent instanceof Enderman && dMaterial.matches(data)) {
((Enderman) entity).setCarriedMaterial(dMaterial.valueOf(data).getMaterialData());
}
else if (ent instanceof Ocelot) {
setSubtype(Ocelot.class, "Type", "setCatType", data);
}
else if (ent instanceof Ocelot) {
setSubtype(Ocelot.class, "Type", "setCatType", data);
}
else if (ent instanceof Skeleton) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Expand Up @@ -5,6 +5,7 @@

import net.aufdemrand.denizen.utilities.Utilities;
import org.bukkit.Material;
import org.bukkit.material.MaterialData;

import net.aufdemrand.denizen.tags.Attribute;

Expand Down Expand Up @@ -101,6 +102,10 @@ public Material getMaterial() {
return material;
}

public MaterialData getMaterialData() {
return new MaterialData(material, (byte) 0);
}


@Override
public String getPrefix() {
Expand Down

0 comments on commit c518821

Please sign in to comment.