mirror of https://github.com/MilkBowl/Vault.git
Update Vault's convert command to support the new UUID-Name map found in
Vault 2. This fail to build until VaultAPI has updated. Pom has not been touched as of yet.
This commit is contained in:
parent
460cb21c62
commit
acc3ecfae4
|
@ -17,9 +17,14 @@ package net.milkbowl.vault;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -36,7 +41,7 @@ import net.milkbowl.vault.chat.plugins.Chat_iChat;
|
||||||
import net.milkbowl.vault.chat.plugins.Chat_mChat;
|
import net.milkbowl.vault.chat.plugins.Chat_mChat;
|
||||||
import net.milkbowl.vault.chat.plugins.Chat_mChatSuite;
|
import net.milkbowl.vault.chat.plugins.Chat_mChatSuite;
|
||||||
import net.milkbowl.vault.chat.plugins.Chat_rscPermissions;
|
import net.milkbowl.vault.chat.plugins.Chat_rscPermissions;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault2.economy.Economy;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import net.milkbowl.vault.permission.plugins.Permission_DroxPerms;
|
import net.milkbowl.vault.permission.plugins.Permission_DroxPerms;
|
||||||
import net.milkbowl.vault.permission.plugins.Permission_GroupManager;
|
import net.milkbowl.vault.permission.plugins.Permission_GroupManager;
|
||||||
|
@ -317,7 +322,7 @@ public class Vault extends JavaPlugin {
|
||||||
sender.sendMessage("You must specify only the economy to convert from and the economy to convert to. (names should not contain spaces)");
|
sender.sendMessage("You must specify only the economy to convert from and the economy to convert to. (names should not contain spaces)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Economy econ1 = null;
|
net.milkbowl.vault.economy.Economy econ1 = null;
|
||||||
Economy econ2 = null;
|
Economy econ2 = null;
|
||||||
String economies = "";
|
String economies = "";
|
||||||
for (RegisteredServiceProvider<Economy> econ : econs) {
|
for (RegisteredServiceProvider<Economy> econ : econs) {
|
||||||
|
@ -343,23 +348,36 @@ public class Vault extends JavaPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("This may take some time to convert, expect server lag.");
|
List<UUID> uuidsToImport = econ1.getUUIDMap().keySet();
|
||||||
for (OfflinePlayer op : Bukkit.getServer().getOfflinePlayers()) {
|
int accountsFound = uuidsToImport.size();
|
||||||
if (econ1.hasAccount(op)) {
|
sender.sendMessage(String.format("%s accounts have been found in %s, this may take some time to convert, server lag may occur.", accountsFound, econ1.getName());
|
||||||
if (econ2.hasAccount(op)) {
|
|
||||||
continue;
|
BigDecimal diff;
|
||||||
}
|
int numConverted = 0;
|
||||||
econ2.createPlayerAccount(op);
|
for (UUID uuid: uuidsToImport) {
|
||||||
double diff = econ1.getBalance(op) - econ2.getBalance(op);
|
// The old eco plugin doesn't actually have an account associated with the UUID, skip it.
|
||||||
if (diff > 0) {
|
if (!econ1.hasAccount(uuid)) {
|
||||||
econ2.depositPlayer(op, diff);
|
continue;
|
||||||
} else if (diff < 0) {
|
|
||||||
econ2.withdrawPlayer(op, -diff);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a new account if it doesn't exist yet.
|
||||||
|
if (!econ2.hasAccount(uuid)) {
|
||||||
|
econ2.createAccount(uuid, econ1.getAccountName(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the old eco plugin balance for the UUID and calculate how much difference
|
||||||
|
// there is between the balances.
|
||||||
|
diff = econ1.getBalance(uuid).subtract(econ2.getBalance(uuid));
|
||||||
|
if (diff.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
econ2.deposit(uuid, diff);
|
||||||
|
} else {
|
||||||
|
econ2.withdraw(uuid, diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
numConverted++;
|
||||||
}
|
}
|
||||||
sender.sendMessage("Converson complete, please verify the data before using it.");
|
sender.sendMessage(String.format("Converson complete, please verify the data before using it. %s/%s accounts found in %s were converted to %s.",
|
||||||
|
numConverted, accountsFound, econ1.getName(), econ2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void infoCommand(CommandSender sender) {
|
private void infoCommand(CommandSender sender) {
|
||||||
|
|
Loading…
Reference in New Issue