Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.iNotLazo.HCF.providers;
- import com.lenis0012.bukkit.npc.NPC;
- import com.lenis0012.bukkit.npc.NPCFactory;
- import com.lenis0012.bukkit.npc.NPCProfile;
- import lombok.Getter;
- import lombok.Setter;
- import me.activated.core.utilities.chat.CC;
- import me.iNotLazo.HCF.HCFactions;
- import me.iNotLazo.HCF.factions.type.PlayerFaction;
- import me.iNotLazo.HCF.playerdata.PlayerData;
- import me.iNotLazo.HCF.utils.LocationUtils;
- import me.iNotLazo.HCF.utils.Tasks;
- import net.frozenorb.qlib.hologram.Holograms;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.World;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import java.util.stream.Collectors;
- public class NPCProvider implements Listener {
- public NPCProvider() {
- Bukkit.getPluginManager().registerEvents(this, HCFactions.getInstance());
- start();
- }
- public final DecimalFormat df = new DecimalFormat("00.00");
- public static final Comparator<PlayerFaction> FACTIONS_KILLS = Comparator.comparingInt(PlayerFaction::getPoints);
- public static final Comparator<PlayerData> PLAYER_KILLS = Comparator.comparingInt(PlayerData::getKills);
- public static final Comparator<PlayerData> PLAYER_KDR = Comparator.comparingDouble(PlayerData::getKdr);
- public void start() {
- // TOP KILLS NPC
- FileConfiguration config = HCFactions.getInstance().getConfig();
- if (HCFactions.isNpcsSpawned()) {
- return;
- }
- if (config.getBoolean("NPCS.KILLS.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.KILLS.LOCATION"));
- List<PlayerData> data = new ArrayList<>(HCFactions.getInstance().getPlayerData().getPlayers().stream().filter(x -> x instanceof PlayerData).map(x -> (PlayerData) x).filter(x -> x.getKills() > 0).collect(Collectors.toSet()));
- Collections.sort(data, PLAYER_KILLS);
- Collections.reverse(data);
- OfflinePlayer offlinePlayer;
- if (data.isEmpty()) {
- offlinePlayer = Bukkit.getOfflinePlayer("Fckml");
- } else {
- offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
- }
- PlayerData playerData = HCFactions.getInstance().getPlayerData().getPlayer(offlinePlayer.getUniqueId());
- final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.KILLS.LINES")) {
- lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kills>", Integer.toString(playerData.getKills())));
- }
- Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
- }
- if (config.getBoolean("NPCS.KDR.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.KDR.LOCATION"));
- List<PlayerData> data = new ArrayList<>(HCFactions.getInstance().getPlayerData().getPlayers().stream().filter(x -> x instanceof PlayerData).map(x -> (PlayerData) x).filter(x -> x.getKdr() > 0).collect(Collectors.toSet()));
- Collections.sort(data, PLAYER_KDR);
- Collections.reverse(data);
- OfflinePlayer offlinePlayer;
- if (data.isEmpty()) {
- offlinePlayer = Bukkit.getOfflinePlayer("Fckml");
- } else {
- offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
- }
- PlayerData playerData = HCFactions.getInstance().getPlayerData().getPlayer(offlinePlayer.getUniqueId());
- final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.KDR.LINES")) {
- lines.add(strings.replace("<kdr>", Double.toString(playerData.getKdr())));
- }
- Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
- }
- if (config.getBoolean("NPCS.FTOP.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.FTOP.LOCATION"));
- List<PlayerFaction> data = new ArrayList<>(HCFactions.getInstance().getFactionManager().getFactions().stream().filter(x -> x instanceof PlayerFaction).map(x -> (PlayerFaction) x).filter(x -> x.getPoints() > 0).collect(Collectors.toSet()));
- Collections.sort(data, FACTIONS_KILLS);
- Collections.reverse(data);
- PlayerFaction playerFaction;
- if (data.isEmpty()) {
- playerFaction = null;
- } else {
- playerFaction = data.get(0);
- }
- final NPCProfile profile;
- if (playerFaction == null) {
- profile = NPCProfile.loadProfile("None", "PatroxWarez");
- } else {
- profile = NPCProfile.loadProfile(playerFaction.getName(), playerFaction.getLeader().getName());
- }
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.FTOP.LINES")) {
- lines.add(strings.replace("<factionName>", (playerFaction != null ? playerFaction.getName() : "None")));
- }
- Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
- }
- Tasks.runTimer(() -> {
- update();
- }, 4000, 0);
- }
- private Location deserializeLocation(String string) {
- String[] args = string.split(";");
- World world = Bukkit.getWorld(args[0]);
- double x = Double.parseDouble(args[1]);
- double y = Double.parseDouble(args[2]);
- double z = Double.parseDouble(args[3]);
- double pitch = Double.parseDouble(args[4]);
- double yaw = Double.parseDouble(args[5]);
- return new Location(world, x, y, z, (float) yaw, (float) pitch);
- }
- private void update() {
- if (true) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- factory.getNPCs().clear();
- factory.despawnAll();
- }
- FileConfiguration config = HCFactions.getInstance().getConfig();
- if (config.getBoolean("NPCS.KILLS.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.KILLS.LOCATION"));
- List<PlayerData> data = new ArrayList<>(HCFactions.getInstance().getPlayerData().getPlayers().stream().filter(x -> x instanceof PlayerData).map(x -> (PlayerData) x).filter(x -> x.getKills() > 0).collect(Collectors.toSet()));
- Collections.sort(data, PLAYER_KILLS);
- Collections.reverse(data);
- OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
- final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.KILLS.LINES")) {
- lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kills>", Integer.toString(data.get(0).getKills())));
- }
- }
- if (config.getBoolean("NPCS.KDR.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.KDR.LOCATION"));
- List<PlayerData> data = new ArrayList<>(HCFactions.getInstance().getPlayerData().getPlayers().stream().filter(x -> x instanceof PlayerData).map(x -> (PlayerData) x).filter(x -> x.getKdr() > 0).collect(Collectors.toSet()));
- Collections.sort(data, PLAYER_KDR);
- Collections.reverse(data);
- OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
- final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.KDR.LINES")) {
- lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kdr>", df.format(data.get(0).getKdr())));
- }
- }
- if (config.getBoolean("NPCS.FTOP.ENABLED")) {
- final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
- final Location location = deserializeLocation(config.getString("NPCS.FTOP.LOCATION"));
- List<PlayerFaction> data = new ArrayList<>(HCFactions.getInstance().getFactionManager().getFactions().stream().filter(x -> x instanceof PlayerFaction).map(x -> (PlayerFaction) x).filter(x -> x.getPoints() > 0).collect(Collectors.toSet()));
- Collections.sort(data, FACTIONS_KILLS);
- Collections.reverse(data);
- OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
- PlayerFaction playerFaction = HCFactions.getInstance().getFactionManager().getPlayerFaction(offlinePlayer.getUniqueId());
- final NPCProfile profile = NPCProfile.loadProfile(playerFaction.getName(), playerFaction.getLeader().getName());
- NPC npc = factory.spawnHumanNPC(location, profile);
- npc.setYaw(location.getYaw());
- npc.lookAt(location);
- List<String> lines = new ArrayList<>();
- for (String strings : config.getStringList("NPCS.FTOP.LINES")) {
- lines.add(strings.replace("<points>", String.valueOf(playerFaction.getPoints())).replace("<factionName>", playerFaction.getName()));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement