Skip to content

Commit

Permalink
Expand arrow mecs, additional minor fixes (#1946)
Browse files Browse the repository at this point in the history
* Minor fix in item.potion_effects meta

* Rename "plant_growth" dMaterial property to "age"

* Fix potions erroring out below 1.11

* Expand existing arrow properties, add new arrow properties

* Fix meta, replace "is_plant" with "is_ageable"

* Fix arrow damage meta to be clearer

* Revert "Minor fix in item.potion_effects meta"
  • Loading branch information
MusicScore authored and mcmonkey4eva committed Apr 7, 2019
1 parent 6bcf3d7 commit d80c938
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 50 deletions.
8 changes: 6 additions & 2 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -31,7 +31,7 @@
import net.aufdemrand.denizen.objects.properties.inventory.InventorySize;
import net.aufdemrand.denizen.objects.properties.inventory.InventoryTitle;
import net.aufdemrand.denizen.objects.properties.item.*;
import net.aufdemrand.denizen.objects.properties.material.MaterialPlantGrowth;
import net.aufdemrand.denizen.objects.properties.material.MaterialAge;
import net.aufdemrand.denizen.objects.properties.trade.*;
import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry;
import net.aufdemrand.denizen.scripts.containers.core.*;
Expand Down Expand Up @@ -809,6 +809,7 @@ public void onEnable() {
PropertyParser.registerProperty(EntityAngry.class, dEntity.class);
PropertyParser.registerProperty(EntityAreaEffectCloud.class, dEntity.class);
PropertyParser.registerProperty(EntityArmorBonus.class, dEntity.class);
PropertyParser.registerProperty(EntityArrowDamage.class, dEntity.class);
PropertyParser.registerProperty(EntityInvulnerable.class, dEntity.class);
PropertyParser.registerProperty(EntityBoatType.class, dEntity.class);
PropertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
Expand Down Expand Up @@ -838,6 +839,9 @@ public void onEnable() {
PropertyParser.registerProperty(EntityMarker.class, dEntity.class);
PropertyParser.registerProperty(EntityMaxFuseTicks.class, dEntity.class);
PropertyParser.registerProperty(EntityPainting.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) {
PropertyParser.registerProperty(EntityPickupStatus.class, dEntity.class);
}
PropertyParser.registerProperty(EntityPotion.class, dEntity.class);
PropertyParser.registerProperty(EntityPowered.class, dEntity.class);
PropertyParser.registerProperty(EntityProfession.class, dEntity.class);
Expand Down Expand Up @@ -896,7 +900,7 @@ public void onEnable() {

if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
// register core dMaterial properties
PropertyParser.registerProperty(MaterialPlantGrowth.class, dMaterial.class);
PropertyParser.registerProperty(MaterialAge.class, dMaterial.class);
}

if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1)) {
Expand Down
32 changes: 32 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -27,6 +27,7 @@
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
Expand Down Expand Up @@ -2263,6 +2264,37 @@ && getBukkitEntity() instanceof Item) {
return new Duration(((Item) getBukkitEntity()).getPickupDelay() * 20).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <e@entity.is_in_block>
// @returns Element(Boolean)
// @group attributes
// @description
// Returns whether or not the arrow/trident entity is in a block.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && attribute.startsWith("is_in_block")) {
if (getBukkitEntity() instanceof Arrow) {
return new Element(((Arrow) getBukkitEntity()).isInBlock()).getAttribute(attribute.fulfill(1));
}
return null;
}

// <--[tag]
// @attribute <e@entity.attached_block>
// @returns dLocation
// @group attributes
// @description
// Returns the location of the block that the arrow/trident entity is attached to.
// -->
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && attribute.startsWith("attached_block")) {
if (getBukkitEntity() instanceof Arrow) {
Block attachedBlock = ((Arrow) getBukkitEntity()).getAttachedBlock();
if (attachedBlock != null) {
return new dLocation(attachedBlock.getLocation()).getAttribute(attribute.fulfill(1));
}
}
return null;
}

// <--[tag]
// @attribute <e@entity.gliding>
// @returns Element(Boolean)
Expand Down
20 changes: 14 additions & 6 deletions plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Expand Up @@ -4,7 +4,7 @@
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.nms.abstracts.ModernBlockData;
import net.aufdemrand.denizen.nms.interfaces.BlockData;
import net.aufdemrand.denizen.objects.properties.material.MaterialPlantGrowth;
import net.aufdemrand.denizen.objects.properties.material.MaterialAge;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.blocks.OldMaterialsHelper;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand Down Expand Up @@ -458,18 +458,26 @@ public String run(Attribute attribute, dObject object) {
});

// <--[tag]
// @attribute <m@material.is_plant>
// @attribute <m@material.is_ageable>
// @returns Element(Boolean)
// @group properties
// @description
// Returns whether the material is a plant block material.
// When this returns true, <@link tag m@material.plant_growth>, <@link tag m@material.maximum_plant_growth>,
// and <@link mechanism dMaterial.plant_growth> are accessible.
// Returns whether the material is an ageable material.
// When this returns true, <@link tag m@material.age>, <@link tag m@material.maximum_age>,
// and <@link mechanism dMaterial.age> are accessible.
// -->
registerTag("is_ageable", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(MaterialAge.describes(object))
.getAttribute(attribute.fulfill(1));
}
});

registerTag("is_plant", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(MaterialPlantGrowth.describes(object))
return new Element(MaterialAge.describes(object))
.getAttribute(attribute.fulfill(1));
}
});
Expand Down
@@ -0,0 +1,120 @@
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.Arrow;

public class EntityArrowDamage implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow;
}

public static EntityArrowDamage getFrom(dObject entity) {
if (!describes(entity)) {
return null;
}
return new EntityArrowDamage((dEntity) entity);
}

public static final String[] handledTags = {
"damage"
};

public static final String[] handledMechs = {
"damage"
};


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

private EntityArrowDamage(dEntity entity) {
dentity = entity;
}

dEntity dentity;

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

@Override
public String getPropertyString() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return String.valueOf(((Arrow) dentity.getBukkitEntity()).getDamage());
}
else {
return String.valueOf(((Arrow) dentity.getBukkitEntity()).spigot().getDamage());
}
}

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

///////////
// dObject Attributes
////////

@Override
public String getAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <e@entity.damage>
// @returns Element(Decimal)
// @mechanism dEntity.damage
// @group properties
// @description
// Returns the damage that the arrow/trident will inflict.
// NOTE: The actual damage dealt by the arrow/trident may be different depending on the projectile's flight speed.
// -->
if (attribute.startsWith("damage")) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return new Element(((Arrow) dentity.getBukkitEntity()).getDamage())
.getAttribute(attribute.fulfill(1));
}
else {
return new Element(((Arrow) dentity.getBukkitEntity()).spigot().getDamage())
.getAttribute(attribute.fulfill(1));
}
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name damage
// @input Element(Decimal)
// @description
// Changes how much damage an arrow/trident will inflict.
// @tags
// <e@entity.damage>
// -->

if (mechanism.matches("damage") && mechanism.requireDouble()) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
((Arrow) dentity.getBukkitEntity()).setDamage(mechanism.getValue().asDouble());
}
else {
((Arrow) dentity.getBukkitEntity()).spigot().setDamage(mechanism.getValue().asDouble());
}
}
}
}
Expand Up @@ -7,12 +7,11 @@
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;

public class EntityCritical implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.ARROW;
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow;
}

public static EntityCritical getFrom(dObject entity) {
Expand Down Expand Up @@ -79,7 +78,7 @@ public String getAttribute(Attribute attribute) {
// @mechanism dEntity.critical
// @group properties
// @description
// If the entity is an arrow, returns whether the arrow is critical.
// If the entity is an arrow or trident, returns whether the arrow/trident is critical.
// -->
if (attribute.startsWith("critical")) {
return new Element(((Arrow) critical.getBukkitEntity()).isCritical())
Expand All @@ -97,7 +96,7 @@ public void adjust(Mechanism mechanism) {
// @name critical
// @input Element(Boolean)
// @description
// Changes whether an arrow is critical.
// Changes whether an arrow/trident is critical.
// @tags
// <e@entity.critical>
// -->
Expand Down
Expand Up @@ -7,12 +7,11 @@
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;

public class EntityKnockback implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.ARROW;
return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow;
}

public static EntityKnockback getFrom(dObject entity) {
Expand Down Expand Up @@ -74,7 +73,7 @@ public String getAttribute(Attribute attribute) {
// @mechanism dEntity.knockback
// @group properties
// @description
// If the entity is an arrow, returns the knockback strength of the arrow.
// If the entity is an arrow or trident, returns the knockback strength of the arrow/trident.
// -->
if (attribute.startsWith("knockback")) {
return new Element(((Arrow) arrow.getBukkitEntity()).getKnockbackStrength())
Expand All @@ -92,7 +91,7 @@ public void adjust(Mechanism mechanism) {
// @name knockback
// @input Element(Number)
// @description
// Changes an arrow's knockback strength.
// Changes an arrow's/trident's knockback strength.
// @tags
// <e@entity.knockback>
// -->
Expand Down

0 comments on commit d80c938

Please sign in to comment.