mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-22 05:26:17 +00:00
90 lines
4.1 KiB
Diff
90 lines
4.1 KiB
Diff
--- a/net/minecraft/world/item/ItemLeash.java
|
|
+++ b/net/minecraft/world/item/ItemLeash.java
|
|
@@ -19,6 +19,12 @@
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
import net.minecraft.world.phys.AxisAlignedBB;
|
|
|
|
+// CraftBukkit start
|
|
+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) {
|
|
@@ -35,14 +41,14 @@
|
|
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 = leashableInArea(world, blockposition, (leashable) -> {
|
|
return leashable.getLeashHolder() == entityhuman;
|
|
@@ -50,22 +56,55 @@
|
|
|
|
Leashable leashable;
|
|
|
|
- for (Iterator iterator = list.iterator(); iterator.hasNext(); leashable.setLeashedTo(entityleash, true)) {
|
|
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop
|
|
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();
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ if (leashable instanceof Entity leashed) {
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(leashed, entityleash, entityhuman, enumhand).isCancelled()) {
|
|
+ iterator.remove();
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ leashable.setLeashedTo(entityleash, true);
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
if (!list.isEmpty()) {
|
|
world.gameEvent((Holder) 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
|
|
+
|
|
public static List<Leashable> leashableInArea(World world, BlockPosition blockposition, Predicate<Leashable> predicate) {
|
|
double d0 = 7.0D;
|
|
int i = blockposition.getX();
|