Skip to content

Commit

Permalink
Workaround Spigot bug that requires manually un-leashing entities bef…
Browse files Browse the repository at this point in the history
…ore re-leashing
  • Loading branch information
me4502 committed Sep 28, 2021
1 parent 265830a commit e5d91d3
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -51,7 +51,7 @@ public class BetterLeads extends AbstractCraftBookMechanic {

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerClick(final PlayerInteractEntityEvent event) {
if (!(event.getRightClicked() instanceof LivingEntity) || !EventUtil.passesFilter(event)) {
if (!(event.getRightClicked() instanceof LivingEntity entity) || entity.isLeashed() || !EventUtil.passesFilter(event)) {
return;
}

Expand All @@ -70,8 +70,8 @@ public void onPlayerClick(final PlayerInteractEntityEvent event) {
CraftBookPlugin.logDebugMessage("It is of type: " + typeName, "betterleads.allowed-mobs");

if (!allowedMobs.contains(typeName)
|| !typeName.startsWith("minecraft:")
|| !allowedMobs.contains(typeName.substring("minecraft:".length()))) {
&& (!typeName.startsWith("minecraft:")
|| !allowedMobs.contains(typeName.substring("minecraft:".length())))) {
return;
}

Expand All @@ -85,14 +85,14 @@ public void onPlayerClick(final PlayerInteractEntityEvent event) {
}

CraftBookPlugin.logDebugMessage("Leashing entity!", "betterleads.allowed-mobs");
if (event.getRightClicked() instanceof Creature && ((Creature) event.getRightClicked()).getTarget() != null && ((Creature) event.getRightClicked()).getTarget().equals(event.getPlayer())) {
((Creature) event.getRightClicked()).setTarget(null); //Rescan for a new target.
if (event.getRightClicked() instanceof Creature creature && creature.getTarget() != null && creature.getTarget().equals(event.getPlayer())) {
creature.setTarget(null); //Rescan for a new target.
}

event.setCancelled(true);

Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), () -> {
if (!((LivingEntity) event.getRightClicked()).setLeashHolder(event.getPlayer())) {
if (!entity.setLeashHolder(event.getPlayer())) {
CraftBookPlugin.logDebugMessage("Failed to leash entity!", "betterleads.allowed-mobs");
return;
}
Expand Down

0 comments on commit e5d91d3

Please sign in to comment.