Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Entity.can_tick property, fixes #2078
- Loading branch information
1 parent
e06856a
commit 00bda1b
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
paper/src/main/java/com/denizenscript/denizen/paper/PaperModule.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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
package com.denizenscript.denizen.paper; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.paper.events.*; | ||
import com.denizenscript.denizen.paper.properties.EntityCanTick; | ||
import com.denizenscript.denizen.utilities.debugging.Debug; | ||
import com.denizenscript.denizencore.events.ScriptEvent; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
|
||
public class PaperModule { | ||
|
||
public static void init() { | ||
Debug.log("Loading Paper support module..."); | ||
// Events | ||
ScriptEvent.registerScriptEvent(new PlayerEquipsArmorScriptEvent()); | ||
ScriptEvent.registerScriptEvent(new PlayerJumpsPaperScriptEventImpl()); | ||
ScriptEvent.registerScriptEvent(new PlayerSpectatesEntityScriptEvent()); | ||
ScriptEvent.registerScriptEvent(new PlayerStopsSpectatingScriptEvent()); | ||
ScriptEvent.registerScriptEvent(new ProjectileCollideScriptEvent()); | ||
ScriptEvent.registerScriptEvent(new TNTPrimesScriptEvent()); | ||
// Properties | ||
PropertyParser.registerProperty(EntityCanTick.class, EntityTag.class); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
paper/src/main/java/com/denizenscript/denizen/paper/properties/EntityCanTick.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,91 @@ | ||
package com.denizenscript.denizen.paper.properties; | ||
|
||
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.objects.properties.PropertyParser; | ||
import org.bukkit.entity.ArmorStand; | ||
|
||
public class EntityCanTick implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag | ||
&& ((EntityTag) entity).getBukkitEntity() instanceof ArmorStand; | ||
} | ||
|
||
public static EntityCanTick getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
return new EntityCanTick((EntityTag) entity); | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"can_tick" | ||
}; | ||
|
||
|
||
/////////////////// | ||
// Instance Fields and Methods | ||
///////////// | ||
|
||
private EntityCanTick(EntityTag entity) { | ||
this.entity = entity; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
///////// | ||
// Property Methods | ||
/////// | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(((ArmorStand) entity.getBukkitEntity()).canTick()); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "can_tick"; | ||
} | ||
|
||
/////////// | ||
// ObjectTag Attributes | ||
//////// | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.can_tick> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism EntityTag.can_tick | ||
// @group properties | ||
// @Plugin Paper | ||
// @description | ||
// If the entity is an armor stand, returns whether the armor stand can tick. | ||
// --> | ||
PropertyParser.<EntityTag>registerTag("can_tick", (attribute, entity) -> { | ||
return new ElementTag(((ArmorStand) entity.getBukkitEntity()).canTick()); | ||
}); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name can_tick | ||
// @input ElementTag(Boolean) | ||
// @Plugin Paper | ||
// @description | ||
// Changes whether an armor stand can tick. | ||
// @tags | ||
// <EntityTag.can_tick> | ||
// --> | ||
if (mechanism.matches("can_tick") && mechanism.requireBoolean()) { | ||
((ArmorStand) entity.getBukkitEntity()).setCanTick(mechanism.getValue().asBoolean()); | ||
} | ||
} | ||
} |