69 lines
1.8 KiB
Java
69 lines
1.8 KiB
Java
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_10_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 0.1
|
|
*/
|
|
public class Pets {
|
|
|
|
public Pets(){
|
|
}
|
|
|
|
void createPet(CustomPlayer p, EntityType type){
|
|
Entity entity = NMSHandler.spawn(type, p.getLocation());
|
|
assert entity != null;
|
|
entity.setCustomName(p.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);
|
|
}
|
|
}
|
|
|
|
} |