Skip to content

Commit

Permalink
gravity trait: Citizens direct compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 30, 2020
1 parent cdcb8f7 commit 9d2ad7f
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import net.citizensnpcs.trait.Gravity;

public class EntityGravity implements Property {

Expand Down Expand Up @@ -67,6 +68,11 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Returns whether the entity has gravity.
// -->
if (attribute.startsWith("gravity")) {
if (dentity.isCitizensNPC()) {
boolean gravityBlocked = dentity.getDenizenNPC().getCitizen().hasTrait(Gravity.class)
&& !dentity.getDenizenNPC().getCitizen().getTrait(Gravity.class).hasGravity();
return new ElementTag(!gravityBlocked);
}
return new ElementTag(dentity.getBukkitEntity().hasGravity())
.getObjectAttribute(attribute.fulfill(1));
}
Expand All @@ -87,7 +93,12 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.gravity>
// -->
if (mechanism.matches("gravity") && mechanism.requireBoolean()) {
dentity.getBukkitEntity().setGravity(mechanism.getValue().asBoolean());
if (dentity.isCitizensNPC()) {
dentity.getDenizenNPC().getCitizen().getTrait(Gravity.class).gravitate(!mechanism.getValue().asBoolean());
}
else {
dentity.getBukkitEntity().setGravity(mechanism.getValue().asBoolean());
}
}
}
}

0 comments on commit 9d2ad7f

Please sign in to comment.