Remove UUID lib dependency. Will resolve #317
This commit is contained in:
@@ -5,24 +5,16 @@ import com.drtshock.playervaults.converters.BackpackConverter;
|
||||
import com.drtshock.playervaults.converters.Converter;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
||||
import com.turt2live.uuid.CachingServiceProvider;
|
||||
import com.turt2live.uuid.ServiceProvider;
|
||||
import com.turt2live.uuid.turt2live.v2.ApiV2Service;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ConvertCommand implements CommandExecutor {
|
||||
|
||||
private final List<Converter> converters = new ArrayList<>();
|
||||
private ServiceProvider uuidProvider;
|
||||
|
||||
public ConvertCommand() {
|
||||
converters.add(new BackpackConverter());
|
||||
@@ -56,27 +48,15 @@ public class ConvertCommand implements CommandExecutor {
|
||||
PlayerVaults.getInstance().getServer().getScheduler().runTaskLaterAsynchronously(PlayerVaults.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (uuidProvider == null) {
|
||||
CachingServiceProvider cachingUuidProvider = new CachingServiceProvider(new ApiV2Service());
|
||||
Map<UUID, String> seed = new HashMap<>();
|
||||
|
||||
for (OfflinePlayer player : PlayerVaults.getInstance().getServer().getOfflinePlayers()) {
|
||||
if (player.hasPlayedBefore()) {
|
||||
seed.put(player.getUniqueId(), player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
cachingUuidProvider.seedLoad(seed, 6 * 60 * 60); // 6 hour cache time
|
||||
uuidProvider = cachingUuidProvider;
|
||||
}
|
||||
|
||||
int converted = 0;
|
||||
VaultOperations.setLocked(true);
|
||||
|
||||
for (Converter converter : applicableConverters) {
|
||||
if (converter.canConvert()) {
|
||||
converted += converter.run(sender, uuidProvider);
|
||||
converted += converter.run(sender);
|
||||
}
|
||||
}
|
||||
|
||||
VaultOperations.setLocked(false);
|
||||
sender.sendMessage(Lang.TITLE + Lang.CONVERT_COMPLETE.toString().replace("%converted", converted + ""));
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.drtshock.playervaults.converters;
|
||||
|
||||
import com.drtshock.playervaults.PlayerVaults;
|
||||
import com.drtshock.playervaults.vaultmanagement.VaultManager;
|
||||
import com.turt2live.uuid.PlayerRecord;
|
||||
import com.turt2live.uuid.ServiceProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -22,10 +22,7 @@ import java.util.UUID;
|
||||
public class BackpackConverter implements Converter {
|
||||
|
||||
@Override
|
||||
public int run(CommandSender initiator, ServiceProvider uuidProvider) {
|
||||
if (uuidProvider == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
public int run(CommandSender initiator) {
|
||||
|
||||
PlayerVaults plugin = PlayerVaults.getInstance();
|
||||
File destination = new File(plugin.getDataFolder().getParentFile(), "Backpack" + File.separator + "backpacks");
|
||||
@@ -39,7 +36,7 @@ public class BackpackConverter implements Converter {
|
||||
int vaultNum = 1;
|
||||
for (File file : worldDirs != null ? worldDirs : new File[0]) {
|
||||
if (file.isDirectory()) {
|
||||
converted += convert(file, vaultNum, uuidProvider);
|
||||
converted += convert(file, vaultNum);
|
||||
vaultNum++;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +44,7 @@ public class BackpackConverter implements Converter {
|
||||
return converted;
|
||||
}
|
||||
|
||||
private int convert(File worldFolder, int intoVaultNum, ServiceProvider uuidProvider) {
|
||||
private int convert(File worldFolder, int intoVaultNum) {
|
||||
PlayerVaults plugin = PlayerVaults.getInstance();
|
||||
VaultManager vaults = VaultManager.getInstance();
|
||||
int converted = 0;
|
||||
@@ -56,11 +53,11 @@ public class BackpackConverter implements Converter {
|
||||
for (File file : files != null ? files : new File[0]) {
|
||||
if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
|
||||
try {
|
||||
PlayerRecord player = uuidProvider.doLookup(file.getName().substring(0, file.getName().lastIndexOf('.')));
|
||||
if (player == null || player.getUuid() == null) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().substring(0, file.getName().lastIndexOf('.')));
|
||||
if (player == null || player.getUniqueId() == null) {
|
||||
plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName()));
|
||||
} else {
|
||||
UUID uuid = player.getUuid();
|
||||
UUID uuid = player.getUniqueId();
|
||||
FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
|
||||
ConfigurationSection section = yaml.getConfigurationSection("backpack");
|
||||
if (section.getKeys(false).size() <= 0) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.drtshock.playervaults.converters;
|
||||
|
||||
import com.turt2live.uuid.ServiceProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
@@ -14,11 +13,10 @@ public interface Converter {
|
||||
* Converts the other plugin's data.
|
||||
*
|
||||
* @param initiator the initiator of the conversion. May be null
|
||||
* @param uuidProvider the UUID provider to use, cannot be null
|
||||
*
|
||||
* @return the number of vaults converted. Returns 0 on none converted or -1 if no vaults were converted.
|
||||
*/
|
||||
int run(CommandSender initiator, ServiceProvider uuidProvider);
|
||||
int run(CommandSender initiator);
|
||||
|
||||
/**
|
||||
* Determines if this converter is applicable for converting to PlayerVaults. This may check for the existance of a
|
||||
|
||||
Reference in New Issue
Block a user