Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand arrow mecs, additional minor fixes (#1946)
* 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
1 parent
6bcf3d7
commit d80c938
Showing
9 changed files
with
320 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityArrowDamage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.