Skip to content

Commit

Permalink
Expanded pose api.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeGBLP committed Jan 26, 2025
1 parent 8226b65 commit 78d00b1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.jakegblp.lusk.elements.minecraft.entities.entity.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import org.bukkit.entity.Entity;

@Name("Entity - has Fixed Pose")
@Description("""
Checks whether the provided entities have a fixed pose.""")
@Examples({"if target has a fixed pose:"})
@Since("1.3.3")
@RequiredPlugins("Paper 1.20.1+")
public class CondEntityHasFixedPose extends PropertyCondition<Entity> {

static {
register(CondEntityHasFixedPose.class, PropertyType.HAVE, "[a] fixed pose", "entities");
}

@Override
public boolean check(Entity value) {
return value.hasFixedPose();
}

@Override
protected String getPropertyName() {
return "a fixed pose";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,63 @@
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import it.jakegblp.lusk.api.skript.SimplerPropertyExpression;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Pose;
import org.jetbrains.annotations.NotNull;

@Name("Entity - Pose")
@Description("Returns the entity's current pose. Note that the pose is only updated at the end of a tick, so it may be inconsistent.")
import static it.jakegblp.lusk.utils.Constants.PAPER_1_20_1;

@Name("Entity - Pose/Fixed Pose")
@Description("""
Returns the provided entities' current pose.
Note that the pose is only updated at the end of a tick, so it may be inconsistent.
Can be set.
Setting the "Fixed" pose will make it stay until manually changed, this requires Paper 1.20.1+
""")
@Examples({"broadcast pose of target"})
@Since("1.0.2, 1.3 (Plural)")
public class ExprEntityPose extends SimplePropertyExpression<Entity, Pose> {
@Since("1.0.2, 1.3 (Plural), Changeable and Fixed")
public class ExprEntityPose extends SimplerPropertyExpression<Entity, Pose> {

static {
register(ExprEntityPose.class, Pose.class, "[entity] pose", "entities");
register(ExprEntityPose.class, Pose.class, (PAPER_1_20_1 ? "[:fixed] " : "") + "[entity] pose", "entities");
}

private boolean fixed;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
fixed = parseResult.hasTag("fixed");
return super.init(expressions, matchedPattern, isDelayed, parseResult);
}

@Override
public @NotNull Class<? extends Pose> getReturnType() {
return Pose.class;
}

@Override
public boolean allowSet() {
return PAPER_1_20_1;
}

@Override
public void set(Entity from, Pose to) {
from.setPose(to, fixed);
}

@Override
public Pose convert(Entity e) {
return e.getPose();
}

@Override
protected @NotNull String getPropertyName() {
return "entity pose";
return (fixed ? "fixed ": "") + "entity pose";
}
}
1 change: 1 addition & 0 deletions src/main/java/it/jakegblp/lusk/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public class Constants {
PAPER_HAS_1_19_2_EXTENDED_ENTITY_API = MINECRAFT_1_19_2 && isPaper(),
// https://github.com/PaperMC/Paper/commit/ec772bb8b8a185ffaea7db643f612211d43c9528
//PAPER_HAS_1_19_3_EXTENDED_ENTITY_API = MINECRAFT_1_19_3 && isPaper(),
PAPER_1_20_1 = MINECRAFT_1_20_1 && isPaper(),
PAPER_1_20_4 = MINECRAFT_1_20_4 && isPaper(),
PAPER_1_20_6 = MINECRAFT_1_20_6 && isPaper(),
PAPER_1_21 = MINECRAFT_1_21 && isPaper(),
Expand Down

0 comments on commit 78d00b1

Please sign in to comment.