Skip to content

Commit 7738797

Browse files
committed
Add shulker color to entity_spec()
1 parent b802db5 commit 7738797

5 files changed

Lines changed: 94 additions & 12 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.laytonsmith.abstraction.bukkit.entities;
2+
3+
import com.laytonsmith.abstraction.entities.MCShulker;
4+
import com.laytonsmith.abstraction.enums.MCDyeColor;
5+
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
6+
import org.bukkit.entity.Entity;
7+
import org.bukkit.entity.Shulker;
8+
9+
public class BukkitMCShulker extends BukkitMCLivingEntity implements MCShulker {
10+
11+
private Shulker sh;
12+
13+
public BukkitMCShulker(Entity be) {
14+
super(be);
15+
this.sh = (Shulker) be;
16+
}
17+
18+
@Override
19+
public MCDyeColor getColor() {
20+
try {
21+
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(sh.getColor());
22+
} catch(NoSuchMethodError ex) {
23+
// probably prior to 1.12
24+
}
25+
return MCDyeColor.PURPLE;
26+
}
27+
28+
@Override
29+
public void setColor(MCDyeColor color) {
30+
try {
31+
sh.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
32+
} catch(NoSuchMethodError ex) {
33+
// probably prior to 1.12
34+
}
35+
}
36+
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCSnowman.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@ public BukkitMCSnowman(AbstractionObject ao) {
1818

1919
@Override
2020
public void setDerp(boolean derp) {
21-
((Snowman) getHandle()).setDerp(derp);
21+
try {
22+
((Snowman) getHandle()).setDerp(derp);
23+
} catch(NoSuchMethodError ex) {
24+
// probably prior to 1.9.4
25+
}
2226
}
2327

2428
@Override
2529
public boolean isDerp() {
26-
return ((Snowman) getHandle()).isDerp();
30+
try {
31+
return ((Snowman) getHandle()).isDerp();
32+
} catch(NoSuchMethodError ex) {
33+
// probably prior to 1.9.4
34+
}
35+
return false;
2736
}
2837

2938
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.laytonsmith.abstraction.entities;
2+
3+
import com.laytonsmith.abstraction.MCLivingEntity;
4+
import com.laytonsmith.abstraction.enums.MCDyeColor;
5+
6+
public interface MCShulker extends MCLivingEntity {
7+
8+
MCDyeColor getColor();
9+
void setColor(MCDyeColor color);
10+
11+
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.laytonsmith.abstraction.entities.MCPigZombie;
6060
import com.laytonsmith.abstraction.entities.MCRabbit;
6161
import com.laytonsmith.abstraction.entities.MCSheep;
62+
import com.laytonsmith.abstraction.entities.MCShulker;
6263
import com.laytonsmith.abstraction.entities.MCShulkerBullet;
6364
import com.laytonsmith.abstraction.entities.MCSkeleton;
6465
import com.laytonsmith.abstraction.entities.MCSlime;
@@ -1971,6 +1972,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
19711972
specArray.set(entity_spec.KEY_SHEEP_COLOR, new CString(sheep.getColor().name(), t), t);
19721973
specArray.set(entity_spec.KEY_SHEEP_SHEARED, CBoolean.get(sheep.isSheared()), t);
19731974
break;
1975+
case SHULKER:
1976+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12)) {
1977+
MCShulker shulker = (MCShulker) entity;
1978+
specArray.set(entity_spec.KEY_SHULKER_COLOR, new CString(shulker.getColor().name(), t), t);
1979+
}
1980+
break;
19741981
case SHULKER_BULLET:
19751982
MCShulkerBullet bullet = (MCShulkerBullet) entity;
19761983
MCEntity target = bullet.getTarget();
@@ -2114,6 +2121,7 @@ public CHVersion since() {
21142121
private static final String KEY_PRIMED_TNT_SOURCE = "source";
21152122
private static final String KEY_SHEEP_COLOR = "color";
21162123
private static final String KEY_SHEEP_SHEARED = "sheared";
2124+
private static final String KEY_SHULKER_COLOR = "color";
21172125
private static final String KEY_SHULKERBULLET_TARGET = "target";
21182126
private static final String KEY_SKELETON_TYPE = "type";
21192127
private static final String KEY_SLIME_SIZE = "size";
@@ -2802,6 +2810,22 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
28022810
}
28032811
}
28042812
break;
2813+
case SHULKER:
2814+
MCShulker shulker = (MCShulker) entity;
2815+
for(String index : specArray.stringKeySet()) {
2816+
switch(index.toLowerCase()) {
2817+
case entity_spec.KEY_SHULKER_COLOR:
2818+
try {
2819+
shulker.setColor(MCDyeColor.valueOf(specArray.get(index, t).val().toUpperCase()));
2820+
} catch(IllegalArgumentException exception) {
2821+
throw new CREFormatException("Invalid shulker color: " + specArray.get(index, t).val(), t);
2822+
}
2823+
break;
2824+
default:
2825+
throwException(index, t);
2826+
}
2827+
}
2828+
break;
28052829
case SHULKER_BULLET:
28062830
MCShulkerBullet bullet = (MCShulkerBullet) entity;
28072831
for(String index : specArray.stringKeySet()) {
@@ -2866,16 +2890,14 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
28662890
}
28672891
break;
28682892
case SNOWMAN:
2869-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9_4)) {
2870-
MCSnowman snowman = (MCSnowman) entity;
2871-
for(String index : specArray.stringKeySet()) {
2872-
switch(index.toLowerCase()) {
2873-
case entity_spec.KEY_SNOWMAN_DERP:
2874-
snowman.setDerp(Static.getBoolean(specArray.get(index, t), t));
2875-
break;
2876-
default:
2877-
throwException(index, t);
2878-
}
2893+
MCSnowman snowman = (MCSnowman) entity;
2894+
for(String index : specArray.stringKeySet()) {
2895+
switch(index.toLowerCase()) {
2896+
case entity_spec.KEY_SNOWMAN_DERP:
2897+
snowman.setDerp(Static.getBoolean(specArray.get(index, t), t));
2898+
break;
2899+
default:
2900+
throwException(index, t);
28792901
}
28802902
}
28812903
break;

src/main/resources/functionDocs/entity_spec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ without knowing the rotations on the other axis or of other body parts beforehan
180180
* %KEY_SHEEP_COLOR%: The color of the sheep (can be %DYE_COLOR%).
181181
* %KEY_SHEEP_SHEARED%: Whether the sheep is sheared.
182182
|-
183+
| SHULKER
184+
|
185+
* %KEY_SHULKER_COLOR%: The color of the shulker (can be %DYE_COLOR%).
186+
|-
183187
| SHULKER_BULLET
184188
|
185189
* %KEY_SHULKERBULLET_TARGET%: The UUID of the entity the bullet will head toward, or null if there is no target.

0 commit comments

Comments
 (0)