mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-26 02:34:42 +02:00
Construct PlayerProfiles in the database manager
- New method, DatabaseManager.loadPlayerProfile(String playerName) - PlayerProfile no longer has magic numbers that were mapped from two different sets of magic numbers, they have migrated to the DatabaseManagers where they belong - Will now be possible to convert SQL -> flatfile, once command is added
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
|
||||
public class FromFlatfileConversionTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String location = mcMMO.getUsersFilePath();
|
||||
|
||||
try {
|
||||
DatabaseManager from = DatabaseManagerFactory.createFlatfileDatabaseManager();
|
||||
DatabaseManager to = mcMMO.getDatabaseManager();
|
||||
|
||||
BufferedReader in = new BufferedReader(new FileReader(location));
|
||||
String line = "";
|
||||
int converted = 0;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
// Find if the line contains the player we want.
|
||||
String[] playerData = line.split(":");
|
||||
String playerName = playerData[0];
|
||||
PlayerProfile profile = from.loadPlayerProfile(playerName, false);
|
||||
if (profile.isLoaded()) {
|
||||
to.saveUser(profile);
|
||||
converted++;
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Database updated from users file, " + converted + " items added/updated to DB");
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?) " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user