Skip to content

Commit

Permalink
add bee properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 20, 2021
1 parent 0025442 commit 4f17f4e
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 0 deletions.
Expand Up @@ -47,6 +47,9 @@ public static void registermainProperties() {
PropertyParser.registerProperty(EntityBeamTarget.class, EntityTag.class);
PropertyParser.registerProperty(EntityBodyArrows.class, EntityTag.class);
PropertyParser.registerProperty(EntityBoundingBox.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_15)) {
PropertyParser.registerProperty(EntityCannotEnterHive.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityChestCarrier.class, EntityTag.class);
PropertyParser.registerProperty(EntityColor.class, EntityTag.class);
PropertyParser.registerProperty(EntityCritical.class, EntityTag.class);
Expand All @@ -59,9 +62,19 @@ public static void registermainProperties() {
PropertyParser.registerProperty(EntityExplosionRadius.class, EntityTag.class);
PropertyParser.registerProperty(EntityFirework.class, EntityTag.class);
PropertyParser.registerProperty(EntityFixed.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_15)) {
PropertyParser.registerProperty(EntityFlower.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityFramed.class, EntityTag.class);
PropertyParser.registerProperty(EntityGravity.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_15)) {
PropertyParser.registerProperty(EntityHasNectar.class, EntityTag.class);
PropertyParser.registerProperty(EntityHasStung.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityHealth.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_15)) {
PropertyParser.registerProperty(EntityHive.class, EntityTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16)) {
PropertyParser.registerProperty(EntityImmune.class, EntityTag.class);
}
Expand Down
@@ -0,0 +1,98 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Entity;

public class EntityCannotEnterHive implements Property {

public static boolean describes(ObjectTag entity) {
if (!(entity instanceof EntityTag)) {
return false;
}
Entity bukkitEntity = ((EntityTag) entity).getBukkitEntity();
return bukkitEntity instanceof Bee;
}

public static EntityCannotEnterHive getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityCannotEnterHive((EntityTag) entity);
}
}

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

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

private EntityCannotEnterHive(EntityTag entity) {
this.entity = entity;
}

EntityTag entity;

public Bee getBee() {
return (Bee) entity.getBukkitEntity();
}

@Override
public String getPropertyString() {
return new DurationTag((long) getBee().getCannotEnterHiveTicks()).identify();
}

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

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <EntityTag.cannot_enter_hive>
// @returns DurationTag
// @mechanism EntityTag.cannot_enter_hive
// @group properties
// @description
// Returns the minimum duration until a Bee entity is allowed to enter a hive.
// -->
if (attribute.startsWith("cannot_enter_hive")) {
return new DurationTag((long) getBee().getCannotEnterHiveTicks())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name cannot_enter_hive
// @input DurationTag
// @description
// Changes the minimum duration until a Bee entity is allowed to enter a hive.
// @tags
// <EntityTag.cannot_enter_hive>
// -->
if (mechanism.matches("cannot_enter_hive") && mechanism.requireObject(DurationTag.class)) {
getBee().setCannotEnterHiveTicks(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
}
@@ -0,0 +1,110 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Entity;

public class EntityFlower implements Property {

public static boolean describes(ObjectTag entity) {
if (!(entity instanceof EntityTag)) {
return false;
}
Entity bukkitEntity = ((EntityTag) entity).getBukkitEntity();
return bukkitEntity instanceof Bee;
}

public static EntityFlower getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityFlower((EntityTag) entity);
}
}

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

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

private EntityFlower(EntityTag entity) {
this.entity = entity;
}

EntityTag entity;

public Bee getBee() {
return (Bee) entity.getBukkitEntity();
}

@Override
public String getPropertyString() {
if (getBee().getFlower() == null) {
return null;
}
return new LocationTag(getBee().getFlower()).identify();
}

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

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <EntityTag.flower>
// @returns LocationTag
// @mechanism EntityTag.flower
// @group properties
// @description
// Returns the location of a bee's flower (if any).
// -->
if (attribute.startsWith("flower")) {
if (getBee().getFlower() == null) {
return null;
}
return new LocationTag(getBee().getFlower())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name flower
// @input LocationTag
// @description
// Changes the location of a bee's flower.
// Give no input to unset the bee's flower.
// @tags
// <EntityTag.flower>
// -->
if (mechanism.matches("flower")) {
if (mechanism.hasValue() && mechanism.requireObject(LocationTag.class)) {
getBee().setFlower(mechanism.valueAsType(LocationTag.class));
}
else {
getBee().setFlower(null);
}
}
}
}
@@ -0,0 +1,98 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Entity;

public class EntityHasNectar implements Property {

public static boolean describes(ObjectTag entity) {
if (!(entity instanceof EntityTag)) {
return false;
}
Entity bukkitEntity = ((EntityTag) entity).getBukkitEntity();
return bukkitEntity instanceof Bee;
}

public static EntityHasNectar getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityHasNectar((EntityTag) entity);
}
}

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

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

private EntityHasNectar(EntityTag entity) {
this.entity = entity;
}

EntityTag entity;

public Bee getBee() {
return (Bee) entity.getBukkitEntity();
}

@Override
public String getPropertyString() {
return getBee().hasNectar() ? "true" : "false";
}

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

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <EntityTag.has_nectar>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.has_nectar
// @group properties
// @description
// Returns whether a bee entity has nectar on it.
// -->
if (attribute.startsWith("has_nectar")) {
return new ElementTag(getBee().hasNectar())
.getObjectAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name has_nectar
// @input ElementTag(Boolean)
// @description
// Changes whether a bee entity has nectar on it.
// @tags
// <EntityTag.has_nectar>
// -->
if (mechanism.matches("has_nectar") && mechanism.requireBoolean()) {
getBee().setHasNectar(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit 4f17f4e

Please sign in to comment.