Lobby/src/main/java/eu/univento/lobby/utils/PetManager.java

57 lines
1.2 KiB
Java

package eu.univento.lobby.utils;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import java.util.HashMap;
/**
* @author joethei
* @version 0.1
*/
public class PetManager {
private static HashMap<CustomPlayer, Entity> pets = new HashMap<>();
public static HashMap<CustomPlayer, Entity> getPets() {
return pets;
}
public static boolean hasPet(CustomPlayer p) {
return pets.containsKey(p);
}
public static Entity getPet(CustomPlayer p) {
return pets.get(p);
}
public static void removePet(CustomPlayer p) {
pets.get(p).remove();
}
public static void setPet(CustomPlayer p, EntityType e) {
if(hasPet(p)) {
removePet(p);
}
new Pets().createPet(p, e);
}
public static void setName(CustomPlayer p, String name) {
if(hasPet(p)) {
getPet(p).setCustomName(name);
}
}
public static String getName(CustomPlayer p) {
if(hasPet(p)) {
return getPet(p).getCustomName();
}else {
return null;
}
}
public static void clearPets() {
pets.values().forEach(Entity::remove);
}
}