Search in sources :

Example 1 with StatSign

use of com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign in project buildinggame by stefvanschie.

the class SignManager method setup.

/**
 * Loads/Reloads all signs
 *
 * @since 2.1.0
 */
public void setup() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration signs = SettingsManager.getInstance().getSigns();
    for (Arena arena : ArenaManager.getInstance().getArenas()) {
        arena.clearSigns();
    }
    randomJoinSigns.clear();
    leaveSigns.clear();
    statSigns.clear();
    spectateSigns.clear();
    for (var string : signs.getKeys(false)) {
        int x = signs.getInt(string + ".x");
        int y = signs.getInt(string + ".y");
        int z = signs.getInt(string + ".z");
        var blockPos = new PotentialBlockPosition(() -> Bukkit.getWorld(signs.getString(string + ".world")), x, y, z);
        ChunkCoordinates chunkCoordinates = blockPos.getChunkCoordinates();
        if (!signs.contains(string + ".type"))
            signs.set(string + ".type", "join");
        switch(signs.getString(string + ".type")) {
            case "join":
                var arena = ArenaManager.getInstance().getArena(signs.getString(string + ".arena"));
                if (arena == null) {
                    randomJoinSigns.putIfAbsent(chunkCoordinates, new HashSet<>());
                    randomJoinSigns.get(chunkCoordinates).add(blockPos);
                    continue;
                }
                arena.addSign(blockPos);
                if (config.getBoolean("debug"))
                    Main.getInstance().getLogger().info("Found join sign for arena " + arena.getName());
                break;
            case "leave":
                leaveSigns.putIfAbsent(chunkCoordinates, new HashSet<>());
                leaveSigns.get(chunkCoordinates).add(blockPos);
                if (config.getBoolean("debug"))
                    Main.getInstance().getLogger().info("Found leave sign");
                break;
            case "stat":
                statSigns.add(new StatSign(blockPos, StatType.valueOf(signs.getString(string + ".stat")), Integer.parseInt(signs.getString(string + ".number"))));
                if (config.getBoolean("debug"))
                    Main.getInstance().getLogger().info("Found stat sign");
                break;
            case "spectate":
                UUID uuid = UUID.fromString(signs.getString(string + ".player"));
                spectateSigns.putIfAbsent(chunkCoordinates, new HashSet<>());
                spectateSigns.get(chunkCoordinates).add(new SpectateSign(blockPos, Bukkit.getOfflinePlayer(uuid)));
                if (config.getBoolean("debug"))
                    Main.getInstance().getLogger().info("Found spectate sign");
                break;
        }
    }
    if (config.getBoolean("signs.glass-colors-enabled")) {
        config.getConfigurationSection("signs.glass-colors").getKeys(false).forEach(key -> {
            try {
                if (config.isInt("signs.glass-colors." + key))
                    gameStatesColor.put(GameState.valueOf(key.toUpperCase(Locale.getDefault())), DyeColor.values()[config.getInt("signs.glass-colors." + key)]);
                else
                    gameStatesColor.put(GameState.valueOf(key.toUpperCase(Locale.getDefault())), DyeColor.valueOf(config.getString("signs.glass-colors." + key)));
            } catch (IllegalArgumentException e) {
                // catch IllegalArgumentException for the easy of your clients.
                Main.getInstance().getLogger().warning("Wrong parameter in config at: sign.glass-colors." + key + '.');
            }
        });
    }
    updateSigns();
    SettingsManager.getInstance().save();
}
Also used : SpectateSign(com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) StatSign(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign) ChunkCoordinates(com.gmail.stefvanschiedev.buildinggame.utils.ChunkCoordinates) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 2 with StatSign

use of com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign in project buildinggame by stefvanschie.

the class StatSignUpdater method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    Map<StatSign, String[]> signTexts = new HashMap<>();
    SignManager.getInstance().getStatSigns().forEach(sign -> {
        String[] lines = new String[4];
        if (sign.getType().isEnabled(config)) {
            var stats = StatManager.getInstance().getStats(sign.getType());
            if (stats == null)
                return;
            OfflinePlayer offlinePlayer = null;
            int value = -1;
            if (stats.size() > sign.getNumber() - 1) {
                Stat stat = stats.get(sign.getNumber() - 1);
                offlinePlayer = stat.getPlayer();
                value = stat.getValue();
            }
            for (int i = 0; i < 4; i++) lines[i] = replace(MessageManager.translate(messages.getString("signs.stat." + sign.getType().toString().toLowerCase(Locale.getDefault()).replace("_", "-") + ".line-" + (i + 1))), sign, offlinePlayer, value);
        } else {
            lines[0] = "";
            lines[1] = ChatColor.RED + "Stat type";
            lines[2] = ChatColor.RED + "is disabled";
            lines[3] = "";
        }
        signTexts.put(sign, lines);
    });
    if (!Main.getInstance().isEnabled())
        return;
    new BukkitRunnable() {

        @Override
        public void run() {
            signTexts.forEach((statSign, lines) -> {
                PotentialBlockPosition blockPos = statSign.getBlockPosition();
                Block block = blockPos.getBlock();
                if (block == null || !(block.getState() instanceof Sign)) {
                    return;
                }
                Sign sign = (Sign) block.getState();
                var length = lines.length;
                for (var i = 0; i < length; i++) sign.setLine(i, lines[i]);
                sign.update();
            });
        }
    }.runTask(Main.getInstance());
}
Also used : Sign(org.bukkit.block.Sign) java.util(java.util) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BiFunction(java.util.function.BiFunction) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Stat(com.gmail.stefvanschiedev.buildinggame.utils.stats.Stat) OfflinePlayer(org.bukkit.OfflinePlayer) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Block(org.bukkit.block.Block) Main(com.gmail.stefvanschiedev.buildinggame.Main) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) SignManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) ChatColor(org.bukkit.ChatColor) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) NotNull(org.jetbrains.annotations.NotNull) StatSign(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Stat(com.gmail.stefvanschiedev.buildinggame.utils.stats.Stat) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) StatSign(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign) OfflinePlayer(org.bukkit.OfflinePlayer) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) StatSign(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign)

Aggregations

PotentialBlockPosition (com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition)2 StatSign (com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign)2 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)2 Main (com.gmail.stefvanschiedev.buildinggame.Main)1 SignManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager)1 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)1 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)1 StatManager (com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)1 ChunkCoordinates (com.gmail.stefvanschiedev.buildinggame.utils.ChunkCoordinates)1 SpectateSign (com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign)1 Arena (com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)1 Stat (com.gmail.stefvanschiedev.buildinggame.utils.stats.Stat)1 java.util (java.util)1 BiFunction (java.util.function.BiFunction)1 ChatColor (org.bukkit.ChatColor)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Block (org.bukkit.block.Block)1 Sign (org.bukkit.block.Sign)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 Contract (org.jetbrains.annotations.Contract)1