From cb9c3c124e79424d1134b6147ca7d2f9eb98f006 Mon Sep 17 00:00:00 2001 From: Jkibbels Date: Fri, 6 Dec 2024 02:04:09 -0500 Subject: [PATCH] [DEV] Comment updates on everything done over the past 6 weeks --- .../27b8b1d6af601e15f202616061490ff2b85aa40c | 2 +- .../BankMgr/AccountNumberGenerator.java | 65 ++++- .../keeblarcraft/BankMgr/BankManager.java | 81 +++++- .../BankMgr/IndividualAccount.java | 100 +++++++- .../keeblarcraft/BankMgr/IndividualBank.java | 190 +++++++++++++- .../keeblarcraft/Commands/BankCommands.java | 164 +++++++++++- .../Commands/FactionCommands.java | 43 +++- .../keeblarcraft/ConfigMgr/ConfigManager.java | 38 ++- .../keeblarcraft/ConfigMgr/GeneralConfig.java | 53 +++- .../EventMgr/DimensionLoadingEvent.java | 52 ++-- .../EventMgr/PlayerJoinListener.java | 24 +- .../FactionMgr/FactionConfig.java | 235 +++++++++++++++++- .../FactionMgr/FactionManager.java | 69 ++++- .../jesse/keeblarcraft/Utils/ChatUtil.java | 5 - .../keeblarcraft/Utils/DirectionalVec.java | 7 + .../jesse/keeblarcraft/Utils/HelpBuilder.java | 109 +++++++- 16 files changed, 1170 insertions(+), 67 deletions(-) diff --git a/src/main/generated/.cache/27b8b1d6af601e15f202616061490ff2b85aa40c b/src/main/generated/.cache/27b8b1d6af601e15f202616061490ff2b85aa40c index c8f8a34..0a694d0 100644 --- a/src/main/generated/.cache/27b8b1d6af601e15f202616061490ff2b85aa40c +++ b/src/main/generated/.cache/27b8b1d6af601e15f202616061490ff2b85aa40c @@ -1,3 +1,3 @@ -// 1.20 2024-12-05T19:59:23.022622275 keeblarcraft/Keeblarcraft World Generation +// 1.20 2024-12-05T22:38:15.935314478 keeblarcraft/Keeblarcraft World Generation afc3340283d1101601bd4d2ca96341a58eceaf83 data/keeblarcraft/dimension_type/keeblarcraftdim_type.json 4398eda2b0c28b2c754c45f5805534bf1921b243 data/keeblarcraft/worldgen/biome/test_biome.json diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/AccountNumberGenerator.java b/src/main/java/jesse/keeblarcraft/BankMgr/AccountNumberGenerator.java index fcd8187..968217c 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/AccountNumberGenerator.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/AccountNumberGenerator.java @@ -24,9 +24,29 @@ import java.util.Random; note for now. It is probably best to keep this consistent in your server/mod so tellers can understand them universally. */ +///////////////////////////////////////////////////////////////////////////// +/// @class AccountNumberGenerator +/// +/// @brief Utility class for the banking system. Can generate new account +/// numbers based on parameters and parse the account number +///////////////////////////////////////////////////////////////////////////// public class AccountNumberGenerator { - // Callers of this function are required to verify the given number is unique. + ///////////////////////////////////////////////////////////////////////////// + /// @fn AccountNumberGenerator + /// + /// @param[in] symbol is the bank/finance institution symbol + /// + /// @param[in] routingNumber is the bank routing number + /// + /// @param[in] accountType is the type of account being generated + /// + /// @param[in] username is the players username who needs the account + /// + /// @brief Creates a new account number for a user + /// + /// @return String representation of account number + ///////////////////////////////////////////////////////////////////////////// public static String GenerateNewAccountNumber(String symbol, Integer routingNumber, Integer accountType, String username) { String generatedAccountNumber = symbol + "-" + routingNumber + "-" + accountType; @@ -59,18 +79,61 @@ public class AccountNumberGenerator { // the below functions must be given a key generated from the above function or they will combust into // not less than one million pieces! :) + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetFinancialSymbolFromId + /// + /// @param[in] accountId is the generated account number + /// + /// @brief Gets the financial symbol from the account id + /// + /// @return String representation of financial symbol + ///////////////////////////////////////////////////////////////////////////// public static String GetFinancialSymbolFromId(String accountId) { return accountId.substring(0, 4); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetRoutingNumberFromId + /// + /// @param[in] accountId is the generated account number + /// + /// @brief Gets the routing number from the account id + /// + /// @return Returns the integer of the account number + ///////////////////////////////////////////////////////////////////////////// public static Integer GetRoutingNumberFromId(String accountId) { return Integer.parseInt(accountId.substring(5, 9)); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountNumberFromId + /// + /// @param[in] accountId is the generated account number + /// + /// @brief Gets the smaller account identifier from the entire account + /// identifier. This would be the ACCOUNT TYPE + GENERATED NUMBER + /// on the end of the whole identifier (so no financial symbol and + /// no routing number) + /// + /// @return String representation of small account number + ///////////////////////////////////////////////////////////////////////////// public static String GetAccountNumberFromId(String accountId) { return accountId.substring(10); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountTypeFromId + /// + /// @param[in] accountId is the generated account number + /// + /// @brief Gets the account type from account ID + /// + /// @note The string representation of a valid account ID will have + /// '0' - '9' (range) in this position; so, subtracting 48 from + /// the ASCII returns the actual account number as an integer. + /// + /// @return Integer representing account type (0-9) + ///////////////////////////////////////////////////////////////////////////// public static Integer GetAccountTypeFromId(String accountId) { return ((int) accountId.charAt(10)) - 48; // ASCII 0 starts at 48. One must subtract 48 to be correct. } diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java index 8f3754c..8f79099 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java @@ -46,6 +46,12 @@ public final class BankManager { public BankManager() {} + // TODO: THIS NEEDS TO READ IN FROM A FILE TO STOP NUKING BANKS ON REBOOT + ///////////////////////////////////////////////////////////////////////////// + /// @fn InitializeBanks + /// + /// @brief Initializes all the banks on the server at construction time + ///////////////////////////////////////////////////////////////////////////// public void InitializeBanks() { banks.put(KEEBLARCRAFT_SERVER_BANK_ID, new IndividualBank(Integer.toString(KEEBLARCRAFT_SERVER_BANK_ID), "KeeblarcraftGlobal")); @@ -55,6 +61,11 @@ public final class BankManager { } } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAllBankNames + /// + /// @return List of all the banks that exist on a server + ///////////////////////////////////////////////////////////////////////////// public List GetAllBankNames() { List names = new ArrayList(); @@ -65,6 +76,11 @@ public final class BankManager { return names; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetBankByRoutingNumber + /// + /// @return The IndividualBank object by routing number if the bank exists + ///////////////////////////////////////////////////////////////////////////// public IndividualBank GetBankByRoutingNumber(Integer number) { IndividualBank bank = null; if (banks.containsKey(number)) { @@ -73,6 +89,11 @@ public final class BankManager { return bank; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetBankByName + /// + /// @return The Individualbank object by name if the bank exists + ///////////////////////////////////////////////////////////////////////////// public IndividualBank GetBankByName(String name) { IndividualBank bank = null; System.out.println("GetBankByName called with value " + name); @@ -86,6 +107,15 @@ public final class BankManager { return bank; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ChangeDefaultPlayerAccount + /// + /// @param[in] player Player object to change default accounts of + /// + /// @param[in] The new default account global account identifier + /// + /// @return Changes the players default account at a selected bank + ///////////////////////////////////////////////////////////////////////////// public void ChangeDefaultPlayerAccount(ServerPlayerEntity player, String newDefaultAccount) { String bankName = AccountNumberGenerator.GetFinancialSymbolFromId(newDefaultAccount); System.out.println("ChangeDefaultPlayerAccount: Received bankName " + bankName); @@ -106,7 +136,23 @@ public final class BankManager { } } - // Change the funds of an account from an administrative perspective + ///////////////////////////////////////////////////////////////////////////// + /// @fn AdminChangeFunds + /// + /// @param[in] initiator The player object who is initiating this call + /// + /// @param[in] accountId The account to change funds of + /// + /// @param[in] amount The amount to change funds of in changeType + /// + /// @param[in] changeType The type of funds change being initiated + /// + /// @param[in] optionalReason The optional reason of changing funds + /// + /// @brief Command manager to initiate a funds change from an admins + /// perspective (safe guards dropped). Valid changeTypes are + /// found inside the switch-case statement in the below function + ///////////////////////////////////////////////////////////////////////////// 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); @@ -141,6 +187,17 @@ public final class BankManager { } } + ///////////////////////////////////////////////////////////////////////////// + /// @fn InitiateBankFundsTransfer + /// + /// @param[in] fromPlayer is the player funds are coming out of + /// + /// @param[in] toAccount is the account the funds are going to + /// + /// @param[in] amount is the amount of money coming from the player + /// + /// @brief Initiate a funds transfer between accounts or banks + ///////////////////////////////////////////////////////////////////////////// public void InitiateBankFundsTransfer(ServerPlayerEntity fromPlayer, String toAccount, Integer amount) { // Get player default selection String fromAccount = playerConfigs.get(fromPlayer.getUuidAsString()).defaultSelectedBank; @@ -174,6 +231,17 @@ public final class BankManager { } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetDefaultSelectedAccount + /// + /// @param[in] playerUuid is the player to get their default account + /// + /// @param[in] bankIdentifier is the bank the default account is at + /// + /// @brief Gets a players default account + /// + /// @return The global account identifier of the default selected account + ///////////////////////////////////////////////////////////////////////////// public String GetDefaultSelectedAccount(String playerUuid, String bankIdentifier) { String account = ""; @@ -184,6 +252,17 @@ public final class BankManager { return account; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn InitiateBankAccountCreation + /// + /// @param[in] bankIdentifier is the bank routing number + /// + /// @param[in] player is the player object trying to create account + /// + /// @paran[in] accountType Is the type of account the player wants to make + /// + /// @brief Initiates a bank account creation with a bank + ///////////////////////////////////////////////////////////////////////////// public void InitiateBankAccountCreation(String bankIdentifier, ServerPlayerEntity player, String accountType) { Boolean success = false; System.out.println("initiating bank creation"); diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/IndividualAccount.java b/src/main/java/jesse/keeblarcraft/BankMgr/IndividualAccount.java index d3fdcdb..2a7191f 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/IndividualAccount.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/IndividualAccount.java @@ -39,7 +39,15 @@ public class IndividualAccount { this.globalAccountNumber = bankLetterIdentifier + "-" + routingNumber + "-" + accountNumber; } - // TODO: Make this a map in the future + ///////////////////////////////////////////////////////////////////////////// + /// @fn AddAccountHolder + /// + /// @param[in] newHolder to be added to account + /// + /// @param[in] newHolderUuid to be added to account + /// + /// @brief Adds another UUID who can access the bank account + ///////////////////////////////////////////////////////////////////////////// public void AddAccountHolder(String newHolder, String newHolderUuid) { if (!accountHolders.contains(newHolder)) { accountHolders.add(newHolder); @@ -50,24 +58,62 @@ public class IndividualAccount { } } - // May have unintended consequences if account can't go negative + ///////////////////////////////////////////////////////////////////////////// + /// @fn SetMoney + /// + /// @param[in] amount is the new account balance + /// + /// @brief Set the balance of the bank account. NOT RECOMMENDED OUTSIDE + /// OF ADMINISTRATIVE USE!!! + /// + /// @note This will forcefully ignore account settings like not being + /// able to go negative. This is not recommended to use + ///////////////////////////////////////////////////////////////////////////// public void SetMoney(Integer amount) { System.out.println("Previous balance on account: " + this.accountBalance + ". New balance: " + amount); this.accountBalance = amount; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AliasAccount + /// + /// @param[in] newAlias to name the account + /// + /// @brief Sets new alias of this account + ///////////////////////////////////////////////////////////////////////////// public void AliasAccount(String newAlias) { this.accountNumberAlias = newAlias; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsLocked + /// + /// @brief Returns if account is locked + /// + /// @return True if locked, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean IsLocked() { return accountLocked; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn LockAccount + /// + /// @brief Locks an account + ///////////////////////////////////////////////////////////////////////////// public void LockAccount() { accountLocked = true; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn Deposit + /// + /// @param[in] amount is amount to be added + /// + /// @brief Deposits (adds) amount of money to account + /// + /// @return True if succeeds, false if fails + ///////////////////////////////////////////////////////////////////////////// public Boolean Deposit(Integer amount) { Boolean success = false; if (!accountLocked) @@ -79,6 +125,15 @@ public class IndividualAccount { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn Withdraw + /// + /// @param[in] amount is amount to be subtracted + /// + /// @brief Withdraws (subtracts) amount from account balance + /// + /// @return True if succeeds, false if fails + ///////////////////////////////////////////////////////////////////////////// public Boolean Withdraw(Integer amount) { Boolean success = false; @@ -96,6 +151,11 @@ public class IndividualAccount { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CanWithdraw + /// + /// @return True if account can afford withdrawal, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean CanWithdraw(Integer amount) { Boolean canWithdraw = false; @@ -106,6 +166,11 @@ public class IndividualAccount { return canWithdraw; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsHolder + /// + /// @return True if name is on name list + ///////////////////////////////////////////////////////////////////////////// public Boolean IsHolder(String name) { Boolean ret = false; @@ -116,28 +181,57 @@ public class IndividualAccount { return ret; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AllowsNegative + /// + /// @return True if account allows negative balances, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean AllowsNegative() { return this.allowNegativeBalance; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountHolders + /// + /// @return List of everyone who has access to this account + ///////////////////////////////////////////////////////////////////////////// public List GetAccountHolders() { return accountHolders; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountBalance + /// + /// @return Account balance + ///////////////////////////////////////////////////////////////////////////// public Integer GetAccountBalance() { return accountBalance; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountNumber + /// + /// @return String representation of account number (SHORT account number) + ///////////////////////////////////////////////////////////////////////////// public String GetAccountNumber() { return accountNumber; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetRoutingNumber + /// + /// @return Routing number of account + ///////////////////////////////////////////////////////////////////////////// public Integer GetRoutingNumber() { return routingNumber; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetGlobalAccountNumber + /// + /// @return Gets global (ENTIRE) account number + ///////////////////////////////////////////////////////////////////////////// public String GetGlobalAccountNumber() { return globalAccountNumber; } - } diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/IndividualBank.java b/src/main/java/jesse/keeblarcraft/BankMgr/IndividualBank.java index 2427e82..500ebab 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/IndividualBank.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/IndividualBank.java @@ -59,6 +59,16 @@ public class IndividualBank { Accounts accounts; private List lockedUsers; // A list of users who are locked out of the bank and are incapable of performing more actions within it + ///////////////////////////////////////////////////////////////////////////// + /// @fn IndividualBank + /// + /// @param[in] routingNumber is the routing number this bank is constructed + /// with + /// + /// @param[in] nameOfBank Will be the display name of this bank to players + /// + /// @brief Constructor for this bank + ///////////////////////////////////////////////////////////////////////////// public IndividualBank(String routingNumber, String nameOfBank) { accounts = new Accounts(); lockedUsers = new ArrayList(); @@ -135,10 +145,24 @@ public class IndividualBank { numberOfAccounts = accounts.accountsList.size(); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetBankName + /// + /// @return Returns this banks name + ///////////////////////////////////////////////////////////////////////////// public String GetBankName() { return registeredBankName; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetAccountsOfUser + /// + /// @param[in] uuid is the players UUID to check + /// + /// @brief Gets all the accounts a user has at this bank by UUID + /// + /// @return List of all bank accounts. List will be EMPTY if no accounts + ///////////////////////////////////////////////////////////////////////////// public List GetAccountsOfUser(String uuid) { System.out.println("UUID passed in: " + uuid); List accountsFromUser = new ArrayList(); @@ -154,26 +178,64 @@ public class IndividualBank { return accountsFromUser; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetBankBalance + /// + /// @return The banks balance + ///////////////////////////////////////////////////////////////////////////// public Integer GetBankBalance() { return bankMoney; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AddBankBalance + /// + /// @param[in] amount Amount to add to the banks balance + /// + /// @brief Adds to the banks balance + ///////////////////////////////////////////////////////////////////////////// public void AddBankBalance(Integer amount) { bankMoney += amount; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn SubtractBankBalance + /// + /// @param[in] amount Amount to subtract from banks balance + /// + /// @brief Subtracts from the banks balance + ///////////////////////////////////////////////////////////////////////////// public void SubtractBankBalance(Integer amount) { bankMoney -= amount; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn SetBankBalance + /// + /// @param[in] amount Amount to give the bank + /// + /// @brief Set the banks balance + ///////////////////////////////////////////////////////////////////////////// public void SetBankBalance(Integer amount) { bankMoney = amount; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsBankInsured + /// + /// @return True if bank is insured, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean IsBankInsured() { return kbicInsured; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn InsuranceAmount + /// + /// @brief Get the insurance amount at this bank + /// + /// @return Insurance amount + ///////////////////////////////////////////////////////////////////////////// public Integer InsuranceAmount() { Integer insuredAmnt = 0; if (kbicInsured) { @@ -184,8 +246,12 @@ public class IndividualBank { return insuredAmnt; } - // Updates the regular bank account list & the fast-access bank account list - // NO values are allowed to be null. Manually update lists separately if that's the behaviour you want! + ///////////////////////////////////////////////////////////////////////////// + /// @fn UpdateBankAccounts + /// + /// @brief Flashes bank account information to disk; updates volatile + /// memory of banking information for this bank + ///////////////////////////////////////////////////////////////////////////// public void UpdateBankAccounts(String newHolderName, String newHolderUuid, String accountIdentifier, IndividualAccount newAccountOnly) { // Update the fast-access map first System.out.println("UpdateBankAccounts called with information " + newHolderName + " " + newHolderUuid + " " + accountIdentifier); @@ -215,21 +281,43 @@ public class IndividualBank { FlashConfig("bank/" + routingNumber + "/accounts"); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetRoutingNumber + /// + /// @return Routing number + ///////////////////////////////////////////////////////////////////////////// public Integer GetRoutingNumber() { return this.routingNumber; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AddMoneyToAccount + /// + /// @param[in] accountId is the account to add money to at this bank + /// + /// @param[in] amount is the amount of money to add to this account + /// + /// @brief Adds money to an account at this bank if it exists + ///////////////////////////////////////////////////////////////////////////// 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"); } - - FlashConfig("bank/" + routingNumber + "/accounts"); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn SubtractMoneyFromAccount + /// + /// @param[in] accountId is the account to subtract money to at this bank + /// + /// @param[in] amount is the amount of money to subtract to this account + /// + /// @brief Subtracts money from an account at this bank if it exists + ///////////////////////////////////////////////////////////////////////////// public void SubtractMoneyFromAccount(String accountId, Integer amount) { IndividualAccount account = accounts.accountsList.get(accountId); @@ -240,11 +328,19 @@ public class IndividualBank { if (account != null) { account.Withdraw(amount); + FlashConfig("bank/" + routingNumber + "/accounts"); } - - FlashConfig("bank/" + routingNumber + "/accounts"); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn SetMoneyOnAccount + /// + /// @param[in] accountId is the account number + /// + /// @param[in] amount is the new balance to give this account + /// + /// @brief Sets a balance on an account if it exists + ///////////////////////////////////////////////////////////////////////////// public void SetMoneyOnAccount(String accountId, Integer amount) { IndividualAccount account = accounts.accountsList.get(accountId); System.out.println("Is account null? " + (account == null ? "YES" : "NO")); @@ -257,11 +353,23 @@ public class IndividualBank { if (account != null) { account.SetMoney(amount); + FlashConfig("bank/" + routingNumber + "/accounts"); } - - FlashConfig("bank/" + routingNumber + "/accounts"); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateAccount + /// + /// @param[in] holderUuid is the new holders UUID of this account + /// + /// @param[in] holderName is the display name of the holder + /// + /// @param[in] accountTypeStr is the account type as a string (will be number) + /// + /// @brief Create a new account at this bank + /// + /// @return True if account can be created, false if it fails + ///////////////////////////////////////////////////////////////////////////// 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); @@ -304,6 +412,15 @@ public class IndividualBank { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @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)) { @@ -311,6 +428,15 @@ public class IndividualBank { } } + ///////////////////////////////////////////////////////////////////////////// + /// @fn LockAccountHolder + /// + /// @param[in] holderName is player to lock account + /// + /// @brief Locks all accounts under a name for this user + /// + /// @return True if lock succeeds, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean LockAccountHolder(String holderName) { Boolean success = false; @@ -321,6 +447,17 @@ public class IndividualBank { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CloseAccount + /// + /// @param[in] accountId is id of account to be closed + /// + /// @brief Closes an account + /// + /// @note Balance of account must be 0 to close successfully + /// + /// @return True if can close, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean CloseAccount(String accountId) { Boolean success = false; @@ -333,6 +470,16 @@ public class IndividualBank { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn HasAccount + /// + /// @param[in] accountIdentifier account number to check to see if it exists + /// at this bank + /// + /// @brief See if an account identifier belongs to this bank + /// + /// @return True if this bank has this account identifier, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean HasAccount(String accountIdentifier) { Boolean containsAccount = false; if (accounts.accountsList.containsKey(accountIdentifier)) { @@ -341,6 +488,18 @@ public class IndividualBank { return containsAccount; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsValidWithdrawal + /// + /// @param[in] withdrawalAmount The amount to be withdrawn + /// + /// @param[in] accountIdentifier account to withdraw from + /// + /// @brief Verifies if a withdrawal will succeed on an account prior to + /// the actual withdrawal itself + /// + /// @return True if this account can afford this withdrawal. False if not + ///////////////////////////////////////////////////////////////////////////// public Boolean IsValidWithdrawal(Integer withdrawalAmount, String accountIdentifier) { Boolean isValid = false; @@ -355,6 +514,18 @@ public class IndividualBank { return isValid; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsAccountHolder + /// + /// @param[in] accountIdentifier Account to check + /// + /// @param[in] uuid Is players UUID to see if they are on this account + /// + /// @brief Check if a player is on this account + /// + /// @return True if player is on this account. False if not or account + /// does not exist + ///////////////////////////////////////////////////////////////////////////// public Boolean IsAccountHolder(String accountIdentifier, String uuid) { Boolean isHolder = false; @@ -369,6 +540,9 @@ public class IndividualBank { ///////////////////////////////////////////////////////////////////////////// /// @fn FlashConfig /// + /// @param[in] dirName is config to flash to. Banking is not trivial and will + /// require separate files to be updated at different locations! + /// /// @brief Flashes the config to the disk /// /// @note dirName should be the relative full path to dir diff --git a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java index 1718273..c6af3e0 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java @@ -190,6 +190,11 @@ public class BankCommands { ConfigManager config = new ConfigManager(); + ///////////////////////////////////////////////////////////////////////////// + /// @fn RegisterCommands + /// + /// @brief Registers all bank commands on the server + ///////////////////////////////////////////////////////////////////////////// public void RegisterCommands() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { @@ -213,7 +218,15 @@ public class BankCommands { }); } - // Remove filler words which only exist for human readability + ///////////////////////////////////////////////////////////////////////////// + /// @fn RemoveFillerWords + /// + /// @brief Takes in a list of arguments with the intention to remove + /// all words found in the filler list. This helps with dynamic + /// typing + /// + /// @return List of arguments without filler words + ///////////////////////////////////////////////////////////////////////////// public List RemoveFillerWords(List argList) { int index = 0; for (String str : argList) { @@ -228,6 +241,11 @@ public class BankCommands { return argList; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ParseBankCommand + /// + /// @brief Parses the global bank command + ///////////////////////////////////////////////////////////////////////////// public int ParseBankCommand(CommandContext context, String unformattedArgList) { List formattedArgList = List.of(unformattedArgList.split("\\s+")); // REGEX is matching 1+ whitespace characters System.out.println("After formatting the arg list, the size of arg list is size { " + formattedArgList.size() + " }"); @@ -292,7 +310,22 @@ public class BankCommands { return 0; } - // General helper parse function and throws correct error for player if fails + ///////////////////////////////////////////////////////////////////////////// + /// @fn ParseToInteger + /// + /// @param[in] player is the player to send message to on failure + /// + /// @param[in] possibleInt is string to be parsed + /// + /// @param[in] helpCmd is help command to send player on failure to parse + /// + /// @brief Helper is designed to parse a string to a number (helpful in + /// banking) and upon a failure of parse send a designated help + /// message for that command (this system is non-trivial to use) + /// + /// @return The parsed integer if successful parse. If false, the server + /// should catch and a help command is sent + ///////////////////////////////////////////////////////////////////////////// public Integer ParseToInteger(ServerPlayerEntity player, String possibleInt, String helpCmd) { Integer amount = 0; try { @@ -305,15 +338,21 @@ public class BankCommands { return amount; } + ///////////////////////////////////////////////////////////////////////////// + /// @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) { - // THIS IS A HACK. REMOVE BEFORE FINAL VERSION - //TODO: JUST RETURN HASPERMISSIONLEVEL - return true; - // if (player.hasPermissionLevel(4)) { - // return true; - // } else { - // return false; - // } + if (player.hasPermissionLevel(4)) { + return true; + } else { + return false; + } } // Possible code paths ({}=required, []=optionals, ()=explanation): @@ -332,6 +371,16 @@ public class BankCommands { // 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) + ///////////////////////////////////////////////////////////////////////////// + /// @fn AdminCommand + /// + /// @param[in] sourcePlayer is player running command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Code paths should be read in above comment. Primary admin list + /// of commands that are possible to run + ///////////////////////////////////////////////////////////////////////////// public void AdminCommand(ServerPlayerEntity sourcePlayer, List argList) { // The player must be opped & the size must be at LEAST 2 (1 keyword + extra for sublist) String pName = sourcePlayer.getDisplayName().toString(); @@ -472,6 +521,22 @@ public class BankCommands { return ""; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AdminBalanceChange + /// + /// @param[in] player is player who ran command + /// + /// @param[in] accountId is account id to change balance of + /// + /// @param[in] amount is amount to change account balance + /// + /// @param[in] type is type of fund change (parsed on @ref BankManager.java) + /// + /// @param[in] optionalReason is the optional reason of balance change + /// + /// @brief Admin command to change the balance of an account by some + /// amount + ///////////////////////////////////////////////////////////////////////////// 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); @@ -512,6 +577,11 @@ public class BankCommands { // Possible code paths: // REQUIRED = {Routing # or Bank name} // OPTIONAL = [] + ///////////////////////////////////////////////////////////////////////////// + /// @fn ManageAccounts + /// + /// @brief Change the balance of a designated account + ///////////////////////////////////////////////////////////////////////////// public void ManageAccounts(ServerPlayerEntity sourcePlayer, List argList) { System.out.println("Manage accounts arg list is { " + argList + " }"); if (argList.size() > 0) { @@ -561,6 +631,15 @@ public class BankCommands { // REQUIRED (path 1) = {AMOUNT} [FROM:{INTERNAL ACCOUNT #|ALIAS}] TO:{INTERNAL ACCOUNT #|ALIAS} ***Note: can be assumed to be SELECTED default if not specified // REQUIRED (path 2) = {INTERNAL ACCOUNT #|ALIAS} {EXTERNAL BANK/FACTION ID} // OPTIONAL = [] + ///////////////////////////////////////////////////////////////////////////// + /// @fn MoveCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Command to move account. Read above comment for code paths + ///////////////////////////////////////////////////////////////////////////// public void MoveCommand(ServerPlayerEntity sourcePlayer, List argList) { if (argList.size() >= 2) { String possibleExternalIdentifier = argList.get(1); @@ -599,6 +678,15 @@ public class BankCommands { // Posible code paths: // REQUIRED = {ACCOUNT-ID|ALIAS} {ALIAS} // OPTIONAL = [] + ///////////////////////////////////////////////////////////////////////////// + /// @fn AliasCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Aliases an account with a nick name + ///////////////////////////////////////////////////////////////////////////// public void AliasCommand(ServerPlayerEntity sourcePlayer, List argList) { if (argList.size() > 0) { @@ -615,6 +703,16 @@ public class BankCommands { // REQUIRED = {...} valid argList required // OPTIONAL = [] // NOTE: This is just a shorthand to get to `/bank create report` + ///////////////////////////////////////////////////////////////////////////// + /// @fn ReportCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Shorthand function call-through to CreateCommand for generating + /// an account(s) report. + ///////////////////////////////////////////////////////////////////////////// public void ReportCommand(ServerPlayerEntity sourcePlayer, List argList) { if (argList.size() > 0) { argList.add(0, "report"); // Since we lose 'report' when we pass it as an alias/passthrough; we just shim it into the first spot @@ -650,6 +748,15 @@ public class BankCommands { // Create command - valid arg list types: // /... CREATE {CA/checking/savings/checking-account/savings-account/report} + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Create a bank account or create report on account + ///////////////////////////////////////////////////////////////////////////// public int CreateCommand(ServerPlayerEntity sourcePlayer, List argList) { System.out.println("Attempting account creation given arg list { " + argList + " }."); System.out.println("argList size is " + argList.size()); @@ -721,6 +828,15 @@ public class BankCommands { // Possible code paths: // REQUIRED = {AMOUNT} {ACCOUNT_ID} [optional] // OPTIONAL = [reason] + ///////////////////////////////////////////////////////////////////////////// + /// @fn WireCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] argList is the argument list to be parsed + /// + /// @brief Create wire on bank account + ///////////////////////////////////////////////////////////////////////////// public int WireCommand(ServerPlayerEntity sourcePlayer, List argList) { System.out.println("WireCommand called with arg size " + argList.size()); if (argList.size() >= 2) { @@ -743,6 +859,16 @@ public class BankCommands { // Possible code paths: // REQUIRED = {} // OPTIONAL = [command|subcommand] + ///////////////////////////////////////////////////////////////////////////// + /// @fn HelpCommand + /// + /// @param[in] player is player who ran command + /// + /// @param[in] helpCommand is the argument list to be parsed + /// + /// @brief Builds a dynamic help list to the player to see all command + /// options on the server + ///////////////////////////////////////////////////////////////////////////// public int HelpCommand(ServerPlayerEntity sourcePlayer, List helpCommand) { System.out.println("Running help command"); if (helpCommand.size() == 0) { @@ -782,6 +908,15 @@ public class BankCommands { // Possible args: // /bank create {SAVINGS/CHECKING} [optional: alias] + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateAccount + /// + /// @param[in] player is player who ran command + /// + /// @param[in] accountArgs is the argument list to be parsed + /// + /// @brief Creates a bank account + ///////////////////////////////////////////////////////////////////////////// public void CreateAccount(ServerPlayerEntity player, List accountArgs) { System.out.println("Attempting to create checking account with arg list { " + accountArgs + " }"); if (accountArgs.size() > 0) { @@ -803,6 +938,15 @@ public class BankCommands { // 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 reportArgs) { if (reportArgs.size() > 0) { String reportIdentifier = reportArgs.get(0).toLowerCase(); diff --git a/src/main/java/jesse/keeblarcraft/Commands/FactionCommands.java b/src/main/java/jesse/keeblarcraft/Commands/FactionCommands.java index cc3937c..168c773 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/FactionCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/FactionCommands.java @@ -14,7 +14,11 @@ import net.minecraft.text.Text; public class FactionCommands { - // Register function for commands + ///////////////////////////////////////////////////////////////////////////// + /// @fn RegisterFactionCommands + /// + /// @brief Registers all commands for factions + ///////////////////////////////////////////////////////////////////////////// public void RegisterFactionCommands() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { var factionNode = CommandManager.literal("faction").build(); @@ -63,7 +67,15 @@ public class FactionCommands { }); } - /// PRIVATE HANDLERS BELOW + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateFaction + /// + /// @param[in] context is the context of where this command runs from + /// + /// @param[in] newFactionName is the faction name to be created + /// + /// @brief Command to create a faction + ///////////////////////////////////////////////////////////////////////////// private int CreateFaction(CommandContext context, String newFactionName) { int retValue = 0; @@ -79,11 +91,20 @@ public class FactionCommands { return retValue; } - private int DeleteFaction(CommandContext context, String newFactionName) { + ///////////////////////////////////////////////////////////////////////////// + /// @fn DeleteFaction + /// + /// @param[in] context is the context of where this command runs from + /// + /// @param[in] newFactionName is the faction name to be deleted + /// + /// @brief Command to create a faction + ///////////////////////////////////////////////////////////////////////////// + private int DeleteFaction(CommandContext context, String factionName) { int retValue = 0; ServerPlayerEntity player = context.getSource().getPlayer(); - FactionManager.GetInstance().DeleteFaction(newFactionName, player); + FactionManager.GetInstance().DeleteFaction(factionName, player); return retValue; } @@ -94,6 +115,13 @@ public class FactionCommands { return retValue; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn LeaveFaction + /// + /// @param[in] context is the context of where this command runs from + /// + /// @brief Command to leave a faction + ///////////////////////////////////////////////////////////////////////////// private int LeaveFaction(CommandContext context) { ServerPlayerEntity player = context.getSource().getPlayer(); @@ -163,6 +191,13 @@ public class FactionCommands { return retValue; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ListAllFactions + /// + /// @param[in] player is the command runner + /// + /// @brief Command to see all factions on the server + ///////////////////////////////////////////////////////////////////////////// private int ListAllFactions(ServerPlayerEntity player) { int retValue = -1; diff --git a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java index 597b934..4d864e2 100644 --- a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java +++ b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java @@ -91,7 +91,17 @@ public class ConfigManager { return ret; } - // Writes NBT (binary?) data to a file + ///////////////////////////////////////////////////////////////////////////// + /// @fn WriteNbtListToFile + /// + /// @param[in] fileName is the file location to write to + /// + /// @param[in] key is the compound key type to store + /// + /// @param[in] data is the NbtList to write + /// + /// @brief Writes NbtList data to disk + ///////////////////////////////////////////////////////////////////////////// public void WriteNbtListToFile(String fileName, String key, NbtList data) { fileName = "config/keeblarcraft/" + fileName; @@ -110,7 +120,18 @@ public class ConfigManager { } } - // Side effect: Files are deleted after being read. Use WriteNbt to write back + ///////////////////////////////////////////////////////////////////////////// + /// @fn ReadAllNbtListFromDirectory + /// + /// @param[in] dir is the directory path to read from + /// + /// @param[in] listType is the NBT Compound list type + /// + /// @brief Reads in NBTList data from a directory; using file names as key. + /// If a file is read in correctly, the file is deleted + /// + /// @return A map of NbtList data with the key being the file name (minus ext) + ///////////////////////////////////////////////////////////////////////////// public HashMap ReadAllNbtListFromDirectory(String dir, int listType) { HashMap list = new HashMap(); dir = "config/keeblarcraft/" + dir; @@ -135,6 +156,19 @@ public class ConfigManager { return list; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ReadNbtListFromFile + /// + /// @param[in] file handler object to read nbt list data from + /// + /// @param[in] key for the nbt compound object + /// + /// @param[in] listType is the NBT Compound list type + /// + /// @brief Reads in NBTList data from a single file + /// + /// @return NbtList data + ///////////////////////////////////////////////////////////////////////////// public NbtList ReadNbtListFromFile(File file, String key, int listType) { NbtList list = null; diff --git a/src/main/java/jesse/keeblarcraft/ConfigMgr/GeneralConfig.java b/src/main/java/jesse/keeblarcraft/ConfigMgr/GeneralConfig.java index 1239ae6..1553530 100644 --- a/src/main/java/jesse/keeblarcraft/ConfigMgr/GeneralConfig.java +++ b/src/main/java/jesse/keeblarcraft/ConfigMgr/GeneralConfig.java @@ -19,7 +19,13 @@ public class GeneralConfig { return static_inst; } - // Guarentee to not be null + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetConfig + /// + /// @brief Returns the mods general configuration file object + /// + /// @return The configuration object + ///////////////////////////////////////////////////////////////////////////// public ImplementedConfig GetConfig() { if (config == null) { config = new ImplementedConfig(); @@ -29,6 +35,11 @@ public class GeneralConfig { return config; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GeneralConfig + /// + /// @brief Constructs the general configuration file for the project + ///////////////////////////////////////////////////////////////////////////// public GeneralConfig() { Boolean existingFile = false; try { @@ -52,20 +63,40 @@ public class GeneralConfig { } } - // Can return null; if null then do not spawn the player because global spawn wasn't set! + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetSpawnCoords + /// + /// @brief Gets the coordinates for the global spawn + /// + /// @return A vector containing how a player should spawn in or null if not + /// set yet. + ///////////////////////////////////////////////////////////////////////////// public DirectionalVec GetSpawnCoords() { System.out.println("Among us"); System.out.println("GetSpawnCoords called. is global_spawn null? " + (config.global_spawn == null ? "YES": "NO")); return config.global_spawn; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn SetSpawnCoords + /// + /// @brief Sets the coordinates for the global spawn + ///////////////////////////////////////////////////////////////////////////// public void SetSpawnCoords(DirectionalVec vec) { config.global_spawn = vec; FlashConfig(); } - // The idea behind this function is a one time check option. If you have the UUID, they must now be joining - // so we wrap adding them to the list in one check + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsNewPlayer + /// + /// @param[in] uuid is the player uuid + /// + /// @brief Checks to see if player uuid has ever joined. If not, then add + /// to global list of uuids who have joined. + /// + /// @return True if player is new, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean IsNewPlayer(String uuid) { System.out.println("IsNewPlayer called. List has: " + config.playerList); Boolean isNew = !config.playerList.contains(uuid); @@ -79,10 +110,19 @@ public class GeneralConfig { return isNew; } + + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetMOTD + /// + /// @brief String object with the MOTD of the server + ///////////////////////////////////////////////////////////////////////////// public String GetMOTD() { return config.MOTD; } + ///////////////////////////////////////////////////////////////////////////// + /// @class ImplementedConfig is the configuration class holder + ///////////////////////////////////////////////////////////////////////////// private class ImplementedConfig { public String MOTD = "Welcome to the server! Have fun!"; @@ -92,6 +132,11 @@ public class GeneralConfig { DirectionalVec global_spawn; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn FlashConfig + /// + /// @brief String object with the MOTD of the server + ///////////////////////////////////////////////////////////////////////////// private void FlashConfig() { System.out.println("Attempting to write generalconfig to file. Is null? " + (config == null ? "YES" : "NO")); try { diff --git a/src/main/java/jesse/keeblarcraft/EventMgr/DimensionLoadingEvent.java b/src/main/java/jesse/keeblarcraft/EventMgr/DimensionLoadingEvent.java index a581abe..f8a1c9d 100644 --- a/src/main/java/jesse/keeblarcraft/EventMgr/DimensionLoadingEvent.java +++ b/src/main/java/jesse/keeblarcraft/EventMgr/DimensionLoadingEvent.java @@ -7,16 +7,19 @@ import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.Utils.ChatUtil; import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; import jesse.keeblarcraft.world.dimension.ModDimensions; -import net.minecraft.entity.player.PlayerInventory; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; public class DimensionLoadingEvent { private static DimensionLoadingEvent static_inst; + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetInstance + /// + /// @brief Static instance getter for this class + ///////////////////////////////////////////////////////////////////////////// public static DimensionLoadingEvent GetInstance() { if (static_inst == null) { static_inst = new DimensionLoadingEvent(); @@ -25,6 +28,7 @@ public class DimensionLoadingEvent { return static_inst; } + // Helper class to manage the single inventory cache of dimension loading private static class InventoryWrapper { public HashMap inventories = new HashMap(); } @@ -39,8 +43,17 @@ public class DimensionLoadingEvent { iw.inventories = config.ReadAllNbtListFromDirectory(CONFIG_LOCATION, NbtElement.COMPOUND_TYPE); } - // TODO: In the future when the attribute system is more complete this will need to filter a whitelist of items - // from the that system + story mode because some items will be able to transcend dimensions! + ///////////////////////////////////////////////////////////////////////////// + /// @fn HandleWorldMove + /// + /// @param[in] player is the player object + /// + /// @param[in] origin is the FROM destination world + /// + /// @param[in] destination is the TO destination world + /// + /// @brief Callback handler for player world move events on server + ///////////////////////////////////////////////////////////////////////////// public void HandleWorldMove(ServerPlayerEntity player, ServerWorld origin, ServerWorld destination) { System.out.println("World move event called!"); @@ -67,28 +80,37 @@ public class DimensionLoadingEvent { FlashConfig(); } - // Call on server close before we lose the volatile memory + ///////////////////////////////////////////////////////////////////////////// + /// @fn SaveInventories + /// + /// @brief Flashes the configuration file on disk (call before server exit + /// to not lose memory!) + ///////////////////////////////////////////////////////////////////////////// public void SaveInventories() { System.out.println("Call to save inventories. Flashing IW.Inventories with size " + iw.inventories.size()); FlashConfig(); } - public void CheckPlayer(ServerPlayerEntity player) { - // Check the players logged in world. If they are logging into the overworld - we need to see if they are in our - // map and give them the inventory back - if ((!player.getWorld().getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) && iw.inventories.containsKey(player.getUuidAsString())) { - // We need to store the contents of the nbt into a regular inventory and magical chest and give it back to the player - player.sendMessage(Text.of("[IMPORTANT]: It appears you have a saved inventory of items on the server! You can claim it with /magic-inventory claim")); - } - } - - // Fetches an inventory from this list. Use MagicInventory to store it along the transfer way! + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetInventories + /// + /// @param Player uuid + /// + /// @brief Gets a player inventory from the map. Calling this action also + /// removes the inventory from the stored map so be sure to use + /// it if you call it! + ///////////////////////////////////////////////////////////////////////////// public NbtList GetInventory(String uuid) { NbtList nbt = iw.inventories.get(uuid); iw.inventories.remove(uuid); return nbt; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn FlashConfig + /// + /// @brief Flashes configuration file to disk + ///////////////////////////////////////////////////////////////////////////// public void FlashConfig() { try { // config.WriteToJsonFile(CONFIG_LOCATION, iw); diff --git a/src/main/java/jesse/keeblarcraft/EventMgr/PlayerJoinListener.java b/src/main/java/jesse/keeblarcraft/EventMgr/PlayerJoinListener.java index 18f3797..7293e67 100644 --- a/src/main/java/jesse/keeblarcraft/EventMgr/PlayerJoinListener.java +++ b/src/main/java/jesse/keeblarcraft/EventMgr/PlayerJoinListener.java @@ -2,7 +2,6 @@ package jesse.keeblarcraft.EventMgr; import jesse.keeblarcraft.AttributeMgr.AttributeMgr; import jesse.keeblarcraft.AttributeMgr.AttributeTree; -import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.ConfigMgr.GeneralConfig; import jesse.keeblarcraft.Utils.DirectionalVec; import net.fabricmc.fabric.api.networking.v1.PacketSender; @@ -15,6 +14,7 @@ import net.minecraft.text.Text; public class PlayerJoinListener { private static PlayerJoinListener static_inst; + // Get the static instance for this class public static PlayerJoinListener GetInstance() { if (static_inst == null) { static_inst = new PlayerJoinListener(); @@ -22,6 +22,17 @@ public class PlayerJoinListener { return static_inst; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn HandleServerJoinEvent + /// + /// @param[in] handler is the network handler + /// + /// @param[in] sender is the packet sender + /// + /// @param[in] server is the MinecraftServer instance + /// + /// @brief Callback function for player join event in minecraft server + ///////////////////////////////////////////////////////////////////////////// public void HandleServerJoinEvent(ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) { var player = handler.player; @@ -35,7 +46,16 @@ public class PlayerJoinListener { IsFirstTimeLogin(player, server); } - // this will be reworked in the future + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsFirstTimeLogin + /// + /// @param[in] player is the player who is joining + /// + /// @param[in] server is the MinecraftServer instance + /// + /// @brief Check to see if player is first time log-in. If so, we teleport + /// them to spawn. This function may be expanded in future + ///////////////////////////////////////////////////////////////////////////// private void IsFirstTimeLogin(ServerPlayerEntity player, MinecraftServer server) { // Send the MOTD + Spawn in global spawn player.sendMessage(Text.of(GeneralConfig.GetInstance().GetMOTD())); diff --git a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java index 5d2470e..b2ff584 100644 --- a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java +++ b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java @@ -1,3 +1,11 @@ +/* + * + * FactionConfig + * + * This class is the configuration file for factions + * +*/ + package jesse.keeblarcraft.FactionMgr; import static java.util.Map.entry; @@ -11,6 +19,10 @@ import java.util.HashMap; // This class is written to a config file typically and represents // all the details surrounding a faction public class FactionConfig { + // Key = Faction identifier + // Val = Faction object + HashMap allFactions = new HashMap(); + // Enum may be extended in future public static enum VALID_FACTION_ROLES { OWNER, @@ -52,6 +64,19 @@ public class FactionConfig { String factionName; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] creatorUuid is the caller of the command's UUID + /// + /// @param[in] creatorDisplayName is the caller's display name + /// + /// @brief Creates a faction on the server + /// + /// @return True if a faction can be created, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean CreateFaction(String factionName, String creatorUuid, String creatorDisplayName) { Boolean success = false; if (!IsValid(factionName)) { @@ -66,6 +91,18 @@ public class FactionConfig { return success; } + + ///////////////////////////////////////////////////////////////////////////// + /// @fn DeleteFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] creatorUuid is the caller of the command's UUID + /// + /// @brief Deletes a faction on the server + /// + /// @return True if a faction can be deleted, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean DeleteFaction(String factionName, String callerUuid) { Boolean success = false; // faction must exist @@ -83,6 +120,18 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CanInvite + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] creatorUuid is the caller of the command's UUID + /// + /// @brief Determines if the player is capable of inviting another player + /// to the faction + /// + /// @return True if player can invite another player, false if not + ///////////////////////////////////////////////////////////////////////////// private Boolean CanInvite(String factionName, String callerUuid) { Boolean success = false; @@ -97,6 +146,17 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsOnInviteList + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] playerUuid is the caller of the command's UUID + /// + /// @brief Checks to see if a player has been invited to a faction + /// + /// @return True if player is on invite list, false if not + ///////////////////////////////////////////////////////////////////////////// private Boolean IsOnInviteList(String factionName, String playerUuid) { Boolean success = false; @@ -109,6 +169,17 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn AddToFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] playerUuid is the caller of the command's UUID + /// + /// @param[in] playerDisplayName is the caller's display name + /// + /// @brief Adds a player to a faction + ///////////////////////////////////////////////////////////////////////////// private void AddToFaction(String factionName, String playerUuid, String playerDisplayName) { if (allFactions.containsKey(factionName)) { allFactions.get(factionName).factionPlayerList.put(playerUuid, VALID_FACTION_ROLES.EMPLOYEE); @@ -116,6 +187,19 @@ public class FactionConfig { } } + ///////////////////////////////////////////////////////////////////////////// + /// @fn InvitePlayerToFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] callerUuid is the player inviting another player's UUID + /// + /// @param[in] invitedUuid is the player being invited's UUID + /// + /// @brief Invites a player to a faction + /// + /// @return True if player successfully can invite another player + ///////////////////////////////////////////////////////////////////////////// public Boolean InvitePlayerToFaction(String factionName, String callerUuid, String invitedUuid) { Boolean success = false; @@ -127,6 +211,19 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn JoinFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] playerUuid is the player inviting another player's UUID + /// + /// @param[in] playerDisplayName is the player being invited's UUID + /// + /// @brief Function to determine if a player can join a faction + /// + /// @return True if they join, false if they cannot + ///////////////////////////////////////////////////////////////////////////// public Boolean JoinFaction(String factionName, String playerUuid, String playerDisplayName) { Boolean success = false; @@ -138,6 +235,19 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn LeaveFaction + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] playerUuid is the player inviting another player's UUID + /// + /// @param[in] playerName is the player being invited's UUID + /// + /// @brief Function to let player leave a faction + /// + /// @return True if they leave, false if they did not + ///////////////////////////////////////////////////////////////////////////// public Boolean LeaveFaction(String factionName, String playerUuid, String playerName) { Boolean success = false; @@ -156,6 +266,17 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn HasPlayer + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] playerUuid is the player inviting another player's UUID + /// + /// @brief Determines if a faction has a specific player by UUID + /// + /// @return True if they have the player, false if not + ///////////////////////////////////////////////////////////////////////////// private Boolean HasPlayer(String factionName, String playerUuid) { Boolean success = false; @@ -166,6 +287,15 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn IsValid + /// + /// @param[in] factionName is the name of the faction + /// + /// @brief Determines if a faction exists + /// + /// @return True if a faction exists with the specified name, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean IsValid(String factionName) { if (allFactions.containsKey(factionName)) { return true; @@ -174,7 +304,17 @@ public class FactionConfig { } } - // Empty string means no faction found. This is expensive! + ///////////////////////////////////////////////////////////////////////////// + /// @fn FindFactionOfPlayer + /// + /// @param[in] playerUuid is the uuid of the player to find + /// + /// @brief Determine the faction of a specified player + /// + /// @return Returns the faction name of the player if the player is in + /// any faction. If the player is not found in any faction, an + /// empty string is returned + ///////////////////////////////////////////////////////////////////////////// public String FindFactionOfPlayer(String playerUuid) { String faction = ""; @@ -189,6 +329,29 @@ public class FactionConfig { return faction; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn PromotePlayer + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] callerUuid is the caller of the command's UUID + /// + /// @param[in] promoteeUuid is the player to be promoted's UUID + /// + /// @param[in] promoteeDisplayName is the player ot be promoted's display name + /// + /// @brief Attempts to promote a player in a faction. Whether or not a + /// player is promoted is determined by their level in the faction + /// and the promoter's level in the faction. Factors that can affect + /// this are: + /// 1. Both the caller and promotee must exist inside + /// the same faction + /// 2. The promoter must be a higher rank than the promotee + /// 3. The promotee's post-promotion rank still must be below + /// the promoter's rank + /// + /// @return True if the player was successfully promoted, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean PromotePlayer(String factionName, String callerUuid, String promoteeUuid, String promoteeDisplayName) { Boolean success = false; @@ -213,8 +376,24 @@ public class FactionConfig { return success; } - // Factions is setup in a way where anybody can demote anybody underneath them and demotions of the lowest level lead to an automatic kick. The - // same behavior is kept here + ///////////////////////////////////////////////////////////////////////////// + /// @fn CanKickPlayer + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] callerUuid is the caller of the command's UUID + /// + /// @param[in] kickeeUuid is the player to be kickee's UUID + /// + /// @param[in] kickeeDisplayName is the player ot be kickeeDisplayName's + /// display name + /// + /// @brief Determines whether or not a player can be kicked. The caller + /// must be a higher rank to kick a player (and they both must + /// exist inside the faction) + /// + /// @return True if the player was successfully kicked, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean CanKickPlayer(String factionName, String callerUuid, String kickeeUuid, String kickeeDisplayName) { Boolean success = false; @@ -232,6 +411,22 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn KickPlayer + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] callerUuid is the caller of the command's UUID + /// + /// @param[in] kickeeUuid is the player to be kickee's UUID + /// + /// @param[in] kickeeDisplayName is the player ot be kickeeDisplayName's + /// display name + /// + /// @brief Kicks a player from a faction + /// + /// @return True if the player was successfully kicked, false if not + ///////////////////////////////////////////////////////////////////////////// private Boolean KickPlayer(String factionName, String callerUuid, String kickeeUuid, String kickeeDisplayName) { Boolean success = false; @@ -244,6 +439,29 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn DemotePlayer + /// + /// @param[in] factionName is the name of the faction + /// + /// @param[in] callerUuid is the caller of the command's UUID + /// + /// @param[in] demoteeUuid is the player to be promoted's UUID + /// + /// @param[in] demoteeDisplayName is the player ot be promoted's display name + /// + /// @brief Attempts to demote a player in a faction. Whether or not a + /// player is demoted is determined by their level in the faction + /// and the demoter's level in the faction. Factors that can affect + /// this are: + /// 1. Both the caller and demotee must exist inside + /// the same faction + /// 2. The demoter must be a higher rank than the promotee + /// 3. Should there be no lower rank left to demote to, the + /// player is kicked from the faction + /// + /// @return True if the player was successfully demoted, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean DemotePlayer(String factionName, String callerUuid, String demoteeUuid, String demoteeDisplayName) { Boolean success = false; @@ -272,6 +490,13 @@ public class FactionConfig { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ListOfAllFactions + /// + /// @brief Get a list of all factions on the server + /// + /// @return List of factions + ///////////////////////////////////////////////////////////////////////////// public List ListOfAllFactions() { List facs = new ArrayList(); @@ -283,8 +508,4 @@ public class FactionConfig { return facs; } - - // Key = Faction identifier - // Val = Faction object - HashMap allFactions = new HashMap(); } diff --git a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java index 1cbea40..e46e4b7 100644 --- a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java +++ b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java @@ -76,6 +76,15 @@ public class FactionManager { } } + ///////////////////////////////////////////////////////////////////////////// + /// @fn LeaveFaction + /// + /// @param[in] player is the player on the server + /// + /// @brief Leave a faction + /// + /// @return True if player can leave their faction, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean LeaveFaction(ServerPlayerEntity player) { Boolean success = false; @@ -91,6 +100,17 @@ public class FactionManager { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn CreateFaction + /// + /// @param[in] factionName is the faction to be created + /// + /// @param[in] player is the player on the server + /// + /// @brief Create a new faction + /// + /// @return True if successfully created, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean CreateFaction(String factionName, ServerPlayerEntity creator) { Boolean success = false; String facOfPlayer = factionConfig.factions.FindFactionOfPlayer(creator.getUuidAsString()); @@ -111,6 +131,17 @@ public class FactionManager { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn DeleteFaction + /// + /// @param[in] factionName is the faction to be created + /// + /// @param[in] caller is the player on the server + /// + /// @brief Delete a faction + /// + /// @return True if successfully deleted, false if not + ///////////////////////////////////////////////////////////////////////////// public Boolean DeleteFaction(String factionName, ServerPlayerEntity caller) { Boolean success = factionConfig.factions.DeleteFaction(factionName, caller.getUuidAsString()); @@ -124,11 +155,27 @@ public class FactionManager { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ListOfFactions + /// + /// @brief Get a list of all factions on the server + /// + /// @return Faction list. Empty list if no factions + ///////////////////////////////////////////////////////////////////////////// public List ListOfFactions() { System.out.println("Callthrough of listoffactions"); return factionConfig.factions.ListOfAllFactions(); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn GetFactionOfPlayer + /// + /// @param[in] playerUuid is the uuid of the player + /// + /// @brief Gets the faction of a player on the server + /// + /// @return String with faction name. Empty string if no faction tie + ///////////////////////////////////////////////////////////////////////////// public String GetFactionOfPlayer(String playerUuid) { return factionConfig.factions.FindFactionOfPlayer(playerUuid); } @@ -145,8 +192,21 @@ public class FactionManager { return success; } - public Boolean DemotePlayer(ServerPlayerEntity caller, String promoteeUuid, String promoteeDisplayName) { - Boolean success = factionConfig.factions.DemotePlayer(GetFactionOfPlayer(caller.getUuidAsString()), caller.getUuidAsString(), promoteeUuid, promoteeDisplayName); + ///////////////////////////////////////////////////////////////////////////// + /// @fn DemotePlayer + /// + /// @param[in] caller is the player who is demoting another player + /// + /// @param[in] demoteeUuid is the player's uuid who is being demoted + /// + /// @param[in] demoteeDisplayName is the players display name who is being demoted + /// + /// @brief Demote a player from a faction + /// + /// @return True if player is demoted. False if not + ///////////////////////////////////////////////////////////////////////////// + public Boolean DemotePlayer(ServerPlayerEntity caller, String demoteeUuid, String demoteeDisplayName) { + Boolean success = factionConfig.factions.DemotePlayer(GetFactionOfPlayer(caller.getUuidAsString()), caller.getUuidAsString(), demoteeUuid, demoteeDisplayName); if (!success) { caller.sendMessage(Text.of("[Factions]: Could not demote player - you need to be a higher rank than them to demote them!")); @@ -157,6 +217,11 @@ public class FactionManager { return success; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn FlashConfig + /// + /// @brief Update the faction configuration file on disk + ///////////////////////////////////////////////////////////////////////////// public void FlashConfig() { try { config.WriteToJsonFile(FACTION_CFG_FILE, factionConfig); diff --git a/src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java b/src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java index 85f815a..087ddca 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java +++ b/src/main/java/jesse/keeblarcraft/Utils/ChatUtil.java @@ -11,12 +11,7 @@ package jesse.keeblarcraft.Utils; import org.slf4j.Logger; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import java.util.HashMap; -import java.util.List; -import java.util.ArrayList; -import java.util.Map.Entry; public class ChatUtil { //This is a private class only used internally to get ANSI colors diff --git a/src/main/java/jesse/keeblarcraft/Utils/DirectionalVec.java b/src/main/java/jesse/keeblarcraft/Utils/DirectionalVec.java index c619f5d..07ce4aa 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/DirectionalVec.java +++ b/src/main/java/jesse/keeblarcraft/Utils/DirectionalVec.java @@ -3,6 +3,13 @@ package jesse.keeblarcraft.Utils; import net.minecraft.registry.RegistryKey; import net.minecraft.world.World; +///////////////////////////////////////////////////////////////////////////// +/// @class DirectionalVec +/// +/// @brief DirectionalVec creates a vector of information that can store +/// world information and a players vector information of where they +/// are in the world + where their camera is looking (yaw & pitch) +///////////////////////////////////////////////////////////////////////////// public class DirectionalVec { public RegistryKey world; public double x; diff --git a/src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java b/src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java index be74fb7..68eb060 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java +++ b/src/main/java/jesse/keeblarcraft/Utils/HelpBuilder.java @@ -20,6 +20,16 @@ public class HelpBuilder { GREEN } + ///////////////////////////////////////////////////////////////////////////// + /// @fn getColor + /// + /// @param[in] code is the color code that is desired + /// + /// @brief Returns the MINECRAFT color code in string form to help build + /// colored messages for players + /// + /// @return String representation of color code + ///////////////////////////////////////////////////////////////////////////// private String getColor(COLOR_CODE code) { String colorStr = COLOR_START; switch(code) { @@ -39,10 +49,38 @@ public class HelpBuilder { return colorStr; } - public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, Integer copyStr) { - return MakeCopyableTxt(terminalTxt, hoverTxt, Integer.toString(copyStr)); + ///////////////////////////////////////////////////////////////////////////// + /// @fn MakeCopyableTxt + /// + /// @param[in] terminalTxt is the text to be seen on screen + /// + /// @param[in] hoverTxt is the desired text to be seen in a new hover event + /// + /// @param[in] copyInt is an integer argument that can be copied when the + /// player clicks on the chat message + /// + /// @brief Creates a copyable text block for the player + /// + /// @return MutableText of text intended to be used to send to player + ///////////////////////////////////////////////////////////////////////////// + public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, Integer copyInt) { + return MakeCopyableTxt(terminalTxt, hoverTxt, Integer.toString(copyInt)); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn MakeCopyableTxt + /// + /// @param[in] terminalTxt is the text to be seen on screen + /// + /// @param[in] hoverTxt is the desired text to be seen in a new hover event + /// + /// @param[in] expandedList takes in a list of strings that can be copied + /// when the player clicks on a chat message + /// + /// @brief Creates a copyable text block for the player + /// + /// @return MutableText of text intended to be used to send to player + ///////////////////////////////////////////////////////////////////////////// public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, List expandedList) { String expanded = "["; int index = 0; @@ -60,6 +98,20 @@ public class HelpBuilder { return MakeCopyableTxt(terminalTxt, hoverTxt, expanded); } + ///////////////////////////////////////////////////////////////////////////// + /// @fn MakeCopyableTxt + /// + /// @param[in] terminalTxt is the text to be seen on screen + /// + /// @param[in] hoverTxt is the desired text to be seen in a new hover event + /// + /// @param[in] copyStr is a regular string that can be copied when the player + /// clicks on a chat message + /// + /// @brief Creates a copyable text block for the player + /// + /// @return MutableText of text intended to be used to send to player + ///////////////////////////////////////////////////////////////////////////// public MutableText MakeCopyableTxt(String terminalTxt, String hoverTxt, String copyStr) { Text copyableText = Text.of(terminalTxt); MutableText testTxt = (MutableText) copyableText; @@ -74,10 +126,36 @@ public class HelpBuilder { return testTxt; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ColorMsg + /// + /// @param[in] msg is an integer message that is desired to be colored + /// + /// @param[in] color is the color option + /// + /// @brief Creates a formatted string that will be colored at the + /// specification of the developer + /// + /// @return Formatted string of colored text + ///////////////////////////////////////////////////////////////////////////// public String ColorMsg(Integer msg, COLOR_CODE color) { return getColor(color) + msg + COLOR_END; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ColorMsg + /// + /// @param[in] msg is a list of strings that is desired to all be colored + /// the same + /// + /// @param[in] color is the color option + /// + /// @brief Creates a formatted list of strings that will be colored + /// at the specification of the developer and will be returned as + /// a list + /// + /// @return Formatted list of strings + ///////////////////////////////////////////////////////////////////////////// public List ColorMsg(List msg, COLOR_CODE color) { List retList = new ArrayList(); @@ -88,12 +166,39 @@ public class HelpBuilder { return retList; } + ///////////////////////////////////////////////////////////////////////////// + /// @fn ColorMsg + /// + /// @param[in] msg to be formatted + /// + /// @param[in] color is the color option + /// + /// @brief Creates a formatted string that will be colored at the + /// specification of the developer + /// + /// @return Formatted string of colored text + ///////////////////////////////////////////////////////////////////////////// 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 + ///////////////////////////////////////////////////////////////////////////// + /// @fn FormatMsg + /// + /// @param[in] helpCmd is outsourced as an intentional help message. The + /// string expects the initial format to stop with a '.' + /// delimiter. + /// + /// @param[in] primaryColor is the color of the string up to the delimiter + /// + /// @param[in] secondaryColor is the color after the delimiter + /// + /// @brief Creates a formatted string + /// + /// @return Formatted string of colored text + ///////////////////////////////////////////////////////////////////////////// public String FormatMsg(String helpCmd, COLOR_CODE primaryColor, COLOR_CODE secondaryColor) { String coloredStr = getColor(primaryColor); List splitStr = List.of(helpCmd.split("\\."));