[SPIGOT-7480] Add a PlayerRemoveEntitiesOnShoulderEvent Created: 13/Sep/23  Updated: 25/Dec/24

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Kami Rori Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Version: 1.20.1-R0.1-SNAPSHOT
Guidelines Read: Yes

 Description   

When a player who has parrot on his/her shoulders jumps or gets damaged, the entities (which are always parrots, but it doesnt matter) will be removed from his/her shoulders.

That will trigger 
removeEntitiesOnShoulder() method in Spigot\Spigot-Server\src\main\java\net\minecraft\world\entity\player\EntityHuman.java.
 

//代码占位符
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
// CraftBukkit start
if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
this.setShoulderEntityLeft(new NBTTagCompound());
}
if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
this.setShoulderEntityRight(new NBTTagCompound());
}
// CraftBukkit end
}

} 

But until now there hasnt been a good way to prevent this method being triggered. So its required to create an event for it.

//代码占位符
protected void removeEntitiesOnShoulder() {
   PlayerRemoveEntitiesOnShoulderEvent event = new PlayerDropItemEvent(this, entityOnLeftShoulder, entityOnRightShoulder);
   this.level().getCraftServer().getPluginManager().callEvent(event);
   if (!event.isCancelled
&& this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
        // CraftBukkit start
        if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
            this.setShoulderEntityLeft(new NBTTagCompound());
        }
        if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
            this.setShoulderEntityRight(new NBTTagCompound());
        }
        // CraftBukkit end
    }

}

This event requires:
getPlayer() - return the HumanEntity
getEntityOnLeftShoulder() - return the entity on the left shoulder (null if nothing)
getEntityOnRightShoulder() - return the entity on the right shoulder (null if nothing)
isCancelled() - return whether canncelled
setCancelled() - set the event canncelled or not


Generated at Tue Apr 15 09:10:46 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.