Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EntityTag.is_sneaking
Paper-only property (#2508)
* Add `EntityTag.sneaking` property * Meta improvements * Deprecate `PlayerTag.is_sneaking` * `ItemTag.trim` minor meta fix * `PlayerTag.is_sneaking` deprecation fix * Cleanup `MaterialAttachmentFace` * Revert `PlayerTag.is_sneaking` deprecation * Register existing tags when the prop isn't present * Rename to `is_sneaking` * Update another place * Bump Paper API, add Citizens dependency * Properly make NPCs sneak * Remove trait when standing up
- Loading branch information
Showing
10 changed files
with
109 additions
and
32 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
63 changes: 63 additions & 0 deletions
63
paper/src/main/java/com/denizenscript/denizen/paper/properties/EntitySneaking.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,63 @@ | ||
package com.denizenscript.denizen.paper.properties; | ||
|
||
import com.denizenscript.denizen.npc.traits.SneakingTrait; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.properties.entity.EntityProperty; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import net.citizensnpcs.api.npc.NPC; | ||
|
||
public class EntitySneaking extends EntityProperty<ElementTag> { | ||
|
||
// <--[property] | ||
// @object EntityTag | ||
// @name is_sneaking | ||
// @input ElementTag(Boolean) | ||
// @plugin Paper | ||
// @description | ||
// Whether an entity is sneaking. | ||
// For most entities this just makes the name tag less visible, and doesn't actually update the pose. | ||
// Note that <@link command sneak> is also available. | ||
// --> | ||
|
||
public static boolean describes(EntityTag entity) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ElementTag getPropertyValue() { | ||
return new ElementTag(getEntity().isSneaking()); | ||
} | ||
|
||
@Override | ||
public boolean isDefaultValue(ElementTag value) { | ||
return !value.asBoolean(); | ||
} | ||
|
||
@Override | ||
public void setPropertyValue(ElementTag value, Mechanism mechanism) { | ||
if (mechanism.requireBoolean()) { | ||
boolean sneaking = value.asBoolean(); | ||
getEntity().setSneaking(sneaking); | ||
if (object.isCitizensNPC()) { | ||
NPC npc = object.getDenizenNPC().getCitizen(); | ||
if (sneaking) { | ||
npc.getOrAddTrait(SneakingTrait.class).sneak(); | ||
} | ||
else if (npc.hasTrait(SneakingTrait.class)) { | ||
npc.getTraitNullable(SneakingTrait.class).stand(); | ||
npc.removeTrait(SneakingTrait.class); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "is_sneaking"; | ||
} | ||
|
||
public static void register() { | ||
autoRegister("is_sneaking", EntitySneaking.class, ElementTag.class, false); | ||
} | ||
} |
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
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