Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in_water_duration and drowned_conversion_duration
- Loading branch information
1 parent
df829b8
commit fb10bd7
Showing
9 changed files
with
290 additions
and
3 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
82 changes: 82 additions & 0 deletions
82
...java/com/denizenscript/denizen/objects/properties/entity/EntityDrownedConversionTime.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,82 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.nms.NMSHandler; | ||
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.objects.properties.PropertyParser; | ||
import org.bukkit.entity.Zombie; | ||
|
||
public class EntityDrownedConversionTime implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Zombie; | ||
} | ||
|
||
public static EntityDrownedConversionTime getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityDrownedConversionTime((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"drowned_conversion_duration" | ||
}; | ||
|
||
private EntityDrownedConversionTime(EntityTag entity) { | ||
this.entity = entity; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return new DurationTag((long) NMSHandler.getEntityHelper().getDrownedConversionTicks((Zombie) entity.getBukkitEntity())).identify(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "drowned_conversion_duration"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.drowned_conversion_duration> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism EntityTag.drowned_conversion_duration | ||
// @group properties | ||
// @description | ||
// If the entity is a zombie mob, returns the duration of time the zombie will be converting to a Drowned for. | ||
// If this value hits 0, the Zombie will become a Drowned. | ||
// See also <@link tag EntityTag.in_water_duration> | ||
// --> | ||
PropertyParser.<EntityDrownedConversionTime, DurationTag>registerTag(DurationTag.class, "drowned_conversion_duration", (attribute, object) -> { | ||
return new DurationTag((long) NMSHandler.getEntityHelper().getDrownedConversionTicks((Zombie) object.entity.getBukkitEntity())); | ||
}); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name drowned_conversion_duration | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// If the entity is a zombie mob, sets the duration of time the zombie will be converting to a Drowned for. | ||
// If this value hits 0, the Zombie will become a Drowned. | ||
// See also <@link mechanism EntityTag.in_water_duration> | ||
// @tags | ||
// <EntityTag.in_water_duration> | ||
// --> | ||
if (mechanism.matches("drowned_conversion_duration") && mechanism.requireObject(DurationTag.class)) { | ||
NMSHandler.getEntityHelper().setDrownedConversionTicks((Zombie) entity.getBukkitEntity(), mechanism.valueAsType(DurationTag.class).getTicksAsInt()); | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityInWaterTime.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,82 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.nms.NMSHandler; | ||
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.objects.properties.PropertyParser; | ||
import org.bukkit.entity.Zombie; | ||
|
||
public class EntityInWaterTime implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Zombie; | ||
} | ||
|
||
public static EntityInWaterTime getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityInWaterTime((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"in_water_duration" | ||
}; | ||
|
||
private EntityInWaterTime(EntityTag entity) { | ||
this.entity = entity; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return new DurationTag((long) NMSHandler.getEntityHelper().getInWaterTime((Zombie) entity.getBukkitEntity())).identify(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "in_water_duration"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.in_water_duration> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism EntityTag.in_water_duration | ||
// @group properties | ||
// @description | ||
// If the entity is a zombie mob, returns the duration of time the zombie has been in water for. | ||
// If this value exceeds 600 ticks, the zombie will begin converted to a Drowned mob. | ||
// See also <@link tag EntityTag.drowned_conversion_duration> | ||
// --> | ||
PropertyParser.<EntityInWaterTime, DurationTag>registerTag(DurationTag.class, "in_water_duration", (attribute, object) -> { | ||
return new DurationTag((long) NMSHandler.getEntityHelper().getInWaterTime((Zombie) object.entity.getBukkitEntity())); | ||
}); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name in_water_duration | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// If the entity is a zombie mob, sets the duration of time the zombie has been in water for. | ||
// If this value exceeds 600 ticks, the zombie will begin converted to a Drowned mob. | ||
// See also <@link mechanism EntityTag.drowned_conversion_duration> | ||
// @tags | ||
// <EntityTag.in_water_duration> | ||
// --> | ||
if (mechanism.matches("in_water_duration") && mechanism.requireObject(DurationTag.class)) { | ||
NMSHandler.getEntityHelper().setInWaterTime((Zombie) entity.getBukkitEntity(), mechanism.valueAsType(DurationTag.class).getTicksAsInt()); | ||
} | ||
} | ||
} |
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
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