Skip to content

Commit

Permalink
add Bee support to EntityAnger
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 20, 2019
1 parent a5ced2a commit 89c6613
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Expand Up @@ -236,7 +236,7 @@ public static void registerTags() {
});

// <--[tag]
// @attribute <ElementTag.parse_color[<prefix>]>
// @attribute <ElementTag.parse_color[(<prefix>)]>
// @returns ElementTag
// @group text manipulation
// @description
Expand Down
@@ -1,18 +1,26 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Entity;
import org.bukkit.entity.PigZombie;

public class EntityAnger implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntityType() == EntityType.PIG_ZOMBIE;
if (!(entity instanceof EntityTag)) {
return false;
}
Entity bukkitEntity = ((EntityTag) entity).getBukkitEntity();
return bukkitEntity instanceof PigZombie ||
(NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14) && bukkitEntity instanceof Bee);
}

public static EntityAnger getFrom(ObjectTag entity) {
Expand Down Expand Up @@ -61,6 +69,15 @@ public String getPropertyId() {
// ObjectTag Attributes
////////

public int getAnger() {
if (entity.getBukkitEntity() instanceof PigZombie) {
return ((PigZombie) entity.getBukkitEntity()).getAnger();
}
else {
return ((Bee) entity.getBukkitEntity()).getAnger();
}
}

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

Expand All @@ -74,13 +91,11 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @mechanism EntityTag.anger
// @group properties
// @description
// Returns the anger level of a PigZombie.
// Returns the anger level of a PigZombie or Bee.
// -->
if (attribute.startsWith("anger")) {
if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
return new ElementTag(((PigZombie) entity.getBukkitEntity()).getAnger())
.getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getAnger())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
Expand All @@ -94,15 +109,18 @@ public void adjust(Mechanism mechanism) {
// @name anger
// @input ElementTag(Boolean)
// @description
// Changes the anger level of a PigZombie.
// Changes the anger level of a PigZombie or Bee.
// @tags
// <EntityTag.anger>
// -->

if (mechanism.matches("anger") && mechanism.requireInteger()) {
if (entity.getBukkitEntityType() == EntityType.PIG_ZOMBIE) {
if (entity.getBukkitEntity() instanceof PigZombie) {
((PigZombie) entity.getBukkitEntity()).setAnger(mechanism.getValue().asInt());
}
else {
((Bee) entity.getBukkitEntity()).setAnger(mechanism.getValue().asInt());
}
}
}
}

0 comments on commit 89c6613

Please sign in to comment.