diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index b061298..e8af988 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -1,5 +1,6 @@ package com.lishid.openinv; +import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -32,7 +33,8 @@ public class ConfigUpdater { if (isConfigOutdated()) { plugin.getLogger().info("[Config] Update found! Performing update..."); performUpdate(); - } else { + } + else { plugin.getLogger().info("[Config] Update not required."); } } @@ -47,9 +49,19 @@ public class ConfigUpdater { } private void updateConfig1To2() { - // Get the old config settings FileConfiguration config = plugin.getConfig(); + // Backup the old config file + File configFile = new File(plugin.getDataFolder(), "config.yml"); + File oldConfigFile = new File(plugin.getDataFolder(), "config_old.yml"); + + configFile.renameTo(oldConfigFile); + + if (configFile.exists()) { + configFile.delete(); + } + + // Get the old config settings int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280); boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); boolean notifySilentChest = config.getBoolean("NotifySilentChest", true); @@ -73,10 +85,15 @@ public class ConfigUpdater { // Clear the old config for (String key : config.getKeys(false)) { - plugin.getConfig().set(key, null); + config.set(key, null); } // Set the new config options + plugin.saveDefaultConfig(); + plugin.reloadConfig(); + + config = plugin.getConfig(); // Refresh the referenced config + config.set("config-version", "2"); config.set("check-for-updates", checkForUpdates); config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); @@ -111,7 +128,9 @@ public class ConfigUpdater { ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName); Set keys = section.getKeys(false); - if (keys == null || keys.isEmpty()) return null; + if (keys == null || keys.isEmpty()) { + return null; + } for (String playerName : keys) { UUID uuid = UUIDUtil.getUUIDOf(playerName); @@ -119,6 +138,9 @@ public class ConfigUpdater { boolean toggled = section.getBoolean(playerName + ".toggle", false); toggles.put(uuid, toggled); } + else { + plugin.getLogger().warning("Failed to retrieve UUID of player: " + playerName); + } } return toggles; diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 22a5c77..26adac5 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -135,7 +135,7 @@ public class OpenInv extends JavaPlugin { String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK"); Material material = Material.getMaterial(itemName); if (material == null) { - mainPlugin.getLogger().info("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick."); + mainPlugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick."); material = Material.STICK; } diff --git a/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java b/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java index 11776a3..2784fb4 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java @@ -44,7 +44,7 @@ public class UUIDFetcher implements Callable> { String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); - uuidMap.put(name, uuid); + uuidMap.put(name.toLowerCase(), uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); diff --git a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java index 22e3928..ce736aa 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; public class UUIDUtil { @@ -32,6 +33,7 @@ public class UUIDUtil { return found; } + @SuppressWarnings("deprecation") public static UUID getUUIDOf(String name) { UUID uuid = null; Player player = getPlayer(name); @@ -47,11 +49,21 @@ public class UUIDUtil { try { response = fetcher.call(); - uuid = response.get(name); + uuid = response.get(name.toLowerCase()); } catch (Exception e) { + /* Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); e.printStackTrace(); + */ + Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); + // Failed to retrieve with UUIDFetcher, server might be offline? + // Fallback on searching for the player via their name + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); + + if (offlinePlayer != null) { + uuid = offlinePlayer.getUniqueId(); + } } }