Bug fix and changes #27
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.lishid.openinv;
 | 
					package com.lishid.openinv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
@@ -32,7 +33,8 @@ public class ConfigUpdater {
 | 
				
			|||||||
        if (isConfigOutdated()) {
 | 
					        if (isConfigOutdated()) {
 | 
				
			||||||
            plugin.getLogger().info("[Config] Update found! Performing update...");
 | 
					            plugin.getLogger().info("[Config] Update found! Performing update...");
 | 
				
			||||||
            performUpdate();
 | 
					            performUpdate();
 | 
				
			||||||
        } else {
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
            plugin.getLogger().info("[Config] Update not required.");
 | 
					            plugin.getLogger().info("[Config] Update not required.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -47,9 +49,19 @@ public class ConfigUpdater {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void updateConfig1To2() {
 | 
					    private void updateConfig1To2() {
 | 
				
			||||||
        // Get the old config settings
 | 
					 | 
				
			||||||
        FileConfiguration config = plugin.getConfig();
 | 
					        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);
 | 
					        int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280);
 | 
				
			||||||
        boolean checkForUpdates = config.getBoolean("CheckForUpdates", true);
 | 
					        boolean checkForUpdates = config.getBoolean("CheckForUpdates", true);
 | 
				
			||||||
        boolean notifySilentChest = config.getBoolean("NotifySilentChest", true);
 | 
					        boolean notifySilentChest = config.getBoolean("NotifySilentChest", true);
 | 
				
			||||||
@@ -73,10 +85,15 @@ public class ConfigUpdater {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Clear the old config
 | 
					        // Clear the old config
 | 
				
			||||||
        for (String key : config.getKeys(false)) {
 | 
					        for (String key : config.getKeys(false)) {
 | 
				
			||||||
            plugin.getConfig().set(key, null);
 | 
					            config.set(key, null);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set the new config options
 | 
					        // Set the new config options
 | 
				
			||||||
 | 
					        plugin.saveDefaultConfig();
 | 
				
			||||||
 | 
					        plugin.reloadConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        config = plugin.getConfig(); // Refresh the referenced config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        config.set("config-version", "2");
 | 
					        config.set("config-version", "2");
 | 
				
			||||||
        config.set("check-for-updates", checkForUpdates);
 | 
					        config.set("check-for-updates", checkForUpdates);
 | 
				
			||||||
        config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
 | 
					        config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
 | 
				
			||||||
@@ -111,7 +128,9 @@ public class ConfigUpdater {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
 | 
					        ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
 | 
				
			||||||
        Set<String> keys = section.getKeys(false);
 | 
					        Set<String> keys = section.getKeys(false);
 | 
				
			||||||
        if (keys == null || keys.isEmpty()) return null;
 | 
					        if (keys == null || keys.isEmpty()) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (String playerName : keys) {
 | 
					        for (String playerName : keys) {
 | 
				
			||||||
            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
					            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
				
			||||||
@@ -119,6 +138,9 @@ public class ConfigUpdater {
 | 
				
			|||||||
                boolean toggled = section.getBoolean(playerName + ".toggle", false);
 | 
					                boolean toggled = section.getBoolean(playerName + ".toggle", false);
 | 
				
			||||||
                toggles.put(uuid, toggled);
 | 
					                toggles.put(uuid, toggled);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                plugin.getLogger().warning("Failed to retrieve UUID of player: " + playerName);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return toggles;
 | 
					        return toggles;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -135,7 +135,7 @@ public class OpenInv extends JavaPlugin {
 | 
				
			|||||||
        String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK");
 | 
					        String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK");
 | 
				
			||||||
        Material material = Material.getMaterial(itemName);
 | 
					        Material material = Material.getMaterial(itemName);
 | 
				
			||||||
        if (material == null) {
 | 
					        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;
 | 
					            material = Material.STICK;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,7 +44,7 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
 | 
				
			|||||||
                String id = (String) jsonProfile.get("id");
 | 
					                String id = (String) jsonProfile.get("id");
 | 
				
			||||||
                String name = (String) jsonProfile.get("name");
 | 
					                String name = (String) jsonProfile.get("name");
 | 
				
			||||||
                UUID uuid = UUIDFetcher.getUUID(id);
 | 
					                UUID uuid = UUIDFetcher.getUUID(id);
 | 
				
			||||||
                uuidMap.put(name, uuid);
 | 
					                uuidMap.put(name.toLowerCase(), uuid);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (rateLimiting && i != requests - 1) {
 | 
					            if (rateLimiting && i != requests - 1) {
 | 
				
			||||||
                Thread.sleep(100L);
 | 
					                Thread.sleep(100L);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import java.util.UUID;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.apache.commons.lang.Validate;
 | 
					import org.apache.commons.lang.Validate;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class UUIDUtil {
 | 
					public class UUIDUtil {
 | 
				
			||||||
@@ -32,6 +33,7 @@ public class UUIDUtil {
 | 
				
			|||||||
        return found;
 | 
					        return found;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @SuppressWarnings("deprecation")
 | 
				
			||||||
    public static UUID getUUIDOf(String name) {
 | 
					    public static UUID getUUIDOf(String name) {
 | 
				
			||||||
        UUID uuid = null;
 | 
					        UUID uuid = null;
 | 
				
			||||||
        Player player = getPlayer(name);
 | 
					        Player player = getPlayer(name);
 | 
				
			||||||
@@ -47,11 +49,21 @@ public class UUIDUtil {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                response = fetcher.call();
 | 
					                response = fetcher.call();
 | 
				
			||||||
                uuid = response.get(name);
 | 
					                uuid = response.get(name.toLowerCase());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception e) {
 | 
					            catch (Exception e) {
 | 
				
			||||||
 | 
					                /*
 | 
				
			||||||
                Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
 | 
					                Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
 | 
				
			||||||
                e.printStackTrace();
 | 
					                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();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user