Search in sources :

Example 1 with SettingsManager

use of com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager 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 2 with SettingsManager

use of com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager 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)

Aggregations

SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)2 Plot (com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot)2 Main (com.gmail.stefvanschiedev.buildinggame.Main)1 ArenaJoinEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent)1 ArenaLeaveEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent)1 ArenaStartEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent)1 ArenaStopEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent)1 ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)1 SignManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager)1 MainSpawnManager (com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager)1 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)1 MainScoreboardManager (com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager)1 BuildTimer (com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)1 LobbyTimer (com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer)1 VoteTimer (com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer)1 WinTimer (com.gmail.stefvanschiedev.buildinggame.timers.WinTimer)1 Timer (com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer)1 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)1 GamePlayer (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)1 GamePlayerType (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType)1