Skip to content

Commit

Permalink
add hoglins to entity immune property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 15, 2020
1 parent 34b9701 commit 652a478
Showing 1 changed file with 26 additions and 4 deletions.
Expand Up @@ -6,13 +6,15 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.entity.Hoglin;
import org.bukkit.entity.PiglinAbstract;

public class EntityImmune implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof PiglinAbstract;
&& (((EntityTag) entity).getBukkitEntity() instanceof PiglinAbstract
|| ((EntityTag) entity).getBukkitEntity() instanceof Hoglin);
}

public static EntityImmune getFrom(ObjectTag entity) {
Expand All @@ -38,13 +40,28 @@ private EntityImmune(EntityTag entity) {

EntityTag dentity;

public boolean isHoglin() {
return dentity.getBukkitEntity() instanceof Hoglin;
}

public Hoglin getHoglin() {
return (Hoglin) dentity.getBukkitEntity();
}

public PiglinAbstract getPiglin() {
return (PiglinAbstract) dentity.getBukkitEntity();
}

public boolean getIsImmune() {
if (isHoglin()) {
return getHoglin().isImmuneToZombification();
}
return getPiglin().isImmuneToZombification();
}

@Override
public String getPropertyString() {
return getPiglin().isImmuneToZombification() ? "true" : "false";
return getIsImmune() ? "true" : "false";
}

@Override
Expand All @@ -68,7 +85,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns whether this piglin entity is immune to zombification.
// -->
if (attribute.startsWith("immune")) {
return new ElementTag(getPiglin().isImmuneToZombification())
return new ElementTag(getIsImmune())
.getObjectAttribute(attribute.fulfill(1));
}

Expand All @@ -88,7 +105,12 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.immune>
// -->
if (mechanism.matches("immune") && mechanism.requireBoolean()) {
getPiglin().setImmuneToZombification(mechanism.getValue().asBoolean());
if (isHoglin()) {
getHoglin().setImmuneToZombification(mechanism.getValue().asBoolean());
}
else {
getPiglin().setImmuneToZombification(mechanism.getValue().asBoolean());
}
}
}
}

0 comments on commit 652a478

Please sign in to comment.