Advertisement
iNotLazo

Untitled

Sep 3rd, 2020
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 KB | None | 0 0
  1. package me.iNotLazo.HCF.providers;
  2.  
  3. import com.lenis0012.bukkit.npc.NPC;
  4. import com.lenis0012.bukkit.npc.NPCFactory;
  5. import com.lenis0012.bukkit.npc.NPCProfile;
  6. import lombok.Getter;
  7. import lombok.Setter;
  8. import me.activated.core.utilities.chat.CC;
  9. import me.iNotLazo.HCF.HCFactions;
  10. import me.iNotLazo.HCF.factions.type.PlayerFaction;
  11. import me.iNotLazo.HCF.playerdata.PlayerData;
  12. import me.iNotLazo.HCF.utils.LocationUtils;
  13. import me.iNotLazo.HCF.utils.Tasks;
  14. import net.frozenorb.qlib.hologram.Holograms;
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.Location;
  17. import org.bukkit.OfflinePlayer;
  18. import org.bukkit.World;
  19. import org.bukkit.configuration.file.FileConfiguration;
  20. import org.bukkit.entity.Player;
  21. import org.bukkit.event.EventHandler;
  22. import org.bukkit.event.Listener;
  23. import org.bukkit.event.player.PlayerJoinEvent;
  24.  
  25. import java.text.DecimalFormat;
  26. import java.util.ArrayList;
  27. import java.util.Collections;
  28. import java.util.Comparator;
  29. import java.util.List;
  30. import java.util.concurrent.TimeUnit;
  31. import java.util.stream.Collectors;
  32.  
  33. public class NPCProvider implements Listener {
  34.  
  35. public NPCProvider() {
  36. Bukkit.getPluginManager().registerEvents(this, HCFactions.getInstance());
  37.  
  38. start();
  39. }
  40.  
  41. public final DecimalFormat df = new DecimalFormat("00.00");
  42. public static final Comparator<PlayerFaction> FACTIONS_KILLS = Comparator.comparingInt(PlayerFaction::getPoints);
  43. public static final Comparator<PlayerData> PLAYER_KILLS = Comparator.comparingInt(PlayerData::getKills);
  44. public static final Comparator<PlayerData> PLAYER_KDR = Comparator.comparingDouble(PlayerData::getKdr);
  45.  
  46. public void start() {
  47. // TOP KILLS NPC
  48. FileConfiguration config = HCFactions.getInstance().getConfig();
  49.  
  50. if (HCFactions.isNpcsSpawned()) {
  51. return;
  52. }
  53.  
  54. if (config.getBoolean("NPCS.KILLS.ENABLED")) {
  55. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  56. final Location location = deserializeLocation(config.getString("NPCS.KILLS.LOCATION"));
  57. 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()));
  58. Collections.sort(data, PLAYER_KILLS);
  59. Collections.reverse(data);
  60.  
  61. OfflinePlayer offlinePlayer;
  62.  
  63. if (data.isEmpty()) {
  64. offlinePlayer = Bukkit.getOfflinePlayer("Fckml");
  65. } else {
  66. offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
  67. }
  68.  
  69. PlayerData playerData = HCFactions.getInstance().getPlayerData().getPlayer(offlinePlayer.getUniqueId());
  70. final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
  71. NPC npc = factory.spawnHumanNPC(location, profile);
  72. npc.setYaw(location.getYaw());
  73. npc.lookAt(location);
  74.  
  75. List<String> lines = new ArrayList<>();
  76.  
  77. for (String strings : config.getStringList("NPCS.KILLS.LINES")) {
  78. lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kills>", Integer.toString(playerData.getKills())));
  79. }
  80. Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
  81. }
  82.  
  83. if (config.getBoolean("NPCS.KDR.ENABLED")) {
  84. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  85. final Location location = deserializeLocation(config.getString("NPCS.KDR.LOCATION"));
  86. 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()));
  87. Collections.sort(data, PLAYER_KDR);
  88. Collections.reverse(data);
  89.  
  90. OfflinePlayer offlinePlayer;
  91.  
  92. if (data.isEmpty()) {
  93. offlinePlayer = Bukkit.getOfflinePlayer("Fckml");
  94. } else {
  95. offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
  96. }
  97. PlayerData playerData = HCFactions.getInstance().getPlayerData().getPlayer(offlinePlayer.getUniqueId());
  98. final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
  99. NPC npc = factory.spawnHumanNPC(location, profile);
  100. npc.setYaw(location.getYaw());
  101. npc.lookAt(location);
  102.  
  103. List<String> lines = new ArrayList<>();
  104.  
  105. for (String strings : config.getStringList("NPCS.KDR.LINES")) {
  106. lines.add(strings.replace("<kdr>", Double.toString(playerData.getKdr())));
  107. }
  108. Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
  109. }
  110.  
  111. if (config.getBoolean("NPCS.FTOP.ENABLED")) {
  112. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  113. final Location location = deserializeLocation(config.getString("NPCS.FTOP.LOCATION"));
  114. 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()));
  115. Collections.sort(data, FACTIONS_KILLS);
  116. Collections.reverse(data);
  117.  
  118. PlayerFaction playerFaction;
  119.  
  120. if (data.isEmpty()) {
  121. playerFaction = null;
  122. } else {
  123. playerFaction = data.get(0);
  124. }
  125.  
  126. final NPCProfile profile;
  127.  
  128. if (playerFaction == null) {
  129. profile = NPCProfile.loadProfile("None", "PatroxWarez");
  130. } else {
  131. profile = NPCProfile.loadProfile(playerFaction.getName(), playerFaction.getLeader().getName());
  132. }
  133. NPC npc = factory.spawnHumanNPC(location, profile);
  134. npc.setYaw(location.getYaw());
  135. npc.lookAt(location);
  136.  
  137. List<String> lines = new ArrayList<>();
  138.  
  139. for (String strings : config.getStringList("NPCS.FTOP.LINES")) {
  140. lines.add(strings.replace("<factionName>", (playerFaction != null ? playerFaction.getName() : "None")));
  141. }
  142. Holograms.newHologram().at(location.add(0, 2, 0)).addLines(lines).at(location).updates().interval(300, TimeUnit.SECONDS).build().send();
  143. }
  144.  
  145. Tasks.runTimer(() -> {
  146. update();
  147. }, 4000, 0);
  148. }
  149.  
  150. private Location deserializeLocation(String string) {
  151. String[] args = string.split(";");
  152.  
  153. World world = Bukkit.getWorld(args[0]);
  154. double x = Double.parseDouble(args[1]);
  155. double y = Double.parseDouble(args[2]);
  156. double z = Double.parseDouble(args[3]);
  157. double pitch = Double.parseDouble(args[4]);
  158. double yaw = Double.parseDouble(args[5]);
  159.  
  160. return new Location(world, x, y, z, (float) yaw, (float) pitch);
  161. }
  162.  
  163. private void update() {
  164. if (true) {
  165. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  166.  
  167. factory.getNPCs().clear();
  168.  
  169. factory.despawnAll();
  170. }
  171.  
  172. FileConfiguration config = HCFactions.getInstance().getConfig();
  173.  
  174. if (config.getBoolean("NPCS.KILLS.ENABLED")) {
  175. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  176. final Location location = deserializeLocation(config.getString("NPCS.KILLS.LOCATION"));
  177. 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()));
  178. Collections.sort(data, PLAYER_KILLS);
  179. Collections.reverse(data);
  180.  
  181. OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
  182. final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
  183. NPC npc = factory.spawnHumanNPC(location, profile);
  184. npc.setYaw(location.getYaw());
  185. npc.lookAt(location);
  186.  
  187. List<String> lines = new ArrayList<>();
  188.  
  189. for (String strings : config.getStringList("NPCS.KILLS.LINES")) {
  190. lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kills>", Integer.toString(data.get(0).getKills())));
  191. }
  192. }
  193.  
  194. if (config.getBoolean("NPCS.KDR.ENABLED")) {
  195. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  196. final Location location = deserializeLocation(config.getString("NPCS.KDR.LOCATION"));
  197. 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()));
  198. Collections.sort(data, PLAYER_KDR);
  199. Collections.reverse(data);
  200.  
  201. OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
  202. final NPCProfile profile = NPCProfile.loadProfile(offlinePlayer.getName(), offlinePlayer.getName());
  203. NPC npc = factory.spawnHumanNPC(location, profile);
  204. npc.setYaw(location.getYaw());
  205. npc.lookAt(location);
  206.  
  207. List<String> lines = new ArrayList<>();
  208.  
  209. for (String strings : config.getStringList("NPCS.KDR.LINES")) {
  210. lines.add(strings.replace("<player>", offlinePlayer.getName()).replace("<kdr>", df.format(data.get(0).getKdr())));
  211. }
  212. }
  213.  
  214. if (config.getBoolean("NPCS.FTOP.ENABLED")) {
  215. final NPCFactory factory = new NPCFactory(HCFactions.getInstance());
  216. final Location location = deserializeLocation(config.getString("NPCS.FTOP.LOCATION"));
  217. 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()));
  218. Collections.sort(data, FACTIONS_KILLS);
  219. Collections.reverse(data);
  220.  
  221. OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(data.get(0).getName());
  222. PlayerFaction playerFaction = HCFactions.getInstance().getFactionManager().getPlayerFaction(offlinePlayer.getUniqueId());
  223. final NPCProfile profile = NPCProfile.loadProfile(playerFaction.getName(), playerFaction.getLeader().getName());
  224. NPC npc = factory.spawnHumanNPC(location, profile);
  225. npc.setYaw(location.getYaw());
  226. npc.lookAt(location);
  227.  
  228. List<String> lines = new ArrayList<>();
  229.  
  230. for (String strings : config.getStringList("NPCS.FTOP.LINES")) {
  231. lines.add(strings.replace("<points>", String.valueOf(playerFaction.getPoints())).replace("<factionName>", playerFaction.getName()));
  232. }
  233. }
  234. }
  235.  
  236. }
  237.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement