1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
--- a/net/minecraft/world/item/LeadItem.java
+++ b/net/minecraft/world/item/LeadItem.java
@@ -11,64 +11,90 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
public class LeadItem extends Item {
- public LeadItem(Item.Properties item_properties) {
- super(item_properties);
+ public LeadItem(Item.Properties properties) {
+ super(properties);
}
@Override
- @Override
- public InteractionResult useOn(UseOnContext useoncontext) {
- Level level = useoncontext.getLevel();
- BlockPos blockpos = useoncontext.getClickedPos();
- BlockState blockstate = level.getBlockState(blockpos);
+ public InteractionResult useOn(UseOnContext context) {
+ Level world = context.getLevel();
+ BlockPos blockposition = context.getClickedPos();
+ IBlockData iblockdata = world.getBlockState(blockposition);
- if (blockstate.is(BlockTags.FENCES)) {
- Player player = useoncontext.getPlayer();
+ if (iblockdata.is(BlockTags.FENCES)) {
+ Player entityhuman = context.getPlayer();
- if (!level.isClientSide && player != null) {
- bindPlayerMobs(player, level, blockpos);
+ if (!world.isClientSide && entityhuman != null) {
+ bindPlayerMobs(entityhuman, world, blockposition, context.getHand()); // CraftBukkit - Pass hand
}
- return InteractionResult.sidedSuccess(level.isClientSide);
+ return InteractionResult.sidedSuccess(world.isClientSide);
} else {
return InteractionResult.PASS;
}
}
- public static InteractionResult bindPlayerMobs(Player player, Level level, BlockPos blockpos) {
- LeashFenceKnotEntity leashfenceknotentity = null;
+ public static InteractionResult bindPlayerMobs(Player entityhuman, Level world, BlockPos blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand
+ LeashFenceKnotEntity entityleash = null;
boolean flag = false;
double d0 = 7.0D;
- int i = blockpos.getX();
- int j = blockpos.getY();
- int k = blockpos.getZ();
- List<Mob> list = level.getEntitiesOfClass(Mob.class, new AABB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D));
+ int i = blockposition.getX();
+ int j = blockposition.getY();
+ int k = blockposition.getZ();
+ List<Mob> list = world.getEntitiesOfClass(Mob.class, new AABB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D));
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
- Mob mob = (Mob) iterator.next();
+ Mob entityinsentient = (Mob) iterator.next();
- if (mob.getLeashHolder() == player) {
- if (leashfenceknotentity == null) {
- leashfenceknotentity = LeashFenceKnotEntity.getOrCreateKnot(level, blockpos);
- leashfenceknotentity.playPlacementSound();
+ if (entityinsentient.getLeashHolder() == entityhuman) {
+ if (entityleash == null) {
+ entityleash = LeashFenceKnotEntity.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, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ entityleash.discard();
+ return InteractionResult.PASS;
+ }
+ // CraftBukkit end
+ entityleash.playPlacementSound();
}
- mob.setLeashedTo(leashfenceknotentity, true);
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end
+
+ entityinsentient.setLeashedTo(entityleash, true);
flag = true;
}
}
if (flag) {
- level.gameEvent(GameEvent.BLOCK_ATTACH, blockpos, GameEvent.Context.of((Entity) player));
+ world.gameEvent(GameEvent.BLOCK_ATTACH, blockposition, GameEvent.Context.of((Entity) entityhuman));
}
return flag ? InteractionResult.SUCCESS : InteractionResult.PASS;
}
+
+ // CraftBukkit start
+ public static InteractionResult bindPlayerMobs(Player player, Level level, BlockPos pos) {
+ return bindPlayerMobs(player, level, pos, net.minecraft.world.EnumHand.MAIN_HAND);
+ }
+ // CraftBukkit end
}
|