package eu.univento.lobby.utils; import eu.univento.core.api.pet.NMSHandler; import eu.univento.core.api.player.CustomPlayer; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftCreature; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import java.util.Random; /** * @author joethei * @version 1.0 */ public class Pets { public Pets(){ } void createPet(CustomPlayer p, EntityType type){ Entity entity = NMSHandler.spawn(type, p.getLocation()); assert entity != null; entity.setCustomName(p.getDatabasePlayer().getRank().getColor() + p.getDisplayName() + "'s"); entity.setCustomNameVisible(true); PetManager.getPets().put(p, entity); } public void followPlayer(Creature creature, Player player, double speed){ Location location = player.getLocation(); Random rnd = new Random(); int rand = rnd.nextInt(6); switch(rand){ case 0: location.add(1.5,0,1.5); break; case 1: location.add(0,0,1.5); break; case 2: location.add(1.5,0,0); break; case 3: location.subtract(1.5,0,1.5); break; case 4: location.subtract(0,0,1.5); break; case 5: location.subtract(1.5,0,0); break; } if(location.distanceSquared(creature.getLocation()) > 100){ if(player.isFlying()){ return; } creature.teleport(location); }else{ ((CraftCreature)creature).getHandle().getNavigation().a(location.getX(),location.getY(),location.getZ(),speed); } } }