diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCShulker.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCShulker.java new file mode 100644 index 000000000..cbcdc1946 --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCShulker.java @@ -0,0 +1,36 @@ +package com.laytonsmith.abstraction.bukkit.entities; + +import com.laytonsmith.abstraction.entities.MCShulker; +import com.laytonsmith.abstraction.enums.MCDyeColor; +import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Shulker; + +public class BukkitMCShulker extends BukkitMCLivingEntity implements MCShulker { + + private Shulker sh; + + public BukkitMCShulker(Entity be) { + super(be); + this.sh = (Shulker) be; + } + + @Override + public MCDyeColor getColor() { + try { + return BukkitMCDyeColor.getConvertor().getAbstractedEnum(sh.getColor()); + } catch(NoSuchMethodError ex) { + // probably prior to 1.12 + } + return MCDyeColor.PURPLE; + } + + @Override + public void setColor(MCDyeColor color) { + try { + sh.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color)); + } catch(NoSuchMethodError ex) { + // probably prior to 1.12 + } + } +} diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCSnowman.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCSnowman.java index 7a4711f69..8570c8a96 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCSnowman.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCSnowman.java @@ -18,12 +18,21 @@ public BukkitMCSnowman(AbstractionObject ao) { @Override public void setDerp(boolean derp) { - ((Snowman) getHandle()).setDerp(derp); + try { + ((Snowman) getHandle()).setDerp(derp); + } catch(NoSuchMethodError ex) { + // probably prior to 1.9.4 + } } @Override public boolean isDerp() { - return ((Snowman) getHandle()).isDerp(); + try { + return ((Snowman) getHandle()).isDerp(); + } catch(NoSuchMethodError ex) { + // probably prior to 1.9.4 + } + return false; } } diff --git a/src/main/java/com/laytonsmith/abstraction/entities/MCShulker.java b/src/main/java/com/laytonsmith/abstraction/entities/MCShulker.java new file mode 100644 index 000000000..0e87ca7fd --- /dev/null +++ b/src/main/java/com/laytonsmith/abstraction/entities/MCShulker.java @@ -0,0 +1,11 @@ +package com.laytonsmith.abstraction.entities; + +import com.laytonsmith.abstraction.MCLivingEntity; +import com.laytonsmith.abstraction.enums.MCDyeColor; + +public interface MCShulker extends MCLivingEntity { + + MCDyeColor getColor(); + void setColor(MCDyeColor color); + +} diff --git a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java index 8290ebf45..5e7698b8e 100644 --- a/src/main/java/com/laytonsmith/core/functions/EntityManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/EntityManagement.java @@ -59,6 +59,7 @@ import com.laytonsmith.abstraction.entities.MCPigZombie; import com.laytonsmith.abstraction.entities.MCRabbit; import com.laytonsmith.abstraction.entities.MCSheep; +import com.laytonsmith.abstraction.entities.MCShulker; import com.laytonsmith.abstraction.entities.MCShulkerBullet; import com.laytonsmith.abstraction.entities.MCSkeleton; import com.laytonsmith.abstraction.entities.MCSlime; @@ -1971,6 +1972,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro specArray.set(entity_spec.KEY_SHEEP_COLOR, new CString(sheep.getColor().name(), t), t); specArray.set(entity_spec.KEY_SHEEP_SHEARED, CBoolean.get(sheep.isSheared()), t); break; + case SHULKER: + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12)) { + MCShulker shulker = (MCShulker) entity; + specArray.set(entity_spec.KEY_SHULKER_COLOR, new CString(shulker.getColor().name(), t), t); + } + break; case SHULKER_BULLET: MCShulkerBullet bullet = (MCShulkerBullet) entity; MCEntity target = bullet.getTarget(); @@ -2114,6 +2121,7 @@ public CHVersion since() { private static final String KEY_PRIMED_TNT_SOURCE = "source"; private static final String KEY_SHEEP_COLOR = "color"; private static final String KEY_SHEEP_SHEARED = "sheared"; + private static final String KEY_SHULKER_COLOR = "color"; private static final String KEY_SHULKERBULLET_TARGET = "target"; private static final String KEY_SKELETON_TYPE = "type"; private static final String KEY_SLIME_SIZE = "size"; @@ -2802,6 +2810,22 @@ public Construct exec(Target t, Environment environment, Construct... args) thro } } break; + case SHULKER: + MCShulker shulker = (MCShulker) entity; + for(String index : specArray.stringKeySet()) { + switch(index.toLowerCase()) { + case entity_spec.KEY_SHULKER_COLOR: + try { + shulker.setColor(MCDyeColor.valueOf(specArray.get(index, t).val().toUpperCase())); + } catch(IllegalArgumentException exception) { + throw new CREFormatException("Invalid shulker color: " + specArray.get(index, t).val(), t); + } + break; + default: + throwException(index, t); + } + } + break; case SHULKER_BULLET: MCShulkerBullet bullet = (MCShulkerBullet) entity; for(String index : specArray.stringKeySet()) { @@ -2866,16 +2890,14 @@ public Construct exec(Target t, Environment environment, Construct... args) thro } break; case SNOWMAN: - if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9_4)) { - MCSnowman snowman = (MCSnowman) entity; - for(String index : specArray.stringKeySet()) { - switch(index.toLowerCase()) { - case entity_spec.KEY_SNOWMAN_DERP: - snowman.setDerp(Static.getBoolean(specArray.get(index, t), t)); - break; - default: - throwException(index, t); - } + MCSnowman snowman = (MCSnowman) entity; + for(String index : specArray.stringKeySet()) { + switch(index.toLowerCase()) { + case entity_spec.KEY_SNOWMAN_DERP: + snowman.setDerp(Static.getBoolean(specArray.get(index, t), t)); + break; + default: + throwException(index, t); } } break; diff --git a/src/main/resources/functionDocs/entity_spec b/src/main/resources/functionDocs/entity_spec index 4abcc150a..cfb6767a0 100644 --- a/src/main/resources/functionDocs/entity_spec +++ b/src/main/resources/functionDocs/entity_spec @@ -180,6 +180,10 @@ without knowing the rotations on the other axis or of other body parts beforehan * %KEY_SHEEP_COLOR%: The color of the sheep (can be %DYE_COLOR%). * %KEY_SHEEP_SHEARED%: Whether the sheep is sheared. |- +| SHULKER +| +* %KEY_SHULKER_COLOR%: The color of the shulker (can be %DYE_COLOR%). +|- | SHULKER_BULLET | * %KEY_SHULKERBULLET_TARGET%: The UUID of the entity the bullet will head toward, or null if there is no target.