Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.nathan.skybattle.utils;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import fr.nathan.skybattle.SkyBattle;
- import fr.nathan.skybattle.listener.PlayerDeathEventListener;
- import net.md_5.bungee.api.ChatColor;
- public class SkyBattleConfig
- {
- private int minPlayer, cooldown, totemHealt, rebootafter;
- private List<Integer> printAt;
- private String fallbackServer, mapName, scoreWaitingName, scoreIGName;
- private Location spawn, redtotem, bluetotem, rednpc, bluenpc;
- private List<Location> redSpawn, blueSpawn;
- private List<String> scoreLinesWaiting, scoreLinesIG;
- private ItemStack teamItem, kitItem, lobbyItem;
- private Map<String, String> messages;
- private Player player;
- public SkyBattleConfig(FileConfiguration config)
- {
- this.minPlayer = config.getInt("minplayers");
- this.cooldown = config.getInt("timer");
- this.totemHealt = config.getInt("totemhealth");
- this.rebootafter = config.getInt("rebootafter");
- this.printAt = config.getIntegerList("printat");
- this.fallbackServer = config.getString("fallbackserver");
- this.mapName = config.getString("mapname");
- this.spawn = this.genLocFromString(config.getString("spawn"));
- this.redtotem = this.genLocFromString(config.getString("redtotem"));
- this.bluetotem = this.genLocFromString(config.getString("bluetotem"));
- this.rednpc = this.genLocFromString(config.getString("rednpc"));
- this.bluenpc = this.genLocFromString(config.getString("bluenpc"));
- this.redSpawn = Lists.newArrayList();
- config.getStringList("spawnteam.red").forEach(l -> this.redSpawn.add(genLocFromString(l)));
- this.blueSpawn = Lists.newArrayList();
- config.getStringList("spawnteam.blue").forEach(l -> this.blueSpawn.add(genLocFromString(l)));
- //Gestion du nom du scoreboard
- this.scoreWaitingName = "§6§lSkyBattle";
- this.scoreIGName = "§6§lSkyBattle";
- //Gestion du scoreboard dans le lobby
- this.scoreLinesWaiting = Arrays.asList(
- "",
- "§7Début dans:" + SkyBattle.getInstance().getCooldownManager().getCooldown(),
- "§7Joueurs: §e" + Bukkit.getOnlinePlayers() + "§8/§e" + Bukkit.getMaxPlayers(),
- "§7",
- "§cEn attente de",
- "§cjoueurs...",
- "§8",
- "§7Carte: " + SkyBattle.getInstance().getSkyConfig().getMapName(),
- "§c",
- "§eplay.xzycraft.fr"
- ).stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList());
- //Gestion du scoreboard en game
- this.scoreLinesIG = Arrays.asList(
- "",
- "§7Temps: " + SkyBattle.getInstance().getGameManager().getTimer(),
- "",
- "§7Morts: §c" + PlayerDeathEventListener.getDeath(player.getUniqueId()),
- "§7Kills: §a" + PlayerDeathEventListener.getKill(player.getUniqueId()),
- "§7Kit: §b" + SkyBattle.getInstance().getKitManager().getKit(player.getUniqueId()),
- "",
- "§c↪§7Coeur: §c" + SkyBattle.getInstance().getGameManager().getRedHearth().toString() + " §c♥",
- "§9↪§7Coueur: §9" + SkyBattle.getInstance().getGameManager().getBlueHearth().toString() + " §9♥",
- "§8",
- "§7Carte: " + SkyBattle.getInstance().getSkyConfig().getMapName(),
- "§c",
- "§eplay.xzycraft.fr"
- ).stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList());
- this.teamItem = genItemFromSec(config.getConfigurationSection("items.team"));
- this.kitItem = genItemFromSec(config.getConfigurationSection("items.kit"));
- this.lobbyItem = genItemFromSec(config.getConfigurationSection("items.lobby"));
- this.messages = Maps.newHashMap();
- for(String key : config.getConfigurationSection("messages").getKeys(false))
- messages.put(key, ChatColor.translateAlternateColorCodes('&', config.getString("messages." + key)));
- }
- private Location genLocFromString(String str)
- {
- try
- {
- String[] data = str.split(",");
- 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]));
- }
- catch(Exception e) { System.out.println("Can't parse " + str); }
- return new Location(Bukkit.getWorlds().get(0), 0, 150, 0);
- }
- private ItemStack genItemFromSec(ConfigurationSection sec)
- {
- try
- {
- ItemStack item = new ItemStack(Material.valueOf(sec.getString("type").toUpperCase()), 1);
- ItemMeta meta = item.getItemMeta();
- meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', sec.getString("name")));
- meta.setLore(sec.getStringList("desc").stream().map(l -> ChatColor.translateAlternateColorCodes('&', l)).collect(Collectors.toList()));
- item.setItemMeta(meta);
- return item;
- }
- catch(Exception e) { System.out.println("Error while laod item : " + e.getMessage()); }
- return null;
- }
- public int getMinPlayer() {
- return minPlayer;
- }
- public int getCooldown() {
- return cooldown;
- }
- public int getTotemHealt() {
- return totemHealt;
- }
- public int getRebootAfter() {
- return rebootafter;
- }
- public List<Integer> getPrintAt() {
- return printAt;
- }
- public String getFallbackServer() {
- return fallbackServer;
- }
- public String getMapName() {
- return mapName;
- }
- public String getScoreWaitingName() {
- return scoreWaitingName;
- }
- public String getScoreIGName() {
- return scoreIGName;
- }
- public Location getSpawn() {
- return spawn;
- }
- public Location getRedTotem() {
- return redtotem;
- }
- public Location getBlueTotem() {
- return bluetotem;
- }
- public Location getRedNPC() {
- return rednpc;
- }
- public Location getBlueNPC() {
- return bluenpc;
- }
- public List<Location> getRedSpawn() {
- return redSpawn;
- }
- private int i = -1;
- public Location getARedSpawn()
- {
- i++;
- if(i >= redSpawn.size()) i = 0;
- return redSpawn.get(i);
- }
- public List<Location> getBlueSpawn() {
- return blueSpawn;
- }
- private int j = -1;
- public Location getABlueSpawn()
- {
- j++;
- if(j >= blueSpawn.size()) j = 0;
- return blueSpawn.get(j);
- }
- public List<String> getScoreLinesWaiting() {
- return scoreLinesWaiting;
- }
- public List<String> getScoreLinesIG() {
- return scoreLinesIG;
- }
- public ItemStack getTeamItem() {
- return teamItem;
- }
- public ItemStack getKitItem() {
- return kitItem;
- }
- public ItemStack getLobbyItem() {
- return lobbyItem;
- }
- public String getMessage(String key) {
- return messages.getOrDefault(key, "Erreur message (" + key + ')');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement