[BANKING] Additions in banking system in order to start getting balance changes... **UNTESTED**
Some checks failed
build / build (21) (push) Has been cancelled
Some checks failed
build / build (21) (push) Has been cancelled
This commit is contained in:
parent
3abdf9b184
commit
8ece2f2d45
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
rm ~/.minecraft/mods/keeblarcraft* # What else could be named this? Really now?
|
||||
cp build/devlibs/*sources.jar ~/.minecraft/mods
|
||||
cp build/libs/keeblarcraft-0.0.1.jar ~/.minecraft/mods
|
||||
echo Moved minecraft to mods dir
|
@ -71,16 +71,34 @@ public final class BankManager {
|
||||
return bank;
|
||||
}
|
||||
|
||||
public void AdminSubtractFunds(String accountId, Integer amount) {
|
||||
// Change the funds of an account from an administrative perspective
|
||||
public void AdminChangeFunds(ServerPlayerEntity initiator, String accountId, Integer amount, String changeType, String optionalReason) {
|
||||
// Check to make sure account id exists
|
||||
Integer routingNum = AccountNumberGenerator.GetRoutingNumberFromId(accountId);
|
||||
IndividualBank bankFromRout = GetBankByRoutingNumber(routingNum);
|
||||
|
||||
// Verify bank exists
|
||||
if (bankFromRout != null) {
|
||||
// Verify account exists
|
||||
String accountNumber = AccountNumberGenerator.GetAccountNumberFromId(accountId);
|
||||
|
||||
switch (changeType) {
|
||||
case "add":
|
||||
bankFromRout.AddMoneyToAccount(accountNumber, amount);
|
||||
break;
|
||||
case "subtract":
|
||||
bankFromRout.SubtractMoneyFromAccount(accountNumber, amount);
|
||||
break;
|
||||
case "set":
|
||||
bankFromRout.SetMoneyOnAccount(accountNumber, amount);
|
||||
break;
|
||||
default:
|
||||
System.out.println("The operation that was specified by the developer does not exist. Valid operations are add/subtract/set");
|
||||
break;
|
||||
}
|
||||
|
||||
public void AdminSetFunds(String accountId, Integer amount) {
|
||||
|
||||
} else {
|
||||
initiator.sendMessage(Text.of("That bank does not exist!"));
|
||||
}
|
||||
|
||||
public void AdminAddFunds(String accountId, Integer amount) {
|
||||
|
||||
}
|
||||
|
||||
public void InitiateBankFundsTransfer(String fromAccount, String toAccount) {
|
||||
|
@ -36,7 +36,6 @@ public class IndividualAccount {
|
||||
this.accountNumberAlias = alias;
|
||||
this.accountType = accountType;
|
||||
this.bankLetterIdentifier = bankLetterIdentifier;
|
||||
|
||||
this.globalAccountNumber = bankLetterIdentifier + "-" + routingNumber + "-" + accountType + accountNumber;
|
||||
}
|
||||
|
||||
@ -51,6 +50,11 @@ public class IndividualAccount {
|
||||
}
|
||||
}
|
||||
|
||||
// May have unintended consequences if account can't go negative
|
||||
public void SetMoney(Integer amount) {
|
||||
this.accountBalance = amount;
|
||||
}
|
||||
|
||||
public void AliasAccount(String newAlias) {
|
||||
this.accountNumberAlias = newAlias;
|
||||
}
|
||||
|
@ -210,6 +210,30 @@ public class IndividualBank {
|
||||
return this.routingNumber;
|
||||
}
|
||||
|
||||
public void AddMoneyToAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
|
||||
if (account != null) {
|
||||
account.Deposit(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void SubtractMoneyFromAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
|
||||
if (account != null) {
|
||||
account.Withdraw(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMoneyOnAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
|
||||
if (account != null) {
|
||||
account.SetMoney(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean CreateAccount(String holderUuid, String holderName, String accountTypeStr) {
|
||||
Boolean success = false;
|
||||
System.out.println("Attempting to create new bank account given args UUID / NAME / TYPE : " + holderUuid + " " + holderName + " " + accountTypeStr);
|
||||
|
@ -73,6 +73,9 @@ public class BankCommands {
|
||||
("wire", "The wire command allows a player to wire money from account to account. You can use /wire like /move ('/bank help move' for more) or more primarily for wiring to any other account. " +
|
||||
"Example usage: \"/wire Notch 500 from 3181-31-3354\". Additional usage: \"/wire 9384-493-2912 400,000 from 3181-31-3354 with reason \"Groceries\"\". CRITICAL NOTE: Because of the way the banking " +
|
||||
"system has its command structure setup - you **CANNOT** use aliases in wire commands! This is because aliases are only unique per PLAYER, not across the entire server."
|
||||
),
|
||||
entry
|
||||
("accounts", "The accounts command allows you to see all of your account information at all banks if you specify nothing else. (COMING IN FUTURE: [optional: ROUT # for bank specific info])"
|
||||
)
|
||||
);
|
||||
|
||||
@ -180,6 +183,17 @@ public class BankCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// General helper parse function and throws correct error for player if fails
|
||||
public Integer ParseToInteger(ServerPlayerEntity player, String possibleInt, String helpCmd) {
|
||||
Integer amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(possibleInt);
|
||||
} catch (NumberFormatException exception) {
|
||||
HelpCommand(player, List.of(helpCmd));
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
// Possible code paths ({}=required, []=optionals, ()=explanation):
|
||||
// REQUIRED (path) = {SetBal|AddMoney|SubMoney} {LONG_ID|BANK_ID} {amount} (Depending on context, changes balance somehow from an account ID or bank)
|
||||
// REQUIRED (path) = {GetBal} {LONG_ID:BANK_ID} (Gets the balance of a bank account or bank)
|
||||
@ -193,17 +207,178 @@ public class BankCommands {
|
||||
// REQUIRED (path) = {close-bank} {BANK_ID} (Closing a bank forces a close on all accounts. Banks money is returned to server bank)
|
||||
// REQUIRED (path) = {lock-bank} {BANK_ID} (Freezes all activities through a bank)
|
||||
// REQUIRED (path) = {unlock} {BANK_ID:ACCOUNT_ID:USER} (will unlock a bank, account, or all of a users accounts)
|
||||
// REQUIRED (path) = {wire} from {ACCOUNT_ID} to {ACCOUNT_ID} (Forces a wire from one account to another. Overrides overdraft setting since it's administrative)
|
||||
// REQUIRED (path) = {wire} {amount} from {ACCOUNT_ID} to {ACCOUNT_ID} (Forces a wire from one account to another. Overrides overdraft setting since it's administrative)
|
||||
// REQUIRED (path) = {get-server-allowance} (Returns the rate of which the server adds money to itself magically & how much)
|
||||
// REQUIRED (path) = {set-server-allowance} {amount} {interval} (Sets the magic allowance rate of server & period in which it does it to add money magically to server bank)
|
||||
public void AdminCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
if (sourcePlayer.hasPermissionLevel(4)) {
|
||||
// The player must be opped & the size must be at LEAST 2 (1 keyword + extra for sublist)
|
||||
if (sourcePlayer.hasPermissionLevel(4) && argList.size() >= 2) {
|
||||
String arg = argList.get(0);
|
||||
List<String> remainingArgs = argList.subList(1, argList.size());
|
||||
switch (arg) {
|
||||
case "account":
|
||||
case "accounts":
|
||||
break;
|
||||
case "submoney":
|
||||
case "subtract-money":
|
||||
case "subtractmoney":
|
||||
case "sub-money":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "subtract", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
}
|
||||
break;
|
||||
case "addmoney":
|
||||
case "add-money":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "add", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
}
|
||||
break;
|
||||
case "setbal":
|
||||
case "set-bal":
|
||||
case "setbalance":
|
||||
case "set-balance":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "set", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
}
|
||||
break;
|
||||
case "getbal":
|
||||
case "get-bal":
|
||||
case "getbalance":
|
||||
case "get-balance":
|
||||
// Require account identifier
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-get-balance"));
|
||||
}
|
||||
break;
|
||||
case "createbank":
|
||||
case "create-bank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-create-bank"));
|
||||
}
|
||||
break;
|
||||
case "closebank":
|
||||
case "close-bank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-close-bank"));
|
||||
}
|
||||
break;
|
||||
case "forcewire":
|
||||
case "force-wire":
|
||||
case "wiremoney":
|
||||
case "wire-money":
|
||||
case "wire":
|
||||
if (remainingArgs.size() >= 3) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-force-wire"));
|
||||
}
|
||||
break;
|
||||
case "lock-bank":
|
||||
case "lockbank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-lock-bank"));
|
||||
}
|
||||
break;
|
||||
case "get-server-allowance":
|
||||
case "getserverallowance":
|
||||
sourcePlayer.sendMessage(Text.of(GetServerAllowance()));
|
||||
break;
|
||||
case "setserverallowance":
|
||||
case "set-server-allowance":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-server-allowance"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
HelpCommand(sourcePlayer, List.of("admin-commands"));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Only admins can use this command!"));
|
||||
}
|
||||
}
|
||||
|
||||
public String GetServerAllowance() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void AdminBalanceChange(ServerPlayerEntity player, String accountId, Integer amount, String type, String optionalReason) {
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
// REQUIRED = {Routing # or Bank name}
|
||||
// OPTIONAL = []
|
||||
@ -219,7 +394,7 @@ public class BankCommands {
|
||||
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() + "]------------"));
|
||||
sourcePlayer.sendMessage(Text.of("[BANK INFO FOR " + bankName.toUpperCase() + "]"));
|
||||
for (int i = 0; i < userAccounts.size(); i++) {
|
||||
sourcePlayer.sendMessage(Text.of("ACCOUNT NUMBER: " + userAccounts.get(i).GetAccountNumber()));
|
||||
sourcePlayer.sendMessage(Text.of("GLOBAL ACCOUNT NUMBER: " + userAccounts.get(i).GetGlobalAccountNumber()));
|
||||
|
Loading…
Reference in New Issue
Block a user