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);
}
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();
}
}
}
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);
}
}
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());
}
}
}
Aggregations