[factions-banking] Retracting clearly bad custom command stuff in banking system to make it more user friendly. Ensured commands tested before worked new in the update
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
cde06d56c0
commit
f6af706a60
@ -0,0 +1,9 @@
|
||||
package jesse.keeblarcraft.BankMgr;
|
||||
|
||||
public class BankAccountType {
|
||||
public enum ACCOUNT_TYPE {
|
||||
CHECKING,
|
||||
SAVINGS
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType.ACCOUNT_TYPE;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
@ -24,7 +25,8 @@ public final class BankManager {
|
||||
|
||||
private class PlayerBankConfig {
|
||||
List<String> activeBanks = new ArrayList<String>(); // List of all banks a player has accounts in
|
||||
String defaultSelectedBank;
|
||||
String defaultSelectedBank = "";
|
||||
String defaultSelectedAccount = "";
|
||||
}
|
||||
|
||||
// Key = player uuid
|
||||
@ -42,7 +44,11 @@ public final class BankManager {
|
||||
// Val = Bank routing number
|
||||
private HashMap<String, Integer> bankNameFastMap = new HashMap<String, Integer>();
|
||||
|
||||
public BankManager() {}
|
||||
public BankManager() {
|
||||
if (playerConfigs == null) {
|
||||
playerConfigs = new HashMap<String, PlayerBankConfig>();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: THIS NEEDS TO READ IN FROM A FILE TO STOP NUKING BANKS ON REBOOT
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -116,10 +122,14 @@ public final class BankManager {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void ChangeDefaultPlayerAccount(ServerPlayerEntity player, String newDefaultAccount) {
|
||||
String bankName = AccountNumberGenerator.GetFinancialSymbolFromId(newDefaultAccount);
|
||||
System.out.println("ChangeDefaultPlayerAccount: Received bankName " + bankName);
|
||||
System.out.println(bankNameFastMap);
|
||||
|
||||
// Verify bank exists first
|
||||
System.out.println(bankNameFastMap);
|
||||
|
||||
for(Entry<String, Integer> entry : bankNameFastMap.entrySet()) {
|
||||
System.out.println("KEY: " + entry.getKey());
|
||||
}
|
||||
|
||||
if (bankNameFastMap.containsKey(bankName)) {
|
||||
Integer routNum = bankNameFastMap.get(bankName);
|
||||
IndividualBank bank = banks.get(routNum);
|
||||
@ -127,10 +137,29 @@ public final class BankManager {
|
||||
// Verify this person has access to this account
|
||||
if(bank.IsAccountHolder(newDefaultAccount, player.getUuidAsString())) {
|
||||
// Finally update config to this account since checks pass
|
||||
playerConfigs.get(player.getUuidAsString()).defaultSelectedBank = newDefaultAccount;
|
||||
playerConfigs.get(player.getUuidAsString()).defaultSelectedAccount = newDefaultAccount;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Text.of("Could not change default selected bank. Bank does not exist!"));
|
||||
player.sendMessage(Text.of("Could not change default selected account. Bank does not exist!"));
|
||||
}
|
||||
}
|
||||
|
||||
// This guarentees a player config exists; and so can be called from many areas. Does not erase pre-existing config
|
||||
public boolean EnsurePlayerConfigExists(String uuid) {
|
||||
if (!playerConfigs.containsKey(uuid)) {
|
||||
playerConfigs.put(uuid, new PlayerBankConfig());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allows the player to select a bank
|
||||
public void ChangeDefaultSelectedBank(ServerPlayerEntity player, String bankName) {
|
||||
if (bankNameFastMap.containsKey(bankName) && EnsurePlayerConfigExists(player.getUuidAsString())) {
|
||||
playerConfigs.get(player.getUuidAsString()).defaultSelectedBank = bankName;
|
||||
player.sendMessage(Text.of("You have successfully selected the following financial institution: " + bankName));
|
||||
player.sendMessage(Text.of("Please be aware the context of commands following this will likely be done under this financial institution"));
|
||||
} else {
|
||||
player.sendMessage(Text.of("That bank does not exist."));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,9 +225,9 @@ public final class BankManager {
|
||||
///
|
||||
/// @brief Initiate a funds transfer between accounts or banks
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void InitiateBankFundsTransfer(ServerPlayerEntity fromPlayer, String toAccount, Integer amount) {
|
||||
public void InitiateBankFundsTransfer(ServerPlayerEntity fromPlayer, String toAccount, Integer amount, String reason) {
|
||||
// Get player default selection
|
||||
String fromAccount = playerConfigs.get(fromPlayer.getUuidAsString()).defaultSelectedBank;
|
||||
String fromAccount = playerConfigs.get(fromPlayer.getUuidAsString()).defaultSelectedAccount;
|
||||
|
||||
String fromAccountSymbol = AccountNumberGenerator.GetFinancialSymbolFromId(fromAccount);
|
||||
String toAccountSymbol = AccountNumberGenerator.GetFinancialSymbolFromId(toAccount);
|
||||
@ -244,12 +273,21 @@ public final class BankManager {
|
||||
String account = "";
|
||||
|
||||
if (playerConfigs.containsKey(playerUuid)) {
|
||||
account = playerConfigs.get(playerUuid).defaultSelectedBank;
|
||||
account = playerConfigs.get(playerUuid).defaultSelectedAccount;
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
public String GetPlayerSelectedBank(String playerUuid) {
|
||||
String bank = "";
|
||||
if (playerConfigs.containsKey(playerUuid)) {
|
||||
bank = playerConfigs.get(playerUuid).defaultSelectedBank;
|
||||
}
|
||||
|
||||
return bank;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn InitiateBankAccountCreation
|
||||
///
|
||||
@ -261,40 +299,18 @@ public final class BankManager {
|
||||
///
|
||||
/// @brief Initiates a bank account creation with a bank
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void InitiateBankAccountCreation(String bankIdentifier, ServerPlayerEntity player, String accountType) {
|
||||
public void InitiateBankAccountCreation(String bankIdentifier, ServerPlayerEntity player, ACCOUNT_TYPE accountType) {
|
||||
Boolean success = false;
|
||||
System.out.println("initiating bank creation");
|
||||
boolean defaultServerBank = bankIdentifier == null || bankIdentifier == "";
|
||||
System.out.println("value of bankIdentifier is " + defaultServerBank);
|
||||
IndividualBank bank = GetBankByName(bankIdentifier);
|
||||
|
||||
System.out.println("The player name is " + player.getEntityName());
|
||||
|
||||
// DEBUG
|
||||
|
||||
System.out.println("BANK NAME: " + banks.get(KEEBLARCRAFT_SERVER_BANK_ID).GetBankName());
|
||||
System.out.println("BANK BALANCE: " + banks.get(KEEBLARCRAFT_SERVER_BANK_ID).GetBankBalance());
|
||||
|
||||
// DEBUG END
|
||||
|
||||
// Create an account via the server-owned bank account
|
||||
if (defaultServerBank) {
|
||||
success = banks.get(KEEBLARCRAFT_SERVER_BANK_ID).CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType);
|
||||
} else {
|
||||
System.out.println("Creating bank on non-server owned bank");
|
||||
// Create an account via a specified bank identifier
|
||||
Integer routingNumber = Integer.parseInt(bankIdentifier);
|
||||
|
||||
if (banks.containsKey(routingNumber)) {
|
||||
banks.get(routingNumber).CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType);
|
||||
} else {
|
||||
player.sendMessage(Text.of("That bank does not exist"));
|
||||
}
|
||||
if (bank != null) {
|
||||
success = bank.CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
player.sendMessage(Text.of("The banking operation was successful and your banking information has been updated"));
|
||||
} else {
|
||||
player.sendMessage(Text.of("The banking operating FAILED. You may need to visit the bank for more information!"));
|
||||
player.sendMessage(Text.of("The banking operating FAILED. Make sure you selected this bank before creating it!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package jesse.keeblarcraft.BankMgr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType.ACCOUNT_TYPE;
|
||||
|
||||
// Contains the information of an individuals player's bank account.
|
||||
// TODO: Add ability to store NBT data of items in the future so we can store not just money but items too
|
||||
// like a safety deposit box
|
||||
@ -16,14 +18,14 @@ public class IndividualAccount {
|
||||
private Integer accountBalance;
|
||||
private Boolean allowNegativeBalance;
|
||||
private Boolean accountLocked;
|
||||
private Integer accountType; // TODO: Replace with enum in future. Valid is "checking" and "savings" right now
|
||||
private ACCOUNT_TYPE accountType;
|
||||
|
||||
|
||||
public IndividualAccount() {}
|
||||
|
||||
public IndividualAccount(String accountNumber, Integer routingNumber, List<String> holders,
|
||||
List<String> accountHolderUuids, Boolean allowNegativeBalance, Integer initialBalance,
|
||||
String alias, Integer accountType, String bankLetterIdentifier) {
|
||||
String alias, ACCOUNT_TYPE accountType, String bankLetterIdentifier) {
|
||||
|
||||
System.out.println("Called to create new IndividualAccount with following values: " + accountNumber + " " + routingNumber + " " + holders + " " +
|
||||
accountHolderUuids + " " + allowNegativeBalance + " " + initialBalance + " " + alias + " " + accountType);
|
||||
|
@ -12,21 +12,21 @@ import java.io.File;
|
||||
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType.ACCOUNT_TYPE;
|
||||
|
||||
// Contains the information of an individual bank
|
||||
//
|
||||
// The bank will keep track of all accounts within its facilities. In addition to accounts, the bank
|
||||
// maintains its own identifier which is unique and other misc things.
|
||||
public class IndividualBank {
|
||||
private Map<String, Integer> ACCOUNT_TYPES = Map.ofEntries(
|
||||
entry("checking", 0),
|
||||
entry("savings", 1)
|
||||
private Map<ACCOUNT_TYPE, Integer> ACCOUNT_TYPES = Map.ofEntries(
|
||||
entry(ACCOUNT_TYPE.CHECKING, 0),
|
||||
entry(ACCOUNT_TYPE.SAVINGS, 1)
|
||||
);
|
||||
|
||||
private ConfigManager config = new ConfigManager();
|
||||
private Integer routingNumber; // this is the banks unique identifier
|
||||
private Integer numberOfAccounts; // Total number of accounts the bank has. This includes only active accounts inside accountsList.
|
||||
private Integer numberOfAccounts = 0; // Total number of accounts the bank has. This includes only active accounts inside accountsList.
|
||||
private Integer maxBankAccounts = 100_000_000; // Making this simple for myself any one type of account has 8 random numbers genereated so 10^8 possible accounts
|
||||
private String bankFourLetterIdentifier;
|
||||
private String registeredBankName;
|
||||
@ -35,13 +35,13 @@ public class IndividualBank {
|
||||
|
||||
// Think FDIC but from the servers account (keeblarcraft insurance corporation)
|
||||
// KBIC will ensure an amount of money based on its trustworthiness to a bank and the number of holders it has.
|
||||
private Integer kbicInsuredAmount;
|
||||
private Boolean kbicInsured;
|
||||
private Integer kbicInsuredAmount = 0;
|
||||
private Boolean kbicInsured = false;
|
||||
|
||||
// bankMoney is the total amount of money the bank possesses itself. The bank itself is personally responsible
|
||||
// for backing the amount of money it claims it has and this is the balance that is withdrawn from for credits.
|
||||
// A bank can have a sum of money that is less than the total amount of money of all its account holders
|
||||
private Integer bankMoney;
|
||||
private Integer bankMoney = 0;
|
||||
|
||||
// Key = ACCOUNT NUMBER
|
||||
// Value = ACCOUNT
|
||||
@ -165,12 +165,9 @@ public class IndividualBank {
|
||||
/// @return List of all bank accounts. List will be EMPTY if no accounts
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public List<IndividualAccount> GetAccountsOfUser(String uuid) {
|
||||
System.out.println("UUID passed in: " + uuid);
|
||||
List<IndividualAccount> accountsFromUser = new ArrayList<IndividualAccount>();
|
||||
List<String> listOfAccounts = accounts.accountsListFromName.get(uuid);
|
||||
|
||||
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)));
|
||||
@ -371,17 +368,14 @@ public class IndividualBank {
|
||||
///
|
||||
/// @return True if account can be created, false if it fails
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public Boolean CreateAccount(String holderUuid, String holderName, String accountTypeStr) {
|
||||
public Boolean CreateAccount(String holderUuid, String holderName, ACCOUNT_TYPE accountType) {
|
||||
Boolean success = false;
|
||||
System.out.println("Attempting to create new bank account given args UUID / NAME / TYPE : " + holderUuid + " " + holderName + " " + accountTypeStr);
|
||||
System.out.println("accounts size is " + accounts.accountsList.size());
|
||||
System.out.println("account string is { " + accountTypeStr + " }. Does this account type exist in this bank? => " + ACCOUNT_TYPES.containsKey(accountTypeStr.toLowerCase()));
|
||||
if (accounts.accountsList.size() <= maxBankAccounts && ACCOUNT_TYPES.containsKey(accountTypeStr.toLowerCase())) {
|
||||
if (accounts.accountsList.size() <= maxBankAccounts) {
|
||||
// Verify this isn't a blacklisted user
|
||||
System.out.println("Is user bank locked? " + lockedUsers.contains(holderName));
|
||||
if (!lockedUsers.contains(holderName)) {
|
||||
Integer maxAttempts = 15; // Reasonably a unique bank account should pop up within 1000 generations. If not, the user may try again.
|
||||
String accountId = AccountNumberGenerator.GenerateNewAccountNumber(bankFourLetterIdentifier, routingNumber, ACCOUNT_TYPES.get(accountTypeStr), holderName);
|
||||
String accountId = AccountNumberGenerator.GenerateNewAccountNumber(bankFourLetterIdentifier, routingNumber, ACCOUNT_TYPES.get(accountType), holderName);
|
||||
|
||||
System.out.println("Account generator came back with bank account id { " + accountId + " }");
|
||||
System.out.println("4 letter bank: " + AccountNumberGenerator.GetFinancialSymbolFromId(accountId));
|
||||
@ -392,7 +386,7 @@ public class IndividualBank {
|
||||
// TODO: Fix in future with a method that will guarentee a one-time necessary number generator. Statistically speaking; this will be okay for the
|
||||
// entire life time of the server. BUT, you never know!
|
||||
while (maxAttempts != 0 && !accounts.accountsList.containsKey(AccountNumberGenerator.GetAccountNumberFromId(accountId))) {
|
||||
accountId = AccountNumberGenerator.GenerateNewAccountNumber(bankFourLetterIdentifier, routingNumber, ACCOUNT_TYPES.get(accountTypeStr), holderName);
|
||||
accountId = AccountNumberGenerator.GenerateNewAccountNumber(bankFourLetterIdentifier, routingNumber, ACCOUNT_TYPES.get(accountType), holderName);
|
||||
System.out.println("Account generator came back with bank account id { " + accountId + " }");
|
||||
maxAttempts--;
|
||||
}
|
||||
@ -403,7 +397,7 @@ public class IndividualBank {
|
||||
if (!accounts.accountsList.containsKey(actualAccountNumber)) {
|
||||
IndividualAccount newAccount = new IndividualAccount(actualAccountNumber, this.routingNumber, List.of(holderName),
|
||||
List.of(holderUuid), false, 0,
|
||||
"", ACCOUNT_TYPES.get(accountTypeStr), bankFourLetterIdentifier);
|
||||
"", accountType, bankFourLetterIdentifier);
|
||||
System.out.println("Updating accounts list for this bank");
|
||||
UpdateBankAccounts(holderName, holderUuid, actualAccountNumber, newAccount);
|
||||
success = true;
|
||||
|
@ -1,17 +1,21 @@
|
||||
package jesse.keeblarcraft.Commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType;
|
||||
import jesse.keeblarcraft.BankMgr.BankManager;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualAccount;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualBank;
|
||||
import jesse.keeblarcraft.BankMgr.BankAccountType.ACCOUNT_TYPE;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
@ -196,25 +200,197 @@ public class BankCommands {
|
||||
/// @brief Registers all bank commands on the server
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void RegisterCommands() {
|
||||
|
||||
// Bank help
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
// This is basically a small re-created SQL language but for bank commands. I recommend asking me for the drawn
|
||||
// image to better understand what this is accomplishing if it is confusing. Essentially it is easy though, as it
|
||||
// is just /bank ACTION-WORD [arguments...] [optionals]
|
||||
var bankRoot = CommandManager.literal("bank").build();
|
||||
var help = CommandManager.literal("help").build();
|
||||
var helpTarget = CommandManager.argument("target", StringArgumentType.greedyString())
|
||||
.executes(context -> HelpCommand(context.getSource().getPlayer(), StringArgumentType.getString(context, "target")))
|
||||
.build();
|
||||
|
||||
var info = CommandManager.literal("info")
|
||||
.executes(context -> ListBankInfo(context.getSource().getPlayer()))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(info);
|
||||
|
||||
var create = CommandManager.literal("create").build();
|
||||
var createAccount = CommandManager.literal("account").build();
|
||||
|
||||
var checking = CommandManager.literal("checking")
|
||||
.executes(context -> CreateAccount(context.getSource().getPlayer(), ACCOUNT_TYPE.CHECKING))
|
||||
.build();
|
||||
|
||||
var savings = CommandManager.literal("savings")
|
||||
.executes(context -> CreateAccount(context.getSource().getPlayer(), ACCOUNT_TYPE.SAVINGS))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(create);
|
||||
create.addChild(createAccount);
|
||||
createAccount.addChild(checking);
|
||||
createAccount.addChild(savings);
|
||||
|
||||
var wireCmd = CommandManager.literal("wire").build();
|
||||
var accountNum = CommandManager.argument("account", StringArgumentType.string()).build();
|
||||
var wireAmount = CommandManager.argument("amount", IntegerArgumentType.integer()).build();
|
||||
var wireReason = CommandManager.argument("reason", StringArgumentType.greedyString())
|
||||
.executes(context -> WireCommand(
|
||||
context.getSource().getPlayer(),
|
||||
IntegerArgumentType.getInteger(context, "amount"),
|
||||
StringArgumentType.getString(context, "account"),
|
||||
StringArgumentType.getString(context, "reason")
|
||||
))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(wireCmd);
|
||||
wireCmd.addChild(accountNum);
|
||||
accountNum.addChild(wireAmount);
|
||||
wireAmount.addChild(wireReason);
|
||||
|
||||
var list = CommandManager.literal("list")
|
||||
.executes(context -> ListAllBanks(context.getSource().getPlayer()))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(list);
|
||||
|
||||
var selectBankAccount = CommandManager.literal("select-default-account").build();
|
||||
var selectBankAccountName = CommandManager.argument("global-account-id", StringArgumentType.string())
|
||||
.executes(context -> SelectDefaultAccount(context.getSource().getPlayer(), StringArgumentType.getString(context, "global-account-id")))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(selectBankAccount);
|
||||
selectBankAccount.addChild(selectBankAccountName);
|
||||
|
||||
var selectBank = CommandManager.literal("select-bank").build();
|
||||
var selectBankName = CommandManager.argument("global_bank_name", StringArgumentType.string())
|
||||
.executes(context -> SelectBank(context.getSource().getPlayer(), StringArgumentType.getString(context, "global_bank_name")))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(selectBank);
|
||||
selectBank.addChild(selectBankName);
|
||||
|
||||
|
||||
|
||||
var close = CommandManager.literal("close").build();
|
||||
var closeAccountId = CommandManager.argument("account", StringArgumentType.string())
|
||||
.executes(context -> CloseCommand(context.getSource().getPlayer(), StringArgumentType.getString(context, "account")))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(close);
|
||||
close.addChild(closeAccountId);
|
||||
|
||||
|
||||
var moveCmd = CommandManager.literal("move").build();
|
||||
var moveAmount = CommandManager.argument("move_amount", IntegerArgumentType.integer()).build();
|
||||
var fromAccount = CommandManager.argument("from_account", StringArgumentType.string()).build();
|
||||
var toAccount = CommandManager.argument("to_account", StringArgumentType.string())
|
||||
.executes(context -> MoveCommand(
|
||||
context.getSource().getPlayer(),
|
||||
IntegerArgumentType.getInteger(context, "move_amount"),
|
||||
StringArgumentType.getString(context, "from_account"),
|
||||
StringArgumentType.getString(context, "to_account")
|
||||
))
|
||||
.build();
|
||||
|
||||
bankRoot.addChild(moveCmd);
|
||||
moveCmd.addChild(moveAmount);
|
||||
moveAmount.addChild(fromAccount);
|
||||
fromAccount.addChild(toAccount);
|
||||
|
||||
|
||||
var admin = CommandManager.literal("admin").build();
|
||||
// var accounts = CommandManager.literal("accounts").build();
|
||||
var subtractMoney = CommandManager.literal("sub-money").build();
|
||||
var subtractAmount = CommandManager.argument("sub_amount", IntegerArgumentType.integer()).build();
|
||||
var subtractAccount = CommandManager.argument("sub_account", StringArgumentType.string()).build();
|
||||
var subtractReason = CommandManager.argument("sub_reason", StringArgumentType.greedyString())
|
||||
.executes(context -> AdminSubtractMoney(
|
||||
context.getSource().getPlayer(),
|
||||
IntegerArgumentType.getInteger(context, "sub_amount"),
|
||||
StringArgumentType.getString(context, "sub_account"),
|
||||
StringArgumentType.getString(context, "sub_reason")
|
||||
))
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
var addMoney = CommandManager.literal("add-money").build();
|
||||
var addAmount = CommandManager.argument("add_amount", IntegerArgumentType.integer()).build();
|
||||
var addAccount = CommandManager.argument("add_account", StringArgumentType.string()).build();
|
||||
var addReason = CommandManager.argument("add_reason", StringArgumentType.greedyString())
|
||||
.executes(context -> AdminAddMoney(
|
||||
context.getSource().getPlayer(),
|
||||
IntegerArgumentType.getInteger(context, "add_amount"),
|
||||
StringArgumentType.getString(context, "add_account"),
|
||||
StringArgumentType.getString(context, "add_reason")
|
||||
))
|
||||
.build();
|
||||
|
||||
var setMoney = CommandManager.literal("set-bal").build();
|
||||
var setAmnt = CommandManager.argument("set_amount", IntegerArgumentType.integer()).build();
|
||||
var setAccount = CommandManager.argument("set_account", StringArgumentType.string()).build();
|
||||
var setReason = CommandManager.argument("set_reason", StringArgumentType.greedyString())
|
||||
.executes(context -> AdminSetMoney(
|
||||
context.getSource().getPlayer(),
|
||||
IntegerArgumentType.getInteger(context, "set_amount"),
|
||||
StringArgumentType.getString(context, "set_account"),
|
||||
StringArgumentType.getString(context, "set_reason")
|
||||
))
|
||||
.build();
|
||||
|
||||
var getBal = CommandManager.literal("get-bal").build();
|
||||
var getBalTgt = CommandManager.argument("get_bal_target", StringArgumentType.string()).build();
|
||||
|
||||
var createBank = CommandManager.literal("create-bank").build();
|
||||
var createBankName = CommandManager.argument("create_bank_name", StringArgumentType.string()).build();
|
||||
|
||||
var closeBank = CommandManager.literal("close-bank").build();
|
||||
var closeBankName = CommandManager.argument("close_bank_name", StringArgumentType.string()).build();
|
||||
|
||||
var setServerBal = CommandManager.literal("set-server-bal").build();
|
||||
var setServerBalAmnt = CommandManager.argument("set_server_bal_amount", StringArgumentType.string()).build();
|
||||
|
||||
var setServerAllowance = CommandManager.literal("set-server-allowance").build();
|
||||
var setServerAllowanceAmount = CommandManager.argument("set_server_allowance", IntegerArgumentType.integer()).build();
|
||||
|
||||
|
||||
bankRoot.addChild(admin);
|
||||
|
||||
admin.addChild(subtractMoney);
|
||||
subtractMoney.addChild(subtractAmount);
|
||||
subtractAmount.addChild(subtractAccount);
|
||||
subtractAccount.addChild(subtractReason);
|
||||
|
||||
admin.addChild(addMoney);
|
||||
addMoney.addChild(addAmount);
|
||||
addAmount.addChild(addAccount);
|
||||
addAccount.addChild(addReason);
|
||||
|
||||
admin.addChild(setMoney);
|
||||
setMoney.addChild(setAmnt);
|
||||
setAmnt.addChild(setAccount);
|
||||
setAccount.addChild(setReason);
|
||||
|
||||
admin.addChild(getBal);
|
||||
getBal.addChild(getBalTgt);
|
||||
|
||||
admin.addChild(createBank);
|
||||
createBank.addChild(createBankName);
|
||||
|
||||
admin.addChild(closeBank);
|
||||
admin.addChild(closeBankName);
|
||||
|
||||
admin.addChild(setServerBal);
|
||||
setServerBal.addChild(setServerBalAmnt);
|
||||
|
||||
admin.addChild(setServerAllowance);
|
||||
setServerAllowance.addChild(setServerAllowanceAmount);
|
||||
|
||||
// Removing "argList" and just running the entire list as an argList from actionWord makes `/bank help` possible
|
||||
var argList = CommandManager.argument("ARG_LIST", StringArgumentType.greedyString())
|
||||
.executes(context -> ParseBankCommand
|
||||
(
|
||||
context,
|
||||
StringArgumentType.getString(context, "ARG_LIST"))
|
||||
)
|
||||
.build();
|
||||
|
||||
// Building the argument tree here
|
||||
dispatcher.getRoot().addChild(bankRoot);
|
||||
bankRoot.addChild(argList);
|
||||
bankRoot.addChild(help);
|
||||
help.addChild(helpTarget);
|
||||
});
|
||||
}
|
||||
|
||||
@ -241,103 +417,12 @@ public class BankCommands {
|
||||
return argList;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn ParseBankCommand
|
||||
///
|
||||
/// @brief Parses the global bank command
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public int ParseBankCommand(CommandContext<ServerCommandSource> context, String unformattedArgList) {
|
||||
List<String> 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() + " }");
|
||||
formattedArgList = RemoveFillerWords(formattedArgList);
|
||||
|
||||
String actionWord = formattedArgList.get(0);
|
||||
System.out.println("The action word for this operation is " + actionWord.toUpperCase());
|
||||
System.out.println("Parsing bank command on action word { " + actionWord + " } with arg list { " + formattedArgList + " }");
|
||||
|
||||
switch(actionWord)
|
||||
{
|
||||
case "create":
|
||||
System.out.println("Calling create command...");
|
||||
CreateCommand(context.getSource().getPlayer(), formattedArgList.subList(1, formattedArgList.size()));
|
||||
break;
|
||||
case "close":
|
||||
CloseCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "select":
|
||||
SelectCommand(context.getSource().getPlayer(), formattedArgList.subList(1, formattedArgList.size()));
|
||||
break;
|
||||
case "wire":
|
||||
WireCommand(context.getSource().getPlayer(), formattedArgList.subList(1, formattedArgList.size()));
|
||||
break;
|
||||
case "balance":
|
||||
BalanceCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "help":
|
||||
HelpCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "move":
|
||||
MoveCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "alias":
|
||||
AliasCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "report":
|
||||
ReportCommand(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "examples":
|
||||
HelpCommand(context.getSource().getPlayer(), List.of(HELPCMD_EXAMPLES));
|
||||
break;
|
||||
case "syntax":
|
||||
HelpCommand(context.getSource().getPlayer(), List.of(HELPCMD_SYNTAX));
|
||||
break;
|
||||
case "list":
|
||||
ListAllBanks(context.getSource().getPlayer(), formattedArgList);
|
||||
break;
|
||||
case "account":
|
||||
case "accounts":
|
||||
ManageAccounts(context.getSource().getPlayer(), formattedArgList.subList(1, formattedArgList.size()));
|
||||
break;
|
||||
case "admin":
|
||||
AdminCommand(context.getSource().getPlayer(), formattedArgList.subList(1, formattedArgList.size()));
|
||||
break;
|
||||
default:
|
||||
if (context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().getPlayer().sendMessage(Text.of("You have entered an improperly formatted message. Please reference the bank manual if you are confused how to form a command!"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
public int SelectBank(ServerPlayerEntity player, String bank) {
|
||||
System.out.println("Select bank called");
|
||||
BankManager.GetInstance().ChangeDefaultSelectedBank(player, bank);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @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 {
|
||||
amount = Integer.parseInt(possibleInt);
|
||||
} catch (NumberFormatException exception) {
|
||||
HelpCommand(player, List.of(helpCmd));
|
||||
}
|
||||
|
||||
System.out.println("ParseToInteger was called. The input was " + possibleInt + " and the parsed int is " + amount);
|
||||
return amount;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn IsOperator
|
||||
///
|
||||
@ -355,166 +440,19 @@ public class BankCommands {
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// REQUIRED (path) = {accounts} {list} {PLAYER_NAME} (Returns summarized account information on a player)
|
||||
// REQUIRED (path) = {accounts} {move} {LONG_ID} to {BANK_ID} (Will move account to diff bank. May generate new account ID)
|
||||
// REQUIRED (path) = {accounts} {force-close} {LOND_ID} (Forces an account to be closed. Money is returned to server bank account)
|
||||
// REQUIRED (path) = {accounts} {add} to {PLAYER_NAME} [BANK_ID] (Adds an account to a player to server by default. Specify other for other)
|
||||
// REQUIRED (path) = {accounts} {transactions} from {LONG_ID} (Gets transaction report from an account by ID)
|
||||
// REQUIRED (path) = {accounts} {lock} {LONG_ID:USER} (Locks a specific bank account OR all bank accounts owned by $USER)
|
||||
// REQUIRED (path) = {create-bank} {BANK_ID} (Create a new bank. Default is owned by server)
|
||||
// REQUIRED (path) = {close-bank} {BANK_ID} (Closing a bank forces a close on all accounts. Banks money is returned to server bank)
|
||||
// REQUIRED (path) = {lock-bank} {BANK_ID} (Freezes all activities through a bank)
|
||||
// REQUIRED (path) = {unlock} {BANK_ID:ACCOUNT_ID:USER} (will unlock a bank, account, or all of a users accounts)
|
||||
// REQUIRED (path) = {wire} {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<String> argList) {
|
||||
// The player must be opped & the size must be at LEAST 2 (1 keyword + extra for sublist)
|
||||
String pName = sourcePlayer.getEntityName();
|
||||
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) {
|
||||
case "account":
|
||||
case "accounts":
|
||||
break;
|
||||
case "submoney":
|
||||
case "subtract-money":
|
||||
case "subtractmoney":
|
||||
case "sub-money":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
public int AdminSubtractMoney(ServerPlayerEntity player, Integer amount, String account, String reason) {
|
||||
AdminBalanceChange(player, account, amount, "subtract", reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "subtract", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "addmoney":
|
||||
case "add-money":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
public int AdminAddMoney(ServerPlayerEntity player, Integer amount, String account, String reason) {
|
||||
AdminBalanceChange(player, account, amount, "add", reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AdminBalanceChange(sourcePlayer, accountId, amount, "add", optionalReason);
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "setbal":
|
||||
case "set-bal":
|
||||
case "setbalance":
|
||||
case "set-balance":
|
||||
// Require account identifier + balance
|
||||
if (remainingArgs.size() >= 2) {
|
||||
String accountId = remainingArgs.get(0);
|
||||
Integer amount = ParseToInteger(sourcePlayer, remainingArgs.get(1), HELPCMD_ADMIN_BALANCE_CHANGE);
|
||||
String optionalReason = "";
|
||||
if (remainingArgs.size() >= 3) {
|
||||
optionalReason = remainingArgs.get(2);
|
||||
}
|
||||
|
||||
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(HELPCMD_ADMIN_BALANCE_CHANGE));
|
||||
}
|
||||
break;
|
||||
case "getbal":
|
||||
case "get-bal":
|
||||
case "getbalance":
|
||||
case "get-balance":
|
||||
// Require account identifier
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_BALANCE_GET));
|
||||
}
|
||||
break;
|
||||
case "createbank":
|
||||
case "create-bank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_CREATE_BANK));
|
||||
}
|
||||
break;
|
||||
case "closebank":
|
||||
case "close-bank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_CLOSE_BANK));
|
||||
}
|
||||
break;
|
||||
case "forcewire":
|
||||
case "force-wire":
|
||||
case "wiremoney":
|
||||
case "wire-money":
|
||||
case "wire":
|
||||
if (remainingArgs.size() >= 3) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_FORCE_WIRE));
|
||||
}
|
||||
break;
|
||||
case "lock-bank":
|
||||
case "lockbank":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_LOCK_BANK));
|
||||
}
|
||||
break;
|
||||
case "get-server-allowance":
|
||||
case "getserverallowance":
|
||||
sourcePlayer.sendMessage(Text.of(GetServerAllowance()));
|
||||
break;
|
||||
case "setserverallowance":
|
||||
case "set-server-allowance":
|
||||
if (remainingArgs.size() >= 1) {
|
||||
|
||||
} else {
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_SET_SERVER_ALLOWANCE));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
HelpCommand(sourcePlayer, List.of(HELPCMD_ADMIN_COMMANDS_LIST));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Only admins can use this command!"));
|
||||
}
|
||||
public int AdminSetMoney(ServerPlayerEntity player, Integer amount, String account, String reason) {
|
||||
AdminBalanceChange(player, account, amount, "set", reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String GetServerAllowance() {
|
||||
@ -538,7 +476,6 @@ public class BankCommands {
|
||||
/// 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);
|
||||
}
|
||||
|
||||
@ -582,49 +519,42 @@ public class BankCommands {
|
||||
///
|
||||
/// @brief Change the balance of a designated account
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void ManageAccounts(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
System.out.println("Manage accounts arg list is { " + argList + " }");
|
||||
if (argList.size() > 0) {
|
||||
// TODO: For now we assume they reference the bank name and not routing #
|
||||
String bankName = argList.get(0).toUpperCase();
|
||||
IndividualBank bank = BankManager.GetInstance().GetBankByName(bankName);
|
||||
System.out.println("Test print on memory");
|
||||
Boolean isNull = bank == null;
|
||||
System.out.println("isNull: " + isNull);
|
||||
public int ListBankInfo(ServerPlayerEntity sourcePlayer) {
|
||||
String bankName = BankManager.GetInstance().GetPlayerSelectedBank(sourcePlayer.getUuidAsString());
|
||||
IndividualBank bank = BankManager.GetInstance().GetBankByName(bankName);
|
||||
|
||||
if (bank != null) {
|
||||
System.out.println("Grabbing user account information");
|
||||
List<IndividualAccount> userAccounts = bank.GetAccountsOfUser(sourcePlayer.getUuidAsString());
|
||||
sourcePlayer.sendMessage(Text.of("[BANK INFO FOR " + bankName.toUpperCase() + "]"));
|
||||
System.out.println("userAccounts size: " + userAccounts.size());
|
||||
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++) {
|
||||
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();
|
||||
for (int i = 0; i < userAccounts.size(); i++) {
|
||||
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);
|
||||
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(msgFormatter.ColorMsg("That bank does not exist", COLOR_CODE.RED)));
|
||||
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("Unrecognized move command. Please use \"/bank help ACCOUNTS\" for more information."));
|
||||
sourcePlayer.sendMessage(Text.of(msgFormatter.ColorMsg("That bank does not exist", COLOR_CODE.RED)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void ListAllBanks(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
public int ListAllBanks(ServerPlayerEntity sourcePlayer) {
|
||||
sourcePlayer.sendMessage(Text.of("Here is a list of available banks on the server: " + BankManager.GetInstance().GetAllBankNames()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
@ -640,39 +570,8 @@ public class BankCommands {
|
||||
///
|
||||
/// @brief Command to move account. Read above comment for code paths
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void MoveCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
if (argList.size() >= 2) {
|
||||
String possibleExternalIdentifier = argList.get(1);
|
||||
|
||||
boolean isExternalTransfer = false;
|
||||
/*
|
||||
* CALL TO BANKMGR TO VERIFY IF ABOVE IS VALID BANK ID. IF NOT; THIS IS INTERNAL TRANSFER
|
||||
*/
|
||||
|
||||
if (isExternalTransfer) {
|
||||
// External move to another bank or faction
|
||||
String targetMoveAccount = argList.get(0);
|
||||
String destBankId = argList.get(1);
|
||||
|
||||
/*
|
||||
* CALL TO BANKMGR TO MOVE ACCOUNTS HERE
|
||||
*/
|
||||
} else {
|
||||
// Internal transfer to this players accounts within system
|
||||
String optionalFromAccount = ""; /* CALL TO BANKMGR TO GET DEFAULT SELECTED ACCOUNT FOR `FROM` FIELD */
|
||||
if (argList.size() == 3) {
|
||||
optionalFromAccount = argList.get(1);
|
||||
}
|
||||
|
||||
String transferAmount = argList.get(0);
|
||||
String destinationTransfer = argList.get(2);
|
||||
/*
|
||||
* BANK MGR CALL HERE
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized move command. Please use \"/bank help MOVE\" for more information."));
|
||||
}
|
||||
public int MoveCommand(ServerPlayerEntity sourcePlayer, Integer amount, String fromAccount, String toAccount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Posible code paths:
|
||||
@ -713,14 +612,14 @@ public class BankCommands {
|
||||
/// @brief Shorthand function call-through to CreateCommand for generating
|
||||
/// an account(s) report.
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void ReportCommand(ServerPlayerEntity sourcePlayer, List<String> 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
|
||||
CreateCommand(sourcePlayer, argList);
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized report command. Please run \"/bank help REPORT\" for more information."));
|
||||
}
|
||||
}
|
||||
// public void ReportCommand(ServerPlayerEntity sourcePlayer, List<String> 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
|
||||
// CreateCommand(sourcePlayer, argList);
|
||||
// } else {
|
||||
// sourcePlayer.sendMessage(Text.of("Unrecognized report command. Please run \"/bank help REPORT\" for more information."));
|
||||
// }
|
||||
// }
|
||||
|
||||
// Possible code paths:
|
||||
// REQUIRED = {}
|
||||
@ -746,82 +645,26 @@ public class BankCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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<String> argList) {
|
||||
System.out.println("Attempting account creation given arg list { " + argList + " }.");
|
||||
System.out.println("argList size is " + argList.size());
|
||||
|
||||
if (argList.size() > 0) {
|
||||
String action = argList.get(0).toLowerCase();
|
||||
System.out.println("action word is " + action);
|
||||
|
||||
switch (action) {
|
||||
// Checking & Savings are handled in the same function so we can just "alias" all of these to the same call!
|
||||
case "ca":
|
||||
case "checking":
|
||||
case "checking-account":
|
||||
case "sa":
|
||||
case "savings":
|
||||
case "savings-account":
|
||||
System.out.println("Creating account. Removing index 0 in argList. New argList is { " + argList + " }");
|
||||
CreateAccount(sourcePlayer, argList);
|
||||
break;
|
||||
case "rep":
|
||||
case "report":
|
||||
GenerateAccountReport(sourcePlayer, argList);
|
||||
break;
|
||||
default:
|
||||
// Unrecognized creation type
|
||||
}
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized create command formed on bank. Please run \"/bank help CREATE\" for more information"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
// REQUIRED = {ACCOUNT ID|ALIAS}
|
||||
// OPTIONAL = []
|
||||
public int CloseCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
if (argList.size() > 0) {
|
||||
String accountToClose = argList.get(0);
|
||||
/*
|
||||
* CALL TO BANKMGR TO DO STUFF
|
||||
*/
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized close command. Please see \"/bank help CLOSE\" for more information."));
|
||||
}
|
||||
public int CloseCommand(ServerPlayerEntity sourcePlayer, String account) {
|
||||
// if (argList.size() > 0) {
|
||||
// String accountToClose = argList.get(0);
|
||||
// /*
|
||||
// * CALL TO BANKMGR TO DO STUFF
|
||||
// */
|
||||
// } else {
|
||||
// sourcePlayer.sendMessage(Text.of("Unrecognized close command. Please see \"/bank help CLOSE\" for more information."));
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths:
|
||||
// required = {account id | alias}
|
||||
// optional = [default|secondary|backup]
|
||||
public int SelectCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
if (argList.size() > 0) {
|
||||
String requiredArg = argList.get(0);
|
||||
|
||||
// If the optional args exist; fetch them
|
||||
String optionalArg = "";
|
||||
if (argList.size() == 2) {
|
||||
optionalArg = argList.get(1);
|
||||
}
|
||||
|
||||
BankManager.GetInstance().ChangeDefaultPlayerAccount(sourcePlayer, requiredArg);
|
||||
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized select command. Please run /bank help select for more information."));
|
||||
}
|
||||
public int SelectDefaultAccount(ServerPlayerEntity sourcePlayer, String account) {
|
||||
BankManager.GetInstance().ChangeDefaultPlayerAccount(sourcePlayer, account);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -837,22 +680,8 @@ public class BankCommands {
|
||||
///
|
||||
/// @brief Create wire on bank account
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public int WireCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||
System.out.println("WireCommand called with arg size " + argList.size());
|
||||
if (argList.size() >= 2) {
|
||||
Integer amountToWire = ParseToInteger(sourcePlayer, argList.get(0), HELPCMD_WIRE);
|
||||
String destAccount = argList.get(1);
|
||||
|
||||
String optionalReason = "";
|
||||
if (argList.size() >= 3) {
|
||||
optionalReason = argList.get(3);
|
||||
}
|
||||
System.out.println("optional reason: " + optionalReason);
|
||||
|
||||
BankManager.GetInstance().InitiateBankFundsTransfer(sourcePlayer, destAccount, amountToWire);
|
||||
} else {
|
||||
sourcePlayer.sendMessage(Text.of("Unrecognized wire command. Please run /bank help wire for more information."));
|
||||
}
|
||||
public int WireCommand(ServerPlayerEntity sourcePlayer, Integer amount, String destAccount, String reason) {
|
||||
BankManager.GetInstance().InitiateBankFundsTransfer(sourcePlayer, destAccount, amount, reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -869,8 +698,10 @@ public class BankCommands {
|
||||
/// @brief Builds a dynamic help list to the player to see all command
|
||||
/// options on the server
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public int HelpCommand(ServerPlayerEntity sourcePlayer, List<String> helpCommand) {
|
||||
public int HelpCommand(ServerPlayerEntity sourcePlayer, String helpCommandList) {
|
||||
System.out.println("Running help command");
|
||||
List<String> helpCommand = new ArrayList<String>(Arrays.asList(helpCommandList.split(" ")));
|
||||
|
||||
if (helpCommand.size() == 0) {
|
||||
// General help command
|
||||
for (Entry<String, String> helpCmd : HELP_COMMANDS.entrySet()) {
|
||||
@ -917,23 +748,14 @@ public class BankCommands {
|
||||
///
|
||||
/// @brief Creates a bank account
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void CreateAccount(ServerPlayerEntity player, List<String> accountArgs) {
|
||||
System.out.println("Attempting to create checking account with arg list { " + accountArgs + " }");
|
||||
if (accountArgs.size() > 0) {
|
||||
String accountType = accountArgs.get(0);
|
||||
String accountAlias = "NO_ALIAS";
|
||||
public int CreateAccount(ServerPlayerEntity player, ACCOUNT_TYPE accountType) {
|
||||
String bank = BankManager.GetInstance().GetPlayerSelectedBank(player.getUuidAsString());
|
||||
System.out.println("Received bank: " + bank);
|
||||
|
||||
// Set the optional account alias for ease-of-reference
|
||||
if (accountArgs.size() >= 2) {
|
||||
accountAlias = accountArgs.get(1).toLowerCase();
|
||||
}
|
||||
|
||||
System.out.println("ACCOUNT CREATION REQUESTED WITH TYPE " + accountType + " AND ALIAS " + accountAlias);
|
||||
// FIXME: This is just a patch at the moment to let players make bank accounts in server bank
|
||||
BankManager.GetInstance().InitiateBankAccountCreation(null, player, accountType);
|
||||
} else {
|
||||
player.sendMessage(Text.of("Unrecognized create account command. Please run /bank help create for more information"));
|
||||
if (bank != "") {
|
||||
BankManager.GetInstance().InitiateBankAccountCreation(bank, player, accountType);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Possible code paths for /bank create report
|
||||
|
@ -95,6 +95,18 @@ public class GeneralConfig {
|
||||
return config.sqlPassword;
|
||||
}
|
||||
|
||||
public String GetSQLUsername() {
|
||||
return config.sqlUsername;
|
||||
}
|
||||
|
||||
public String GetSQLAddress() {
|
||||
return config.sqlAddress;
|
||||
}
|
||||
|
||||
public String GetSQLDatabase() {
|
||||
return config.sqlDatabaseName;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn IsNewPlayer
|
||||
///
|
||||
@ -133,7 +145,10 @@ public class GeneralConfig {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private class ImplementedConfig {
|
||||
public String MOTD = "Welcome to the server! Have fun!";
|
||||
public String sqlPassword = "PUT SQL PASSWORD HERE";
|
||||
public String sqlAddress = "localhost";
|
||||
public String sqlDatabaseName = "keeblarcraft";
|
||||
public String sqlUsername = "SQL_USERNAME";
|
||||
public String sqlPassword = "SQL_PASSWORD";
|
||||
|
||||
// This is lazy, but this will fill with every unique UUID that has joined the server. This is how I am checking
|
||||
// to see if a player has just joined the server for a first time or not
|
||||
|
@ -6,8 +6,16 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import jesse.keeblarcraft.Utils.CommonStructures.Pair;
|
||||
|
||||
public class SQLConfig {
|
||||
private static SQLConfig static_inst;
|
||||
private String dbName;
|
||||
private String dbUser;
|
||||
private String dbPass;
|
||||
private String dbAddr;
|
||||
private Boolean connected = false;
|
||||
private Connection conn = null; // Actual connection object
|
||||
|
||||
public static SQLConfig GetInstance() {
|
||||
if (static_inst == null) {
|
||||
@ -17,22 +25,25 @@ public class SQLConfig {
|
||||
return static_inst;
|
||||
}
|
||||
|
||||
Connection conn = null;
|
||||
|
||||
public SQLConfig() {
|
||||
Boolean canConnect = false;
|
||||
connected = false;
|
||||
try {
|
||||
// According to some random online tutorial; this loads the driver!
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
canConnect = true;
|
||||
connected = true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Could not find the proper SQL JDBC Drivers. Cannot connect to SQL Config");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (canConnect) {
|
||||
if (connected) {
|
||||
try {
|
||||
conn = DriverManager.getConnection("jdbc:mysql://localhost/keeblarcraft", "keeblarcraft", GeneralConfig.GetInstance().GetSQLPassword());
|
||||
dbName = GeneralConfig.GetInstance().GetSQLDatabase();
|
||||
dbUser = GeneralConfig.GetInstance().GetSQLUsername();
|
||||
dbPass = GeneralConfig.GetInstance().GetSQLPassword();
|
||||
dbAddr = "jdbc:mysql://" + GeneralConfig.GetInstance().GetSQLAddress() + "/" + dbName;
|
||||
conn = DriverManager.getConnection(dbAddr, dbUser, dbPass);
|
||||
Statement stmnt = conn.createStatement();
|
||||
String testSql = "SELECT * FROM test_table";
|
||||
ResultSet rs = stmnt.executeQuery(testSql);
|
||||
@ -44,4 +55,66 @@ public class SQLConfig {
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
private ResultSet RunCommand(String sqlCommand) {
|
||||
ResultSet cmdResult = null;
|
||||
if (conn != null) {
|
||||
try {
|
||||
Statement statement = conn.createStatement();
|
||||
cmdResult = statement.executeQuery(sqlCommand);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
return cmdResult;
|
||||
}
|
||||
|
||||
// Re-attempt the connection
|
||||
public Boolean Connect() {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
Boolean success = false;
|
||||
try {
|
||||
conn = DriverManager.getConnection(dbAddr, dbUser, dbPass);
|
||||
success = true;
|
||||
} catch (Exception e) {}
|
||||
return success;
|
||||
}
|
||||
|
||||
public Boolean IsConnected() {
|
||||
return conn != null && this.connected;
|
||||
}
|
||||
|
||||
private Boolean TableExists(String name) {
|
||||
boolean tableExists = false;
|
||||
try (ResultSet rs = conn.getMetaData().getTables(null, null, name, null)) {
|
||||
while (rs.next()) {
|
||||
String tName = rs.getString("TABLE_NAME");
|
||||
if (tName != null && tName.equals(name)) {
|
||||
tableExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {}
|
||||
return tableExists;
|
||||
}
|
||||
|
||||
// Might fix heap pollution decay in future with enum types or something. For now we assume the user isn't horrifically stupid and will give a SQL-able type
|
||||
public Boolean CreateTable(String tableName, Pair<String, Object>... columnPairs) {
|
||||
Boolean success = false;
|
||||
|
||||
if (!TableExists(tableName.toUpperCase())) {
|
||||
String sqlCommand = "CREATE TABLE " + tableName.toUpperCase() + "(";
|
||||
for (Pair<String, Object> colPair : columnPairs) {
|
||||
sqlCommand = sqlCommand + " " + colPair.GetKey() + " " + String.valueOf(colPair.GetValue()) + ",";
|
||||
}
|
||||
|
||||
System.out.println("DEBUG STATEMENT, SQL STATEMENT: " + sqlCommand);
|
||||
ResultSet rs = RunCommand(sqlCommand);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
@ -68,9 +68,10 @@ public class PlayerJoinListener {
|
||||
var player = handler.player;
|
||||
|
||||
// Handle skill tree map instance
|
||||
if (AttributeMgr.activeTrees.containsKey(player.getUuidAsString()) == false) {
|
||||
AttributeMgr.activeTrees.put(player.getUuidAsString(), new AttributeTree(player.getUuidAsString()));
|
||||
}
|
||||
/// TODO: Turning this off for now because it's not out yet and breaking!
|
||||
// if (AttributeMgr.activeTrees.containsKey(player.getUuidAsString()) == false) {
|
||||
// AttributeMgr.activeTrees.put(player.getUuidAsString(), new AttributeTree(player.getUuidAsString()));
|
||||
// }
|
||||
|
||||
// Handle first time joining events (world spawn teleport, MOTD, etc)
|
||||
System.out.println("Running first time login stuff");
|
||||
|
@ -0,0 +1,26 @@
|
||||
package jesse.keeblarcraft.Utils.CommonStructures;
|
||||
|
||||
public class Pair<KEY, VALUE> {
|
||||
KEY key;
|
||||
VALUE value;
|
||||
public Pair(KEY key, VALUE val) {
|
||||
this.key = key;
|
||||
this.value = val;
|
||||
}
|
||||
|
||||
public KEY GetKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public VALUE GetValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void SetKey(KEY newKey) {
|
||||
this.key = newKey;
|
||||
}
|
||||
|
||||
public void SetValue(VALUE newValue) {
|
||||
this.value = newValue;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user