[factions-banking] Final commit for this branch that has grown out of control. The other stuff will be added in their own respective branches
This commit is contained in:
parent
cb91f722e9
commit
e164a489b2
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType.ACCOUNT_TYPE;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatFormatting;
|
||||
@ -64,6 +65,27 @@ public final class BankManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieves balance of the default selected account should that be selected
|
||||
public void GetBalance(ServerPlayerEntity player) {
|
||||
if (playerConfigs.containsKey(player.getUuidAsString()) && !playerConfigs.get(player.getUuidAsString()).defaultSelectedAccount.isEmpty()) {
|
||||
String playerSelectedBank = GetPlayerSelectedBank(player.getUuidAsString());
|
||||
|
||||
if (!playerSelectedBank.isEmpty()) {
|
||||
IndividualBank bank = GetBankByName(playerSelectedBank);
|
||||
Optional<Integer> amount = bank.GetAccountBalance(AccountNumberGenerator.GetAccountNumberFromId(playerConfigs.get(player.getUuidAsString()).defaultSelectedAccount));
|
||||
if (amount.isPresent()) {
|
||||
player.sendMessage(Text.of(ChatMsg.ColorMsg("You have " + amount.get() + " keebucks", ChatFormatting.COLOR_CODE.GREEN)));
|
||||
} else {
|
||||
player.sendMessage(Text.of(ChatMsg.ColorMsg("It appears your default account cannot be found at this bank! Re-select your default account maybe?", ChatFormatting.COLOR_CODE.RED)));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Text.of(ChatMsg.ColorMsg("You don't have a bank selected first! To use balance you need a default bank AND account selected!", ChatFormatting.COLOR_CODE.RED)));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Text.of(ChatMsg.ColorMsg("You don't have a bank selected first! To use balance you need a default bank AND account selected!", ChatFormatting.COLOR_CODE.RED)));
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean IsDefaultAccount(String playerUuid, String globalAccountId) {
|
||||
return playerConfigs.containsKey(playerUuid) && playerConfigs.get(playerUuid).defaultSelectedAccount.equals(globalAccountId);
|
||||
}
|
||||
|
@ -166,11 +166,6 @@ public class IndividualBank {
|
||||
List<IndividualAccount> accountsFromUser = new ArrayList<IndividualAccount>();
|
||||
List<String> listOfAccounts = accounts.accountsListFromName.get(uuid);
|
||||
|
||||
System.out.println("Account list size: " + accounts.accountsList.size());
|
||||
System.out.println("GetAccountsOfUser debug");
|
||||
System.out.println("Is listOfAccounts null? " + (listOfAccounts == null));
|
||||
System.out.println("If not null, what is size? " + listOfAccounts.size());
|
||||
|
||||
if (listOfAccounts != null && !listOfAccounts.isEmpty()) {
|
||||
for (String listOfAccount : listOfAccounts) {
|
||||
accountsFromUser.add(accounts.accountsList.get(listOfAccount));
|
||||
@ -435,20 +430,14 @@ public class IndividualBank {
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn AliasAccount
|
||||
///
|
||||
/// @param[in] accountId to alias
|
||||
///
|
||||
/// @param[in] newAlias is name to give this account
|
||||
///
|
||||
/// @brief Alias an account
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void AliasAccount(String accountId, String newAlias) {
|
||||
String accountNumber = AccountNumberGenerator.GetAccountNumberFromId(accountId);
|
||||
if (accounts.accountsList.containsKey(accountNumber)) {
|
||||
accounts.accountsList.get(accountNumber).AliasAccount(newAlias);
|
||||
// The value 0 should be treated as either non-exist
|
||||
public Optional<Integer> GetAccountBalance(String accountId) {
|
||||
Optional<Integer> amount = Optional.empty();
|
||||
if (accounts.accountsList.containsKey(accountId)) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
amount = Optional.of(account.GetAccountBalance());
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -463,7 +452,7 @@ public class IndividualBank {
|
||||
public Boolean LockAccountHolder(String holderName) {
|
||||
Boolean success = false;
|
||||
|
||||
Integer accountIter = 0;
|
||||
int accountIter = 0;
|
||||
for (Entry<String, List<String>> holderAccounts : accounts.accountsListFromName.entrySet()) {
|
||||
accounts.accountsList.get(holderAccounts.getValue().get(accountIter++)).LockAccount();
|
||||
}
|
||||
|
@ -213,6 +213,11 @@ public class BankCommands {
|
||||
|
||||
bankRoot.addChild(info);
|
||||
|
||||
var balance = CommandManager.literal("balance")
|
||||
.executes(context -> GetBalance(context.getSource().getPlayer()))
|
||||
.build();
|
||||
bankRoot.addChild(balance);
|
||||
|
||||
var create = CommandManager.literal("create").build();
|
||||
var createAccount = CommandManager.literal("account").build();
|
||||
|
||||
@ -416,19 +421,6 @@ public class BankCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn IsOperator
|
||||
///
|
||||
/// @param[in] player is the player to be tested
|
||||
///
|
||||
/// @brief Check to see if player is operator (move to util in future)
|
||||
///
|
||||
/// @return True if player is operator, false if not
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public Boolean IsOperator(ServerPlayerEntity player) {
|
||||
return player.hasPermissionLevel(4);
|
||||
}
|
||||
|
||||
public int AdminSubtractMoney(ServerPlayerEntity player, Integer amount, String account, String reason) {
|
||||
AdminBalanceChange(player, account, amount, "subtract", reason);
|
||||
return 0;
|
||||
@ -464,36 +456,9 @@ public class BankCommands {
|
||||
BankManager.GetInstance().AdminChangeFunds(player, accountId, amount, type, optionalReason);
|
||||
}
|
||||
|
||||
public void AdminGetBalance(String accountId) {
|
||||
|
||||
}
|
||||
|
||||
public void AdminWireMoney(String fromAccount, String toAccount, Integer amount, String optionalReason) {
|
||||
|
||||
}
|
||||
|
||||
public void AdminCreateBank(String bankName, Integer initialBankBalance, Integer kbicInsuredAmount) {
|
||||
|
||||
}
|
||||
|
||||
public void AdminCloseBank(String bankIdentifier, String optionalReason, Boolean forceClosure) {
|
||||
|
||||
}
|
||||
|
||||
public void AdminAccounts() {
|
||||
|
||||
}
|
||||
|
||||
public void LockBank(String bankIdentifier, String optionalReason) {
|
||||
|
||||
}
|
||||
|
||||
public void LockPlayer(String playerName, String optionalReason) {
|
||||
|
||||
}
|
||||
|
||||
public void LockBankAccount(String accountId, String optionalReason) {
|
||||
|
||||
public int GetBalance(ServerPlayerEntity player) {
|
||||
BankManager.GetInstance().GetBalance(player);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -506,10 +471,8 @@ public class BankCommands {
|
||||
IndividualBank bank = BankManager.GetInstance().GetBankByName(bankName);
|
||||
|
||||
if (bank != null) {
|
||||
System.out.println("Grabbing user account information");
|
||||
List<IndividualAccount> userAccounts = bank.GetAccountsOfUser(sourcePlayer.getUuidAsString());
|
||||
sourcePlayer.sendMessage(Text.of("[BANK INFO FOR " + bankName.toUpperCase() + "]"));
|
||||
System.out.println("userAccounts size: " + userAccounts.size());
|
||||
|
||||
for (IndividualAccount userAccount : userAccounts) {
|
||||
String accountNumber = userAccount.GetAccountNumber();
|
||||
@ -594,9 +557,6 @@ public class BankCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
// REQUIRED = {}
|
||||
// OPTIONAL = [command|subcommand]
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn HelpCommand
|
||||
///
|
||||
@ -647,8 +607,6 @@ public class BankCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible args:
|
||||
// /bank create {SAVINGS/CHECKING} [optional: alias]
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn CreateAccount
|
||||
///
|
||||
@ -662,35 +620,9 @@ public class BankCommands {
|
||||
String bank = BankManager.GetInstance().GetPlayerSelectedBank(player.getUuidAsString());
|
||||
System.out.println("Received bank: " + bank);
|
||||
|
||||
if (bank != "") {
|
||||
if (!bank.isEmpty()) {
|
||||
BankManager.GetInstance().InitiateBankAccountCreation(bank, player, accountType);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths for /bank create report
|
||||
// required = {ACCOUNT ID / ALIAS} or {ALL}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn GenerateAccountReport
|
||||
///
|
||||
/// @param[in] player is player who ran command
|
||||
///
|
||||
/// @param[in] reportArgs is the argument list to be parsed
|
||||
///
|
||||
/// @brief Creates a bank account(s) report
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void GenerateAccountReport(ServerPlayerEntity player, List<String> reportArgs) {
|
||||
if (reportArgs.size() > 0) {
|
||||
String reportIdentifier = reportArgs.get(0).toLowerCase();
|
||||
|
||||
// First path is just to run a report on all accounts this player is attached to:
|
||||
if (reportIdentifier == "all") {
|
||||
/* BANKMANAGER CALL HERE. LOOP LIKELY NEEDED */
|
||||
} else {
|
||||
/* BANKMANAGER CALL HERE */
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Text.of("Unrecognized report field data. Please run /bank help report for more information"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user