Skip to content

Commit

Permalink
add llamas to entity.color, fixes #1877
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 16, 2019
1 parent 0ab93cd commit e756b4d
Showing 1 changed file with 21 additions and 8 deletions.
Expand Up @@ -3,6 +3,7 @@
import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.entity.ParrotHelper;
import net.aufdemrand.denizen.utilities.entity.RabbitType;
import net.aufdemrand.denizencore.objects.Element;
Expand All @@ -28,6 +29,7 @@ public static boolean describes(dObject entity) {
type == EntityType.WOLF ||
type == EntityType.OCELOT ||
type == EntityType.RABBIT ||
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) && type == EntityType.LLAMA) ||
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.PARROT);
}

Expand Down Expand Up @@ -71,6 +73,9 @@ else if (type == EntityType.OCELOT) {
else if (type == EntityType.RABBIT) {
return ((Rabbit) colored.getBukkitEntity()).getRabbitType().name();
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) && type == EntityType.LLAMA) {
return ((Llama) colored.getBukkitEntity()).getColor().name();
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.PARROT) {
return ParrotHelper.parrotColor(colored);
}
Expand Down Expand Up @@ -145,12 +150,13 @@ public String getAttribute(Attribute attribute) {
// @group properties
// @description
// If the entity can have a color, returns the entity's color.
// Currently, only Horse, Wolf, Ocelot, Sheep, Rabbit, and Parrot type entities can have a color.
// Currently, only Horse, Wolf, Ocelot, Sheep, Rabbit, Llama, and Parrot type entities can have a color.
// For horses, the output is COLOR|STYLE(|VARIANT), see <@link language horse types>.
// NOTE: HORSE VARIANTS DEPRECATED SINCE 1.11, use spawn instead
// For ocelots, the types are BLACK_CAT, RED_CAT, SIAMESE_CAT, or WILD_OCELOT.
// For rabbit types, see <@link language rabbit types>.
// For parrots, the types are BLUE, CYAN, GRAY, GREEN, or RED.
// For llamas, the types are CREAMY, WHITE, BROWN, and GRAY.
// -->
if (attribute.startsWith("color")) {
return new Element(CoreUtilities.toLowerCase(getColor()))
Expand Down Expand Up @@ -214,17 +220,24 @@ else if (type == EntityType.OCELOT
((Ocelot) colored.getBukkitEntity())
.setCatType(Ocelot.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (type == EntityType.RABBIT) {
if (mechanism.getValue().matchesEnum(RabbitType.values())) {
((Rabbit) colored.getBukkitEntity()).setRabbitType(RabbitType.valueOf(mechanism.getValue().asString().toUpperCase()).getType());
}
else if (mechanism.getValue().matchesEnum(Rabbit.Type.values())) {
((Rabbit) colored.getBukkitEntity()).setRabbitType(Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (type == EntityType.RABBIT
&& mechanism.getValue().matchesEnum(RabbitType.values())) {
((Rabbit) colored.getBukkitEntity()).setRabbitType(RabbitType.valueOf(mechanism.getValue().asString().toUpperCase()).getType());
}
else if (type == EntityType.RABBIT
&& mechanism.getValue().matchesEnum(Rabbit.Type.values())) {
((Rabbit) colored.getBukkitEntity()).setRabbitType(Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) && type == EntityType.LLAMA
&& mechanism.getValue().matchesEnum(Llama.Color.values())) {
((Llama) colored.getBukkitEntity()).setColor(Llama.Color.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.PARROT) {
ParrotHelper.setParrotColor(colored, mechanism);
}
else {
dB.echoError("Could not apply color '" + mechanism.getValue().toString() + "' to entity of type " + type.name() + ".");
}

}
}
Expand Down

0 comments on commit e756b4d

Please sign in to comment.