Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ProjectCranked</artifactId>
<groupId>net.crankedpvp</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Leaderboards</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>TempTournament</artifactId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>StorageUtilsShaded</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
</dependency>
<dependency>
<groupId>net.astropvp</groupId>
<artifactId>FactionsKore</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/../.lib/FactionsKore-1.3.431.jar</systemPath>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,147 @@
package net.crankedpvp.leaderboards;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.RandomUtils;
import net.crankedpvp.crankedutils.utils.SortUtils;
import net.crankedpvp.leaderboards.struct.Leaderboard;
import net.crankedpvp.leaderboards.struct.PlayerStats;
import net.crankedpvp.tournaments.CrankedTournaments;
import net.crankedpvp.tournaments.objects.TournamentPlayer;
import org.bukkit.Bukkit;
import java.text.DecimalFormat;
import java.util.*;
public class LeaderboardsAPI {
public static Map<Leaderboard, List<String>> leaderboardListMap = new HashMap<>();
private static final DecimalFormat format = new DecimalFormat("#,###");
private static final DecimalFormat decimalFormat = new DecimalFormat("#,###.#");
public static PlayerStats getPlayerStats(UUID uuid) {
return LeaderboardsPlugin.getInstance().getPlayerStatsManager().getPlayerStats(uuid);
}
public static void updateLeaderboard(Leaderboard leaderboard) {
List<String> list = new ArrayList<>();
Map<UUID, Double> map = SortUtils.sort(getUpdatedLeaderboardRankings(leaderboard));
int index = 1;
list.add("&8&m------------------");
for(Map.Entry<UUID, Double> playerDoubleEntry : map.entrySet()) {
String value = playerDoubleEntry.getValue() % 1 == 0 ? format.format(playerDoubleEntry.getValue().intValue()) : decimalFormat.format(playerDoubleEntry.getValue());
list.add("&7" + index + ". " + leaderboard.getPrimaryColor() + Bukkit.getOfflinePlayer(playerDoubleEntry.getKey()).getName() +
" &7[" + leaderboard.getSecondaryColor() + value + "&7]");
if(index++==10) break;
}
list.add("&8&m------------------");
leaderboardListMap.put(leaderboard, list);
}
public static List<String> getTopThreeAsStrings(Leaderboard leaderboard) {
List<String> list = new ArrayList<>();
Map<UUID, Double> map = SortUtils.sort(getUpdatedLeaderboardRankings(leaderboard));
int index = 1;
list.add(CC.translate(leaderboard.getSecondaryColor() + "Top 3 '" + leaderboard.getName() + "' Leaderboard"));
//list.add("&8&m------------------");
for(Map.Entry<UUID, Double> playerDoubleEntry : map.entrySet()) {
String value = playerDoubleEntry.getValue() % 1 == 0 ? format.format(playerDoubleEntry.getValue().intValue()) : decimalFormat.format(playerDoubleEntry.getValue());
list.add(" &7" + index + ". " + leaderboard.getPrimaryColor() + Bukkit.getOfflinePlayer(playerDoubleEntry.getKey()).getName() +
" &7[" + leaderboard.getSecondaryColor() + value + "&7]");
if(index++==3) break;
}
//list.add("&8&m------------------");
return list;
}
public static void updateLeaderboard(String leaderboard) {
updateLeaderboard(LeaderboardsPlugin.getInstance().getLeaderboardRegister().getLeaderboardFromID(leaderboard));
}
public static Leaderboard selectRandomLeaderboard() {
return RandomUtils.getRandomCollectionElement(LeaderboardsPlugin.getInstance().getLeaderboardRegister().getLeaderboards());
}
private static Map<UUID, Double> getUpdatedLeaderboardRankings(Leaderboard leaderboard) {
Map<UUID, Double> map = new HashMap<>();
String leaderboardId = leaderboard.getID().toLowerCase(Locale.ROOT);
for(PlayerStats playerStats : LeaderboardsPlugin.getInstance().getPlayerStatsManager().getCacheValues()) {
switch(leaderboardId) {
case "kills":
map.put(playerStats.getUuid(), (double) playerStats.getKills());
break;
case "deaths":
map.put(playerStats.getUuid(), (double) playerStats.getDeaths());
break;
case "kdr":
map.put(playerStats.getUuid(), playerStats.getKDR());
break;
case "petuses":
map.put(playerStats.getUuid(), (double) playerStats.getPetsUsed());
break;
case "staritemsapplied":
map.put(playerStats.getUuid(), (double) playerStats.getStarItemsApplied());
break;
case "bosskills":
map.put(playerStats.getUuid(), (double) playerStats.getBossKills());
break;
case "mobkills":
map.put(playerStats.getUuid(), (double) playerStats.getMobKills());
break;
case "expgained":
map.put(playerStats.getUuid(), (double) playerStats.getExpGained());
break;
case "envoysopened":
map.put(playerStats.getUuid(), (double) playerStats.getEnvoysOpened());
break;
case "averagexppermob":
map.put(playerStats.getUuid(), playerStats.getAverageXPPerMobKilled());
break;
case "coresbroken":
map.put(playerStats.getUuid(), (double) playerStats.getCoresBroken());
break;
case "shardsspent":
map.put(playerStats.getUuid(), playerStats.getShardsSpent());
break;
case "underworldmobskilled":
map.put(playerStats.getUuid(), (double) playerStats.getUnderworldMobsKilled());
break;
case "underworldessencegained":
map.put(playerStats.getUuid(), (double) playerStats.getUnderworldEssenceGained());
break;
case "underworldskipsused":
map.put(playerStats.getUuid(), (double) playerStats.getUnderworldSkipsUsed());
break;
case "tournamentkills":
map.put(playerStats.getUuid(), getTournamentStat(playerStats.getUuid(), false));
break;
case "tournamentwins":
map.put(playerStats.getUuid(), getTournamentStat(playerStats.getUuid(), true));
break;
case "cratekeysopened":
map.put(playerStats.getUuid(), (double) playerStats.getCrateKeysOpened());
break;
}
}
return map;
}
private static double getTournamentStat(UUID uuid, boolean wins) {
try {
CrankedTournaments tournaments = CrankedTournaments.getInstance();
if (tournaments == null || tournaments.getTournamentManager() == null) {
return 0;
}
TournamentPlayer player = tournaments.getTournamentManager().getFromCache(uuid.toString());
if (player == null) {
return 0;
}
return wins ? player.getTournamenWins() : player.getKills();
} catch (NoClassDefFoundError | NoSuchMethodError unavailableLegacyApi) {
// The newer CrankedTournaments plugin does not provide the legacy stats API.
return 0;
}
}
}
@@ -0,0 +1,72 @@
package net.crankedpvp.leaderboards;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import lombok.Getter;
import lombok.Setter;
import me.mattstudios.mf.base.CommandManager;
import net.crankedpvp.leaderboards.commands.LeaderboardCommand;
import net.crankedpvp.leaderboards.inventory.LeaderboardsInventory;
import net.crankedpvp.leaderboards.listeners.PlayerDeathListener;
import net.crankedpvp.leaderboards.struct.LeaderboardRegister;
import net.crankedpvp.leaderboards.struct.PlayerStatsManager;
import net.crankedpvp.leaderboards.tasks.HologramUpdateTask;
import net.crankedpvp.leaderboards.tasks.LeaderboardUpdateTask;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class LeaderboardsPlugin extends JavaPlugin {
@Getter @Setter
private LeaderboardsInventory leaderboardsInventory;
@Getter
private static LeaderboardsPlugin instance;
private CommandManager commandManager;
@Getter
private LeaderboardRegister leaderboardRegister;
@Getter
private PlayerStatsManager playerStatsManager;
@Getter
private Hologram hologram;
@Override
public void onEnable() {
instance = this;
this.commandManager = new CommandManager(this);
this.commandManager.register(new LeaderboardCommand(this));
this.leaderboardRegister = new LeaderboardRegister();
this.leaderboardRegister.initialize();
this.playerStatsManager = new PlayerStatsManager(this);
this.playerStatsManager.loadAll();
new LeaderboardUpdateTask().runTaskTimer(this, 0L, 300 * 20L);
this.hologram = HologramsAPI.createHologram(this, this.getLeaderboardRegister().getHologramLocation());
for (int i = 0; i < 12; i++) {
hologram.appendTextLine("");
}
this.registerListeners();
new HologramUpdateTask().runTaskTimer(this, 60L, 10 * 20L);
//new BroadcastRandomLeaderboardTask().runTaskTimer(this, 10 * 20L, 10 * 60 * 20L);
}
private void registerListeners() {
PluginManager pluginManager = this.getServer().getPluginManager();
pluginManager.registerEvents(new PlayerDeathListener(this), this);
}
@Override
public void onDisable() {
this.playerStatsManager.saveAll();
this.playerStatsManager = null;
}
}
@@ -0,0 +1,59 @@
package net.crankedpvp.leaderboards.commands;
import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import net.crankedpvp.leaderboards.LeaderboardsPlugin;
import net.crankedpvp.leaderboards.inventory.LeaderboardsInventory;
import net.crankedpvp.leaderboards.struct.Leaderboard;
import net.crankedpvp.leaderboards.struct.PlayerStats;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Command("leaderboard")
@Alias("leaderboards")
public class LeaderboardCommand extends CommandBase {
private final LeaderboardsPlugin plugin;
public LeaderboardCommand(LeaderboardsPlugin plugin) {
this.plugin = plugin;
}
@Default
public void defaultCommand(Player sender, @Optional Player toFind) {
if(toFind == null) {
LeaderboardsInventory leaderboardsInventory = this.plugin.getLeaderboardsInventory();
leaderboardsInventory.getUI().open(sender);
return;
}
PlayerStats playerStats = this.plugin.getPlayerStatsManager().getPlayerStats(toFind.getUniqueId());
for(String statString : playerStats.getAllStats()) {
sender.sendMessage(statString);
}
}
@SubCommand("sync")
@Permission("cranked.admin")
public void locationCommand(CommandSender commandSender) {
long millis = System.currentTimeMillis();
for(Leaderboard leaderboard : LeaderboardsPlugin.getInstance().getLeaderboardRegister().getLeaderboards()) {
LeaderboardsAPI.updateLeaderboard(leaderboard);
}
LeaderboardsPlugin.getInstance().setLeaderboardsInventory(new LeaderboardsInventory());
commandSender.sendMessage(CC.translate("&aLeaderboards synced in " + (System.currentTimeMillis() - millis) + "ms"));
}
@SubCommand("print")
@Permission("cranked.admin")
public void print(CommandSender commandSender, String leaderboardName) {
Leaderboard leaderboard = this.plugin.getLeaderboardRegister().getLeaderboardFromID(leaderboardName);
Bukkit.broadcastMessage("");
Bukkit.broadcastMessage(CC.translate(leaderboard.getSecondaryColor() + leaderboard.getName() + " Leaderboard"));
for(String string : LeaderboardsAPI.leaderboardListMap.get(leaderboard)) {
Bukkit.broadcastMessage(CC.translate(string));
}
}
}
@@ -0,0 +1,44 @@
package net.crankedpvp.leaderboards.inventory;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import net.crankedpvp.leaderboards.struct.Leaderboard;
import net.crankedpvp.leaderboards.struct.LeaderboardRegister;
import java.text.DecimalFormat;
import java.util.*;
public class LeaderboardsInventory {
private static final DecimalFormat format = new DecimalFormat("#,###");
private static final DecimalFormat decimalFormat = new DecimalFormat("#,###.#");
private final Gui leaderboardInventory;
public Gui getUI() {
return this.leaderboardInventory;
}
Collection<Leaderboard> allLeaderboards = LeaderboardRegister.getInstance().getLeaderboards();
public LeaderboardsInventory() {
this.leaderboardInventory = new Gui(3, "Leaderboards");
this.leaderboardInventory.setDefaultClickAction(event -> event.setCancelled(true));
for(Leaderboard Leaderboard : this.allLeaderboards) {
this.addLeaderboardItemToInventory(Leaderboard);
}
}
private void addLeaderboardItemToInventory(Leaderboard leaderboard) {
ItemBuilder itemBuilder = new ItemBuilder(leaderboard.getMaterial(), leaderboard.getSecondaryColor() + leaderboard.getName() + " Leaderboard");
for(String string : LeaderboardsAPI.leaderboardListMap.get(leaderboard)) {
itemBuilder.addLoreLine(string);
}
this.leaderboardInventory.addItem(new GuiItem(itemBuilder.colorize().build()));
}
}
@@ -0,0 +1,25 @@
package net.crankedpvp.leaderboards.listeners;
import net.crankedpvp.leaderboards.LeaderboardsPlugin;
import net.crankedpvp.leaderboards.struct.PlayerStats;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
public class PlayerDeathListener implements Listener {
private LeaderboardsPlugin plugin;
public PlayerDeathListener(LeaderboardsPlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void playerDeathEvent(PlayerDeathEvent event) {
if(event.getEntity() == null) return;
PlayerStats victimStats = this.plugin.getPlayerStatsManager().getPlayerStats(event.getEntity().getUniqueId());
victimStats.incrementDeaths();
if(event.getEntity().getKiller() == null) return;
PlayerStats killerStats = this.plugin.getPlayerStatsManager().getPlayerStats(event.getEntity().getKiller().getUniqueId());
killerStats.incrementKills();
}
}
@@ -0,0 +1,26 @@
package net.crankedpvp.leaderboards.struct;
import lombok.Getter;
import org.bukkit.Material;
import java.util.Locale;
@Getter
public class Leaderboard {
private final String name;
private final String primaryColor;
private final String secondaryColor;
private final Material material;
public Leaderboard(String name, String primaryColor, String secondaryColor, Material material) {
this.name = name;
this.primaryColor = primaryColor;
this.secondaryColor = secondaryColor;
this.material = material;
}
public String getID() { return this.getName().toLowerCase(Locale.ROOT).replace(" ", ""); }
}
@@ -0,0 +1,106 @@
package net.crankedpvp.leaderboards.struct;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import java.util.*;
public class LeaderboardRegister {
@Getter
private static LeaderboardRegister instance;
private final Map<String, Leaderboard> leaderboards;
@Setter
@Getter
private Location hologramLocation;
public LeaderboardRegister() {
instance = this;
this.leaderboards = new HashMap<>();
this.hologramLocation = new Location(Bukkit.getWorld("world"), -18.5, 193.8, -6.5);
}
public void initialize() {
this.registerAll(
new Leaderboard("Kills", "&2", "&a", Material.DIAMOND_SWORD),
new Leaderboard("KDR", "&3", "&b", Material.IRON_SWORD),
new Leaderboard("Deaths", "&4", "&c", Material.REDSTONE),
new Leaderboard("Envoys Opened", "&6", "&e", Material.CHEST),
new Leaderboard("Boss Kills", "&4", "&c", Material.DRAGON_EGG),
new Leaderboard("Mob Kills", "&1", "&3", Material.BLAZE_POWDER),
new Leaderboard("EXP Gained", "&6", "&e", Material.EXP_BOTTLE),
new Leaderboard("Pet Uses", "&3", "&b", Material.EGG),
new Leaderboard("Star Items Applied", "&5", "&d", Material.NETHER_STAR),
new Leaderboard("Average XP Per Mob", "&e", "&6", Material.BLAZE_ROD),
new Leaderboard("Cores Broken", "&e", "&6", Material.BEACON),
new Leaderboard("Shards Spent", "&3", "&b", Material.PRISMARINE_SHARD),
new Leaderboard("Tournament Kills", "&e", "&6", Material.STONE_SWORD),
new Leaderboard("Tournament Wins", "&4", "&c", Material.DIAMOND),
new Leaderboard("Underworld Mobs Killed", "&c", "&4", Material.EYE_OF_ENDER),
new Leaderboard("Underworld Skips Used", "&b", "&3", Material.PRISMARINE_CRYSTALS),
new Leaderboard("Crate Keys Opened", "&a", "&2", Material.TRIPWIRE_HOOK),
//new Leaderboard("Walking Distance Travelled", "&e", "&6", Material.LEATHER_BOOTS),
//new Leaderboard("Flying Distance Travelled", "&f", "&b", Material.IRON_BOOTS),
new Leaderboard("Underworld Essence Gained", "&3", "&b", Material.FEATHER)
);
}
public void registerAll(Leaderboard... leaderboards) {
for (Leaderboard leaderboard : leaderboards) {
this.register(leaderboard);
}
}
public void register(Leaderboard Leaderboard) {
try {
this.leaderboards.put(Leaderboard.getID(), Leaderboard);
} catch (Exception e) {
Bukkit.getLogger().warning("Failed to register Leaderboard " + Leaderboard.getID());
System.out.println(e.getMessage());
}
}
public void unregisterAll() {
this.leaderboards.clear();
}
public void unregister(Leaderboard Leaderboard) {
this.leaderboards.remove(Leaderboard.getID());
}
public void reload() {
this.unregisterAll();
this.initialize();
}
public boolean isLeaderboard(String name) {
return (this.getLeaderboardFromID(name) != null);
}
public Leaderboard getLeaderboardFromID(String name) {
Validate.notNull(name);
Validate.notEmpty(name);
return this.leaderboards.get(name.toLowerCase());
}
public Leaderboard getLeaderboardFromName(String name) {
Validate.notNull(name);
Validate.notEmpty(name);
name = this.getLeaderboardIDFromName(name);
return this.leaderboards.get(name.toLowerCase());
}
public String getLeaderboardIDFromName(String name) {
return name.replace(" ", "").toLowerCase(Locale.ROOT);
}
public Collection<Leaderboard> getLeaderboards() {
return Collections.unmodifiableCollection(this.leaderboards.values());
}
}
@@ -0,0 +1,151 @@
package net.crankedpvp.leaderboards.struct;
import lombok.Getter;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.storageutils.struct.NewKeyToSave;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Getter
public class PlayerStats implements NewKeyToSave<UUID> {
private UUID uuid;
private int kills;
private int deaths;
private int petsUsed;
private int starItemsApplied;
private int envoysOpened;
private int bossKills;
private long mobKills;
private long expGained;
private int coresBroken;
private double shardsSpent;
private int underworldMobsKilled;
private int underworldEssenceGained;
private int underworldSkipsUsed;
private int crateKeysOpened;
public PlayerStats(UUID uuid) {
this.uuid = uuid;
this.kills = 0;
this.deaths = 0;
this.petsUsed = 0;
this.starItemsApplied = 0;
this.envoysOpened = 0;
this.bossKills = 0;
this.mobKills = 0;
this.expGained = 0;
this.coresBroken = 0;
this.shardsSpent = 0;
this.underworldMobsKilled = 0;
this.underworldEssenceGained = 0;
this.underworldSkipsUsed = 0;
this.crateKeysOpened = 0;
}
public List<String> getAllStats() {
List<String> allStats = new ArrayList<>();
allStats.add("&6Player Stats: " + Bukkit.getOfflinePlayer(this.uuid).getName());
allStats.add("&2Kills: &7[&a" + this.kills + "&7]");
allStats.add("&4Deaths: &7[&c" + this.deaths + "&7]");
allStats.add("&3KDR: &7[&b" + this.getKDR() + "&7]");
allStats.add("&3Pets Used: &7[&b" + this.petsUsed + "&7]");
allStats.add("&5Star Items Applied: &7[&d" + this.starItemsApplied + "&7]");
allStats.add("&6Envoys Opened: &7[&e" + this.envoysOpened + "&7]");
allStats.add("&4Boss Kills: &7[&c" + this.bossKills + "&7]");
allStats.add("&1Mob Kills: &3[&a" + this.mobKills + "&7]");
allStats.add("&6EXP Gained: &7[&e" + this.expGained + "&7]");
allStats.add("&eAverage EXP Per Mob: &7[&6" + this.getAverageXPPerMobKilled() + "&7]");
allStats.add("&eCores Broken: &7[&6" + this.coresBroken + "&7]");
allStats.add("&6Shards Spent: &7[&e" + this.shardsSpent + "&7]");
allStats.add("&cUnderworld Mobs Killed: &7[&4" + this.underworldMobsKilled + "&7]");
allStats.add("&3Underworld Essence Gained: &7[&b" + this.underworldEssenceGained + "&7]");
allStats.add("&bUnderworld Skips Used: &7[&3" + this.underworldSkipsUsed + "&7]");
allStats.add("&aCrate Keys Opened: &7[&2" + this.crateKeysOpened + "&7]");
allStats.add("");
return allStats.stream().map(CC::translate).collect(Collectors.toList());
}
public double getKDR() {
if(this.deaths <= 1) return this.kills;
if(this.kills == 0) return 0.0D;
return (double) this.kills / this.deaths;
}
public double getAverageXPPerMobKilled() {
if(this.mobKills == 0 || this.expGained == 1) return 0.0D;
return (double) this.expGained / this.mobKills;
}
public void incrementKills() {
this.kills++;
}
public void incrementDeaths() {
this.deaths++;
}
public void incrementPetsUsed() {
this.petsUsed++;
}
public void incrementStarItemsApplied() {
this.starItemsApplied++;
}
public void incrementEnvoysOpened() {
this.envoysOpened++;
}
public void incrementBossKills() {
this.bossKills++;
}
public void incrementCoresBroken() {
this.coresBroken++;
}
public void incrementUnderworldSkipsUsed() {
this.underworldSkipsUsed++;
}
public void incrementUnderworldMobsKilled() {
this.underworldMobsKilled++;
}
public void addMobsKilled(int mobsKilled) {
this.mobKills = this.mobKills + mobsKilled;
}
public void addShardsSpent(double shardsSpent) {
this.shardsSpent = this.shardsSpent + shardsSpent;
}
public void addEXPGained(int expGained) {
this.expGained = this.expGained + expGained;
}
public void addUnderworldEssenceGained(int essenceGained) {
this.underworldEssenceGained = this.underworldEssenceGained + essenceGained;
}
public void addCrateKeysOpened(int crateKeysOpened) {
this.crateKeysOpened = this.crateKeysOpened + crateKeysOpened;
}
@Override
public UUID getKey() {
return uuid;
}
@Override
public void setKey(UUID uuid) {
this.uuid = uuid;
}
}
@@ -0,0 +1,32 @@
package net.crankedpvp.leaderboards.struct;
import net.crankedpvp.storageutils.StorageUtils;
import net.crankedpvp.storageutils.struct.NewSaveLoadManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
public class PlayerStatsManager extends NewSaveLoadManager<UUID, PlayerStats> {
public PlayerStatsManager(JavaPlugin plugin) {
super(plugin, StorageUtils.getInstance().getGson(), "data/", PlayerStats.class);
}
@Override
public String serialize(UUID uuid) {
return uuid.toString();
}
@Override
public UUID deserialize(String s) {
return UUID.fromString(s);
}
public PlayerStats getPlayerStats(UUID uuid) {
if (!containsKey(uuid)) {
PlayerStats playerStats = new PlayerStats(uuid);
addToCache(playerStats);
}
return getFromCache(uuid);
}
}
@@ -0,0 +1,17 @@
package net.crankedpvp.leaderboards.tasks;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
public class BroadcastRandomLeaderboardTask extends BukkitRunnable {
@Override
public void run() {
for(String topThreeAsString : LeaderboardsAPI.getTopThreeAsStrings(LeaderboardsAPI.selectRandomLeaderboard())) {
Bukkit.broadcastMessage(CC.translate(topThreeAsString));
}
}
}
@@ -0,0 +1,44 @@
package net.crankedpvp.leaderboards.tasks;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import net.crankedpvp.leaderboards.LeaderboardsPlugin;
import net.crankedpvp.leaderboards.struct.Leaderboard;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collections;
import java.util.List;
public class HologramUpdateTask extends BukkitRunnable {
private final LeaderboardsPlugin plugin = LeaderboardsPlugin.getInstance();
@Override
public void run() {
Hologram hologram = plugin.getHologram();
if (hologram == null || hologram.isDeleted() || plugin.getLeaderboardRegister().getLeaderboards().isEmpty()) {
return;
}
Leaderboard leaderboard = LeaderboardsAPI.selectRandomLeaderboard();
List<String> stringList = LeaderboardsAPI.leaderboardListMap.get(leaderboard);
if (stringList == null) {
stringList = Collections.singletonList("&7Leaderboard data is loading...");
}
int lineCount = stringList.size() + 1;
while (hologram.size() < lineCount) {
hologram.appendTextLine("");
}
while (hologram.size() > lineCount) {
hologram.removeLine(hologram.size() - 1);
}
((TextLine) hologram.getLine(0)).setText(CC.translate(leaderboard.getSecondaryColor() + "&l" + leaderboard.getName() + " Leaderboard"));
for (int i = 0; i < stringList.size(); i++) {
((TextLine) hologram.getLine(i + 1)).setText(CC.translate(stringList.get(i)));
}
}
}
@@ -0,0 +1,27 @@
package net.crankedpvp.leaderboards.tasks;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import net.crankedpvp.leaderboards.LeaderboardsPlugin;
import net.crankedpvp.leaderboards.inventory.LeaderboardsInventory;
import net.crankedpvp.leaderboards.struct.Leaderboard;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
public class LeaderboardUpdateTask extends BukkitRunnable {
@Override
public void run() {
for(Leaderboard leaderboard : LeaderboardsPlugin.getInstance().getLeaderboardRegister().getLeaderboards()) {
LeaderboardsAPI.updateLeaderboard(leaderboard);
}
this.updateInventory();
}
private void updateInventory() {
Bukkit.getLogger().info("[Leaderboard] Started updating leaderboard inventory");
LeaderboardsPlugin.getInstance().setLeaderboardsInventory(new LeaderboardsInventory());
Bukkit.getLogger().info("[Leaderboard] Finished updating leaderboard inventory");
}
}
@@ -0,0 +1,8 @@
name: CrankedLeaderboards
main: net.crankedpvp.leaderboards.LeaderboardsPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils
- CrankedTournaments