Search in sources :

Example 1 with SpectateSign

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

the class ClickSpectateSign method onPlayerInteract.

/**
 * Handles players clicking on a leave sign
 *
 * @param e an event representing a player interacting
 * @see PlayerInteractEvent
 * @since 2.1.0
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    var player = e.getPlayer();
    var clickedBlock = e.getClickedBlock();
    if (clickedBlock == null)
        return;
    BlockState state = clickedBlock.getState();
    if (e.getAction() != Action.RIGHT_CLICK_BLOCK || !(state instanceof Sign))
        return;
    for (SpectateSign spectateSign : SignManager.getInstance().getSpectateSigns()) {
        Block block = spectateSign.getPotentialBlockPosition().getBlock();
        if (!clickedBlock.equals(block)) {
            continue;
        }
        OfflinePlayer offlinePlayer = spectateSign.getOfflinePlayer();
        if (!offlinePlayer.isOnline()) {
            MessageManager.getInstance().send(player, ChatColor.RED + offlinePlayer.getName() + " is offline");
            return;
        }
        Arena arena = ArenaManager.getInstance().getArena(offlinePlayer.getPlayer());
        if (arena == null) {
            MessageManager.getInstance().send(player, ChatColor.RED + "This player is not in an arena");
            return;
        }
        arena.getPlot(offlinePlayer.getPlayer()).addSpectator(player, getPlayer(arena, offlinePlayer.getPlayer()));
        break;
    }
}
Also used : SpectateSign(com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) OfflinePlayer(org.bukkit.OfflinePlayer) Sign(org.bukkit.block.Sign) SpectateSign(com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SpectateSign

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

the class SignManager method updateSpectateSign.

/**
 * Updates all spectator signs
 *
 * @since 5.4.0
 */
private void updateSpectateSign(@NotNull SpectateSign spectateSign) {
    Sign sign = tryGetSign(spectateSign.getPotentialBlockPosition());
    if (sign == null) {
        return;
    }
    sign.setLine(0, ChatColor.BOLD + "Building Game");
    sign.setLine(1, "spectate");
    sign.setLine(2, ChatColor.UNDERLINE + spectateSign.getOfflinePlayer().getName());
    sign.update();
}
Also used : Sign(org.bukkit.block.Sign) SpectateSign(com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign) StatSign(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign)

Example 3 with SpectateSign

use of com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign 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)

Aggregations

SpectateSign (com.gmail.stefvanschiedev.buildinggame.utils.SpectateSign)3 Arena (com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)2 StatSign (com.gmail.stefvanschiedev.buildinggame.utils.stats.StatSign)2 Sign (org.bukkit.block.Sign)2 ChunkCoordinates (com.gmail.stefvanschiedev.buildinggame.utils.ChunkCoordinates)1 PotentialBlockPosition (com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Block (org.bukkit.block.Block)1 BlockState (org.bukkit.block.BlockState)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 EventHandler (org.bukkit.event.EventHandler)1