Search in sources :

Example 6 with Plot

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

Example 7 with Plot

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

the class CommandManager method onSpectate.

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

Example 8 with Plot

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

the class EntityOptionsMenu method onEntityInteract.

/**
 * Called whenever a player interacts with an entity
 *
 * @param e the event that is called when a player interacts with an entity
 * @since 5.3.0
 */
@EventHandler
public void onEntityInteract(PlayerInteractEntityEvent e) {
    SettingsManager settingsManager = SettingsManager.getInstance();
    if (e.getHand() != EquipmentSlot.HAND || !settingsManager.getConfig().getBoolean("mobs.options.enable")) {
        return;
    }
    var entity = e.getRightClicked();
    EntityType entityType = entity.getType();
    Player player = e.getPlayer();
    if (SHIFT_CLICK_TYPES.contains(entityType) && !player.isSneaking()) {
        return;
    }
    Plot plot = null;
    loop: for (var arena : ArenaManager.getInstance().getArenas()) {
        for (Plot p : arena.getUsedPlots()) {
            if (p.getEntities().containsKey(entity)) {
                plot = p;
                break loop;
            }
        }
    }
    if (plot == null || plot.getArena().getState() != GameState.BUILDING) {
        return;
    }
    switch(entityType) {
        case CHICKEN:
        case COW:
        case GOAT:
        case OCELOT:
        case SKELETON_HORSE:
        case POLAR_BEAR:
        case HUSK:
        case ZOMBIE:
        case TURTLE:
        case PIGLIN:
        case HOGLIN:
        case STRIDER:
        case ZOGLIN:
            new BabyMenu(plot, entity).show(player);
            break;
        case DONKEY:
        case MULE:
            new ChestMenu(plot, (ChestedHorse) entity).show(player);
            break;
        case VILLAGER:
        case ZOMBIE_VILLAGER:
            new VillagerlikeMenu(plot, (Creature) entity).show(player);
            break;
        case PHANTOM:
        case MAGMA_CUBE:
        case SLIME:
            new SizeMenu(plot, (Mob) entity).show(player);
            break;
        case AXOLOTL:
            new AxolotlMenu(plot, (Axolotl) entity).show(player);
            break;
        case PIG:
            new PigMenu(plot, (Pig) entity).show(player);
            break;
        case RABBIT:
            new RabbitMenu(plot, (Rabbit) entity).show(player);
            break;
        case SHEEP:
            new SheepMenu(plot, (Sheep) entity).show(player);
            break;
        case CREEPER:
            new CreeperMenu(plot, (Creeper) entity).show(player);
            break;
        case SHULKER:
            new ShulkerMenu(plot, (Shulker) entity).show(player);
            break;
        case HORSE:
            new HorseMenu(plot, (Horse) entity).show(player);
            break;
        case LLAMA:
            new LlamaMenu(plot, (Llama) entity).show(player);
            break;
        case PARROT:
            new ParrotMenu(plot, (Parrot) entity).show(player);
            break;
        case WOLF:
            new ColorMenu(plot, (Animals) entity).show(player);
            break;
        case SNOWMAN:
            new SnowGolemMenu(plot, (Snowman) entity).show(player);
            break;
        case PUFFERFISH:
            new PufferfishMenu(plot, (PufferFish) entity).show(player);
            break;
        case TROPICAL_FISH:
            new TropicalFishMenu(plot, (TropicalFish) entity).show(player);
            break;
        case MUSHROOM_COW:
            new MooshroomMenu(plot, (MushroomCow) entity).show(player);
            break;
        case PANDA:
            new PandaMenu(plot, (Panda) entity).show(player);
            break;
        case CAT:
            new CatMenu(plot, (Cat) entity).show(player);
            break;
        case FOX:
            new FoxMenu(plot, (Fox) entity).show(player);
            break;
        case BEE:
            new BeeMenu(plot, (Bee) entity).show(player);
            break;
        case IRON_GOLEM:
            new IronGolemMenu(plot, (IronGolem) entity).show(player);
            break;
        default:
            new RemoveMenu(plot, entity).show(player);
            break;
    }
    e.setCancelled(true);
}
Also used : TropicalFishMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.tropicalfish.TropicalFishMenu) LlamaMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.llama.LlamaMenu) ChestMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.ChestMenu) PufferfishMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.pufferfish.PufferfishMenu) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) BabyMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.BabyMenu) VillagerlikeMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.villagerlike.VillagerlikeMenu) ParrotMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.parrot.ParrotMenu) FoxMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.fox.FoxMenu) AxolotlMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.axolotl.AxolotlMenu) ColorMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.color.ColorMenu) RabbitMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.rabbit.RabbitMenu) IronGolemMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.irongolem.IronGolemMenu) MooshroomMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.mooshroom.MooshroomMenu) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) HorseMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.horse.HorseMenu) RemoveMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.RemoveMenu) SizeMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.size.SizeMenu) PandaMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.panda.PandaMenu) CatMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.moboptions.mobs.cat.CatMenu) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Plot

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

the class PlotManager method setup.

/**
 * Loads/Reloads all plots
 */
@SuppressWarnings("MethodMayBeStatic")
public void setup() {
    ArenaManager.getInstance().getArenas().forEach(arena -> {
        arena.getPlots().clear();
        SettingsManager.getInstance().getArenas().getConfigurationSection(arena.getName()).getKeys(false).forEach(plot -> {
            int id;
            try {
                id = Integer.parseInt(plot);
            } catch (NumberFormatException e) {
                return;
            }
            Plot p = new Plot(arena, id);
            arena.addPlot(p);
            if (SettingsManager.getInstance().getConfig().getBoolean("debug"))
                Main.getInstance().getLogger().info("Loaded plot " + p.getId() + " in arena " + arena.getName());
        });
    });
}
Also used : Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot)

Example 10 with Plot

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

the class TreeGrow method onStructureGrow.

/**
 * Handles trees growing
 *
 * @param e an event representing a structure growing
 * @see StructureGrowEvent
 * @since 2.1.0
 */
@EventHandler
public static void onStructureGrow(StructureGrowEvent e) {
    Plot plot = null;
    for (var arena : ArenaManager.getInstance().getArenas()) {
        for (Plot p : arena.getPlots()) {
            Region boundary = p.getBoundary();
            if (boundary == null)
                continue;
            if (boundary.isInside(e.getLocation())) {
                plot = p;
                break;
            }
        }
    }
    if (plot == null)
        return;
    Region boundary = plot.getBoundary();
    if (boundary == null)
        return;
    e.getBlocks().removeIf(blockState -> !boundary.isInside(blockState.getLocation()));
}
Also used : Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) 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