Код:
public static Villager villager;
public static HashMap<UUID, Entity> spawned = new HashMap<>();
public int search(int min, int max) {
max -= min;
return ((int) (Math.random() * ++max)) + min;
}
FileConfiguration cfg;
public LocationsFinder (Main pl) {
cfg = pl.cfg;
}
public void createAndSpawnVillager(World world, Location location) {
villager = (Villager) world.spawnEntity(location, EntityType.VILLAGER);
villager.setAdult();
villager.setAI(false);
villager.setCanPickupItems(false);
villager.setGravity(false);
villager.setGliding(false);
villager.setCollidable(false);
villager.setCustomName(color(cfg.getString("villager.customname")));
villager.setCustomNameVisible(true);
villager.setProfession(Villager.Profession.valueOf(cfg.getString("villager.profession")));
spawned.put(villager.getUniqueId(), villager);
new BukkitRunnable() {
@Override
public void run() {
for (Player plr : Bukkit.getOnlinePlayers())
cfg.getStringList("strings.exit").forEach(msg -> plr.sendMessage(color(msg.replace("$x", String.format("%.1f", location.getX())
.replace("$y", String.format("%.1f", location.getY()))))
.replace("$z", String.format("%.1f", location.getZ()))));
rgm.removeRegion(pcr.getId());
villager.setHealth(0);
villager.remove();
spawned.remove(villager.getUniqueId(), villager);
}
}.runTaskLater(Main.getPlugin(Main.class), cfg.getInt("timers.despawn") * 20L * 60);
}