Skip to content

Commit

Permalink
Add riptide entity property
Browse files Browse the repository at this point in the history
  • Loading branch information
mergu committed Jan 17, 2019
1 parent 5fb7de1 commit 8f50532
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 12 deletions.
Expand Up @@ -18,6 +18,8 @@

public interface EntityHelper {

void setRiptide(Entity entity, boolean state);

int getBodyArrows(Entity entity);

void setBodyArrows(Entity entity, int numArrows);
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -848,6 +848,9 @@ public Property get(dObject o) {
PropertyParser.registerProperty(EntityPotion.class, dEntity.class);
PropertyParser.registerProperty(EntityPowered.class, dEntity.class);
PropertyParser.registerProperty(EntityProfession.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
PropertyParser.registerProperty(EntityRiptide.class, dEntity.class);
}
PropertyParser.registerProperty(EntityRotation.class, dEntity.class);
PropertyParser.registerProperty(EntitySmall.class, dEntity.class);
PropertyParser.registerProperty(EntitySilent.class, dEntity.class);
Expand Down
12 changes: 0 additions & 12 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -2282,18 +2282,6 @@ && getBukkitEntity() instanceof Item) {
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <e@entity.is_using_riptide>
// @returns Element(Boolean)
// @group attributes
// @description
// Returns whether this entity is using the Riptide enchantment.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2) && attribute.startsWith("is_using_riptide")) {
return new Element(getLivingEntity().isRiptiding())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <e@entity.glowing>
// @returns Element(Boolean)
Expand Down
@@ -0,0 +1,85 @@
package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.nms.NMSHandler;
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;

public class EntityRiptide implements Property {
public static boolean describes(dObject object) {
return object instanceof dEntity && ((dEntity) object).isLivingEntity();
}

public static EntityRiptide getFrom(dObject object) {
if (!describes(object)) {
return null;
}
else {
return new EntityRiptide((dEntity) object);
}
}

///////////////////
// Instance Fields and Methods
/////////////

private EntityRiptide(dEntity entity) {
this.entity = entity;
}

dEntity entity;

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return entity.getLivingEntity().isRiptiding() ? "true" : null;
}

@Override
public String getPropertyId() {
return "is_using_riptide";
}

@Override
public String getAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}

// <--[tag]
// @attribute <e@entity.is_using_riptide>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether this entity is using the Riptide enchantment.
// -->
if (attribute.startsWith("is_using_riptide")) {
return new Element(entity.getLivingEntity().isRiptiding())
.getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name is_using_riptide
// @input Element(Boolean)
// @description
// Sets whether this entity is using the Riptide enchantment.
// -->
if (mechanism.matches("is_using_riptide") && mechanism.requireBoolean()) {
NMSHandler.getInstance().getEntityHelper().setRiptide(entity.getBukkitEntity(), mechanism.getValue().asBoolean());
}
}
}
Expand Up @@ -37,6 +37,11 @@ public class EntityHelper_v1_10_R1 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// Intentionally empty
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down
Expand Up @@ -37,6 +37,11 @@ public class EntityHelper_v1_11_R1 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// Intentionally empty
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down
Expand Up @@ -42,6 +42,11 @@ public class EntityHelper_v1_12_R1 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// Intentionally empty
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down
Expand Up @@ -43,6 +43,13 @@ public class EntityHelper_v1_13_R2 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(6, DataWatcherRegistry.a), (byte) (state ? 4 : 0));
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down
Expand Up @@ -38,6 +38,11 @@ public class EntityHelper_v1_8_R3 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// Intentionally empty
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down
Expand Up @@ -37,6 +37,11 @@ public class EntityHelper_v1_9_R2 implements EntityHelper {
General Entity Methods
*/

@Override
public void setRiptide(Entity entity, boolean state) {
// Intentionally empty
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
Expand Down

0 comments on commit 8f50532

Please sign in to comment.