public static void convert(FileConfiguration data, Logger log) { if (data.isSet("economy")) { log.info("It seems that you last ran an older version"); log.info("of CrystalQuest. CrystalQuest is now converting"); log.info("all players' economy to the new UUID format."); log.info("This could take a while... Please be patient!"); /* * CRYSTALS */ for (String playerName : data.getConfigurationSection("economy.crystals").getKeys(false)) { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(playerName)); Map<String, UUID> response = null; try { response = fetcher.call(); String uuid = response.get(playerName).toString(); data.set( "shop.crystals." + uuid + ".xp", data.getInt("economy.crystals." + playerName + ".xp")); data.set( "shop.crystals." + uuid + ".smash", data.getInt("economy.crystals." + playerName + ".smash")); data.set( "shop.crystals." + uuid + ".win", data.getInt("economy.crystals." + playerName + ".win")); data.set( "shop.crystals." + uuid + ".blood", data.getInt("economy.crystals." + playerName + ".blood")); } catch (Exception e) { log.warning("Oops could't fetch one's UUID, don't worry! The process continues!"); e.printStackTrace(); } } /* * BALANCE */ for (String playerName : data.getConfigurationSection("economy.balance").getKeys(false)) { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(playerName)); Map<String, UUID> response = null; try { response = fetcher.call(); String uuid = response.get(playerName).toString(); data.set("shop.balance." + uuid, data.getInt("economy.balance." + playerName)); } catch (Exception e) { log.warning("Oops could't fetch one's UUID, don't worry! The process continues!"); e.printStackTrace(); } } /* * UPGRADE */ for (String playerName : data.getConfigurationSection("economy.upgrade").getKeys(false)) { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(playerName)); Map<String, UUID> response = null; try { response = fetcher.call(); String uuid = response.get(playerName).toString(); data.set( "shop.upgrade." + uuid + ".buff", data.getInt("economy.upgrade." + playerName + ".buff")); data.set( "shop.upgrade." + uuid + ".debuff", data.getInt("economy.upgrade." + playerName + ".debuff")); data.set( "shop.upgrade." + uuid + ".explosive", data.getInt("economy.upgrade." + playerName + ".explosive")); data.set( "shop.upgrade." + uuid + ".weaponry", data.getInt("economy.upgrade." + playerName + ".weaponry")); data.set( "shop.upgrade." + uuid + ".creepers", data.getInt("economy.upgrade." + playerName + ".creepers")); data.set( "shop.upgrade." + uuid + ".wolf", data.getInt("economy.upgrade." + playerName + ".wolf")); } catch (Exception e) { log.warning("Oops could't fetch one's UUID, don't worry! The process continues!"); e.printStackTrace(); } } /* * CLASSES */ for (String playerName : data.getConfigurationSection("economy.classes").getKeys(false)) { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(playerName)); Map<String, UUID> response = null; try { response = fetcher.call(); String uuid = response.get(playerName).toString(); data.set("shop.classes." + uuid, data.getStringList("economy.classes." + playerName)); } catch (Exception e) { log.warning("Oops could't fetch one's UUID, don't worry! The process continues!"); e.printStackTrace(); } } data.set("economy", null); log.info("Finished converting!"); } }
public final UUID getTranslatedUuid(@NonNull String player, boolean expensiveLookups) { // If the player is online, give them their UUID. // Remember, local data > remote data. if (ProxyServer.getInstance().getPlayer(player) != null) return ProxyServer.getInstance().getPlayer(player).getUniqueId(); // Check if it exists in the map CachedUUIDEntry cachedUUIDEntry = nameToUuidMap.get(player.toLowerCase()); if (cachedUUIDEntry != null) { if (!cachedUUIDEntry.expired()) return cachedUUIDEntry.getUuid(); else nameToUuidMap.remove(player); } // Check if we can exit early if (UUID_PATTERN.matcher(player).find()) { return UUID.fromString(player); } if (MOJANGIAN_UUID_PATTERN.matcher(player).find()) { // Reconstruct the UUID return UUIDFetcher.getUUID(player); } // If we are in offline mode, UUID generation is simple. // We don't even have to cache the UUID, since this is easy to recalculate. if (!plugin.getProxy().getConfig().isOnlineMode()) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8)); } // Let's try Redis. try (Jedis jedis = plugin.getPool().getResource()) { String stored = jedis.hget("uuid-cache", player.toLowerCase()); if (stored != null) { // Found an entry value. Deserialize it. CachedUUIDEntry entry = RedisBungee.getGson().fromJson(stored, CachedUUIDEntry.class); // Check for expiry: if (entry.expired()) { jedis.hdel("uuid-cache", player.toLowerCase()); // Doesn't hurt to also remove the UUID entry as well. jedis.hdel("uuid-cache", entry.getUuid().toString()); } else { nameToUuidMap.put(player.toLowerCase(), entry); uuidToNameMap.put(entry.getUuid(), entry); return entry.getUuid(); } } // That didn't work. Let's ask Mojang. if (!expensiveLookups || !ProxyServer.getInstance().getConfig().isOnlineMode()) return null; Map<String, UUID> uuidMap1; try { uuidMap1 = new UUIDFetcher(Collections.singletonList(player)).call(); } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID from Mojang for " + player, e); return null; } for (Map.Entry<String, UUID> entry : uuidMap1.entrySet()) { if (entry.getKey().equalsIgnoreCase(player)) { persistInfo(entry.getKey(), entry.getValue(), jedis); return entry.getValue(); } } } catch (JedisException e) { plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e); } return null; // Nope, game over! }