Search in sources :

Example 6 with Arena

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

the class CommandManager method onJoin.

/**
 * Called whenever a player wants to join an arena
 *
 * @param player the player
 * @param arena the arena to join
 * @since 5.8.0
 */
@Subcommand("join")
@Description("Join an arena")
@CommandPermission("bg.join")
@CommandCompletion("@arenas")
public void onJoin(Player player, @Optional Arena arena) {
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    if (arena == null) {
        for (Arena a : ArenaManager.getInstance().getArenas()) {
            if (!a.canJoin()) {
                continue;
            }
            new ArenaSelection().show(player);
            return;
        }
        MessageManager.getInstance().send(player, messages.getStringList("join.no-arena"));
        return;
    }
    arena.join(player);
}
Also used : ArenaSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.ArenaSelection) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 7 with Arena

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

the class CommandManager method onCreateArena.

/**
 * Called whenever a command sender wants to create a new arena
 *
 * @param sender the command sender
 * @param name the arena name
 * @since 5.8.0
 */
@Subcommand("createarena")
@Description("Create an arena")
@CommandPermission("bg.createarena")
public void onCreateArena(CommandSender sender, @Conditions("arenanotexist") @Single String name) {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    int buildTime = config.getInt("timers.build");
    int lobbyTime = config.getInt("timers.lobby");
    int voteTime = config.getInt("timers.vote");
    int winTime = config.getInt("timers.win");
    arenas.set(name + ".mode", "SOLO");
    arenas.set(name + ".timer", buildTime);
    arenas.set(name + ".lobby-timer", lobbyTime);
    arenas.set(name + ".vote-timer", voteTime);
    arenas.set(name + ".win-timer", winTime);
    SettingsManager.getInstance().save();
    Arena arena = new Arena(name);
    arena.setMode(ArenaMode.SOLO);
    arena.setBuildTimer(new BuildTimer(buildTime, arena));
    arena.setLobbyTimer(new LobbyTimer(lobbyTime, arena));
    arena.setVoteTimer(new VoteTimer(voteTime, arena));
    arena.setWinTimer(new WinTimer(winTime, arena));
    ArenaManager.getInstance().getArenas().add(arena);
    messages.getStringList("commands.createarena.success").forEach(message -> MessageManager.getInstance().send(sender, message.replace("%arena%", name)));
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 8 with Arena

use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena 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 9 with Arena

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

the class Main method loadPlugin.

/**
 * Loads the entire plugin
 *
 * @since 2.1.0
 */
public void loadPlugin(boolean reload) {
    long start = System.currentTimeMillis();
    // this has to be done quite early
    if (!reload) {
        Gui.registerProperty("particle-type", Particle::valueOf);
        Gui.registerProperty("biome", Biome::valueOf);
        Gui.registerProperty("dye-color", DyeColor::valueOf);
        Gui.registerProperty("material", Material::valueOf);
    }
    getLogger().info("Loading files");
    SettingsManager.getInstance().setup(this, false);
    getLogger().info("Loading arenas");
    ArenaManager.getInstance().setup();
    ArenaModeManager.getInstance().setup();
    BuildTimerManager.getInstance().setup();
    LobbyManager.getInstance().setup();
    LobbyTimerManager.getInstance().setup();
    MinPlayersManager.getInstance().setup();
    MatchesManager.getInstance().setup();
    VoteTimerManager.getInstance().setup();
    WinTimerManager.getInstance().setup();
    getLogger().info("Loading plots");
    PlotManager.getInstance().setup();
    // has to be down here for some config stuff
    MaxPlayersManager.getInstance().setup();
    LocationManager.getInstance().setup();
    BoundaryManager.getInstance().setup();
    FloorManager.getInstance().setup();
    getLogger().info("Loading main spawn");
    MainSpawnManager.getInstance().setup();
    PluginManager pm = Bukkit.getPluginManager();
    getLogger().info("Loading soft dependencies");
    if (pm.isPluginEnabled("Vault"))
        SDVault.getInstance().setup();
    if (pm.isPluginEnabled("PlaceholderAPI")) {
        try {
            String version = pm.getPlugin("PlaceholderAPI").getDescription().getVersion();
            var number = Integer.parseInt(version.replace(".", ""));
            // This ensures the versions don't get mixed up (e.g. 2.7.5 being bigger than 2.9).
            for (var i = version.split("\\.").length; i < 3; i++) number *= 10;
            // 290 is the first version with offline player support
            if (number >= 290) {
                if (!new PlaceholderAPIPlaceholders().register())
                    getLogger().warning("Unable to register placeholders for PlaceholderAPI");
            } else
                getLogger().warning("PlaceholderAPI is outdated, update to a later version to keep BuildingGame compatible with PlaceholderAPI.");
        } catch (NumberFormatException e) {
            getLogger().warning("Unable to get PlaceholderAPI version, contact the plugin author about this.");
            e.printStackTrace();
        }
    }
    if (pm.isPluginEnabled("MVdWPlaceholderAPI")) {
        PlaceholderSupplier.getPlaceholderReplacements().forEach((placeholder, biFunction) -> PlaceholderAPI.registerPlaceholder(this, placeholder, event -> biFunction.apply(event.getOfflinePlayer(), event.getPlaceholder())));
    }
    getLogger().info("Loading commands");
    if (!reload) {
        var manager = new BukkitCommandManager(this);
        // noinspection deprecation
        manager.enableUnstableAPI("help");
        // register contexts
        manager.getCommandContexts().registerContext(Arena.class, context -> {
            var arena = ArenaManager.getInstance().getArena(context.popFirstArg());
            if (arena == null)
                throw new InvalidCommandArgument("This arena doesn't exist");
            return arena;
        });
        manager.getCommandContexts().registerContext(ArenaMode.class, context -> {
            var mode = ArenaMode.valueOf(context.popFirstArg().toUpperCase(Locale.getDefault()));
            if (mode == null)
                throw new InvalidCommandArgument("This game mode doesn't exist");
            return mode;
        });
        manager.getCommandContexts().registerContext(StatType.class, context -> {
            var type = StatType.valueOf(context.popFirstArg().toUpperCase(Locale.getDefault()));
            if (type == null)
                throw new InvalidCommandArgument("This statistic type doesn't exist");
            return type;
        });
        // register completions
        manager.getCommandCompletions().registerCompletion("arenas", context -> ArenaManager.getInstance().getArenas().stream().map(Arena::getName).collect(Collectors.toList()));
        manager.getCommandCompletions().registerCompletion("arenamodes", context -> Stream.of(ArenaMode.values()).map(mode -> mode.toString().toUpperCase(Locale.getDefault())).collect(Collectors.toList()));
        manager.getCommandCompletions().registerCompletion("stattypes", context -> Stream.of(StatType.values()).map(Enum::toString).collect(Collectors.toList()));
        manager.getCommandCompletions().registerCompletion("holograms", context -> TopStatHologram.getHolograms().stream().map(TopStatHologram::getName).collect(Collectors.toList()));
        // register conditions
        manager.getCommandConditions().addCondition(String.class, "arenanotexist", (context, executionContext, string) -> {
            if (ArenaManager.getInstance().getArena(string) != null || string.equals("main-spawn"))
                throw new ConditionFailedException("Arena already exists");
        });
        // hd stands for Holographic Displays, but it's shorten to hd since the full name is a bit long
        manager.getCommandConditions().addCondition("hdenabled", context -> pm.isPluginEnabled("HolographicDisplays"));
        manager.registerCommand(new CommandManager());
    }
    getLogger().info("Loading stats");
    StatManager.getInstance().setup();
    // loading achievements should happen after the statistics have been loaded
    Achievement.loadAchievements();
    getLogger().info("Loading listeners");
    if (!reload) {
        pm.registerEvents(new BlockDispenseItem(), this);
        pm.registerEvents(new BlockEdit(), this);
        pm.registerEvents(new JoinSignCreate(), this);
        pm.registerEvents(new LeaveSignCreate(), this);
        pm.registerEvents(new StatSignCreate(), this);
        pm.registerEvents(new UpdateLoadedSigns(), this);
        pm.registerEvents(new SpectateSignCreate(), this);
        pm.registerEvents(new SignBreak(), this);
        pm.registerEvents(new LiquidFlow(), this);
        pm.registerEvents(new PistonBlockMove(), this);
        // starts the connection to bungeecord
        if (SettingsManager.getInstance().getConfig().getBoolean("bungeecord.enable"))
            BungeeCordHandler.getInstance();
        // per world inventory compatibility fix
        if (pm.isPluginEnabled("PerWorldInventory")) {
            try {
                String version = pm.getPlugin("PerWorldInventory").getDescription().getVersion();
                var number = Integer.parseInt(version.replace(".", ""));
                // This ensures the versions don't get mixed up (e.g. 1.7.5 being bigger than 1.11).
                for (var i = version.split("\\.").length; i < 3; i++) number *= 10;
                // 200 is the first version with the new package name
                if (number >= 200)
                    pm.registerEvents(new PerWorldInventoryCancel(), this);
                else
                    getLogger().warning("PerWorldInventory is outdated, update to a later version to keep BuildingGame compatible with PerWorldInventory.");
            } catch (NumberFormatException e) {
                getLogger().warning("Unable to get PerWorldInventory version, contact the plugin author about this.");
                e.printStackTrace();
            }
        }
        if (pm.isPluginEnabled("WorldEdit"))
            WorldEdit.getInstance().getEventBus().register(new WorldEditBoundaryAssertion());
        if (pm.isPluginEnabled("Citizens")) {
            pm.registerEvents(new NPCCreate(), this);
            TraitInfo traitInfo = TraitInfo.create(NPCFloorChangeTrait.class).withName("buildinggame:floorchange");
            CitizensAPI.getTraitFactory().registerTrait(traitInfo);
        }
        pm.registerEvents(new ClickJoinSign(), this);
        pm.registerEvents(new ClickLeaveSign(), this);
        pm.registerEvents(new ClickSpectateSign(), this);
        pm.registerEvents(new Drop(), this);
        pm.registerEvents(new Interact(), this);
        pm.registerEvents(new Leave(), this);
        pm.registerEvents(new Move(), this);
        pm.registerEvents(new PlaceBucket(), this);
        pm.registerEvents(new PlaceIgnoreSpectators(), this);
        if (SettingsManager.getInstance().getConfig().getBoolean("chat.adjust"))
            pm.registerEvents(new Chat(), this);
        pm.registerEvents(new CommandBlocker(), this);
        pm.registerEvents(new EntityDamage(), this);
        pm.registerEvents(new TakeDamage(), this);
        pm.registerEvents(new LoseFood(), this);
        // entity events
        pm.registerEvents(new ChickenSpawnByEgg(), this);
        pm.registerEvents(new EntityExplode(), this);
        pm.registerEvents(new EntityOptionsMenu(), this);
        pm.registerEvents(new EntitySpawn(), this);
        // scoreboards
        pm.registerEvents(new MainScoreboardJoinShow(), this);
        pm.registerEvents(new MainScoreboardWorldChange(), this);
        // stats
        // saved
        pm.registerEvents(new BreakStat(), this);
        pm.registerEvents(new FirstStat(), this);
        pm.registerEvents(new PlaceStat(), this);
        pm.registerEvents(new PlaysStat(), this);
        pm.registerEvents(new SecondStat(), this);
        pm.registerEvents(new ThirdStat(), this);
        // unsaved
        pm.registerEvents(new UnsavedStatsPlace(), this);
        // structure
        pm.registerEvents(new TreeGrow(), this);
        if (StatManager.getInstance().getMySQLDatabase() != null) {
            pm.registerEvents(new JoinPlayerStats(), this);
            pm.registerEvents(new QuitPlayerStats(), this);
        }
    }
    getLogger().info("Loading signs");
    SignManager.getInstance().setup();
    getLogger().info("Loading timer");
    new ParticleRender().runTaskTimer(this, 0L, 10L);
    new ScoreboardUpdater().runTaskTimer(this, 0L, SettingsManager.getInstance().getConfig().getLong("scoreboard-update-delay"));
    new StatSaveTimer().runTaskTimerAsynchronously(this, 0L, SettingsManager.getInstance().getConfig().getLong("stats.save-delay"));
    new EntityTimer().runTaskTimer(this, 0L, 20L);
    new StatSignUpdater().runTaskTimerAsynchronously(this, 0L, 1L);
    long end = System.currentTimeMillis();
    long duration = end - start;
    String time;
    if (duration < 1000) {
        time = duration + " milliseconds";
    } else if (duration < 60000) {
        time = duration / 1000.0 + " seconds";
    } else {
        time = (duration / 60000) + ":" + (duration % 60000) / 1000.0 + " minutes";
    }
    getLogger().info("BuildingGame has been enabled in " + time + '!');
}
Also used : CommandManager(com.gmail.stefvanschiedev.buildinggame.managers.commands.CommandManager) LocationManager(com.gmail.stefvanschiedev.buildinggame.managers.plots.LocationManager) EntityExplode(com.gmail.stefvanschiedev.buildinggame.events.entity.EntityExplode) Biome(org.bukkit.block.Biome) UnsavedStatsPlace(com.gmail.stefvanschiedev.buildinggame.events.stats.unsaved.UnsavedStatsPlace) CitizensAPI(net.citizensnpcs.api.CitizensAPI) PerWorldInventoryCancel(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.PerWorldInventoryCancel) EntitySpawn(com.gmail.stefvanschiedev.buildinggame.events.entity.EntitySpawn) LiquidFlow(com.gmail.stefvanschiedev.buildinggame.events.block.LiquidFlow) PlotManager(com.gmail.stefvanschiedev.buildinggame.managers.plots.PlotManager) TopStatHologram(com.gmail.stefvanschiedev.buildinggame.utils.TopStatHologram) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) ClickSpectateSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickSpectateSign) Gui(com.github.stefvanschie.inventoryframework.gui.type.util.Gui) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) JoinPlayerStats(com.gmail.stefvanschiedev.buildinggame.events.stats.database.JoinPlayerStats) EntityOptionsMenu(com.gmail.stefvanschiedev.buildinggame.events.entity.EntityOptionsMenu) ArenaMode(com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode) com.gmail.stefvanschiedev.buildinggame.events.block.signs(com.gmail.stefvanschiedev.buildinggame.events.block.signs) FirstStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.FirstStat) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Collectors(java.util.stream.Collectors) MainScoreboardJoinShow(com.gmail.stefvanschiedev.buildinggame.events.scoreboards.MainScoreboardJoinShow) ThirdStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.ThirdStat) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Contract(org.jetbrains.annotations.Contract) Stream(java.util.stream.Stream) com.gmail.stefvanschiedev.buildinggame.managers.arenas(com.gmail.stefvanschiedev.buildinggame.managers.arenas) TreeGrow(com.gmail.stefvanschiedev.buildinggame.events.structure.TreeGrow) FloorManager(com.gmail.stefvanschiedev.buildinggame.managers.plots.FloorManager) Achievement(com.gmail.stefvanschiedev.buildinggame.utils.Achievement) NotNull(org.jetbrains.annotations.NotNull) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) QuitPlayerStats(com.gmail.stefvanschiedev.buildinggame.events.stats.database.QuitPlayerStats) PlaysStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.PlaysStat) java.util(java.util) BreakStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.BreakStat) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) com.gmail.stefvanschiedev.buildinggame.events.player(com.gmail.stefvanschiedev.buildinggame.events.player) PlaceholderAPIPlaceholders(com.gmail.stefvanschiedev.buildinggame.managers.softdependencies.PlaceholderAPIPlaceholders) MetricsLite(org.bstats.bukkit.MetricsLite) BlockDispenseItem(com.gmail.stefvanschiedev.buildinggame.events.block.BlockDispenseItem) ChickenSpawnByEgg(com.gmail.stefvanschiedev.buildinggame.events.entity.ChickenSpawnByEgg) WorldEditBoundaryAssertion(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.WorldEditBoundaryAssertion) BungeeCordHandler(com.gmail.stefvanschiedev.buildinggame.utils.bungeecord.BungeeCordHandler) Interact(com.gmail.stefvanschiedev.buildinggame.events.player.voting.Interact) NPCCreate(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.NPCCreate) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) PistonBlockMove(com.gmail.stefvanschiedev.buildinggame.events.block.PistonBlockMove) ConditionFailedException(co.aikar.commands.ConditionFailedException) WorldEdit(com.sk89q.worldedit.WorldEdit) SDVault(com.gmail.stefvanschiedev.buildinggame.managers.softdependencies.SDVault) BoundaryManager(com.gmail.stefvanschiedev.buildinggame.managers.plots.BoundaryManager) BlockEdit(com.gmail.stefvanschiedev.buildinggame.events.block.BlockEdit) PlaceholderAPI(be.maximvdw.placeholderapi.PlaceholderAPI) Particle(org.bukkit.Particle) TraitInfo(net.citizensnpcs.api.trait.TraitInfo) ClickJoinSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickJoinSign) MainScoreboardWorldChange(com.gmail.stefvanschiedev.buildinggame.events.scoreboards.MainScoreboardWorldChange) PlaceholderSupplier(com.gmail.stefvanschiedev.buildinggame.utils.PlaceholderSupplier) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) com.gmail.stefvanschiedev.buildinggame.timers(com.gmail.stefvanschiedev.buildinggame.timers) PlaceStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.PlaceStat) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) DyeColor(org.bukkit.DyeColor) ClickLeaveSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickLeaveSign) SecondStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.SecondStat) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) PluginManager(org.bukkit.plugin.PluginManager) BlockDispenseItem(com.gmail.stefvanschiedev.buildinggame.events.block.BlockDispenseItem) BreakStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.BreakStat) TreeGrow(com.gmail.stefvanschiedev.buildinggame.events.structure.TreeGrow) PlaysStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.PlaysStat) JoinPlayerStats(com.gmail.stefvanschiedev.buildinggame.events.stats.database.JoinPlayerStats) Interact(com.gmail.stefvanschiedev.buildinggame.events.player.voting.Interact) Particle(org.bukkit.Particle) PluginManager(org.bukkit.plugin.PluginManager) CommandManager(com.gmail.stefvanschiedev.buildinggame.managers.commands.CommandManager) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) TraitInfo(net.citizensnpcs.api.trait.TraitInfo) EntitySpawn(com.gmail.stefvanschiedev.buildinggame.events.entity.EntitySpawn) SecondStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.SecondStat) PlaceStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.PlaceStat) TopStatHologram(com.gmail.stefvanschiedev.buildinggame.utils.TopStatHologram) ChickenSpawnByEgg(com.gmail.stefvanschiedev.buildinggame.events.entity.ChickenSpawnByEgg) DyeColor(org.bukkit.DyeColor) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ClickSpectateSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickSpectateSign) QuitPlayerStats(com.gmail.stefvanschiedev.buildinggame.events.stats.database.QuitPlayerStats) ThirdStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.ThirdStat) WorldEditBoundaryAssertion(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.WorldEditBoundaryAssertion) MainScoreboardWorldChange(com.gmail.stefvanschiedev.buildinggame.events.scoreboards.MainScoreboardWorldChange) PerWorldInventoryCancel(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.PerWorldInventoryCancel) ClickLeaveSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickLeaveSign) PlaceholderAPIPlaceholders(com.gmail.stefvanschiedev.buildinggame.managers.softdependencies.PlaceholderAPIPlaceholders) Biome(org.bukkit.block.Biome) ConditionFailedException(co.aikar.commands.ConditionFailedException) PistonBlockMove(com.gmail.stefvanschiedev.buildinggame.events.block.PistonBlockMove) ClickJoinSign(com.gmail.stefvanschiedev.buildinggame.events.player.signs.ClickJoinSign) EntityExplode(com.gmail.stefvanschiedev.buildinggame.events.entity.EntityExplode) FirstStat(com.gmail.stefvanschiedev.buildinggame.events.stats.saved.FirstStat) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) NPCCreate(com.gmail.stefvanschiedev.buildinggame.events.softdependencies.NPCCreate) EntityOptionsMenu(com.gmail.stefvanschiedev.buildinggame.events.entity.EntityOptionsMenu) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) LiquidFlow(com.gmail.stefvanschiedev.buildinggame.events.block.LiquidFlow) Material(org.bukkit.Material) PistonBlockMove(com.gmail.stefvanschiedev.buildinggame.events.block.PistonBlockMove) UnsavedStatsPlace(com.gmail.stefvanschiedev.buildinggame.events.stats.unsaved.UnsavedStatsPlace) BlockEdit(com.gmail.stefvanschiedev.buildinggame.events.block.BlockEdit) MainScoreboardJoinShow(com.gmail.stefvanschiedev.buildinggame.events.scoreboards.MainScoreboardJoinShow)

Example 10 with Arena

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

the class CommandManager method onSetBounds.

/**
 * Called whenever a player wants to set the boundary of a plot
 *
 * @param player the player
 * @param arena the arena
 * @param id the plot id to set the boundary of
 * @since 5.8.0
 */
@Subcommand("setbounds")
@Description("Set the boundary of a plot (inclusive)")
@CommandPermission("bg.setbounds")
@CommandCompletion("@arenas @nothing")
public void onSetBounds(Player player, Arena arena, int id) {
    final var plot = arena.getPlot(id);
    if (plot == null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "That's not a valid plot");
        return;
    }
    player.getInventory().setItemInMainHand(new ItemBuilder(player, Material.STICK).setDisplayName(ChatColor.LIGHT_PURPLE + "Wand").setClickEvent(new Consumer<>() {

        private Location previousLocation;

        @Override
        public void accept(PlayerInteractEvent event) {
            YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
            YamlConfiguration messages = SettingsManager.getInstance().getMessages();
            var player = event.getPlayer();
            var action = event.getAction();
            if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK)
                return;
            if (previousLocation == null) {
                previousLocation = event.getClickedBlock().getLocation();
                MessageManager.getInstance().send(player, ChatColor.GREEN + "Now click on the other corner");
            } else {
                // second time
                var location = event.getClickedBlock().getLocation();
                String name = arena.getName();
                int plotID = plot.getId();
                World world = location.getWorld();
                if (previousLocation.getWorld().equals(world)) {
                    arenas.set(name + '.' + plotID + ".high.world", world.getName());
                    arenas.set(name + '.' + plotID + ".low.world", previousLocation.getWorld().getName());
                } else {
                    MessageManager.getInstance().send(player, ChatColor.RED + "The world has to be the same");
                    event.setCancelled(true);
                    return;
                }
                int highestX = Math.max(previousLocation.getBlockX(), location.getBlockX());
                int lowestX = Math.min(previousLocation.getBlockX(), location.getBlockX());
                int highestY = Math.max(previousLocation.getBlockY(), location.getBlockY());
                int lowestY = Math.min(previousLocation.getBlockY(), location.getBlockY());
                int highestZ = Math.max(previousLocation.getBlockZ(), location.getBlockZ());
                int lowestZ = Math.min(previousLocation.getBlockZ(), location.getBlockZ());
                // x
                arenas.set(name + '.' + plotID + ".high.x", highestX);
                arenas.set(name + '.' + plotID + ".low.x", lowestX);
                // y
                arenas.set(name + '.' + plotID + ".high.y", highestY);
                arenas.set(name + '.' + plotID + ".low.y", lowestY);
                // z
                arenas.set(name + '.' + plotID + ".high.z", highestZ);
                arenas.set(name + '.' + plotID + ".low.z", lowestZ);
                SettingsManager.getInstance().save();
                String worldName = world.getName();
                Supplier<World> worldSupplier = () -> Bukkit.getWorld(worldName);
                Region region = RegionFactory.createRegion(worldSupplier, highestX, highestY, highestZ, lowestX, lowestY, lowestZ);
                plot.setBoundary(region);
                messages.getStringList("commands.setbounds.success").forEach(message -> MessageManager.getInstance().send(player, message.replace("%place%", plotID + "").replace("%arena%", name)));
                previousLocation = null;
                player.getInventory().setItemInMainHand(null);
            }
            event.setCancelled(true);
        }
    }).build());
    MessageManager.getInstance().send(player, ChatColor.GREEN + "Please click on one corner");
}
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) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) Supplier(java.util.function.Supplier) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation)

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