Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
EntityTag.auto_expire
property (#2340)
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 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
88 changes: 88 additions & 0 deletions
88
paper/src/main/java/com/denizenscript/denizen/paper/properties/EntityAutoExpire.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,88 @@ | ||
package com.denizenscript.denizen.paper.properties; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import org.bukkit.entity.FallingBlock; | ||
|
||
public class EntityAutoExpire implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag | ||
&& ((EntityTag) entity).getBukkitEntity() instanceof FallingBlock; | ||
} | ||
|
||
public static EntityAutoExpire getFrom(ObjectTag _entity) { | ||
if (!describes(_entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityAutoExpire((EntityTag) _entity); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"auto_expire" | ||
}; | ||
|
||
private EntityAutoExpire(EntityTag _entity) { | ||
entity = _entity; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.auto_expire> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism EntityTag.auto_expire | ||
// @group properties | ||
// @Plugin Paper | ||
// @description | ||
// Returns whether a falling_block will auto-expire (after 30 seconds, or 5 when outside the world). | ||
PropertyParser.<EntityAutoExpire, ElementTag>registerTag(ElementTag.class, "auto_expire", (attribute, object) -> { | ||
return new ElementTag(object.doesAutoExpire()); | ||
}); | ||
} | ||
|
||
public FallingBlock getFallingBlock() { | ||
return (FallingBlock) entity.getBukkitEntity(); | ||
} | ||
|
||
public boolean doesAutoExpire() { | ||
return getFallingBlock().doesAutoExpire(); | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return doesAutoExpire() ? null : "false"; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "auto_expire"; | ||
} | ||
|
||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name auto_expire | ||
// @input ElementTag(Boolean) | ||
// @Plugin Paper | ||
// @description | ||
// Sets whether a falling_block will auto-expire (after 30 seconds, or 5 when outside the world). | ||
// @tags | ||
// <EntityTag.auto_expire> | ||
// --> | ||
if (mechanism.matches("auto_expire") && mechanism.requireBoolean()) { | ||
getFallingBlock().shouldAutoExpire(mechanism.getValue().asBoolean()); | ||
} | ||
} | ||
} |