Search in sources :

Example 11 with Arena

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

the class CommandManager method onReload.

/**
 * Called whenever a command sender wants to reload the plugin
 *
 * @param sender the command sender
 * @since 5.8.0
 */
@Subcommand("reload")
@Description("Reload the plugin")
@CommandPermission("bg.reload")
public void onReload(CommandSender sender) {
    ArenaManager.getInstance().getArenas().stream().filter(arena -> arena.getPlayers() > 0).forEach(Arena::stop);
    StatManager instance = StatManager.getInstance();
    if (instance.getMySQLDatabase() == null)
        instance.saveToFile();
    else
        instance.saveToDatabase();
    FileCheckerTimer runnable = SettingsManager.getInstance().getRunnable();
    if (!runnable.isCancelled())
        runnable.cancel();
    Main.getInstance().loadPlugin(true);
    MessageManager.getInstance().send(sender, ChatColor.GREEN + "Reloaded the plugin!");
}
Also used : CommandHelp(co.aikar.commands.CommandHelp) Player(org.bukkit.entity.Player) ReportMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.ReportMenu) Action(org.bukkit.event.block.Action) Supplier(java.util.function.Supplier) org.bukkit(org.bukkit) Main(com.gmail.stefvanschiedev.buildinggame.Main) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Locale(java.util.Locale) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) CommandSender(org.bukkit.command.CommandSender) co.aikar.commands.annotation(co.aikar.commands.annotation) ArenaSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.ArenaSelection) BaseCommand(co.aikar.commands.BaseCommand) RegionFactory(com.gmail.stefvanschiedev.buildinggame.utils.region.RegionFactory) ArenaMode(com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Consumer(java.util.function.Consumer) List(java.util.List) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) com.gmail.stefvanschiedev.buildinggame.timers(com.gmail.stefvanschiedev.buildinggame.timers) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 12 with Arena

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

the class CommandManager method onSpectate.

/**
 * Called whenever a player wants to spectate
 *
 * @param player the player
 * @param toSpectate the player to spectate
 * @since 5.8.0
 */
@Subcommand("spectate")
@Description("Spectate a player")
@CommandPermission("bg.spectate")
public void onSpectate(Player player, Player toSpectate) {
    var arena = ArenaManager.getInstance().getArena(toSpectate);
    if (arena == null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "Arena not found");
        return;
    }
    if (arena.getState() != GameState.BUILDING) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate right now");
        return;
    }
    GamePlayer toSpectateGamePlayer = arena.getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).filter(gamePlayer -> gamePlayer.getPlayer().equals(toSpectate)).findAny().orElse(null);
    if (toSpectateGamePlayer == null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "Couldn't find the player to spectate");
        return;
    }
    if (toSpectateGamePlayer.getGamePlayerType() == GamePlayerType.SPECTATOR) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate a spectator");
        return;
    }
    // check if the player is playing the game
    if (ArenaManager.getInstance().getArena(player) != null && ArenaManager.getInstance().getArena(player).getPlot(player).getGamePlayer(player).getGamePlayerType() == GamePlayerType.PLAYER) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate while you're in game");
        return;
    }
    // check if we are already spectating
    Plot spectating = null;
    for (Arena a : ArenaManager.getInstance().getArenas()) {
        for (Plot plot : a.getUsedPlots()) {
            for (GamePlayer gamePlayer : plot.getSpectators()) {
                if (gamePlayer.getPlayer().equals(player)) {
                    spectating = plot;
                    break;
                }
            }
        }
    }
    if (spectating != null)
        spectating.removeSpectator(spectating.getGamePlayer(player));
    arena.getPlot(toSpectateGamePlayer.getPlayer()).addSpectator(player, toSpectateGamePlayer);
    MessageManager.getInstance().send(player, ChatColor.GREEN + "Now spectating " + toSpectateGamePlayer.getPlayer().getName() + '!');
}
Also used : CommandHelp(co.aikar.commands.CommandHelp) Player(org.bukkit.entity.Player) ReportMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.ReportMenu) Action(org.bukkit.event.block.Action) Supplier(java.util.function.Supplier) org.bukkit(org.bukkit) Main(com.gmail.stefvanschiedev.buildinggame.Main) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Locale(java.util.Locale) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) CommandSender(org.bukkit.command.CommandSender) co.aikar.commands.annotation(co.aikar.commands.annotation) ArenaSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.ArenaSelection) BaseCommand(co.aikar.commands.BaseCommand) RegionFactory(com.gmail.stefvanschiedev.buildinggame.utils.region.RegionFactory) ArenaMode(com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Consumer(java.util.function.Consumer) List(java.util.List) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) com.gmail.stefvanschiedev.buildinggame.timers(com.gmail.stefvanschiedev.buildinggame.timers) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 13 with Arena

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

the class LobbyTimer method run.

/**
 * Called whenever a second has passed
 *
 * @since 2.1.0
 */
@Override
public void run() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    if (seconds <= 0) {
        arena.preStart();
        running = false;
        this.cancel();
        return;
    } else if (seconds % 15 == 0 || (seconds <= 10 && seconds >= 1)) {
        arena.getUsedPlots().stream().flatMap(plot -> plot.getGamePlayers().stream()).forEach(gamePlayer -> {
            var player = gamePlayer.getPlayer();
            messages.getStringList("lobbyCountdown.message").forEach(message -> MessageManager.getInstance().send(player, message.replace("%seconds%", seconds + "").replace("%minutes%", getMinutes() + "").replace("%time%", getMinutes() + ":" + getSecondsFromMinute()).replace("%seconds_from_minute%", getSecondsFromMinute() + "")));
        });
    }
    arena.getUsedPlots().forEach(plot -> plot.getGamePlayers().forEach(gamePlayer -> gamePlayer.getPlayer().setLevel(seconds)));
    // timings
    try {
        config.getConfigurationSection("timings.lobby-timer.at").getKeys(false).forEach(key -> {
            if (seconds == Integer.parseInt(key)) {
                config.getStringList("timings.lobby-timer.at." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
            }
        });
        config.getConfigurationSection("timings.lobby-timer.every").getKeys(false).forEach(key -> {
            if (seconds % Integer.parseInt(key) == 0) {
                config.getStringList("timings.lobby-timer.every." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
            }
        });
    } catch (NullPointerException | NumberFormatException ignore) {
    }
    seconds--;
}
Also used : Plugin(org.bukkit.plugin.Plugin) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Timer(com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) BukkitTask(org.bukkit.scheduler.BukkitTask) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) NotNull(org.jetbrains.annotations.NotNull) CommandUtil(com.gmail.stefvanschiedev.buildinggame.utils.CommandUtil) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Example 14 with Arena

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

the class ClickJoinSign method onPlayerInteract.

/**
 * Handles players clicking on join signs
 *
 * @param e an event representing a player interacting
 * @see PlayerInteractEvent
 * @since 2.1.0
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    if (e.getHand() != EquipmentSlot.HAND) {
        return;
    }
    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;
    Arena arena = null;
    for (Arena a : ArenaManager.getInstance().getArenas()) {
        for (PotentialBlockPosition blockPos : a.getSigns()) {
            Block block = blockPos.getBlock();
            if (block != null && block.equals(clickedBlock)) {
                arena = a;
                break;
            }
        }
    }
    var playerArena = ArenaManager.getInstance().getArena(player);
    if (arena == null) {
        for (PotentialBlockPosition blockPos : SignManager.getInstance().getRandomJoinSigns()) {
            Block block = blockPos.getBlock();
            if (block == null || !block.equals(clickedBlock)) {
                continue;
            }
            arena = getRandomArena();
            if (arena == null)
                MessageManager.getInstance().send(player, ChatColor.RED + "Unable to join an arena right now");
            else if (playerArena != null)
                MessageManager.getInstance().send(player, ChatColor.RED + "You're already in an arena");
            else
                arena.join(player);
        }
    } else {
        if (playerArena != null)
            MessageManager.getInstance().send(player, ChatColor.RED + "You're already in an arena");
        else
            arena.join(player);
    }
    e.setCancelled(true);
}
Also used : BlockState(org.bukkit.block.BlockState) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 15 with Arena

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

the class ArenaManager method setup.

/**
 * Loads/Reloads all arena instances from the arenas.yml file
 *
 * @since 2.1.0
 */
public void setup() {
    arenas.clear();
    YamlConfiguration arenasYaml = SettingsManager.getInstance().getArenas();
    Set<String> arenas = arenasYaml.getKeys(false);
    for (String arena : arenas) {
        if (!arena.equals("main-spawn")) {
            Arena a = new Arena(arena);
            a.setMoneyEnabled(arenasYaml.getBoolean(arena + ".enable-money", true));
            this.arenas.add(a);
            if (SettingsManager.getInstance().getConfig().getBoolean("debug"))
                Main.getInstance().getLogger().info("Loaded arena " + arena);
        }
    }
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Aggregations

Arena (com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)15 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)10 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)7 Main (com.gmail.stefvanschiedev.buildinggame.Main)6 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)6 Player (org.bukkit.entity.Player)6 ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)4 MainSpawnManager (com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager)4 StatManager (com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)4 com.gmail.stefvanschiedev.buildinggame.timers (com.gmail.stefvanschiedev.buildinggame.timers)4 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)4 ArenaMode (com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode)4 GamePlayerType (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType)4 ArenaSelection (com.gmail.stefvanschiedev.buildinggame.utils.guis.ArenaSelection)4 Plot (com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot)4 Region (com.gmail.stefvanschiedev.buildinggame.utils.region.Region)4 StatType (com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType)4 BaseCommand (co.aikar.commands.BaseCommand)3 CommandHelp (co.aikar.commands.CommandHelp)3 co.aikar.commands.annotation (co.aikar.commands.annotation)3