Skip to content

Commit

Permalink
Add shulker color to entity_spec()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jun 3, 2018
1 parent b802db5 commit 7738797
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 12 deletions.
@@ -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
}
}
}
Expand Up @@ -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;
}

}
11 changes: 11 additions & 0 deletions 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);

}
42 changes: 32 additions & 10 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/functionDocs/entity_spec
Expand Up @@ -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.
Expand Down

0 comments on commit 7738797

Please sign in to comment.