Skip to content

Commit

Permalink
add Entity.can_tick property, fixes #2078
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 25, 2019
1 parent e06856a commit 00bda1b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
@@ -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);
}
}
@@ -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());
}
}
}

0 comments on commit 00bda1b

Please sign in to comment.