Search in sources :

Example 1 with Warlords

use of com.ebicep.warlords.Warlords in project Warlords by ebicep.

the class PlayerMessage method register.

public void register(Warlords instance) {
    instance.getCommand("msg").setExecutor(this);
    new BukkitRunnable() {

        @Override
        public void run() {
            lastPlayerMessages.entrySet().removeIf(playerMessageLongEntry -> System.currentTimeMillis() - playerMessageLongEntry.getValue() >= 300000);
        }
    }.runTaskTimer(Warlords.getInstance(), 40, 20 * 60 * 5);
}
Also used : CommandSender(org.bukkit.command.CommandSender) java.util(java.util) BaseCommand(com.ebicep.warlords.commands.BaseCommand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Warlords(com.ebicep.warlords.Warlords) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Player(org.bukkit.entity.Player) CommandExecutor(org.bukkit.command.CommandExecutor) Bukkit(org.bukkit.Bukkit) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 2 with Warlords

use of com.ebicep.warlords.Warlords in project Warlords by ebicep.

the class DatabaseManager method init.

public static void init() {
    if (!enabled) {
        NPCManager.createGameNPC();
        return;
    }
    if (!LeaderboardManager.enabled) {
        NPCManager.createGameNPC();
    }
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
    try {
        playerService = context.getBean("playerService", PlayerService.class);
        gameService = context.getBean("gameService", GameService.class);
    } catch (Exception e) {
        playerService = null;
        gameService = null;
        NPCManager.createGameNPC();
        e.printStackTrace();
        return;
    }
    try {
        System.out.println("CACHES");
        for (String cacheName : MultipleCacheResolver.playersCacheManager.getCacheNames()) {
            System.out.println(Objects.requireNonNull(((CaffeineCache) MultipleCacheResolver.playersCacheManager.getCache(cacheName)).getNativeCache()).asMap());
            Objects.requireNonNull(MultipleCacheResolver.playersCacheManager.getCache(cacheName)).clear();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Loading all online players
    Bukkit.getOnlinePlayers().forEach(player -> {
        loadPlayer(player.getUniqueId(), PlayersCollections.LIFETIME, () -> {
            updateName(player.getUniqueId());
        });
    });
    // Loading last 5 games
    Warlords.newChain().asyncFirst(() -> gameService.getLastGames(10)).syncLast((games) -> {
        previousGames.addAll(games);
        LeaderboardManager.addHologramLeaderboards(UUID.randomUUID().toString(), true);
    }).execute();
    MongoCollection<Document> resetTimings = warlordsDatabase.getCollection("Reset_Timings");
    // checking weekly date, if over 10,000 minutes (10080 == 1 week) reset weekly
    Document weeklyDocumentInfo = resetTimings.find().filter(eq("time", "weekly")).first();
    Date current = new Date();
    if (weeklyDocumentInfo != null && weeklyDocumentInfo.get("last_reset") != null) {
        Date lastReset = weeklyDocumentInfo.getDate("last_reset");
        long timeDiff = current.getTime() - lastReset.getTime();
        System.out.println("Reset Time: " + timeDiff / 60000);
        if (timeDiff > 0 && timeDiff / (1000 * 60) > 10000) {
            Warlords.newSharedChain(UUID.randomUUID().toString()).delay(// to make sure leaderboards are cached
            20 * 10).async(() -> {
                // adding new document with top weekly players
                Document topPlayers = LeaderboardManager.getTopPlayersOnLeaderboard();
                MongoCollection<Document> weeklyLeaderboards = warlordsDatabase.getCollection("Weekly_Leaderboards");
                weeklyLeaderboards.insertOne(topPlayers);
                ExperienceManager.awardWeeklyExperience(topPlayers);
                // clearing weekly
                playerService.deleteAll(PlayersCollections.WEEKLY);
                // reloading boards
                LeaderboardManager.addHologramLeaderboards(UUID.randomUUID().toString(), false);
                // updating date to current
                resetTimings.updateOne(and(eq("time", "weekly"), eq("last_reset", lastReset)), new Document("$set", new Document("time", "weekly").append("last_reset", current)));
            }).sync(() -> Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Weekly player information reset")).execute();
        }
    }
    // checking daily date, if over 1,400 minutes (1440 == 1 day) reset daily
    Document dailyDocumentInfo = resetTimings.find().filter(eq("time", "daily")).first();
    if (dailyDocumentInfo != null && dailyDocumentInfo.get("last_reset") != null) {
        Date lastReset = dailyDocumentInfo.getDate("last_reset");
        long timeDiff = current.getTime() - lastReset.getTime();
        if (timeDiff > 0 && timeDiff / (1000 * 60) > 1400) {
            Warlords.newSharedChain(UUID.randomUUID().toString()).async(() -> {
                // clearing daily
                playerService.deleteAll(PlayersCollections.DAILY);
                // updating date to current
                resetTimings.updateOne(and(eq("time", "daily"), eq("last_reset", lastReset)), new Document("$set", new Document("time", "daily").append("last_reset", current)));
            }).sync(() -> Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Daily player information reset")).execute();
        }
    }
}
Also used : PlayerService(com.ebicep.warlords.database.repositories.player.PlayerService) Document(org.bson.Document) PlayerService(com.ebicep.warlords.database.repositories.player.PlayerService) java.util(java.util) ApplicationConfiguration(com.ebicep.warlords.database.configuration.ApplicationConfiguration) MongoClient(com.mongodb.client.MongoClient) MongoCollection(com.mongodb.client.MongoCollection) URL(java.net.URL) DatabaseGameBase.previousGames(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase.previousGames) MongoDatabase(com.mongodb.client.MongoDatabase) Player(org.bukkit.entity.Player) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) JSONArray(org.json.simple.JSONArray) AtomicReference(java.util.concurrent.atomic.AtomicReference) Filters.and(com.mongodb.client.model.Filters.and) ParseException(org.json.simple.parser.ParseException) JSONValue(org.json.simple.JSONValue) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) Filters.eq(com.mongodb.client.model.Filters.eq) Bukkit(org.bukkit.Bukkit) Warlords(com.ebicep.warlords.Warlords) IOException(java.io.IOException) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) com.ebicep.warlords.player(com.ebicep.warlords.player) IOUtils(org.apache.commons.io.IOUtils) JSONObject(org.json.simple.JSONObject) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) GamesCollections(com.ebicep.warlords.database.repositories.games.GamesCollections) NPCManager(com.ebicep.customentities.npc.NPCManager) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) ChatColor(org.bukkit.ChatColor) GameService(com.ebicep.warlords.database.repositories.games.GameService) MultipleCacheResolver(com.ebicep.warlords.database.cache.MultipleCacheResolver) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) GameService(com.ebicep.warlords.database.repositories.games.GameService) Document(org.bson.Document) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException)

Example 3 with Warlords

use of com.ebicep.warlords.Warlords in project Warlords by ebicep.

the class LeaderboardManager method addHologramLeaderboards.

public static void addHologramLeaderboards(String sharedChainName, boolean init) {
    if (!Warlords.holographicDisplaysEnabled)
        return;
    if (!DatabaseManager.enabled)
        return;
    if (DatabaseManager.playerService == null || DatabaseManager.gameService == null)
        return;
    HolographicDisplaysAPI.get(Warlords.getInstance()).getHolograms().forEach(hologram -> {
        Location hologramLocation = hologram.getPosition().toLocation();
        if (!DatabaseGameBase.lastGameStatsLocation.equals(hologramLocation) && !DatabaseGameBase.topDamageLocation.equals(hologramLocation) && !DatabaseGameBase.topHealingLocation.equals(hologramLocation) && !DatabaseGameBase.topAbsorbedLocation.equals(hologramLocation) && !DatabaseGameBase.topDHPPerMinuteLocation.equals(hologramLocation) && !DatabaseGameBase.topDamageOnCarrierLocation.equals(hologramLocation) && !DatabaseGameBase.topHealingOnCarrierLocation.equals(hologramLocation)) {
            hologram.delete();
        }
    });
    putLeaderboards();
    if (enabled) {
        loaded = false;
        Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Warlords] Adding Holograms");
        // caching all sorted players for each lifetime and weekly
        AtomicInteger loadedBoards = new AtomicInteger();
        long startTime = System.nanoTime();
        for (PlayersCollections value : PlayersCollections.values()) {
            // newSharedChain(sharedChainName)
            Warlords.newChain().asyncFirst(() -> DatabaseManager.playerService.findAll(value)).syncLast((collection) -> {
                addHologramsToGameType(value, collection, leaderboardGeneral.getGeneral(), "All Modes - " + value.name);
                addHologramsToGameType(value, collection, leaderboardGeneral.getComps(), "All Modes - Comps - " + value.name);
                addHologramsToGameType(value, collection, leaderboardGeneral.getPubs(), "All Modes - Pubs - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getGeneral(), "CTF - All Queues - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getComps(), "CTF - Comps - " + value.name);
                addHologramsToGameType(value, collection, leaderboardCTF.getPubs(), "CTF - Pubs - " + value.name);
                System.out.println("Loaded " + value.name + " leaderboards");
                loadedBoards.getAndIncrement();
                if (value == PlayersCollections.SEASON_5 && init) {
                    SRCalculator.databasePlayerCache = collection;
                    SRCalculator.recalculateSR();
                }
            }).execute();
        }
        // depending on what player has selected, set visibility
        new BukkitRunnable() {

            int counter = 0;

            @Override
            public void run() {
                if (loadedBoards.get() == 5) {
                    loaded = true;
                    long endTime = System.nanoTime();
                    long timeToLoad = (endTime - startTime) / 1000000;
                    System.out.println("Time it took for LB to load (ms): " + timeToLoad);
                    LeaderboardManager.playerGameHolograms.forEach((uuid, integer) -> {
                        LeaderboardManager.playerGameHolograms.put(uuid, DatabaseGameBase.previousGames.size() - 1);
                    });
                    Bukkit.getOnlinePlayers().forEach(player -> {
                        setLeaderboardHologramVisibility(player);
                        DatabaseGameBase.setGameHologramVisibility(player);
                        Warlords.playerScoreboards.get(player.getUniqueId()).giveMainLobbyScoreboard();
                    });
                    System.out.println("Set Hologram Visibility");
                    if (init) {
                        NPCManager.createGameNPC();
                    }
                    this.cancel();
                } else if (counter++ > 2 * 300) {
                    // holograms should all load within 5 minutes or ???
                    this.cancel();
                }
            }
        }.runTaskTimer(Warlords.getInstance(), 20, 10);
    }
}
Also used : Document(org.bson.Document) java.util(java.util) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) LeaderboardCategory(com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) LeaderboardCTF(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardCTF) Location(org.bukkit.Location) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) World(org.bukkit.World) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) Bukkit(org.bukkit.Bukkit) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Warlords(com.ebicep.warlords.Warlords) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) SRCalculator(com.ebicep.warlords.sr.SRCalculator) VisibilitySettings(me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings) Collectors(java.util.stream.Collectors) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) LeaderboardGeneral(com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardGeneral) Stream(java.util.stream.Stream) NPCManager(com.ebicep.customentities.npc.NPCManager) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) ChatColor(org.bukkit.ChatColor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Example 4 with Warlords

use of com.ebicep.warlords.Warlords in project Warlords by ebicep.

the class FlagRenderer method render.

public void render() {
    if (this.lastLocation != null) {
        this.reset();
    }
    this.lastLocation = info.getFlag();
    Warlords plugin = Warlords.getInstance();
    if (this.lastLocation instanceof GroundFlagLocation || this.lastLocation instanceof SpawnFlagLocation) {
        Block block = this.lastLocation.getLocation().getBlock();
        for (int i = 0; !block.isEmpty() && block.getType() != Material.STANDING_BANNER && i < 4; i++) {
            block = block.getRelative(0, 1, 0);
        }
        if (block.isEmpty() || block.getType() == Material.STANDING_BANNER) {
            renderedBlocks.add(block);
            block.setType(Material.STANDING_BANNER);
            org.bukkit.block.Banner banner = (org.bukkit.block.Banner) block.getState();
            banner.setBaseColor(info.getTeam() == Team.BLUE ? DyeColor.BLUE : DyeColor.RED);
            banner.addPattern(new Pattern(DyeColor.BLACK, PatternType.SKULL));
            banner.addPattern(new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_TOP));
            banner.update();
            MaterialData newData = block.getState().getData();
            Vector target = this.lastLocation.getLocation().getDirection();
            Vector toTest = new Vector(0, 0, 0);
            BlockFace dir = SOUTH;
            double distance = Double.MAX_VALUE;
            for (BlockFace face : new BlockFace[] { SOUTH, SOUTH_SOUTH_WEST, SOUTH_WEST, WEST_SOUTH_WEST, WEST, WEST_NORTH_WEST, NORTH_WEST, NORTH_NORTH_WEST, NORTH, NORTH_NORTH_EAST, NORTH_EAST, EAST_NORTH_EAST, EAST, EAST_SOUTH_EAST, SOUTH_SOUTH_EAST, SOUTH_EAST }) {
                toTest.setX(face.getModX());
                toTest.setZ(face.getModZ());
                toTest.normalize();
                double newDistance = toTest.distanceSquared(target);
                if (newDistance < distance) {
                    dir = face;
                    distance = newDistance;
                }
            }
            ((Banner) newData).setFacingDirection(dir);
            block.setData(newData.getData());
        }
        ArmorStand stand = this.lastLocation.getLocation().getWorld().spawn(block.getLocation().add(.5, 0, .5), ArmorStand.class);
        renderedArmorStands.add(stand);
        stand.setGravity(false);
        stand.setCanPickupItems(false);
        stand.setCustomName(info.getTeam() == Team.BLUE ? ChatColor.BLUE + "" + ChatColor.BOLD + "BLU FLAG" : ChatColor.RED + "" + ChatColor.BOLD + "RED FLAG");
        stand.setCustomNameVisible(true);
        stand.setMetadata("INFO", new FixedMetadataValue(plugin, info));
        stand.setVisible(false);
        ArmorStand stand1 = this.lastLocation.getLocation().getWorld().spawn(block.getLocation().add(.5, -0.3, .5), ArmorStand.class);
        renderedArmorStands.add(stand1);
        stand1.setGravity(false);
        stand1.setCanPickupItems(false);
        stand1.setCustomName(ChatColor.WHITE + "" + ChatColor.BOLD + "LEFT-CLICK TO STEAL IT");
        stand1.setCustomNameVisible(true);
        stand.setMetadata("INFO", new FixedMetadataValue(plugin, info));
        stand1.setVisible(false);
    } else if (this.lastLocation instanceof PlayerFlagLocation) {
        PlayerFlagLocation flag = (PlayerFlagLocation) this.lastLocation;
        runningTasksCancel.add(flag.getPlayer().getSpeed().addSpeedModifier("FLAG", -20, 0, true));
        LivingEntity entity = ((PlayerFlagLocation) this.lastLocation).getPlayer().getEntity();
        if (entity instanceof Player) {
            Player player = (Player) entity;
            this.affectedPlayers.add(player);
            ItemStack item = new ItemStack(Material.BANNER);
            BannerMeta banner = (BannerMeta) item.getItemMeta();
            banner.setBaseColor(info.getTeam() == Team.BLUE ? DyeColor.BLUE : DyeColor.RED);
            banner.addPattern(new Pattern(DyeColor.BLACK, PatternType.SKULL));
            banner.addPattern(new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_TOP));
            item.setItemMeta(banner);
            player.getInventory().setHelmet(item);
            player.getInventory().setItem(6, new ItemBuilder(Material.BANNER, 1).name("§aDrop Flag").get());
        }
    }
}
Also used : Pattern(org.bukkit.block.banner.Pattern) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Player(org.bukkit.entity.Player) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) Banner(org.bukkit.material.Banner) BlockFace(org.bukkit.block.BlockFace) Warlords(com.ebicep.warlords.Warlords) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) LivingEntity(org.bukkit.entity.LivingEntity) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) ArmorStand(org.bukkit.entity.ArmorStand) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Aggregations

Warlords (com.ebicep.warlords.Warlords)4 Player (org.bukkit.entity.Player)4 java.util (java.util)3 Bukkit (org.bukkit.Bukkit)3 ChatColor (org.bukkit.ChatColor)3 NPCManager (com.ebicep.customentities.npc.NPCManager)2 DatabaseGameBase (com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase)2 PlayersCollections (com.ebicep.warlords.database.repositories.player.PlayersCollections)2 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)2 Document (org.bson.Document)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 BaseCommand (com.ebicep.warlords.commands.BaseCommand)1 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)1 MultipleCacheResolver (com.ebicep.warlords.database.cache.MultipleCacheResolver)1 ApplicationConfiguration (com.ebicep.warlords.database.configuration.ApplicationConfiguration)1 LeaderboardManager (com.ebicep.warlords.database.leaderboards.LeaderboardManager)1 LeaderboardCategory (com.ebicep.warlords.database.leaderboards.sections.LeaderboardCategory)1 LeaderboardCTF (com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardCTF)1 LeaderboardGeneral (com.ebicep.warlords.database.leaderboards.sections.subsections.LeaderboardGeneral)1 GameService (com.ebicep.warlords.database.repositories.games.GameService)1