Skip to content

Commit ea73543

Browse files
committed
Fix some issues in set_entity_pose()
* Fix exception when setting poses on Spigot * Fix being able to set poses for Mannequins on Spigot * Fix exception when Mannequins are set to now invalid poses * Add 'fixed' argument for function on Paper servers
1 parent d8fe6d8 commit ea73543

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/main/java/com/laytonsmith/abstraction/MCEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ public interface MCEntity extends MCMetadatable {
126126

127127
MCPose getPose();
128128

129-
void setPose(MCPose pose);
129+
void setPose(MCPose pose, boolean fixed);
130130

131131
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,11 @@ public MCPose getPose() {
446446
}
447447

448448
@Override
449-
public void setPose(MCPose pose) {
450-
e.setPose(BukkitMCPose.getConvertor().getConcreteEnum(pose));
449+
public void setPose(MCPose pose, boolean fixed) {
450+
try {
451+
e.setPose(BukkitMCPose.getConvertor().getConcreteEnum(pose), fixed);
452+
} catch (NoSuchMethodError ex) {
453+
// either Spigot or prior to 1.20.1
454+
}
451455
}
452456
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCMannequin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.laytonsmith.abstraction.bukkit.entities;
22

33
import com.laytonsmith.abstraction.entities.MCMannequin;
4+
import com.laytonsmith.abstraction.enums.MCPose;
5+
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPose;
46
import org.bukkit.entity.Entity;
57
import org.bukkit.entity.Mannequin;
68

@@ -27,4 +29,9 @@ public boolean isImmovable() {
2729
public void setImmovable(boolean immovable) {
2830
this.m.setImmovable(immovable);
2931
}
32+
33+
@Override
34+
public void setPose(MCPose pose, boolean fixed) {
35+
this.m.setPose(BukkitMCPose.getConvertor().getConcreteEnum(pose));
36+
}
3037
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5831,6 +5831,9 @@ public String docs() {
58315831
! Goat
58325832
| LONG_JUMPING
58335833
|-
5834+
! Mannequin
5835+
| Only FALL_FLYING, SLEEPING, SNEAKING, STANDING, SWIMMING
5836+
|-
58345837
! Player
58355838
| SPIN_ATTACK
58365839
|-
@@ -5861,12 +5864,20 @@ public String getName() {
58615864
return "set_entity_pose";
58625865
}
58635866

5867+
@Override
5868+
public Integer[] numArgs() {
5869+
return new Integer[]{2, 3};
5870+
}
5871+
58645872
@Override
58655873
public String docs() {
58665874
return """
5867-
void {entityUUID, pose} Sets an entity's pose. While you can set any pose to any entity, only
5868-
certain poses will result in a visual change for a particular entity type. Poses can affect entity
5869-
hitboxes but do not change entity state. See {{function|get_entity_pose}} for a list of poses.
5875+
void {entityUUID, pose, [fixed]} Sets an entity's pose. (only Mannequins on Spigot)
5876+
The fixed argument is a boolean for whether the pose should stay unless manually changed.
5877+
(defaults to false) While in most cases you can set any pose to any entity,
5878+
only certain poses will result in a noticable change for a particular entity type.
5879+
Poses can affect entity hitboxes but do not otherwise change entity state.
5880+
See {{function|get_entity_pose}} for a list of poses.
58705881
""";
58715882
}
58725883

@@ -5876,10 +5887,14 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
58765887
MCPose pose;
58775888
try {
58785889
pose = MCPose.valueOf(args[1].val().toUpperCase());
5890+
boolean fixed = false;
5891+
if(args.length == 3) {
5892+
fixed = ArgumentValidation.getBooleanObject(args[2], t);
5893+
}
5894+
entity.setPose(pose, fixed);
58795895
} catch(IllegalArgumentException ex) {
5880-
throw new CREFormatException("Invalid pose: " + args[1].val(), t);
5896+
throw new CREFormatException("Invalid pose for this entity: " + args[1].val(), t);
58815897
}
5882-
entity.setPose(pose);
58835898
return CVoid.VOID;
58845899
}
58855900

0 commit comments

Comments
 (0)