Skip to content

Commit

Permalink
Delaying the undoing of the invulnerability
Browse files Browse the repository at this point in the history
Previously plugin would instantaneously undo the invulnerability status after teleporting, rendering it pretty useless. Now, we wait 30 ticks before unsetting it (to ensure the entity does not take unintended damage during the teleport).
  • Loading branch information
CoolLord22 committed Mar 30, 2023
1 parent b9e8d7a commit d761865
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/coollord22/otheranimalteleport/OATMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void run() {
if(plugin.toUseTickets)
fromChunk.removePluginChunkTicket(plugin);

ent.setInvulnerable(invulnerable);
undoInvulnerable(ent, invulnerable, plugin);
}
}.runTaskLater(plugin, 2);
}
Expand All @@ -60,11 +60,21 @@ public void run() {
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Teleporting entity" + ent.getType(), Verbosity.HIGH);
ent.teleport(to);

if(plugin.toUseTickets)
if(plugin.toUseTickets)
fromChunk.removePluginChunkTicket(plugin);

ent.setInvulnerable(invulnerable);
undoInvulnerable(ent, invulnerable, plugin);
}
}.runTaskLater(plugin, 2);
}

private static void undoInvulnerable(Entity ent, boolean invulnerable, OtherAnimalTeleport plugin) {
new BukkitRunnable() {
@Override
public void run() {
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Reverting invulnerability status.", Verbosity.HIGHEST);
ent.setInvulnerable(invulnerable);
}
}.runTaskLater(plugin, 30L);
}
}

0 comments on commit d761865

Please sign in to comment.