Skip to content

Commit

Permalink
extend gravity mec/tag to all entities post-1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
mergu committed Dec 26, 2017
1 parent ca005ca commit c1a602e
Showing 1 changed file with 27 additions and 5 deletions.
@@ -1,18 +1,22 @@
package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;

public class EntityGravity implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.ARMOR_STAND;
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)) {
return entity instanceof dEntity;
}
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof ArmorStand;
}

public static EntityGravity getFrom(dObject entity) {
Expand Down Expand Up @@ -41,6 +45,15 @@ private EntityGravity(dEntity entity) {

@Override
public String getPropertyString() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)) {
if (dentity.getBukkitEntity().hasGravity()) {
return null;
}
else {
return "false";
}
}

if (((ArmorStand) dentity.getBukkitEntity()).hasGravity()) {
return null;
}
Expand Down Expand Up @@ -71,9 +84,13 @@ public String getAttribute(Attribute attribute) {
// @mechanism dEntity.gravity
// @group properties
// @description
// If the entity is an armor stand, returns whether the armor stand has gravity.
// Returns whether the entity has gravity.
// -->
if (attribute.startsWith("gravity")) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)) {
return new Element(dentity.getBukkitEntity().hasGravity())
.getAttribute(attribute.fulfill(1));
}
return new Element(((ArmorStand) dentity.getBukkitEntity()).hasGravity())
.getAttribute(attribute.fulfill(1));
}
Expand All @@ -89,13 +106,18 @@ public void adjust(Mechanism mechanism) {
// @name gravity
// @input Element(Boolean)
// @description
// Changes the gravity state of an armor stand.
// Changes the gravity state of an entity.
// @tags
// <e@entity.gravity>
// -->

if (mechanism.matches("gravity") && mechanism.requireBoolean()) {
((ArmorStand) dentity.getBukkitEntity()).setGravity(mechanism.getValue().asBoolean());
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_10_R1)) {
dentity.getBukkitEntity().setGravity(mechanism.getValue().asBoolean());
}
else {
((ArmorStand) dentity.getBukkitEntity()).setGravity(mechanism.getValue().asBoolean());
}
}
}
}

0 comments on commit c1a602e

Please sign in to comment.