More fixes and improvements
This commit is contained in:
		@@ -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<String> 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
 | 
			
		||||
                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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user