Skip to content

Commit

Permalink
entity color axolotl and goat
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 17, 2021
1 parent 86ce242 commit 5ab2395
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.utilities.entity.ColorHelper1_17;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
Expand Down Expand Up @@ -36,7 +39,8 @@ public static boolean describes(ObjectTag entity) {
type == EntityType.ARROW ||
type == EntityType.VILLAGER ||
type == EntityType.TRADER_LLAMA ||
type == EntityType.TROPICAL_FISH;
type == EntityType.TROPICAL_FISH ||
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && ColorHelper1_17.colorIsApplicable(type));
}

public static EntityColor getFrom(ObjectTag entity) {
Expand Down Expand Up @@ -119,6 +123,9 @@ else if (type == EntityType.ARROW) {
return null;
}
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && ColorHelper1_17.colorIsApplicable(type)) {
return ColorHelper1_17.getColor(colored.getBukkitEntity());
}
else {
return null;
}
Expand Down Expand Up @@ -177,6 +184,9 @@ else if (type == EntityType.PANDA) {
else if (type == EntityType.VILLAGER) {
return listForEnum(Villager.Type.values());
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && ColorHelper1_17.colorIsApplicable(type)) {
return ColorHelper1_17.getAllowedColors(type);
}
else { // includes Ocelot (deprecated) and arrow (ColorTag)
return null;
}
Expand Down Expand Up @@ -218,6 +228,8 @@ public String getPropertyId() {
// and PATTERN is KOB, SUNSTREAK, SNOOPER, DASHER, BRINELY, SPOTTY, FLOPPER, STRIPEY, GLITTER, BLOCKFISH, BETTY, is CLAYFISH.
// For sheep, wolf, and shulker entities, the input is a Dye Color.
// For Tipped Arrow entities, the input is a ColorTag.
// For goats, the input is SCREAMING or NORMAL.
// For axolotl, the input is BLUE, CYAN, GOLD, LUCY, or WILD.
//
// For all places where a DyeColor is needed, the options are:
// BLACK, BLUE, BROWN, CYAN, GRAY, GREEN, LIGHT_BLUE, LIGHT_GRAY, LIME, MAGENTA, ORANGE, PINK, PURPLE, RED, WHITE, or YELLOW.
Expand Down Expand Up @@ -354,6 +366,9 @@ else if (type == EntityType.VILLAGER) {
else if (type == EntityType.ARROW) {
((Arrow) colored.getBukkitEntity()).setColor(mechanism.valueAsType(ColorTag.class).getColor());
}
else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && ColorHelper1_17.colorIsApplicable(type)) {
ColorHelper1_17.setColor(colored.getBukkitEntity(), mechanism);
}
else { // Should never happen
mechanism.echoError("Could not apply color '" + mechanism.getValue().toString() + "' to entity of type " + type.name() + ".");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.denizenscript.denizen.utilities.entity;

import com.denizenscript.denizen.objects.properties.entity.EntityColor;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Goat;

public class ColorHelper1_17 {

public static boolean colorIsApplicable(EntityType type) {
return type == EntityType.GOAT || type == EntityType.AXOLOTL;
}

public static String getColor(Entity entity) {
if (entity instanceof Goat) {
return ((Goat) entity).isScreaming() ? "screaming" : "normal";
}
else if (entity instanceof Axolotl) {
return ((Axolotl) entity).getVariant().name();
}
return null;
}

public static ListTag getAllowedColors(EntityType type) {
if (type == EntityType.GOAT) {
ListTag result = new ListTag();
result.add("screaming");
result.add("normal");
return result;
}
else if (type == EntityType.AXOLOTL) {
return EntityColor.listForEnum(Axolotl.Variant.values());
}
return null;
}

public static void setColor(Entity entity, Mechanism mech) {
if (entity instanceof Goat) {
((Goat) entity).setScreaming(CoreUtilities.toLowerCase(mech.getValue().asString()).equals("screaming"));
}
else if (entity instanceof Axolotl && mech.requireEnum(false, Axolotl.Variant.values())) {
((Axolotl) entity).setVariant(Axolotl.Variant.valueOf(mech.getValue().asString().toUpperCase()));
}
}
}

0 comments on commit 5ab2395

Please sign in to comment.