Search in sources :

Example 1 with Plot

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

the class Arena method leave.

/**
 * Leaves the specified player. This will send messages to the player, restore their inventory, exp, armor etc.,
 * reset their time and weather to the one by the server, will make all invisible players visible again, cancel
 * timers if needed, updates the join signs for this arena and will leave the plot for the player. An
 * ArenaLeaveEvert may fire once this method is called.
 *
 * @param player the player to leave
 * @since 2.1.0
 */
public void leave(Player player) {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    if (ArenaManager.getInstance().getArena(player) == null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You're not in a game");
        return;
    }
    // call event
    ArenaLeaveEvent event = new ArenaLeaveEvent(this, player);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    var plot = getPlot(player);
    // this shouldn't happen unless you screwed up with the api
    if (plot == null) {
        MessageManager.getInstance().send(player, "You're not in a game");
        ArenaManager.getInstance().getArena(player).leave(player);
        return;
    }
    GamePlayer p = plot.getGamePlayer(player);
    p.restore();
    if (MainSpawnManager.getInstance().getMainSpawn() != null)
        p.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn());
    if (config.getBoolean("scoreboards.main.enable"))
        MainScoreboardManager.getInstance().register(player);
    player.resetPlayerTime();
    player.resetPlayerWeather();
    // show all players again
    Bukkit.getOnlinePlayers().forEach(pl -> player.showPlayer(Main.getInstance(), pl));
    // reset player display name of removed player
    getPlots().forEach(pl -> {
        getLobbyScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getBuildScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getVoteScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getWinScoreboard(pl).getRedTeam().removeEntry(player.getName());
    });
    getUsedPlots().forEach(usedPlot -> {
        for (GamePlayer gamePlayer : usedPlot.getGamePlayers()) {
            Player pl = gamePlayer.getPlayer();
            if (pl.equals(player)) {
                usedPlot.leave(gamePlayer);
                if (state == GameState.WAITING)
                    MessageManager.getInstance().send(player, messages.getStringList("leave.message.lobby"));
                else
                    MessageManager.getInstance().send(player, messages.getStringList("leave.message.in-game"));
                break;
            }
        }
    });
    getUsedPlots().forEach(usedPlot -> usedPlot.getGamePlayers().forEach(gamePlayer -> {
        Player pl = gamePlayer.getPlayer();
        if (state == GameState.WAITING)
            messages.getStringList("leave.other-players.lobby").forEach(message -> MessageManager.getInstance().send(pl, message.replace("%player%", player.getName())));
        else
            messages.getStringList("leave.other-players.in-game").forEach(message -> MessageManager.getInstance().send(pl, message.replace("%player%", player.getName())));
        if (config.getBoolean("scoreboards.lobby.enable"))
            getLobbyScoreboard(usedPlot).show(pl);
    }));
    // cancel wait timer when user amount drops below minimum
    if (getPlayers() < minPlayers && lobbyTimer.isActive()) {
        lobbyTimer.cancel();
        setLobbyTimer(new LobbyTimer(arenas.getInt(name + ".lobby-timer"), this));
    }
    if (getPlayers() <= 1) {
        if (getLobbyTimer().isActive()) {
            lobbyTimer.cancel();
            setLobbyTimer(new LobbyTimer(arenas.getInt(name + ".lobby-timer"), this));
            setState(GameState.WAITING);
        }
        if (buildTimer.isActive()) {
            buildTimer.cancel();
            setBuildTimer(new BuildTimer(arenas.getInt(name + ".timer"), this));
            forceStop();
        }
        if (getVoteTimer().isActive()) {
            voteTimer.cancel();
            setVoteTimer(new VoteTimer(arenas.getInt(name + ".vote-timer"), this));
            forceStop();
        }
        if (getWinTimer().isActive()) {
            winTimer.cancel();
            setWinTimer(new WinTimer(arenas.getInt(name + ".win-timer"), this));
            forceStop();
        }
    }
    if (getBossBar().getPlayers().contains(player))
        getBossBar().removePlayer(player);
    SignManager.getInstance().updateJoinSigns(this);
}
Also used : java.util(java.util) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) org.bukkit(org.bukkit) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer) ArenaLeaveEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent) BarColor(org.bukkit.boss.BarColor) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Main(com.gmail.stefvanschiedev.buildinggame.Main) Timer(com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BarStyle(org.bukkit.boss.BarStyle) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) Attribute(org.bukkit.attribute.Attribute) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) ArenaStopEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent) Entity(org.bukkit.entity.Entity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) com.gmail.stefvanschiedev.buildinggame.utils.scoreboards(com.gmail.stefvanschiedev.buildinggame.utils.scoreboards) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) SubjectMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Collectors(java.util.stream.Collectors) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) TeamSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.TeamSelection) MainScoreboardManager(com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) BossBar(org.bukkit.boss.BossBar) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) DateTimeFormatter(java.time.format.DateTimeFormatter) SignManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager) When(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu.When) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) ArenaJoinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) Player(org.bukkit.entity.Player) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) ArenaLeaveEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)

Example 2 with Plot

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

the class VoteTimer method run.

/**
 * Called whenever a second has passed. This will generate a new plot if needed or end the game if all plots have
 * been voted on.
 *
 * @since 2.1.0
 */
@Override
public void run() {
    running = true;
    if (seconds == originalSeconds) {
        plot = getNextPlot();
        if (plot == null) {
            arena.setState(GameState.RESETING);
            Plot first = null;
            Plot second = null;
            Plot third = null;
            for (var plot : arena.getPlots()) {
                if (first == null || first.getPoints() < plot.getPoints()) {
                    third = second;
                    second = first;
                    first = plot;
                    continue;
                }
                if (second == null || second.getPoints() < plot.getPoints()) {
                    third = second;
                    second = plot;
                    continue;
                }
                if (third == null || third.getPoints() < plot.getPoints())
                    third = plot;
            }
            // call events
            if (first != null)
                Bukkit.getPluginManager().callEvent(new PlayerWinEvent(arena, first.getGamePlayers(), Win.FIRST));
            if (second != null)
                Bukkit.getPluginManager().callEvent(new PlayerWinEvent(arena, second.getGamePlayers(), Win.SECOND));
            if (third != null)
                Bukkit.getPluginManager().callEvent(new PlayerWinEvent(arena, third.getGamePlayers(), Win.THIRD));
            arena.setFirstPlot(first);
            arena.setSecondPlot(second);
            arena.setThirdPlot(third);
            // create a schematic of the first plot
            if (config.getBoolean("schematics.enable") && Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
                Region region = arena.getFirstPlot().getBoundary();
                var dateTimeFormatter = DateTimeFormatter.ofPattern("yyy-MM-dd_HH-mm-ss");
                String players = arena.getFirstPlot().getGamePlayers().stream().map(gp -> '-' + gp.getPlayer().getName()).reduce("", String::concat);
                var fileName = LocalDateTime.now().format(dateTimeFormatter) + players + ".schem";
                var file = new File(SettingsManager.getInstance().getWinnerSchematicsFolder(), fileName);
                region.saveSchematic(file);
            }
            for (var plot : arena.getUsedPlots()) {
                for (var gamePlayer : plot.getAllGamePlayers()) {
                    var player = gamePlayer.getPlayer();
                    player.getInventory().clear();
                    if (first != null)
                        first.getLocation().teleport(player);
                    MessageManager.getInstance().send(player, messages.getStringList("game-ends.message"));
                    if (second != null && third != null) {
                        for (String message : messages.getStringList("game-ends.winners")) MessageManager.getInstance().send(player, message.replace("%first_players%", first.getPlayerFormat()).replace("%second_players%", second.getPlayerFormat()).replace("%third_players%", third.getPlayerFormat()));
                    }
                    // noinspection ConstantConditions
                    gamePlayer.addTitleAndSubtitle(messages.getString("winner.title").replace("%first%", first.getPlayerFormat()).replace("%second%", second == null ? "" : second.getPlayerFormat()).replace("%third%", third == null ? "" : third.getPlayerFormat()).replace("%first_points%", first.getPoints() + "").replace("%second_points%", second == null ? "0" : second.getPoints() + "").replace("%third_points%", third == null ? "0" : third.getPoints() + ""), messages.getString("winner.subtitle").replace("%first%", first.getPlayerFormat()).replace("%second%", second == null ? "" : second.getPlayerFormat()).replace("%third%", third == null ? "" : third.getPlayerFormat()).replace("%first_points%", first.getPoints() + "").replace("%second_points%", second == null ? "0" : second.getPoints() + "").replace("%third_points%", third == null ? "0" : second.getPoints() + ""));
                    gamePlayer.sendActionbar(messages.getString("winner.actionbar").replace("%first%", first.getPlayerFormat()).replace("%second%", second == null ? "" : second.getPlayerFormat()).replace("%third%", third == null ? "" : third.getPlayerFormat()).replace("%first_points%", String.valueOf(first.getPoints())).replace("%second_points%", second == null ? "0" : String.valueOf(second.getPoints())).replace("third_points", third == null ? "0" : String.valueOf(third.getPoints())));
                    if (SDVault.getInstance().isEnabled() && gamePlayer.getGamePlayerType() == GamePlayerType.PLAYER) {
                        String moneyString;
                        if (first.equals(plot)) {
                            moneyString = config.getString("money.first");
                            messages.getStringList("winner.first").forEach(message -> MessageManager.getInstance().send(player, message.replace("%points%", plot.getPoints() + "")));
                            config.getStringList("commands.first").forEach(command -> CommandUtil.dispatch(command.replace("%player%", player.getName())));
                        } else if (second.equals(plot)) {
                            moneyString = config.getString("money.second");
                            messages.getStringList("winner.second").forEach(message -> MessageManager.getInstance().send(player, message.replace("%points%", plot.getPoints() + "")));
                            config.getStringList("commands.second").forEach(command -> CommandUtil.dispatch(command.replace("%player%", player.getName())));
                        } else if (third.equals(plot)) {
                            moneyString = config.getString("money.third");
                            messages.getStringList("winner.third").forEach(message -> MessageManager.getInstance().send(player, message.replace("%points%", plot.getPoints() + "")));
                            config.getStringList("commands.third").forEach(command -> CommandUtil.dispatch(command.replace("%player%", player.getName())));
                        } else {
                            moneyString = config.getString("money.others");
                            config.getStringList("commands.others").forEach(command -> CommandUtil.dispatch(command.replace("%player%", player.getName())));
                        }
                        // compute money
                        MathElement element = MathElementFactory.parseText(moneyString.replace("%points%", String.valueOf(arena.getPlot(player).getVotes().stream().mapToInt(Vote::getPoints).sum())));
                        double money = element == null ? Double.NaN : element.compute();
                        if (Double.isNaN(money))
                            Main.getInstance().getLogger().warning("Unable to parse mathematical equation");
                        if (Double.isFinite(money) && arena.hasMoneyEnabled()) {
                            if (player.hasPermission("bg.rewards.money.double"))
                                money *= 2;
                            // booster multiplier
                            money *= Booster.getMultiplier(player);
                            if (SDVault.getEconomy().depositPlayer(player, money).transactionSuccess()) {
                                if (Booster.hasBooster(player)) {
                                    for (String message : messages.getStringList("vault.message.booster")) MessageManager.getInstance().send(player, message.replace("%money%", money + ""));
                                } else {
                                    for (String message : messages.getStringList("vault.message.no-booster")) MessageManager.getInstance().send(player, message.replace("%money%", money + ""));
                                }
                            }
                        }
                    }
                }
            }
            if (first != null) {
                first.getGamePlayers().forEach(gamePlayer -> config.getStringList("win-commands").forEach(command -> {
                    command = command.replace("%winner%", gamePlayer.getPlayer().getName());
                    if (!command.isEmpty() && command.charAt(0) == '@') {
                        String targetText = command.split(" ")[0];
                        Target.parse(targetText).execute(command.substring(targetText.length() + 1));
                    } else {
                        Bukkit.dispatchCommand(gamePlayer.getPlayer(), command);
                    }
                }));
            }
            arena.getWinTimer().runTaskTimer(Main.getInstance(), 20L, 20L);
            running = false;
            this.cancel();
            return;
        }
        arena.setVotingPlot(plot);
        arena.getUsedPlots().forEach(plot -> plot.getAllGamePlayers().forEach(gamePlayer -> {
            var player = gamePlayer.getPlayer();
            if (!config.getBoolean("names-after-voting") && config.getBoolean("scoreboards.vote.enable")) {
                arena.getVoteScoreboard(plot).show(player);
            }
            player.setPlayerTime(this.plot.getTime(), false);
            player.setPlayerWeather(this.plot.isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR);
        }));
    }
    // timings
    try {
        config.getConfigurationSection("timings.vote-timer.at").getKeys(false).forEach(key -> {
            if (seconds == Integer.parseInt(key)) {
                config.getStringList("timings.vote-timer.at." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
            }
        });
        config.getConfigurationSection("timings.vote-timer.every").getKeys(false).forEach(key -> {
            if (seconds % Integer.parseInt(key) == 0) {
                config.getStringList("timings.vote-timer.every." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
            }
        });
    } catch (NullPointerException | NumberFormatException ignore) {
    }
    seconds--;
    if (seconds <= 0) {
        arena.getUsedPlots().stream().flatMap(plot -> plot.getGamePlayers().stream()).forEach(player -> {
            Player pl = player.getPlayer();
            if (config.getBoolean("names-after-voting")) {
                messages.getStringList("voting.message").forEach(message -> MessageManager.getInstance().send(pl, message.replace("%playerplot%", this.plot.getPlayerFormat())));
                player.addTitleAndSubtitle(messages.getString("voting.title").replace("%playerplot%", this.plot.getPlayerFormat()), messages.getString("voting.subtitle").replace("%playerplot%", this.plot.getPlayerFormat()));
                player.sendActionbar(messages.getString("voting.actionbar").replace("%playerplot%", this.plot.getPlayerFormat()));
            }
            if (!this.plot.hasVoted(pl) && !this.plot.getGamePlayers().contains(player))
                this.plot.addVote(new Vote(config.getInt("voting.default-vote-points"), pl));
        });
        seconds = originalSeconds;
    }
}
Also used : GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) MathElement(com.gmail.stefvanschiedev.buildinggame.utils.math.MathElement) MathElementFactory(com.gmail.stefvanschiedev.buildinggame.utils.math.util.MathElementFactory) Win(com.gmail.stefvanschiedev.buildinggame.api.Win) PlayerWinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.PlayerWinEvent) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) LocalDateTime(java.time.LocalDateTime) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Main(com.gmail.stefvanschiedev.buildinggame.Main) Timer(com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer) DateTimeFormatter(java.time.format.DateTimeFormatter) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) SDVault(com.gmail.stefvanschiedev.buildinggame.managers.softdependencies.SDVault) Bukkit(org.bukkit.Bukkit) WeatherType(org.bukkit.WeatherType) PlayerWinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.PlayerWinEvent) MathElement(com.gmail.stefvanschiedev.buildinggame.utils.math.MathElement) Player(org.bukkit.entity.Player) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) File(java.io.File)

Example 3 with Plot

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

the class CommandManager method onSetSpawn.

/**
 * Called whenever a player wants to set a new spawn
 *
 * @param player the player
 * @param arena the arena
 * @since 5.8.0
 */
@Subcommand("setspawn")
@Description("Set a new spawn")
@CommandPermission("bg.setspawn")
@CommandCompletion("@arenas")
public void onSetSpawn(Player player, Arena arena) {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    int place = arena.getMaxPlayers() + 1;
    String name = arena.getName();
    Location location = player.getLocation();
    String worldName = location.getWorld().getName();
    int blockX = location.getBlockX();
    int blockY = location.getBlockY();
    int blockZ = location.getBlockZ();
    float pitch = location.getPitch();
    float yaw = location.getYaw();
    arenas.set(name + '.' + place + ".server", player.getServer().getName());
    arenas.set(name + '.' + place + ".world", worldName);
    arenas.set(name + '.' + place + ".x", blockX);
    arenas.set(name + '.' + place + ".y", blockY);
    arenas.set(name + '.' + place + ".z", blockZ);
    arenas.set(name + '.' + place + ".pitch", pitch);
    arenas.set(name + '.' + place + ".yaw", yaw);
    arenas.set(name + ".maxplayers", place);
    SettingsManager.getInstance().save();
    Plot plot = new Plot(arena, place);
    plot.setLocation(new PotentialLocation(() -> Bukkit.getWorld(worldName), blockX, blockY, blockZ, yaw, pitch));
    arena.addPlot(plot);
    arena.setMaxPlayers(place);
    messages.getStringList("commands.setspawn.success").forEach(message -> MessageManager.getInstance().send(player, message.replace("%place%", place + "")));
}
Also used : PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation)

Example 4 with Plot

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

the class Arena method stop.

/**
 * Stops the arena and resets it so it's open for new players. If you want to stop the arena while it's still
 * running use {@link #forceStop()}.
 *
 * @since 2.1.0
 */
public void stop() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    // call event
    ArenaStopEvent event = new ArenaStopEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> gamePlayer.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn()));
    // update bossbar
    getBossBar().setTitle(MessageManager.translate(messages.getString("global.bossbar-header").replace("%subject%", "?")));
    getBossBar().setVisible(false);
    getBossBar().getPlayers().forEach(player -> getBossBar().removePlayer(player));
    getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> {
        Player player = gamePlayer.getPlayer();
        gamePlayer.restore();
        player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
        // show all players again
        if (config.getBoolean("tab-list.adjust"))
            Bukkit.getOnlinePlayers().forEach(pl -> player.showPlayer(Main.getInstance(), pl));
        // reset scoreboard
        getUsedPlots().stream().flatMap(p -> p.getGamePlayers().stream()).forEach(gp -> gp.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()));
    });
    getPlots().forEach(plot -> plot.getAllGamePlayers().clear());
    this.matches = 0;
    SignManager.getInstance().updateJoinSigns(this);
}
Also used : java.util(java.util) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) org.bukkit(org.bukkit) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer) ArenaLeaveEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent) BarColor(org.bukkit.boss.BarColor) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Main(com.gmail.stefvanschiedev.buildinggame.Main) Timer(com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BarStyle(org.bukkit.boss.BarStyle) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) Attribute(org.bukkit.attribute.Attribute) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) ArenaStopEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent) Entity(org.bukkit.entity.Entity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) com.gmail.stefvanschiedev.buildinggame.utils.scoreboards(com.gmail.stefvanschiedev.buildinggame.utils.scoreboards) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) SubjectMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Collectors(java.util.stream.Collectors) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) TeamSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.TeamSelection) MainScoreboardManager(com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) BossBar(org.bukkit.boss.BossBar) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) DateTimeFormatter(java.time.format.DateTimeFormatter) SignManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager) When(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu.When) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) ArenaJoinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) Player(org.bukkit.entity.Player) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) ArenaStopEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Example 5 with Plot

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

the class NPCCreate method onNPCSpawn.

/**
 * Called when a {@link NPC} is spawned
 *
 * @param event the event fired when an {@link NPC} is spawned
 * @since 7.1.0
 */
@EventHandler
private void onNPCSpawn(@NotNull NPCSpawnEvent event) {
    toBeSpawned.entrySet().stream().filter(entry -> event.getNPC().equals(entry.getKey())).findAny().ifPresent(entry -> {
        NPC npc = entry.getKey();
        toBeSpawned.remove(npc);
        if (ArenaManager.getInstance().getArenas().stream().flatMap(arena -> arena.getPlots().stream()).map(Plot::getBoundary).anyMatch(boundary -> boundary.isInside(event.getLocation()))) {
            Player player = entry.getValue();
            TextComponent textComponent = TextComponent.of("You have spawned an NPC inside a plot, would you like to allow players to use this NPC to change their plot's floor? Please click ").color(TextColor.GOLD).append(TextComponent.of("here").color(TextColor.AQUA).clickEvent(ClickEvent.runCommand('/' + CommandUtil.createTempCommand(sender -> {
                if (!sender.equals(player)) {
                    return;
                }
                npc.addTrait(new NPCFloorChangeTrait());
                MessageManager.getInstance().send(player, ChatColor.GREEN + "This NPC now allows players to change their plot's floor");
            })))).append(TextComponent.of(" if so, otherwise ignore this message. This will expire in 60 seconds.").color(TextColor.GOLD));
            TextAdapter.sendComponent(player, textComponent);
        }
    });
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) TextComponent(net.kyori.text.TextComponent) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) NPCSpawnEvent(net.citizensnpcs.api.event.NPCSpawnEvent) TextAdapter(net.kyori.text.adapter.bukkit.TextAdapter) PlayerCreateNPCEvent(net.citizensnpcs.api.event.PlayerCreateNPCEvent) Player(org.bukkit.entity.Player) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) TextComponent(net.kyori.text.TextComponent) NPC(net.citizensnpcs.api.npc.NPC) EventHandler(org.bukkit.event.EventHandler) TextColor(net.kyori.text.format.TextColor) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) CommandUtil(com.gmail.stefvanschiedev.buildinggame.utils.CommandUtil) WeakHashMap(java.util.WeakHashMap) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Plot (com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot)15 Player (org.bukkit.entity.Player)11 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)10 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)10 Region (com.gmail.stefvanschiedev.buildinggame.utils.region.Region)10 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)10 Main (com.gmail.stefvanschiedev.buildinggame.Main)9 ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)9 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)9 GamePlayerType (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType)9 PotentialLocation (com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation)9 MainSpawnManager (com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager)8 GamePlayer (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)8 org.bukkit (org.bukkit)8 Timer (com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer)7 File (java.io.File)7 LocalDateTime (java.time.LocalDateTime)7 DateTimeFormatter (java.time.format.DateTimeFormatter)7 ArenaJoinEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent)6 ArenaLeaveEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent)6