mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2025-07-17 00:05:49 +00:00
87 lines
4.0 KiB
Diff
87 lines
4.0 KiB
Diff
--- a/net/minecraft/world/item/ItemLeash.java
|
|
+++ b/net/minecraft/world/item/ItemLeash.java
|
|
@@ -14,6 +14,13 @@
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
import net.minecraft.world.phys.Vec3D;
|
|
|
|
+// CraftBukkit start
|
|
+import java.util.Iterator;
|
|
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
+import org.bukkit.event.hanging.HangingPlaceEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class ItemLeash extends Item {
|
|
|
|
public ItemLeash(Item.Info item_info) {
|
|
@@ -30,27 +37,47 @@
|
|
EntityHuman entityhuman = itemactioncontext.getPlayer();
|
|
|
|
if (!world.isClientSide && entityhuman != null) {
|
|
- return bindPlayerMobs(entityhuman, world, blockposition);
|
|
+ return bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand
|
|
}
|
|
}
|
|
|
|
return EnumInteractionResult.PASS;
|
|
}
|
|
|
|
- public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
|
|
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand
|
|
EntityLeash entityleash = null;
|
|
List<Leashable> list = Leashable.leashableInArea(world, Vec3D.atCenterOf(blockposition), (leashable) -> {
|
|
return leashable.getLeashHolder() == entityhuman;
|
|
});
|
|
boolean flag = false;
|
|
|
|
- for (Leashable leashable : list) {
|
|
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop
|
|
+ Leashable leashable = (Leashable) iterator.next();
|
|
if (entityleash == null) {
|
|
entityleash = EntityLeash.getOrCreateKnot(world, blockposition);
|
|
+
|
|
+ // CraftBukkit start - fire HangingPlaceEvent
|
|
+ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand);
|
|
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, CraftBlock.at(world, blockposition), org.bukkit.block.BlockFace.SELF, hand);
|
|
+ world.getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause
|
|
+ return EnumInteractionResult.PASS;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
entityleash.playPlacementSound();
|
|
}
|
|
|
|
if (leashable.canHaveALeashAttachedTo(entityleash)) {
|
|
+ // CraftBukkit start
|
|
+ if (leashable instanceof Entity leashed) {
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(leashed, entityleash, entityhuman, enumhand).isCancelled()) {
|
|
+ iterator.remove();
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
leashable.setLeashedTo(entityleash, true);
|
|
flag = true;
|
|
}
|
|
@@ -60,7 +87,18 @@
|
|
world.gameEvent(GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman));
|
|
return EnumInteractionResult.SUCCESS_SERVER;
|
|
} else {
|
|
+ // CraftBukkit start- remove leash if we do not leash any entity because of the cancelled event
|
|
+ if (entityleash != null) {
|
|
+ entityleash.discard(null);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
return EnumInteractionResult.PASS;
|
|
}
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
|
|
+ return bindPlayerMobs(entityhuman, world, blockposition, net.minecraft.world.EnumHand.MAIN_HAND);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|