[BANKING] Bug fixing on account number having extra digit + formatting colors for help messages. Includes setting balances with admin command too
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
8ece2f2d45
commit
afbb2533e7
@ -77,10 +77,15 @@ public final class BankManager {
|
||||
Integer routingNum = AccountNumberGenerator.GetRoutingNumberFromId(accountId);
|
||||
IndividualBank bankFromRout = GetBankByRoutingNumber(routingNum);
|
||||
|
||||
System.out.println("Is bank null? " + (bankFromRout == null ? "YES" : "NO"));
|
||||
System.out.println("Bank specified: " + bankFromRout);
|
||||
System.out.println("Routing number: " + routingNum);
|
||||
// Verify bank exists
|
||||
if (bankFromRout != null) {
|
||||
// Verify account exists
|
||||
System.out.println("accountNumber is " + accountId);
|
||||
String accountNumber = AccountNumberGenerator.GetAccountNumberFromId(accountId);
|
||||
System.out.println("changeType is " + changeType);
|
||||
|
||||
switch (changeType) {
|
||||
case "add":
|
||||
|
@ -36,7 +36,7 @@ public class IndividualAccount {
|
||||
this.accountNumberAlias = alias;
|
||||
this.accountType = accountType;
|
||||
this.bankLetterIdentifier = bankLetterIdentifier;
|
||||
this.globalAccountNumber = bankLetterIdentifier + "-" + routingNumber + "-" + accountType + accountNumber;
|
||||
this.globalAccountNumber = bankLetterIdentifier + "-" + routingNumber + "-" + accountNumber;
|
||||
}
|
||||
|
||||
// TODO: Make this a map in the future
|
||||
@ -52,6 +52,7 @@ public class IndividualAccount {
|
||||
|
||||
// May have unintended consequences if account can't go negative
|
||||
public void SetMoney(Integer amount) {
|
||||
System.out.println("Previous balance on account: " + this.accountBalance + ". New balance: " + amount);
|
||||
this.accountBalance = amount;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,8 @@ public class IndividualBank {
|
||||
List<IndividualAccount> accountsFromUser = new ArrayList<IndividualAccount>();
|
||||
List<String> listOfAccounts = accounts.accountsListFromName.get(uuid);
|
||||
|
||||
System.out.println("Is list of accounts null? " + listOfAccounts == null);
|
||||
System.out.println("Is list of accounts null? " + (listOfAccounts == null ? "YES" : "NO"));
|
||||
System.out.println("List of account size: " + listOfAccounts.size());
|
||||
if (listOfAccounts != null && listOfAccounts.size() > 0) {
|
||||
for (int i = 0; i < listOfAccounts.size(); i++) {
|
||||
accountsFromUser.add(accounts.accountsList.get(listOfAccounts.get(i)));
|
||||
@ -180,14 +181,15 @@ public class IndividualBank {
|
||||
// NO values are allowed to be null. Manually update lists separately if that's the behaviour you want!
|
||||
public void UpdateBankAccounts(String newHolderName, String newHolderUuid, String accountIdentifier, IndividualAccount newAccountOnly) {
|
||||
// Update the fast-access map first
|
||||
if (accounts.accountsListFromName.containsKey(newHolderName)) {
|
||||
System.out.println("UpdateBankAccounts called with information " + newHolderName + " " + newHolderUuid + " " + accountIdentifier);
|
||||
if (accounts.accountsListFromName.containsKey(newHolderUuid)) {
|
||||
// Check if user is already in map
|
||||
System.out.println("User found in fast access map. Adding account identifier to fast-access map");
|
||||
accounts.accountsListFromName.get(newHolderUuid).add(accountIdentifier);
|
||||
} else {
|
||||
// Add new entry to map
|
||||
System.out.println("User not found in fast access map. Adding completely new entry");
|
||||
accounts.accountsListFromName.put(newHolderUuid, List.of(accountIdentifier));
|
||||
List<String> userAccountList = new ArrayList<String>(); // Lists are immutable; must make ArrayList
|
||||
userAccountList.add(accountIdentifier);
|
||||
accounts.accountsListFromName.put(newHolderUuid, userAccountList);
|
||||
}
|
||||
|
||||
// Update regular account list
|
||||
@ -212,26 +214,45 @@ public class IndividualBank {
|
||||
|
||||
public void AddMoneyToAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
System.out.println("Received account # " + accountId + " and money amnt " + amount);
|
||||
|
||||
if (account != null) {
|
||||
account.Deposit(amount);
|
||||
}
|
||||
|
||||
FlashConfig("bank/" + routingNumber + "/accounts");
|
||||
}
|
||||
|
||||
public void SubtractMoneyFromAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
|
||||
for (Entry<String, IndividualAccount> debug : accounts.accountsList.entrySet()) {
|
||||
System.out.println("ACCOUNT ID: " + debug.getKey());
|
||||
System.out.println("ACCOUNT NUM: " + debug.getValue().GetAccountNumber());
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
account.Withdraw(amount);
|
||||
}
|
||||
|
||||
FlashConfig("bank/" + routingNumber + "/accounts");
|
||||
}
|
||||
|
||||
public void SetMoneyOnAccount(String accountId, Integer amount) {
|
||||
IndividualAccount account = accounts.accountsList.get(accountId);
|
||||
System.out.println("Is account null? " + (account == null ? "YES" : "NO"));
|
||||
System.out.println("Received account # " + accountId + " and money amnt " + amount);
|
||||
|
||||
for (Entry<String, IndividualAccount> debug : accounts.accountsList.entrySet()) {
|
||||
System.out.println("ACCOUNT ID: " + debug.getKey());
|
||||
System.out.println("ACCOUNT NUM: " + debug.getValue().GetAccountNumber());
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
account.SetMoney(amount);
|
||||
}
|
||||
|
||||
FlashConfig("bank/" + routingNumber + "/accounts");
|
||||
}
|
||||
|
||||
public Boolean CreateAccount(String holderUuid, String holderName, String accountTypeStr) {
|
||||
|
@ -13,69 +13,181 @@ import jesse.keeblarcraft.BankMgr.BankManager;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualAccount;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualBank;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Utils.HelpBuilder;
|
||||
import jesse.keeblarcraft.Utils.HelpBuilder.COLOR_CODE;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
|
||||
public class BankCommands {
|
||||
private static List<String> FILLER_WORDS = new ArrayList<String>(List.of("of", "from", "as", "with", "name", "dubbed", "coined", "note"));
|
||||
private static String HELPCMD_HELP = "help";
|
||||
private static String HELPCMD_CREATE = "create";
|
||||
private static String HELPCMD_SELECT = "select";
|
||||
private static String HELPCMD_CLOSE = "close";
|
||||
private static String HELPCMD_REPORT = "report";
|
||||
private static String HELPCMD_BALANCE = "balance";
|
||||
private static String HELPCMD_EXAMPLES = "examples";
|
||||
private static String HELPCMD_MOVE = "move";
|
||||
private static String HELPCMD_SYNTAX = "syntax";
|
||||
private static String HELPCMD_ALIAS = "alias";
|
||||
private static String HELPCMD_WIRE = "wire";
|
||||
private static String HELPCMD_ACCOUNTS = "accounts";
|
||||
private static String HELPCMD_ADMIN_BALANCE_CHANGE = "admin-set-balance";
|
||||
private static String HELPCMD_ADMIN_BALANCE_GET = "admin-get-balance";
|
||||
private static String HELPCMD_ADMIN_CREATE_BANK = "admin-create-bank";
|
||||
private static String HELPCMD_ADMIN_CLOSE_BANK = "admin-close-bank";
|
||||
private static String HELPCMD_ADMIN_FORCE_WIRE = "admin-force-wire";
|
||||
private static String HELPCMD_ADMIN_LOCK_BANK = "admin-lock-bank";
|
||||
private static String HELPCMD_SET_SERVER_ALLOWANCE = "admin-set-server-allowance";
|
||||
private static String HELPCMD_GET_SERVER_ALLOWANCE = "admin-get-server-allowance";
|
||||
private static String HELPCMD_ADMIN_COMMANDS_LIST = "admin-commands-list";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS = "admin-accounts";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_LIST = "admin-accounts-list";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_MOVE = "admin-accounts-move";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_FORCE_CLOSE = "admin-accounts-force-close";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_ADD = "admin-accounts-add";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_TRANSACTIONS = "admin-accounts-transactions";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_LOCK = "admin-accounts-lock";
|
||||
|
||||
HelpBuilder msgFormatter = new HelpBuilder();
|
||||
|
||||
private static Map<String, String> HELP_COMMANDS = Map.ofEntries(
|
||||
entry
|
||||
("help", "This is the general help message for the bank system. For detailed help messages, please run /bank help <command OR subcommand>. List of possible " +
|
||||
(
|
||||
HELPCMD_HELP, "Usage: /bank help. This is the general help message for the bank system. For detailed help messages, please run /bank help <command OR subcommand>. List of possible " +
|
||||
"commands are: CREATE, SELECT, CLOSE, REPORT, BALANCE, EXAMPLES, WIRE, MOVE, SYNTAX, ALIAS"
|
||||
),
|
||||
entry
|
||||
(
|
||||
"create", "The create command is used for creating an account type with the bank system! You can also alias your bank account names for easier access. Example: " +
|
||||
"\"/bank create checking primary\" will create an account with a unique identifier (the checking #). HOWEVER, you can use the alias 'primary' to also refer to it in other commands!"
|
||||
HELPCMD_CREATE, "Usage: /bank create {checking|savings}. This will create a bank account with the default selected bank (/bank select {BANK_ID} to choose other)."
|
||||
),
|
||||
entry
|
||||
("select", "The SELECT command provides a powerful tool for selecting a default account that the bank system automagically does transactions out of. Whether it be wires from you " +
|
||||
"to someone else - it will use this as a default. Example usage: \"/bank select primary\" will make your account that is aliased as 'primary' your primary bank account. You can also " +
|
||||
"use the accounts unique number too. In addition to just normal usage, you can set backup accounts too that transactions will come out of should your primary account (or another backup) " +
|
||||
"reach a 0 balance. Just use \"/bank select 3181-31-3354 as backup\"."
|
||||
(
|
||||
HELPCMD_SELECT, "Usage: /bank select {BANK_ID}. Do `/bank list` for a list of banks on the server."
|
||||
),
|
||||
entry
|
||||
("close", "The CLOSE command provides the ability to close an account PROVIDING that there is a 0-balance inside that account. It is your responsibility to ensure all debts are paid " +
|
||||
"and any remaining money in the account is moved to another account. To avoid magic money vanishing, closing accounts with balances of negative or positive amounts is impossible. " +
|
||||
"Example usage: \"/bank close 3181-31-3354\""
|
||||
(
|
||||
HELPCMD_CLOSE, "Usage: /bank close {ACCOUNT_ID}. Do `/bank accounts list` to see all the accounts you have! Note: CANNOT close accounts that aren't 0 balance."
|
||||
),
|
||||
entry
|
||||
("report", "The report command provides a powerful ability of generating reports of all bank transactions and activities on one or multiple accounts at a single command-call. Example " +
|
||||
"usage: \"/bank report 3181-31-3354\" will generate a bank report of all transactions to and from this account from its creation. If you wanted to generate reports on all your accounts " +
|
||||
"at once, you would run \"/bank report all\" instead."
|
||||
(
|
||||
HELPCMD_REPORT, "Usage: /bank report [ACCOUNT_ID|none]. Optional args mean you can get a specific report list for one account; but if none specified we default to all accounts."
|
||||
),
|
||||
entry
|
||||
("balance", "The balance command is the primary way to get your bank accounts balance. If no account is specified, it will use your default account (if not set, then default is first created). " +
|
||||
"Example usages: \"/balance 3181-31-3354\". \"/balance aliased-name\"."
|
||||
(
|
||||
HELPCMD_BALANCE, "Usage: /bank balance [ACCOUNT_ID]. Optional args get balances for other accounts that aren't the default selected account. You may run `/bank accounts list` to " +
|
||||
"see all possible options to get a balance for."
|
||||
),
|
||||
entry
|
||||
("examples", "Random example commands. \"/wire Notch 900 from primary-checking\". \"/balance on secondary-savings\". \"/bank report all\". \"/bank create savings-account MyFirstSavings\". " +
|
||||
"\"/wire 3181-31-3354 8767.43 with note \"Dinner payment\"\""
|
||||
(
|
||||
HELPCMD_EXAMPLES, "Usage: /bank examples. This will print a much larger command with more thorough examples (and even shortcuts!) of all the commands from the bank system."
|
||||
),
|
||||
entry
|
||||
("move", "Move provides the ability to transfer money from one account to another without the double withdraw-then-deposit dilemma. Additionally, move lets a player move an account to a SEPARATE " +
|
||||
"bank or faction (providing these are in the game and supported). Example usage: \"/bank move 900 from savings to checking\". Or, \"/bank move 3181-31-3354 to {/FACTION_OR_BANK_IDENTIFIER}\""
|
||||
(
|
||||
HELPCMD_MOVE, "Usage: /bank move {ACCOUNT_ID} to {BANK_ID}. The intended use of this command is to move accounts across banks, but you could also plug in another ACCOUNT_ID in " +
|
||||
" the `BANK_ID` part to perform an internal wire instead. NOTE: Moving might not succeed based on bank rules!"
|
||||
),
|
||||
entry
|
||||
("syntax", "This banking system was written to be human readable in command-form and often operates like a database. You can put certain filler-words inside your commands that are " +
|
||||
(
|
||||
HELPCMD_SYNTAX, "Usage: /bank syntax. This banking system was written to be human readable in command-form and often operates like a database. You can put certain filler-words inside your commands that are " +
|
||||
"parsed out at runtime if it helps with reading. Example command: \"/bank select 942-3449-42\" will work just fine to select a bank account as a primary account. HOWEVER, you can also " +
|
||||
"type \"/bank select for-bills as default\" so long as you aliased the account identifier as 'for-bills'. Much nicer to read and work with. [Related: /bank help aliases]"
|
||||
),
|
||||
entry
|
||||
("alias", "Alias provides a way for the player to alias an existing account (or re-alias) if they did not do that at the account creation (tip, you can! run /bank help create). NOTE: Aliases " +
|
||||
"MUST be unique across ALL bank accounts a player possesses. This means even bank accounts across banks/factions. Additionally, a re-alias to an alias that already exists will fail. " +
|
||||
"Example usage: \"/bank alias 3181-31-3354 to \"for-bills\"\". More usage: \"/bank alias 'for-bills' to 'for-all-outgoing-transactions'\""
|
||||
(
|
||||
HELPCMD_ALIAS, "Usage: /bank alias {ACCOUNT_ID} {UNIQUE_NAME}. Alias provides a handy way to refer to bank accounts by their unique names instead of long-form account ids. NOTE: Aliases " +
|
||||
"are ONLY unique within the context of an individual bank and not across all banks, but generally you can replace `ACCOUNT_ID` as seen in other commands with the alias if it exists."
|
||||
),
|
||||
entry
|
||||
("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."
|
||||
(
|
||||
HELPCMD_WIRE, "Usage: /bank wire {AMOUNT} to {ACCOUNT_ID|NAME}. It is recommended to wire a specific account ID over a name since it works if the other player is offline. If name is specified, " +
|
||||
" the wire will go through to that players default account. Use with caution!"
|
||||
),
|
||||
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])"
|
||||
(
|
||||
HELPCMD_ACCOUNTS, "Usage: /bank accounts {BANK_ID}. Prints out all of your banking information at a bank assuming you have any."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_BALANCE_CHANGE, "Usage: /bank admin {set-bal|add-money|subtract-money} {ACCOUNT_ID|BANK_ID} {AMOUNT}. This command covers set/add/subtract money. Usage varies on context, but general help command is going to be " +
|
||||
"/bank admin {set-bal|add-money|sub-money} {USER_ACCOUNT_ID|BANK_ROUTING_NUM} {amount}. Please note that the \"|\" in this context means OR - you do not put both! " +
|
||||
"So you can set a banks balance or accounts balance with this command."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_BALANCE_GET, "Usage: /bank admin get {USER_ACCOUNT_ID|BANK_ID}. Please note that the \"|\" in this means OR. Do NOT put both!"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_CREATE_BANK, "Usage: /bank admin create {new bank name}. Bank name must be longer than 4 letters!"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_CLOSE_BANK, "Usage: /bank admin close {BANK_ID}. Please be aware if the bank has an active balance or user accounts you will be asked to " +
|
||||
"confirm if this is really what you want to do. Money is not magic, so if you specify to close the bank the bank balance is transferred back " +
|
||||
"to the servers primary bank account & all user accounts money are transferred to the server bank. Accounts will automatically be opened to preserve " +
|
||||
"the money for users to claim because banks are not ordinarily supposed to just close. Only run this command if you absolutely have to!"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_FORCE_WIRE, "Usage: /bank admin wire {AMOUNT} from {ACCOUNT_ID} to {ACCOUNT_ID}. Please be aware this is a heavy handed command and may " +
|
||||
"unintentionally override a bank accounts default setting. A bank account with a rule that can't go negative WILL go negative if this command is " +
|
||||
"run because it's an administrative command! Use with caution"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_LOCK_BANK, "Usage: /bank admin lock-bank {BANK_ID}. Completely freezes all activity in and out of a bank."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_SET_SERVER_ALLOWANCE, "Usage: /bank admin set-server-allowance {amount} {interval}. Example usage: /bank admin set-server-allowance 1,000,000 " +
|
||||
"30d. Supported interval characters: d/m/y (day/month/year). These times are in MINECRAFT in-game time, not real life time! Months are assumed to be equally " +
|
||||
"30 days and years are 365 days. If you need precision, just specify your amount in days!"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_GET_SERVER_ALLOWANCE, "Usage: /bank admin get-server-allowance. Returns the amount of money in the allowance for server and the interval it is in. "
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_COMMANDS_LIST, "Usage: /bank admin {sub-command} [optionals]. POSSIBLE ADMIN COMMANDS LIST: [set-bal, add-money, get-bal, sub-money, accounts, create-bank, close-bank, lock-bank, unlock, " +
|
||||
"force-wire, get-server-allowance, set-server-allowance]. Commands FROM [accounts] cmd => [list, move, force-close, add, transactions, lock]"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS, "Usage: /bank admin accounts {sub-command} [optionals]. This command has sub-commands that are expected. Possible => [list, move, force-close, add, transactions, lock]. General syntax is " +
|
||||
"/bank admin accounts [sub-command]"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_ADD, "Usage: /bank admin accounts add {ONLINE_PLAYER} [BANK_ID]. Adds a regular checking account to a bank for a player who is online. " +
|
||||
"If BANK_ID not specified; defaults to the servers default bank"
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_FORCE_CLOSE, "Usage: /bank admin accounts force-close {ACCOUNT_ID}. Command not supported in this version."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_LIST, "Usage: /bank admin accounts list {USERNAME}. Command not supported in this version."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_LOCK, "Usage: /bank admin accounts lock {ACCOUNT_ID}. Command not supported in this version."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_MOVE, "Usage: /bank admin accounts move {ACCOUNT_ID} to {BANK_ID}. Command not supported in this version."
|
||||
),
|
||||
entry
|
||||
(
|
||||
HELPCMD_ADMIN_ACCOUNTS_TRANSACTIONS, "Usage: /bank admin accounts transactions {ACCOUNT_ID}. Command not supported in this version."
|
||||
)
|
||||
);
|
||||
|
||||
@ -159,10 +271,10 @@ public class BankCommands {
|
||||
ReportCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "examples":
|
||||
HelpCommand(context.getSource().getPlayer(), List.of("examples"));
|
||||
HelpCommand(context.getSource().getPlayer(), List.of(HELPCMD_EXAMPLES));
|
||||
break;
|
||||
case "syntax":
|
||||
HelpCommand(context.getSource().getPlayer(), List.of("syntax"));
|
||||
HelpCommand(context.getSource().getPlayer(), List.of(HELPCMD_SYNTAX));
|
||||
break;
|
||||
case "list":
|
||||
ListAllBanks(context.getSource().getPlayer(), formattedArgList);
|
||||
@ -191,9 +303,22 @@ public class BankCommands {
|
||||
} catch (NumberFormatException exception) {
|
||||
HelpCommand(player, List.of(helpCmd));
|
||||
}
|
||||
|
||||
System.out.println("ParseToInteger was called. The input int was " + possibleInt + " and the parsed int is " + amount);
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Boolean IsOperator(ServerPlayerEntity player) {
|
||||
// THIS IS A HACK. REMOVE BEFORE FINAL VERSION
|
||||
//TODO: JUST RETURN HASPERMISSIONLEVEL
|
||||
return true;
|
||||
// if (player.hasPermissionLevel(4)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
// 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)
|
||||
@ -212,7 +337,9 @@ public class BankCommands {
|
||||
// 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) {
|
||||
// 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 pName = sourcePlayer.getDisplayName().toString();
|
||||
System.out.println("Is player admin? " + (IsOperator(sourcePlayer) ? "YES" : "NO"));
|
||||
if (IsOperator(sourcePlayer) && argList.size() >= 1) {
|
||||
String arg = argList.get(0);
|
||||
List<String> remainingArgs = argList.subList(1, argList.size());
|
||||
switch (arg) {
|
||||
@ -226,7 +353,7 @@ public class BankCommands {
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
@ -234,7 +361,7 @@ public class BankCommands {
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "subtract", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "addmoney":
|
||||
@ -242,7 +369,7 @@ public class BankCommands {
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
@ -250,7 +377,7 @@ public class BankCommands {
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "add", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "setbal":
|
||||
@ -260,15 +387,20 @@ public class BankCommands {
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), "admin-set-balance");
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "set", optionalReason);
|
||||
System.out.println("Running set-balance with amount " + amount);
|
||||
if (amount != 0) {
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "set", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-balance"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "getbal":
|
||||
@ -279,7 +411,7 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-get-balance"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_GET));
|
||||
}
|
||||
break;
|
||||
case "createbank":
|
||||
@ -287,7 +419,7 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-create-bank"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_CREATE_BANK));
|
||||
}
|
||||
break;
|
||||
case "closebank":
|
||||
@ -295,7 +427,7 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-close-bank"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_CLOSE_BANK));
|
||||
}
|
||||
break;
|
||||
case "forcewire":
|
||||
@ -306,7 +438,7 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 3) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-force-wire"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_FORCE_WIRE));
|
||||
}
|
||||
break;
|
||||
case "lock-bank":
|
||||
@ -314,7 +446,7 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-lock-bank"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_LOCK_BANK));
|
||||
}
|
||||
break;
|
||||
case "get-server-allowance":
|
||||
@ -326,11 +458,11 @@ public class BankCommands {
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of("admin-set-server-allowance"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_SET_SERVER_ALLOWANCE));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
HelpCommand(sourcePlayer, List.of("admin-commands"));
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_COMMANDS_LIST));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -344,6 +476,7 @@ public class BankCommands {
|
||||
}
|
||||
|
||||
public void AdminBalanceChange(ServerPlayerEntity player, String accountId, Integer amount, String type, String optionalReason) {
|
||||
System.out.println("AdminChangeFunds on account " + accountId);
|
||||
BankManager.GetInstance().AdminChangeFunds(player, accountId, amount, type, optionalReason);
|
||||
}
|
||||
|
||||
@ -391,19 +524,32 @@ public class BankCommands {
|
||||
System.out.println("Test print on memory");
|
||||
Boolean isNull = bank == null;
|
||||
System.out.println("isNull: " + isNull);
|
||||
|
||||
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 (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()));
|
||||
sourcePlayer.sendMessage(Text.of("HOLDERS: " + userAccounts.get(i).GetAccountHolders()));
|
||||
sourcePlayer.sendMessage(Text.of("BALANCE: " + userAccounts.get(i).GetAccountBalance()));
|
||||
String accountNumber = userAccounts.get(i).GetAccountNumber();
|
||||
String globalAccountNumber = userAccounts.get(i).GetGlobalAccountNumber();
|
||||
List<String> accountHolders = userAccounts.get(i).GetAccountHolders();
|
||||
Integer accountBalance = userAccounts.get(i).GetAccountBalance();
|
||||
|
||||
String l1 = "ACCOUNT NUMBER: " + msgFormatter.ColorMsg(accountNumber, COLOR_CODE.BLUE);
|
||||
String l2 = "GLOBAL ACCOUNT NUMBER: " + msgFormatter.ColorMsg(globalAccountNumber, COLOR_CODE.BLUE);
|
||||
String l3 = "HOLDERS: " + msgFormatter.ColorMsg(accountHolders, COLOR_CODE.GRAY);
|
||||
String l4 = "BALANCE: " + msgFormatter.ColorMsg(accountBalance, COLOR_CODE.GREEN);
|
||||
|
||||
sourcePlayer.sendMessage((Text) msgFormatter.MakeCopyableTxt(l1, "Click to copy", accountNumber));
|
||||
sourcePlayer.sendMessage((Text) msgFormatter.MakeCopyableTxt(l2, "Click to copy", globalAccountNumber));
|
||||
sourcePlayer.sendMessage((Text) msgFormatter.MakeCopyableTxt(l3, "Click to copy", accountHolders));
|
||||
sourcePlayer.sendMessage((Text) msgFormatter.MakeCopyableTxt(l4, "Click to copy", accountBalance));
|
||||
sourcePlayer.sendMessage(Text.of("\n"));
|
||||
}
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("That bank does not exist"));
|
||||
sourcePlayer.sendMessage(Text.of(msgFormatter.ColorMsg("That bank does not exist", COLOR_CODE.RED)));
|
||||
}
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized move command. Please use \"/bank help ACCOUNTS\" for more information."));
|
||||
@ -580,7 +726,7 @@ public class BankCommands {
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
// REQUIRED = {account id | player} {amount} [optional] NOTE: A wire CANNOT be performed on an alias; as a possible conflict can happen between player accounts since aliases are ONLY unique PER player
|
||||
// REQUIRED = {AMOUNT} {ACCOUNT_ID|PLAYER_NAME} [optional] NOTE: A wire CANNOT be performed on an alias; as a possible conflict can happen between player accounts since aliases are ONLY unique PER player
|
||||
// OPTIONAL = [account id | alias] [reason] NOTE: This is the account the wire comes from. If none selected, DEFAULT is chosen (if exists)
|
||||
public int WireCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
if (argList.size() >= 2) {
|
||||
@ -614,11 +760,13 @@ public class BankCommands {
|
||||
// OPTIONAL = [command|subcommand]
|
||||
public int HelpCommand(ServerPlayerEntity sourcePlayer, List<String> helpCommand) {
|
||||
System.out.println("Running help command");
|
||||
// TODO: Make a prettier way of printing this to the player with color
|
||||
if (helpCommand.size() == 0) {
|
||||
// General help command
|
||||
for (Entry<String, String> helpCmd : HELP_COMMANDS.entrySet()) {
|
||||
sourcePlayer.sendMessage(Text.of(helpCmd.getKey() + " --> " + helpCmd.getValue()));
|
||||
String cmd = msgFormatter.ColorMsg(helpCmd.getKey(), COLOR_CODE.GOLD);
|
||||
String details = msgFormatter.FormatMsg(helpCmd.getValue(), COLOR_CODE.BLUE, COLOR_CODE.GRAY);
|
||||
|
||||
sourcePlayer.sendMessage(Text.of(cmd + " --> " + details));
|
||||
sourcePlayer.sendMessage(Text.of("\n"));
|
||||
}
|
||||
} else {
|
||||
@ -628,7 +776,10 @@ public class BankCommands {
|
||||
String newHelpCmd = helpCommand.get(i);
|
||||
if (HELP_COMMANDS.containsKey(newHelpCmd)) {
|
||||
// Print help for this specific command
|
||||
sourcePlayer.sendMessage(Text.of(newHelpCmd + " -> " + HELP_COMMANDS.get(newHelpCmd)));
|
||||
String cmd = msgFormatter.ColorMsg(newHelpCmd, COLOR_CODE.GOLD);
|
||||
String details = msgFormatter.FormatMsg(HELP_COMMANDS.get(newHelpCmd), COLOR_CODE.BLUE, COLOR_CODE.GRAY);
|
||||
|
||||
sourcePlayer.sendMessage(Text.of(cmd + " -> " + details));
|
||||
} else {
|
||||
// Add to unknown list at end
|
||||
unknownCmds.add(newHelpCmd);
|
||||
@ -637,7 +788,8 @@ public class BankCommands {
|
||||
|
||||
// After all prints have finished tell the player the commands they plugged in that we did not recognize
|
||||
if (unknownCmds.size() > 0) {
|
||||
sourcePlayer.sendMessage(Text.of("The following commands do not exist or were mispelt: " + unknownCmds));
|
||||
String msg = msgFormatter.ColorMsg("The following commands do not exist or were mispelt: ", COLOR_CODE.RED);
|
||||
sourcePlayer.sendMessage(Text.of(msg + unknownCmds));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
114
src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java
Normal file
114
src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java
Normal file
@ -0,0 +1,114 @@
|
||||
package jesse.keeblarcraft.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.HoverEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class HelpBuilder {
|
||||
private String COLOR_START = "§";
|
||||
private String COLOR_END = "§f";
|
||||
public enum COLOR_CODE {
|
||||
BLUE,
|
||||
GRAY,
|
||||
GOLD,
|
||||
RED,
|
||||
GREEN
|
||||
}
|
||||
|
||||
private String getColor(COLOR_CODE code) {
|
||||
String colorStr = COLOR_START;
|
||||
switch(code) {
|
||||
case BLUE:
|
||||
return colorStr + "9";
|
||||
case GRAY:
|
||||
return colorStr + "7";
|
||||
case GOLD:
|
||||
return colorStr + "6";
|
||||
case RED:
|
||||
return colorStr + "4";
|
||||
case GREEN:
|
||||
return colorStr + "2";
|
||||
}
|
||||
|
||||
// If this code is reachable, then someone has not properly handled the above switch-case
|
||||
return colorStr;
|
||||
}
|
||||
|
||||
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, Integer copyStr) {
|
||||
return MakeCopyableTxt(terminalTxt, hoverTxt, Integer.toString(copyStr));
|
||||
}
|
||||
|
||||
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, List<String> expandedList) {
|
||||
String expanded = "[";
|
||||
int index = 0;
|
||||
for (String str : expandedList) {
|
||||
expanded += str;
|
||||
|
||||
// Add delimiter if next index is not at size
|
||||
if (++index < expandedList.size()) {
|
||||
expanded += ",";
|
||||
}
|
||||
}
|
||||
|
||||
expanded += "]";
|
||||
|
||||
return MakeCopyableTxt(terminalTxt, hoverTxt, expanded);
|
||||
}
|
||||
|
||||
public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, String copyStr) {
|
||||
Text copyableText = Text.of(terminalTxt);
|
||||
MutableText testTxt = (MutableText) copyableText;
|
||||
System.out.println("Making hoverable stuff");
|
||||
testTxt.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, copyStr))
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of(hoverTxt))));
|
||||
System.out.println("Done making hoverable stuff");
|
||||
|
||||
System.out.println("Value of copyAbleText: " + copyableText.getString());
|
||||
System.out.println("Value of testTxt: " + testTxt.getString());
|
||||
|
||||
return testTxt;
|
||||
}
|
||||
|
||||
public String ColorMsg(Integer msg, COLOR_CODE color) {
|
||||
return getColor(color) + msg + COLOR_END;
|
||||
}
|
||||
|
||||
public List<String> ColorMsg(List<String> msg, COLOR_CODE color) {
|
||||
List<String> retList = new ArrayList<String>();
|
||||
|
||||
for (String str : msg) {
|
||||
retList.add(getColor(color) + str + COLOR_END);
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
public String ColorMsg(String msg, COLOR_CODE color) {
|
||||
return getColor(color) + msg + COLOR_END;
|
||||
}
|
||||
|
||||
// Parses a help command and color codes it. assume everything up to first '.' is the
|
||||
// help cmd usage and color it with primaryColor. secondaryColor applied to rest
|
||||
public String FormatMsg(String helpCmd, COLOR_CODE primaryColor, COLOR_CODE secondaryColor) {
|
||||
String coloredStr = getColor(primaryColor);
|
||||
List<String> splitStr = List.of(helpCmd.split("\\."));
|
||||
|
||||
Boolean isFirst = true;
|
||||
for (String str : splitStr) {
|
||||
if (isFirst) {
|
||||
coloredStr += str;
|
||||
isFirst = false;
|
||||
coloredStr += getColor(secondaryColor);
|
||||
} else {
|
||||
coloredStr += str;
|
||||
}
|
||||
}
|
||||
|
||||
return coloredStr + COLOR_END;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user