Adds some code for teleporting creatures leashed by a player

This commit is contained in:
Kristian Knarvik 2021-11-01 16:27:29 +01:00
parent 2b5d791581
commit 8bb9c464d6

View File

@ -13,7 +13,9 @@ import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList;
@ -247,4 +249,21 @@ public abstract class Teleporter {
return chunksToLoad;
}
/**
* Teleports any creatures leashed by the player
*
* @param player <p>The player which is teleported</p>
* @param origin <p>The portal the player is teleporting from</p>
*/
protected void teleportLeashedCreatures(Player player, Portal origin) {
//Find any nearby leashed entities to teleport with the player
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
for (Entity entity : nearbyEntities) {
//Teleport all creatures leashed by the player to the portal the player is to exit from
if (entity instanceof Creature creature && creature.isLeashed() && creature.getLeashHolder() == player) {
new EntityTeleporter(portal, creature).teleport(origin);
}
}
}
}