Skip to content

Commit efbcfb3

Browse files
authored
AntiBuild: Properly handle shear interactions (#6262)
Fixes #6257
1 parent 19f7e99 commit efbcfb3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,24 @@ public void onHangingBreak(final HangingBreakByEntityEvent event) {
262262
}
263263

264264
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
265-
public void onItemFrameInteract(final PlayerInteractEntityEvent event) {
265+
public void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
266266
if (event.getPlayer().hasMetadata("NPC")) {
267267
return;
268268
}
269269

270270
final User user = ess.getUser(event.getPlayer());
271271

272+
final ItemStack hand = event.getPlayer().getInventory().getItem(event.getHand());
273+
if (hand != null && hand.getType() == Material.SHEARS) {
274+
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !metaPermCheck(user, "interact", hand)) {
275+
if (ess.getSettings().warnOnBuildDisallow()) {
276+
user.sendTl("antiBuildUse", hand.getType().toString());
277+
}
278+
event.setCancelled(true);
279+
return;
280+
}
281+
}
282+
272283
if (!(event.getRightClicked() instanceof ItemFrame)) {
273284
return;
274285
}
@@ -295,13 +306,24 @@ public void onItemFrameInteract(final PlayerInteractEntityEvent event) {
295306
}
296307

297308
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
298-
public void onArmorStandInteract(final PlayerInteractAtEntityEvent event) {
309+
public void onPlayerInteractAtEntity(final PlayerInteractAtEntityEvent event) {
299310
if (event.getPlayer().hasMetadata("NPC")) {
300311
return;
301312
}
302313

303314
final User user = ess.getUser(event.getPlayer());
304315

316+
final ItemStack hand = event.getPlayer().getInventory().getItem(event.getHand());
317+
if (hand != null && hand.getType() == Material.SHEARS) {
318+
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !metaPermCheck(user, "interact", hand)) {
319+
if (ess.getSettings().warnOnBuildDisallow()) {
320+
user.sendTl("antiBuildUse", hand.getType().toString());
321+
}
322+
event.setCancelled(true);
323+
return;
324+
}
325+
}
326+
305327
if (!(event.getRightClicked() instanceof ArmorStand)) {
306328
return;
307329
}

0 commit comments

Comments
 (0)