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 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 getLeaderboards() { return Collections.unmodifiableCollection(this.leaderboards.values()); } }