Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. package fr.nathan.skybattle.utils;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.stream.Collectors;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.configuration.ConfigurationSection;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.inventory.meta.ItemMeta;
  16.  
  17. import com.google.common.collect.Lists;
  18. import com.google.common.collect.Maps;
  19.  
  20. import fr.nathan.skybattle.SkyBattle;
  21. import fr.nathan.skybattle.listener.PlayerDeathEventListener;
  22. import net.md_5.bungee.api.ChatColor;
  23.  
  24. public class SkyBattleConfig
  25. {
  26. private int minPlayer, cooldown, totemHealt, rebootafter;
  27. private List<Integer> printAt;
  28. private String fallbackServer, mapName, scoreWaitingName, scoreIGName;
  29. private Location spawn, redtotem, bluetotem, rednpc, bluenpc;
  30. private List<Location> redSpawn, blueSpawn;
  31. private List<String> scoreLinesWaiting, scoreLinesIG;
  32. private ItemStack teamItem, kitItem, lobbyItem;
  33. private Map<String, String> messages;
  34. private Player player;
  35.  
  36. public SkyBattleConfig(FileConfiguration config)
  37. {
  38. this.minPlayer = config.getInt("minplayers");
  39. this.cooldown = config.getInt("timer");
  40. this.totemHealt = config.getInt("totemhealth");
  41. this.rebootafter = config.getInt("rebootafter");
  42. this.printAt = config.getIntegerList("printat");
  43. this.fallbackServer = config.getString("fallbackserver");
  44. this.mapName = config.getString("mapname");
  45. this.spawn = this.genLocFromString(config.getString("spawn"));
  46. this.redtotem = this.genLocFromString(config.getString("redtotem"));
  47. this.bluetotem = this.genLocFromString(config.getString("bluetotem"));
  48. this.rednpc = this.genLocFromString(config.getString("rednpc"));
  49. this.bluenpc = this.genLocFromString(config.getString("bluenpc"));
  50.  
  51. this.redSpawn = Lists.newArrayList();
  52. config.getStringList("spawnteam.red").forEach(l -> this.redSpawn.add(genLocFromString(l)));
  53.  
  54. this.blueSpawn = Lists.newArrayList();
  55. config.getStringList("spawnteam.blue").forEach(l -> this.blueSpawn.add(genLocFromString(l)));
  56.  
  57. //Gestion du nom du scoreboard
  58. this.scoreWaitingName = "§6§lSkyBattle";
  59. this.scoreIGName = "§6§lSkyBattle";
  60.  
  61. //Gestion du scoreboard dans le lobby
  62. this.scoreLinesWaiting = Arrays.asList(
  63. "",
  64. "§7Début dans:" + SkyBattle.getInstance().getCooldownManager().getCooldown(),
  65. "§7Joueurs: §e" + Bukkit.getOnlinePlayers() + "§8/§e" + Bukkit.getMaxPlayers(),
  66. "§7",
  67. "§cEn attente de",
  68. "§cjoueurs...",
  69. "§8",
  70. "§7Carte: " + SkyBattle.getInstance().getSkyConfig().getMapName(),
  71. "§c",
  72. "§eplay.xzycraft.fr"
  73. ).stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList());
  74.  
  75. //Gestion du scoreboard en game
  76. this.scoreLinesIG = Arrays.asList(
  77. "",
  78. "§7Temps: " + SkyBattle.getInstance().getGameManager().getTimer(),
  79. "",
  80. "§7Morts: §c" + PlayerDeathEventListener.getDeath(player.getUniqueId()),
  81. "§7Kills: §a" + PlayerDeathEventListener.getKill(player.getUniqueId()),
  82. "§7Kit: §b" + SkyBattle.getInstance().getKitManager().getKit(player.getUniqueId()),
  83. "",
  84. "§c↪§7Coeur: §c" + SkyBattle.getInstance().getGameManager().getRedHearth().toString() + " §c♥",
  85. "§9↪§7Coueur: §9" + SkyBattle.getInstance().getGameManager().getBlueHearth().toString() + " §9♥",
  86. "§8",
  87. "§7Carte: " + SkyBattle.getInstance().getSkyConfig().getMapName(),
  88. "§c",
  89. "§eplay.xzycraft.fr"
  90. ).stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList());
  91.  
  92. this.teamItem = genItemFromSec(config.getConfigurationSection("items.team"));
  93. this.kitItem = genItemFromSec(config.getConfigurationSection("items.kit"));
  94. this.lobbyItem = genItemFromSec(config.getConfigurationSection("items.lobby"));
  95.  
  96. this.messages = Maps.newHashMap();
  97. for(String key : config.getConfigurationSection("messages").getKeys(false))
  98. messages.put(key, ChatColor.translateAlternateColorCodes('&', config.getString("messages." + key)));
  99. }
  100.  
  101. private Location genLocFromString(String str)
  102. {
  103. try
  104. {
  105. String[] data = str.split(",");
  106. return data.length == 4 ? new Location(Bukkit.getWorld(data[0]), Double.valueOf(data[1]), Double.valueOf(data[2]), Double.valueOf(data[3])) : new Location(Bukkit.getWorld(data[0]), Double.valueOf(data[1]), Double.valueOf(data[2]), Double.valueOf(data[3]), Float.valueOf(data[4]), Float.valueOf(data[5]));
  107. }
  108. catch(Exception e) { System.out.println("Can't parse " + str); }
  109. return new Location(Bukkit.getWorlds().get(0), 0, 150, 0);
  110. }
  111.  
  112. private ItemStack genItemFromSec(ConfigurationSection sec)
  113. {
  114. try
  115. {
  116. ItemStack item = new ItemStack(Material.valueOf(sec.getString("type").toUpperCase()), 1);
  117. ItemMeta meta = item.getItemMeta();
  118. meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', sec.getString("name")));
  119. meta.setLore(sec.getStringList("desc").stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList()));
  120. item.setItemMeta(meta);
  121. return item;
  122. }
  123. catch(Exception e) { System.out.println("Error while laod item : " + e.getMessage()); }
  124. return null;
  125. }
  126.  
  127. public int getMinPlayer() {
  128. return minPlayer;
  129. }
  130.  
  131. public int getCooldown() {
  132. return cooldown;
  133. }
  134.  
  135. public int getTotemHealt() {
  136. return totemHealt;
  137. }
  138.  
  139. public int getRebootAfter() {
  140. return rebootafter;
  141. }
  142.  
  143. public List<Integer> getPrintAt() {
  144. return printAt;
  145. }
  146.  
  147. public String getFallbackServer() {
  148. return fallbackServer;
  149. }
  150.  
  151. public String getMapName() {
  152. return mapName;
  153. }
  154.  
  155. public String getScoreWaitingName() {
  156. return scoreWaitingName;
  157. }
  158.  
  159. public String getScoreIGName() {
  160. return scoreIGName;
  161. }
  162.  
  163. public Location getSpawn() {
  164. return spawn;
  165. }
  166.  
  167. public Location getRedTotem() {
  168. return redtotem;
  169. }
  170.  
  171. public Location getBlueTotem() {
  172. return bluetotem;
  173. }
  174.  
  175. public Location getRedNPC() {
  176. return rednpc;
  177. }
  178.  
  179. public Location getBlueNPC() {
  180. return bluenpc;
  181. }
  182.  
  183. public List<Location> getRedSpawn() {
  184. return redSpawn;
  185. }
  186.  
  187. private int i = -1;
  188. public Location getARedSpawn()
  189. {
  190. i++;
  191. if(i >= redSpawn.size()) i = 0;
  192. return redSpawn.get(i);
  193. }
  194.  
  195. public List<Location> getBlueSpawn() {
  196. return blueSpawn;
  197. }
  198.  
  199. private int j = -1;
  200. public Location getABlueSpawn()
  201. {
  202. j++;
  203. if(j >= blueSpawn.size()) j = 0;
  204. return blueSpawn.get(j);
  205. }
  206.  
  207. public List<String> getScoreLinesWaiting() {
  208. return scoreLinesWaiting;
  209. }
  210.  
  211. public List<String> getScoreLinesIG() {
  212. return scoreLinesIG;
  213. }
  214.  
  215. public ItemStack getTeamItem() {
  216. return teamItem;
  217. }
  218.  
  219. public ItemStack getKitItem() {
  220. return kitItem;
  221. }
  222.  
  223. public ItemStack getLobbyItem() {
  224. return lobbyItem;
  225. }
  226.  
  227. public String getMessage(String key) {
  228. return messages.getOrDefault(key, "Erreur message (" + key + ')');
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement