Search in sources :

Example 11 with Plot

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

the class Arena method preStart.

/**
 * This is called before starting the game as to allow the players to vote on a subject if the subject choosing
 * should be done at {@link When#BEFORE_BUILD}. This will automatically progress the game when needed. When starting
 * the game this should be called rather than {@link #postStart()}.
 *
 * @since 6.4.0
 */
public void preStart() {
    if (getSubjectMenu().getWhen() == SubjectMenu.When.BEFORE_BUILD) {
        new BukkitRunnable() {

            @Override
            public void run() {
                postStart();
            }
        }.runTaskLater(Main.getInstance(), 200L);
        getUsedPlots().forEach(plot -> plot.getGamePlayers().forEach(gamePlayer -> {
            var player = gamePlayer.getPlayer();
            plot.getLocation().teleport(player);
            giveSubjectMenuItem(player);
            if (getSubjectMenu().opensInstantly()) {
                getSubjectMenu().show(player);
            }
        }));
        return;
    }
    postStart();
}
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) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 12 with Plot

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

the class Arena method join.

/**
 * Joins the given player this arena, with all messages being send and all items given to the player. It'll teleport
 * the player to the {@link #lobby} and will join the first open plot. An ArenaJoinEvent may fire once this method
 * is called.
 *
 * @param player the player to join this arena
 * @since 2.1.0
 */
public void join(final Player player) {
    final YamlConfiguration config = SettingsManager.getInstance().getConfig();
    final YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    // check if everything is set up
    if (!isSetup()) {
        MessageManager.getInstance().send(player, ChatColor.RED + "Your arena isn't setup right, you still need to do this:");
        if (lobby == null)
            MessageManager.getInstance().send(player, ChatColor.RED + " - The lobby of arena " + getName() + "(/bg setlobby " + getName() + ')');
        if (MainSpawnManager.getInstance().getMainSpawn() == null)
            MessageManager.getInstance().send(player, ChatColor.RED + " - The main spawn (/bg setmainspawn)");
        getPlots().stream().filter(plot -> plot.getBoundary() == null).forEach(plot -> MessageManager.getInstance().send(player, ChatColor.RED + " - The boundary of plot " + plot.getId() + " (/bg setbounds " + getName() + ' ' + plot.getId() + ')'));
        getPlots().stream().filter(plot -> plot.getFloor() == null).forEach(plot -> MessageManager.getInstance().send(player, ChatColor.RED + " - The floor of plot " + plot.getId() + " (/bg setfloor " + getName() + ' ' + plot.getId() + ')'));
        return;
    }
    if (ArenaManager.getInstance().getArena(player) != null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You're already in a game");
        return;
    }
    if (!canJoin()) {
        MessageManager.getInstance().send(player, messages.getStringList("join.in-game"));
        return;
    }
    if (isFull()) {
        MessageManager.getInstance().send(player, ChatColor.RED + "This arena is full");
        return;
    }
    // call event
    ArenaJoinEvent event = new ArenaJoinEvent(this, player);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    GamePlayer p = new GamePlayer(player, GamePlayerType.PLAYER);
    Plot plot = null;
    for (Plot pl : getPlots()) {
        if (!pl.isFull()) {
            plot = pl;
            pl.join(p);
            break;
        }
    }
    if (config.getBoolean("scoreboards.main.enable"))
        MainScoreboardManager.getInstance().remove(player);
    boolean enableLobbyScoreboard = config.getBoolean("scoreboards.lobby.enable");
    if (enableLobbyScoreboard && (getState() == GameState.WAITING || getState() == GameState.STARTING)) {
        getLobbyScoreboard(plot).show(player);
    } else {
        getBuildScoreboard(plot).show(player);
    }
    String name = player.getName();
    // add player to red scoreboard of others
    getPlots().stream().filter(pl -> !pl.getGamePlayers().contains(p)).forEach(pl -> {
        getLobbyScoreboard(pl).getRedTeam().addEntry(name);
        getBuildScoreboard(pl).getRedTeam().addEntry(name);
        getVoteScoreboard(pl).getRedTeam().addEntry(name);
        getWinScoreboard(pl).getRedTeam().addEntry(name);
    });
    messages.getStringList("join.message").forEach(message -> MessageManager.getInstance().send(player, message.replace("%players%", getPlayers() + "").replace("%max_players%", getMaxPlayers() + "")));
    getUsedPlots().stream().flatMap(pl -> pl.getGamePlayers().stream()).forEach(gamePlayer -> {
        Player pla = gamePlayer.getPlayer();
        messages.getStringList("join.otherPlayers").forEach(message -> MessageManager.getInstance().send(pla, message.replace("%player%", name).replace("%players%", getPlayers() + "").replace("%max_players%", getMaxPlayers() + "")));
    });
    if (lobby != null && (getState() == GameState.WAITING || getState() == GameState.STARTING)) {
        lobby.teleport(player);
    } else {
        plot.getLocation().teleport(player);
    }
    if (enableLobbyScoreboard && (getState() == GameState.WAITING || getState() == GameState.STARTING)) {
        getUsedPlots().forEach(pl -> pl.getGamePlayers().forEach(gamePlayer -> lobbyScoreboards.get(pl).show(gamePlayer.getPlayer())));
    } else {
        getUsedPlots().forEach(pl -> pl.getGamePlayers().forEach(gamePlayer -> buildScoreboards.get(pl).show(gamePlayer.getPlayer())));
    }
    player.getInventory().clear();
    player.getInventory().setArmorContents(null);
    // fill lives and hunger
    player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    player.setFoodLevel(20);
    if (getState() == GameState.WAITING || getState() == GameState.STARTING) {
        player.setGameMode(GameMode.ADVENTURE);
    } else {
        player.setGameMode(GameMode.CREATIVE);
    }
    // time
    if (config.getBoolean("join.time-change.change"))
        player.setPlayerTime(config.getInt("join.time-change.time"), false);
    // bossbar
    getBossBar().addPlayer(player);
    // hide players from tab list
    if (config.getBoolean("tab-list.adjust"))
        Bukkit.getOnlinePlayers().stream().filter(pl -> !contains(pl)).forEach(pl -> player.hidePlayer(Main.getInstance(), pl));
    // show current joined player to others
    getUsedPlots().stream().flatMap(pl -> pl.getGamePlayers().stream()).forEach(gamePlayer -> gamePlayer.getPlayer().showPlayer(Main.getInstance(), player));
    if (getPlayers() >= minPlayers && !lobbyTimer.isActive() && (getState() == GameState.WAITING || getState() == GameState.STARTING)) {
        lobbyTimer.runTaskTimer(Main.getInstance(), 0L, 20L);
    }
    if (getPlayers() >= getMaxPlayers())
        lobbyTimer.setSeconds(0);
    var arena = this;
    // bukkit runnable because of instant leaving and instant subject opening
    var runnable = new BukkitRunnable() {

        @Override
        public void run() {
            // give team selection
            if (getState() == GameState.WAITING || getState() == GameState.STARTING) {
                if (getMode() == ArenaMode.TEAM) {
                    Material material = SettingsManager.getInstance().getMaterial("team-selection.item.id", Material.BARRIER);
                    player.getInventory().setItem(0, new ItemBuilder(player, material).setDisplayName(MessageManager.translate(messages.getString("team-gui.item.name"), player)).setLore(MessageManager.translate(messages.getStringList("team-gui.item.lores"), player)).setClickEvent(event -> {
                        getTeamSelection().show(player);
                        event.setCancelled(true);
                    }).build());
                }
                // give paper for subject
                if (player.hasPermission("bg.subjectmenu") && config.getBoolean("enable-subject-voting") && getSubjectMenu().getWhen() == SubjectMenu.When.LOBBY) {
                    giveSubjectMenuItem(player);
                    if (getSubjectMenu().opensInstantly()) {
                        getSubjectMenu().show(player);
                    }
                }
                Material material = SettingsManager.getInstance().getMaterial("leave-item.id", Material.BARRIER);
                player.getInventory().setItem(config.getInt("leave-item.slot"), new ItemBuilder(player, material).setDisplayName(MessageManager.translate(messages.getString("leave-item.name"), player)).setClickEvent(event -> {
                    leave(player);
                    event.setCancelled(true);
                }).build());
                player.updateInventory();
            } else if (getState() == GameState.BUILDING) {
                tryGiveOptionsMenu(player);
            }
        }

        /**
         * Returns the team selection and creates one if it doesn't exist yet
         *
         * @return the team selection
         * @see TeamSelection
         * @since 2.1.0
         */
        @NotNull
        private TeamSelection getTeamSelection() {
            if (teamSelection == null)
                teamSelection = new TeamSelection(arena);
            return teamSelection;
        }
    };
    runnable.runTaskLater(Main.getInstance(), 1L);
    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) ArenaJoinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent) Player(org.bukkit.entity.Player) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) TeamSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.TeamSelection) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)

Example 13 with Plot

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

the class Arena method setVotingPlot.

/**
 * Sets the new voting plot, send messages and titles, teleports all players, gives them new vote items and changes
 * their time and weather.
 *
 * @param votingPlot the new voting plot
 * @see Plot
 * @since 2.1.0
 */
public void setVotingPlot(Plot votingPlot) {
    SettingsManager instance = SettingsManager.getInstance();
    YamlConfiguration config = instance.getConfig();
    YamlConfiguration messages = instance.getMessages();
    this.votingPlot = votingPlot;
    Region boundary = votingPlot.getBoundary();
    Location safeLocation = boundary.getSafeLocation();
    Location center = boundary.getCenter();
    // https://bukkit.org/threads/lookat-and-move-functions.26768/
    if (safeLocation != null) {
        // Clone the loc to prevent applied changes to the input loc
        safeLocation = safeLocation.clone();
        // Values of change in distance (make it relative)
        double dx = center.getX() - safeLocation.getX();
        double dz = center.getZ() - safeLocation.getZ();
        // Set yaw
        if (dx != 0)
            safeLocation.setYaw((dx < 0 ? ((float) (1.5 * Math.PI)) : ((float) (0.5 * Math.PI))) - (float) Math.atan(dz / dx));
        else if (dz < 0)
            safeLocation.setYaw((float) Math.PI);
        // Set pitch
        safeLocation.setPitch((float) -Math.atan((center.getY() - safeLocation.getY()) / (Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2)))));
        // Set values, convert to degrees (invert the yaw since Bukkit uses a different yaw dimension format)
        safeLocation.setYaw(-safeLocation.getYaw() * 180f / (float) Math.PI);
        safeLocation.setPitch(safeLocation.getPitch() * 180f / (float) Math.PI);
    }
    for (Plot plot : getUsedPlots()) {
        for (GamePlayer gamePlayer : plot.getAllGamePlayers()) {
            Player player = gamePlayer.getPlayer();
            if (!config.getBoolean("names-after-voting")) {
                messages.getStringList("voting.message").forEach(message -> MessageManager.getInstance().send(player, message.replace("%playerplot%", votingPlot.getPlayerFormat())));
                gamePlayer.addTitleAndSubtitle(messages.getString("voting.title").replace("%playerplot%", votingPlot.getPlayerFormat()), messages.getString("voting.subtitle").replace("%playerplot%", votingPlot.getPlayerFormat()));
                gamePlayer.sendActionbar(messages.getString("voting.actionbar").replace("%playerplot%", votingPlot.getPlayerFormat()));
            }
            int blockIndex = ThreadLocalRandom.current().nextInt(votingPlot.getBoundary().getAllBlocks().size());
            player.teleport(Objects.requireNonNullElseGet(safeLocation, () -> boundary.getAllBlocks().get(blockIndex).getLocation()));
            // give blocks
            player.getInventory().clear();
            if (gamePlayer.getGamePlayerType() == GamePlayerType.PLAYER) {
                config.getConfigurationSection("voting.items").getKeys(false).forEach(identifier -> {
                    boolean save = false;
                    if (!messages.contains("voting.items." + identifier + ".name")) {
                        messages.set("voting.items." + identifier + ".name", "Type: Null");
                        save = true;
                    }
                    if (!messages.contains("voting.items." + identifier + ".lore")) {
                        messages.set("voting.items." + identifier + ".lore", new ArrayList<String>(0));
                        save = true;
                    }
                    if (save)
                        instance.save();
                    Material material = SettingsManager.getInstance().getMaterial("voting.items." + identifier + ".id", Material.BARRIER);
                    player.getInventory().setItem(config.getInt("voting.items." + identifier + ".slot") - 1, new ItemBuilder(player, material).setDisplayName(MessageManager.translate(messages.getString("voting.items." + identifier + ".name"))).setLore(MessageManager.translate(messages.getStringList("voting.items." + identifier + ".lore"))).movable(false).setClickEvent(event -> {
                        int points = config.getInt("voting.items." + identifier + ".points");
                        votingPlot.addVote(new Vote(points, player));
                        event.setCancelled(true);
                    }).build());
                });
                boolean worldEditEnabled = Bukkit.getPluginManager().isPluginEnabled("WorldEdit");
                if (worldEditEnabled && config.getBoolean("reports.enable")) {
                    player.getInventory().setItem(8, new ItemBuilder(player, Material.BOOK).setDisplayName(ChatColor.RED + "Report build").movable(false).setClickEvent(event -> {
                        var dateTimeFormatter = DateTimeFormatter.ofPattern("yyy-MM-dd_HH-mm-ss");
                        String players = getVotingPlot().getGamePlayers().stream().map(gp -> '-' + gp.getPlayer().getName()).reduce("", String::concat);
                        var fileName = LocalDateTime.now().format(dateTimeFormatter) + players + ".schem";
                        var file = new File(instance.getReportsSchematicsFolder(), fileName);
                        getVotingPlot().getBoundary().saveSchematic(file, () -> MessageManager.getInstance().send(event.getPlayer(), ChatColor.GREEN + "Your report has been saved."));
                        getVotingPlot().getGamePlayers().forEach(gp -> Report.add(new Report(gp.getPlayer(), player, ZonedDateTime.now(), file)));
                    }).build());
                }
            }
            // update scoreboard and update time and weather
            if (config.getBoolean("scoreboards.vote.enable"))
                getVoteScoreboard(plot).show(player);
            player.setPlayerTime(plot.getTime(), false);
            player.setPlayerWeather(plot.isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR);
        }
    }
    getVotedPlots().add(votingPlot);
}
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) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) File(java.io.File) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation)

Example 14 with Plot

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

the class Arena method postStart.

/**
 * Starts a new match. An ArenaStartEvent will be fired once this method is called.
 *
 * @since 2.1.0
 */
private void postStart() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    // call event
    ArenaStartEvent event = new ArenaStartEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    subject = getSubjectMenu().getHighestVote();
    // update bossbar
    getBossBar().setTitle(MessageManager.translate(messages.getString("global.bossbar-header").replace("%subject%", getSubject())));
    getUsedPlots().forEach(plot -> plot.getGamePlayers().forEach(gamePlayer -> {
        plot.getLocation().teleport(gamePlayer.getPlayer());
        MessageManager.getInstance().send(gamePlayer.getPlayer(), messages.getStringList("gameStarts.message"));
        messages.getStringList("gameStarts.subject").forEach(message -> MessageManager.getInstance().send(gamePlayer.getPlayer(), message.replace("%subject%", getSubject())));
        gamePlayer.addTitleAndSubtitle(messages.getString("gameStarts.title").replace("%subject%", getSubject()), messages.getString("gameStarts.subtitle").replace("%subject%", getSubject()));
        gamePlayer.sendActionbar(messages.getString("gameStarts.actionbar").replace("%subject%", subject));
        final var player = gamePlayer.getPlayer();
        player.getInventory().clear();
        player.setGameMode(GameMode.CREATIVE);
        player.setPlayerTime(plot.getTime(), false);
        // hotbar
        for (int i = 0; i < 9; i++) {
            Material material = SettingsManager.getInstance().getMaterial("hotbar.default.slot-" + (i + 1), Material.AIR);
            player.getInventory().setItem(i, new ItemStack(material));
        }
        // bossbar
        getBossBar().setVisible(true);
        tryGiveOptionsMenu(player);
    }));
    setState(GameState.BUILDING);
    // save blocks
    getPlots().forEach(Plot::save);
    matches++;
    SignManager.getInstance().updateJoinSigns(this);
    buildTimer.runTaskTimer(Main.getInstance(), 20L, 20L);
}
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) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemStack(org.bukkit.inventory.ItemStack)

Example 15 with Plot

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

the class ParticlesMenu method particleClick.

/**
 * Called whenever a user clicks on a particle item
 *
 * @param event the event called when clicking
 * @since 5.6.0
 */
public void particleClick(InventoryClickEvent event, org.bukkit.Particle particleType) {
    var player = (Player) event.getWhoClicked();
    var arena = ArenaManager.getInstance().getArena(player);
    if (arena == null)
        return;
    Location location = player.getLocation();
    Plot plot = arena.getPlot(player);
    if (particleType == org.bukkit.Particle.FALLING_DUST) {
        Particle particle;
        if (event.getCursor() == null) {
            particle = new FallingDustParticle(location, Bukkit.createBlockData(Material.SAND));
        } else {
            particle = new FallingDustParticle(location, Bukkit.createBlockData(event.getCursor().getType()));
        }
        plot.addParticle(particle, player);
    } else if (particleType == org.bukkit.Particle.REDSTONE) {
        plot.addParticle(new RedstoneParticle(location), player);
    } else {
        plot.addParticle(new Particle(location, particleType), player);
    }
    event.setCancelled(true);
}
Also used : FallingDustParticle(com.gmail.stefvanschiedev.buildinggame.utils.particle.FallingDustParticle) Particle(com.gmail.stefvanschiedev.buildinggame.utils.particle.Particle) RedstoneParticle(com.gmail.stefvanschiedev.buildinggame.utils.particle.RedstoneParticle) Player(org.bukkit.entity.Player) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) RedstoneParticle(com.gmail.stefvanschiedev.buildinggame.utils.particle.RedstoneParticle) Location(org.bukkit.Location) FallingDustParticle(com.gmail.stefvanschiedev.buildinggame.utils.particle.FallingDustParticle)

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