Skip to content

Commit

Permalink
add shulkers to entity color property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 3, 2019
1 parent 75e5352 commit 548ea89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Expand Up @@ -7,6 +7,7 @@
import net.aufdemrand.denizen.utilities.entity.LlamaHelper;
import net.aufdemrand.denizen.utilities.entity.ParrotHelper;
import net.aufdemrand.denizen.utilities.entity.RabbitType;
import net.aufdemrand.denizen.utilities.entity.ShulkerHelper;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dList;
Expand All @@ -31,7 +32,8 @@ public static boolean describes(dObject entity) {
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);
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1)
&& (type == EntityType.PARROT || type == EntityType.SHULKER));
}

public static EntityColor getFrom(dObject entity) {
Expand Down Expand Up @@ -88,6 +90,9 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) && type == Entit
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.PARROT) {
return ParrotHelper.parrotColor(colored);
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.SHULKER) {
return ShulkerHelper.getColor(colored).name();
}
else // Should never happen
{
return null;
Expand Down Expand Up @@ -166,6 +171,7 @@ public String getAttribute(Attribute attribute) {
// 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.
// For sheep, wolf, and shulker entities, see <@link url https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/DyeColor.html>
// -->
if (attribute.startsWith("color")) {
return new Element(CoreUtilities.toLowerCase(getColor()))
Expand All @@ -184,12 +190,14 @@ public void adjust(Mechanism mechanism) {
// @input Element
// @description
// Changes 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, Parrot, and Shulker type entities can have a color.
// For horses, the input 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.
// For sheep, wolf, and shulker entities, see <@link url https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/DyeColor.html>
// @tags
// <e@entity.color>
// <e@entity.is_colorable>
Expand Down Expand Up @@ -243,6 +251,10 @@ else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) && type == Entit
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.PARROT) {
ParrotHelper.setParrotColor(colored, mechanism);
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && type == EntityType.SHULKER
&& mechanism.getValue().matchesEnum(DyeColor.values())) {
ShulkerHelper.setColor(colored, DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else {
dB.echoError("Could not apply color '" + mechanism.getValue().toString() + "' to entity of type " + type.name() + ".");
}
Expand Down
@@ -0,0 +1,16 @@
package net.aufdemrand.denizen.utilities.entity;

import net.aufdemrand.denizen.objects.dEntity;
import org.bukkit.DyeColor;
import org.bukkit.entity.Shulker;

public class ShulkerHelper {

public static DyeColor getColor(dEntity shulker) {
return ((Shulker) shulker.getBukkitEntity()).getColor();
}

public static void setColor(dEntity shulker, DyeColor color) {
((Shulker) shulker.getBukkitEntity()).setColor(color);
}
}

0 comments on commit 548ea89

Please sign in to comment.