Skip to content

Commit

Permalink
use UUIDs instead of Name + add a converter for it
Browse files Browse the repository at this point in the history
closes #77
  • Loading branch information
mastercake10 committed Aug 24, 2020
1 parent c10169c commit 5a4c9f5
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Plugin/src/main/java/de/Linus122/TimeIsMoney/ATM.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.TreeMap;

import static de.Linus122.TimeIsMoney.tools.Utils.CC;
Expand Down Expand Up @@ -93,6 +96,7 @@ public ATM(Main plugin) {
worths = Doubles.toArray(Main.finalconfig.getDoubleList("atm_worth_gradation"));
}


/**
* Withdraws the specified amount of money from the specified player's bank.
*
Expand Down Expand Up @@ -192,7 +196,7 @@ private static void saveBanks() {
*/
@Deprecated
private static void convertOldBank(Player p) {
String bankString = getBankString(p);
String bankString = getBankString(p, p.getWorld());
if (Main.economy.hasAccount(bankString)) {
if (Main.economy.getBalance(bankString) > 0) {
p.sendMessage(CC("&aSuccessfully converted your old TIM-Bank to new version!"));
Expand All @@ -204,17 +208,33 @@ private static void convertOldBank(Player p) {

/**
* Gets the bank string for the specified player.
* Converts old bank accounts (those saved using the user name) to new bank accounts using UUID's.
*
* @param player The player to get the bank string of.
* @param inWorld The World. Only needs to be specified when working with grouped ATM's (world-wise)
* @return The bank string of the specified player.
*/
private static String getBankString(Player player) {
return getBankString(player, player.getWorld());
private static String getBankString(OfflinePlayer player, World inWorld) {
String oldBank = getBankStringByPrefix(player.getName(), inWorld);
if(bankAccountsConfig.contains(oldBank)) {
double oldMoneyAmount = bankAccountsConfig.getDouble(oldBank);
bankAccountsConfig.set(getBankStringByPrefix(player.getUniqueId().toString(), inWorld), oldMoneyAmount);
bankAccountsConfig.set(oldBank, null);
}

return getBankStringByPrefix(player.getUniqueId().toString(), inWorld);
}

private static String getBankString(OfflinePlayer offlinePlayer, World inWorld) {
/**
* Returns the bank string of a player that is used internally for storing the money on.
*
* @param prefix The prefix to work with
* @param inWorld The World. Only needs to be specified when working with grouped ATM's (world-wise)
* @return The bank string of the specified player.
*/
private static String getBankStringByPrefix(String prefix, World inWorld) {
if (!Main.finalconfig.getBoolean("group-atms")) {
return offlinePlayer.getName() + "_TimBANK";
return prefix + "_TimBANK";
} else {
for (String key : Main.finalconfig.getConfigurationSection("atm_groups").getKeys(false)) {
List<String> list = Main.finalconfig.getStringList("atm_groups." + key);
Expand All @@ -223,7 +243,7 @@ private static String getBankString(OfflinePlayer offlinePlayer, World inWorld)
}
}
}
return offlinePlayer.getName() + "_TimBANK";
return prefix + "_TimBANK";
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down

0 comments on commit 5a4c9f5

Please sign in to comment.