use of me.filoghost.holographicdisplays.api.beta.hologram.Hologram in project Warlords by ebicep.
the class Warlords method onDisable.
@Override
public void onDisable() {
if (BotManager.task != null) {
BotManager.task.cancel();
}
try {
// Pre-caution
for (Player player : Bukkit.getOnlinePlayers()) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
player.getActivePotionEffects().clear();
player.removeMetadata("WARLORDS_PLAYER", this);
PacketUtils.sendTitle(player, "", "", 0, 0, 0);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
CraftServer server = (CraftServer) Bukkit.getServer();
server.getEntityMetadata().invalidateAll(this);
server.getWorldMetadata().invalidateAll(this);
server.getPlayerMetadata().invalidateAll(this);
} catch (Exception e) {
e.printStackTrace();
}
try {
gameManager.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
if (holographicDisplaysEnabled) {
HolographicDisplaysAPI.get(instance).getHolograms().forEach(Hologram::delete);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
NPCManager.gameStartNPC.destroy();
} catch (Exception e) {
e.printStackTrace();
}
try {
Bukkit.getWorld("MainLobby").getEntities().stream().filter(entity -> entity.getName().equals("capture-the-flag")).forEach(Entity::remove);
} catch (Exception e) {
e.printStackTrace();
}
try {
BotManager.deleteStatusMessage();
BotManager.jda.shutdownNow();
} catch (Exception e) {
e.printStackTrace();
}
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[Warlords] Plugin is disabled");
// TODO persist this.playerSettings to a database
}
use of me.filoghost.holographicdisplays.api.beta.hologram.Hologram 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 me.filoghost.holographicdisplays.api.beta.hologram.Hologram in project Warlords by ebicep.
the class LeaderboardManager method createSwitchHologram.
private static Hologram createSwitchHologram(Player player, Location location) {
Hologram switchHologram = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(location);
switchHologram.getLines().appendText(ChatColor.AQUA.toString() + ChatColor.UNDERLINE + "Click to Toggle");
switchHologram.getLines().appendText("");
return switchHologram;
}
use of me.filoghost.holographicdisplays.api.beta.hologram.Hologram in project Warlords by ebicep.
the class DatabaseGameCTF method createHolograms.
@Override
public void createHolograms() {
List<Hologram> holograms = new ArrayList<>();
// readding game holograms
Hologram lastGameStats = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.lastGameStatsLocation);
holograms.add(lastGameStats);
lastGameStats.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Last " + (isPrivate() ? "Comp" : "Pub") + " Game Stats");
Hologram topDamage = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topDamageLocation);
holograms.add(topDamage);
topDamage.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top Damage");
Hologram topHealing = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topHealingLocation);
holograms.add(topHealing);
topHealing.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top Healing");
Hologram topAbsorbed = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topAbsorbedLocation);
holograms.add(topAbsorbed);
topAbsorbed.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top Absorbed");
Hologram topDHPPerMinute = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topDHPPerMinuteLocation);
holograms.add(topDHPPerMinute);
topDHPPerMinute.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top DHP per Minute");
Hologram topDamageOnCarrier = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topDamageOnCarrierLocation);
holograms.add(topDamageOnCarrier);
topDamageOnCarrier.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top Damage On Carrier");
Hologram topHealingOnCarrier = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.topHealingOnCarrierLocation);
holograms.add(topHealingOnCarrier);
topHealingOnCarrier.getLines().appendText(ChatColor.AQUA + ChatColor.BOLD.toString() + "Top Healing On Carrier");
// last game stats
int minutes = (15 - (int) Math.round(timeLeft / 60.0)) == 0 ? 1 : 15 - (int) Math.round(timeLeft / 60.0);
lastGameStats.getLines().appendText(ChatColor.GRAY + date);
lastGameStats.getLines().appendText(ChatColor.GREEN + map.getMapName() + ChatColor.GRAY + " - " + ChatColor.GREEN + timeLeft / 60 + ":" + timeLeft % 60 + (timeLeft % 60 < 10 ? "0" : ""));
lastGameStats.getLines().appendText(ChatColor.BLUE.toString() + bluePoints + ChatColor.GRAY + " - " + ChatColor.RED + redPoints);
List<DatabaseGamePlayersCTF.DatabaseGamePlayerCTF> bluePlayers = players.blue;
List<DatabaseGamePlayersCTF.DatabaseGamePlayerCTF> redPlayers = players.red;
List<DatabaseGamePlayersCTF.DatabaseGamePlayerCTF> allPlayers = new ArrayList<>();
allPlayers.addAll(bluePlayers);
allPlayers.addAll(redPlayers);
List<String> players = new ArrayList<>();
for (String s : Utils.specsOrdered) {
StringBuilder playerSpecs = new StringBuilder(ChatColor.AQUA + s).append(": ");
final boolean[] add = { false };
allPlayers.stream().filter(o -> o.getSpec().name.equalsIgnoreCase(s)).forEach(p -> {
playerSpecs.append(bluePlayers.contains(p) ? ChatColor.BLUE : ChatColor.RED).append(p.getName()).append(p.getKDAString()).append(ChatColor.GRAY).append(", ");
add[0] = true;
});
if (add[0]) {
playerSpecs.setLength(playerSpecs.length() - 2);
players.add(playerSpecs.toString());
}
}
players.forEach(s -> lastGameStats.getLines().appendText(s));
// top dmg/healing/absorbed + dhp per game + dmg/heal on carrier
List<String> topDamagePlayers = new ArrayList<>();
List<String> topHealingPlayers = new ArrayList<>();
List<String> topAbsorbedPlayers = new ArrayList<>();
List<String> topDHPPerGamePlayers = new ArrayList<>();
List<String> topDamageOnCarrierPlayers = new ArrayList<>();
List<String> topHealingOnCarrierPlayers = new ArrayList<>();
Map<ChatColor, Long> totalDamage = new HashMap<>();
Map<ChatColor, Long> totalHealing = new HashMap<>();
Map<ChatColor, Long> totalAbsorbed = new HashMap<>();
allPlayers.stream().sorted(Comparator.comparingLong(DatabaseGamePlayersCTF.DatabaseGamePlayerCTF::getTotalDamage).reversed()).forEach(databaseGamePlayer -> {
totalDamage.put(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, totalDamage.getOrDefault(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, 0L) + databaseGamePlayer.getTotalDamage());
topDamagePlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalDamage()));
});
allPlayers.stream().sorted(Comparator.comparingLong(DatabaseGamePlayersCTF.DatabaseGamePlayerCTF::getTotalHealing).reversed()).forEach(databaseGamePlayer -> {
totalHealing.put(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, totalHealing.getOrDefault(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, 0L) + databaseGamePlayer.getTotalHealing());
topHealingPlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalHealing()));
});
allPlayers.stream().sorted(Comparator.comparingLong(DatabaseGamePlayersCTF.DatabaseGamePlayerCTF::getTotalAbsorbed).reversed()).forEach(databaseGamePlayer -> {
totalAbsorbed.put(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, totalAbsorbed.getOrDefault(bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED, 0L) + databaseGamePlayer.getTotalAbsorbed());
topAbsorbedPlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalAbsorbed()));
});
allPlayers.stream().sorted((o1, o2) -> {
Long p1DHPPerGame = o1.getTotalDHP() / minutes;
Long p2DHPPerGame = o2.getTotalDHP() / minutes;
return p2DHPPerGame.compareTo(p1DHPPerGame);
}).forEach(databaseGamePlayer -> {
topDHPPerGamePlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalDHP() / minutes));
});
allPlayers.stream().sorted(Comparator.comparingLong(DatabaseGamePlayersCTF.DatabaseGamePlayerCTF::getTotalDamageOnCarrier).reversed()).forEach(databaseGamePlayer -> {
topDamageOnCarrierPlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalDamageOnCarrier()));
});
allPlayers.stream().sorted(Comparator.comparingLong(DatabaseGamePlayersCTF.DatabaseGamePlayerCTF::getTotalHealingOnCarrier).reversed()).forEach(databaseGamePlayer -> {
topHealingOnCarrierPlayers.add((bluePlayers.contains(databaseGamePlayer) ? ChatColor.BLUE : ChatColor.RED) + databaseGamePlayer.getName() + ": " + ChatColor.YELLOW + NumberFormat.addCommaAndRound(databaseGamePlayer.getTotalHealingOnCarrier()));
});
appendTeamDHP(topDamage, totalDamage);
appendTeamDHP(topHealing, totalHealing);
appendTeamDHP(topAbsorbed, totalAbsorbed);
topDamagePlayers.forEach(s -> topDamage.getLines().appendText(s));
topHealingPlayers.forEach(s -> topHealing.getLines().appendText(s));
topAbsorbedPlayers.forEach(s -> topAbsorbed.getLines().appendText(s));
topDHPPerGamePlayers.forEach(s -> topDHPPerMinute.getLines().appendText(s));
topDamageOnCarrierPlayers.forEach(s -> topDamageOnCarrier.getLines().appendText(s));
topHealingOnCarrierPlayers.forEach(s -> topHealingOnCarrier.getLines().appendText(s));
// setting visibility to none
holograms.forEach(hologram -> {
hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN);
});
this.holograms = holograms;
}
use of me.filoghost.holographicdisplays.api.beta.hologram.Hologram in project Warlords by ebicep.
the class LeaderboardManager method addPlayerPositionLeaderboards.
public static void addPlayerPositionLeaderboards(Player player) {
if (!Warlords.holographicDisplaysEnabled)
return;
if (enabled) {
// leaderboards
removeLeaderboardPlayerSpecificHolograms(player);
PlayersCollections selectedTime = playerLeaderboardTime.get(player.getUniqueId());
LeaderboardCategory<?> leaderboardCategory = getLeaderboardCategoryFromPlayer(player);
if (leaderboardCategory == null)
return;
List<Hologram> playerHolograms = new ArrayList<>();
for (Leaderboard leaderboard : leaderboardCategory.leaderboards) {
Location location = leaderboard.getLocation().clone().add(0, -3.5, 0);
Hologram hologram = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(location);
List<DatabasePlayer> databasePlayers;
switch(selectedTime) {
case LIFETIME:
databasePlayers = leaderboard.getSortedAllTime();
break;
case SEASON_5:
databasePlayers = leaderboard.getSortedSeason5();
break;
case SEASON_4:
databasePlayers = leaderboard.getSortedSeason4();
break;
case WEEKLY:
databasePlayers = leaderboard.getSortedWeekly();
break;
case DAILY:
databasePlayers = leaderboard.getSortedDaily();
break;
default:
return;
}
for (int i = 0; i < databasePlayers.size(); i++) {
DatabasePlayer databasePlayer = databasePlayers.get(i);
if (databasePlayer.getUuid().equals(player.getUniqueId().toString())) {
hologram.getLines().appendText(ChatColor.YELLOW.toString() + ChatColor.BOLD + (i + 1) + ". " + ChatColor.DARK_AQUA + ChatColor.BOLD + databasePlayer.getName() + ChatColor.GRAY + ChatColor.BOLD + " - " + ChatColor.YELLOW + ChatColor.BOLD + leaderboard.getStringFunction().apply(databasePlayer));
break;
}
}
hologram.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN);
hologram.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE);
playerHolograms.add(hologram);
}
playerSpecificHolograms.put(player.getUniqueId(), playerHolograms);
}
}
Aggregations