diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java index af077ba..01e6e06 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java @@ -31,8 +31,7 @@ public class BankManager { if (!existingFile) { System.out.println(ChatUtil.ColoredString("Trying to create new file", CONSOLE_COLOR.BLUE)); try { - bankInfo.uuid = uuid; - FlashConfig(); + FlashConfig(bankInfo.uuid); } catch (Exception e) { System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED)); } @@ -58,7 +57,7 @@ public class BankManager { } long balance = 0; - String reason; + String reason; //not sure why my compiler is saying unused long payment; String otherParty; Integer time; @@ -98,55 +97,55 @@ public class BankManager { } return ret; } - - public void SetBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { + //https://maven.fabricmc.net/docs/fabric-api-0.34.8+1.17/net/fabricmc/fabric/api/networking/v1/PlayerLookup.html maybe this for getting the players im still not sure + public void SetBalance(Integer newBalance, String reason, String otherParty) { Integer transactionNumber = bankInfo.bank.size(); bankInfo.bank.put(transactionNumber.toString(), - new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); + new BankManagerMetaData(newBalance, reason, newBalance, otherParty, 0)); - FlashConfig(); + FlashConfig(PlayerListNameChecker(otherParty)); } - public void AddMoney(Integer newBalance, String reason, long payment, String otherParty, Integer time) { + public void AddMoney(String reason, long payment, String otherParty) { if (bankInfo.bank.size() > 0) { for (Entry entry : bankInfo.bank.entrySet()) { - entry.getValue().balance += newBalance; - entry.getValue().reason = reason; + entry.getValue().balance += payment; + entry.getValue().reason = "SERVER: " + reason; entry.getValue().payment = payment; entry.getValue().otherParty = otherParty; - entry.getValue().time = time; + entry.getValue().time = 0; } } else { - bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); + bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(payment, reason, payment, otherParty, 0)); } - FlashConfig(); + FlashConfig(PlayerListNameChecker(otherParty)); } - public void SubtractBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { + public void SubtractBalance(String reason, long payment, String otherParty) { if (bankInfo.bank.size() > 0) { for (Entry entry : bankInfo.bank.entrySet()) { - entry.getValue().balance -= newBalance; - entry.getValue().reason = reason; + entry.getValue().balance -= payment;//not working? + entry.getValue().reason = "SERVER: " + reason; entry.getValue().payment = payment; entry.getValue().otherParty = otherParty; - entry.getValue().time = time; + entry.getValue().time = 0; } } else { - bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); + bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(0, reason, payment, otherParty, 0)); } - FlashConfig(); + FlashConfig(PlayerListNameChecker(otherParty)); } - public void Wire(Integer newBalance, String reason, long payment, String otherParty, Integer time) { + public void Wire(String reason, long payment, String otherParty) { if (bankInfo.bank.size() > 0) { for (Entry entry : bankInfo.bank.entrySet()) { - entry.getValue().balance -= newBalance; + entry.getValue().balance -= payment; entry.getValue().reason = reason; entry.getValue().payment = payment; entry.getValue().otherParty = otherParty; - entry.getValue().time = time; + entry.getValue().time = 0; if (payment <= 0) { // add a error for the PLAYER not the server @@ -180,15 +179,15 @@ public class BankManager { newBankInfo = config.GetJsonObjectFromFile("bank/" + GetUuidByName(server, otherParty) + ".json", BankManagerFile.class); // for now we will only use adding valance and not subtracting since that dosent make any sense for (Entry entry : newBankInfo.bank.entrySet()) { - entry.getValue().balance += newBalance; + entry.getValue().balance += payment; entry.getValue().reason = reason; entry.getValue().payment = payment; entry.getValue().otherParty = otherParty; - entry.getValue().time = time; + entry.getValue().time = 0; } //cannot use regular flash config since the hard coded values need to add agurment for the uuid //needs to be inside the player check - FlashConfig(); + FlashConfig(newBankInfo.uuid); try { config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", bankInfo); } catch (FILE_WRITE_EXCEPTION e) { @@ -216,9 +215,40 @@ public class BankManager { } } - public void FlashConfig() { + String PlayerListNameChecker(String otherParty) { + MinecraftServer server = CommonServerUtils.GetServerInstance(); + String[] playerList = server.getPlayerNames(); + + for (int i = 0; i < playerList.length; i++) { + System.out.println(ChatUtil.ColoredString("PLAYERS: " + playerList, CONSOLE_COLOR.YELLOW)); + if (playerList[i] == otherParty) { + System.out.println(ChatUtil.ColoredString("Found Player: " + otherParty, CONSOLE_COLOR.GREEN)); + // we will use getuuidbyname then set the other VALID players bank BE SURE TO + // MAKE THEM A BANK FIRST IF THEY DONT HAVE ONE fortnite forever + if (config.GetFile("bank/" + GetUuidByName(server, otherParty) + ".json").size() < 1) { + BankManagerFile newBankInfo = new BankManagerFile(); + BankManagerMetaData newBank = new BankManagerMetaData(0, "Account Created", 0, "Server", 0); + newBankInfo.bank.put(GetUuidByName(server, otherParty).toString(), newBank); + try { + config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", newBankInfo); + } catch (FILE_WRITE_EXCEPTION e) { + System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED)); + return ""; + } + } + else { + System.out.println(ChatUtil.ColoredString("Bank Account Found", CONSOLE_COLOR.GREEN)); + } + return GetUuidByName(server, otherParty); + } + } + System.out.println(ChatUtil.ColoredString("For Loop condition bypassed Null Playerlist or Null Server instance", CONSOLE_COLOR.RED)); + return ""; + } + + public void FlashConfig(String uuid) { try { - config.WriteToJsonFile("bank/" + bankInfo.uuid.toString() + ".json", bankInfo); + config.WriteToJsonFile("bank/" + uuid + ".json", bankInfo); } catch (FILE_WRITE_EXCEPTION e) { System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED)); } diff --git a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java index b672424..9030c5f 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java @@ -23,82 +23,62 @@ public class BankCommands { .executes(context -> GetBalance(context))); }); - // Command: "/setbalance" + // Command: "/setbalance || rootSetBalance" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { final var rootSetBalance = dispatcher.register(CommandManager.literal("setbalance") .then(CommandManager.argument("newBalance", IntegerArgumentType.integer()) .then(CommandManager.argument("reason", StringArgumentType.string()) - .then(CommandManager.argument("payment", LongArgumentType.longArg()) .then(CommandManager.argument("otherParty", StringArgumentType.string()) - //probably will remove time and otherParty from this agurment list not sure yet - .then(CommandManager.argument("time", IntegerArgumentType.integer()) .executes(context -> SetBalance( IntegerArgumentType.getInteger(context, "newBalance"), StringArgumentType.getString(context, "reason"), - LongArgumentType.getLong(context, "payment"), StringArgumentType.getString(context, "otherParty"), - IntegerArgumentType.getInteger(context, "time"), - context)))))))); + context)))))); - dispatcher.register(CommandManager.literal("resetbalance").redirect(rootSetBalance)); + dispatcher.register(CommandManager.literal("setbalance").redirect(rootSetBalance)); }); // Command: "/AddMoney" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("AddMoney") - .then(CommandManager.argument("newBalance", IntegerArgumentType.integer()) .then(CommandManager.argument("reason", StringArgumentType.string()) .then(CommandManager.argument("payment", LongArgumentType.longArg()) .then(CommandManager.argument("otherParty", StringArgumentType.string()) - //probably will remove time and otherParty from this agurment list not sure yet - .then(CommandManager.argument("time", IntegerArgumentType.integer()) .executes(context -> AddMoney( - IntegerArgumentType.getInteger(context, "newBalance"), StringArgumentType.getString(context, "reason"), LongArgumentType.getLong(context, "payment"), StringArgumentType.getString(context, "otherParty"), - IntegerArgumentType.getInteger(context, "time"), - context)))))))); + context)))))); }); - // Command: "/removebalance" + // Command: "/subtractbalance || /SubtractBalance" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - final var rootSubtractBalance = dispatcher.register(CommandManager.literal("subtractbalance") - .then(CommandManager.argument("newBalance", IntegerArgumentType.integer()) + final var SubtractBalance = dispatcher.register(CommandManager.literal("subtractbalance") .then(CommandManager.argument("reason", StringArgumentType.string()) .then(CommandManager.argument("payment", LongArgumentType.longArg()) .then(CommandManager.argument("otherParty", StringArgumentType.string()) - //probably will remove time and otherParty from this agurment list not sure yet - .then(CommandManager.argument("time", IntegerArgumentType.integer()) .executes(context -> SubtractBalance( - IntegerArgumentType.getInteger(context, "newBalance"), StringArgumentType.getString(context, "reason"), LongArgumentType.getLong(context, "payment"), StringArgumentType.getString(context, "otherParty"), - IntegerArgumentType.getInteger(context, "time"), - context)))))))); + context)))))); - dispatcher.register(CommandManager.literal("-balance").redirect(rootSubtractBalance)); + dispatcher.register(CommandManager.literal("subtractbalance").redirect(SubtractBalance)); }); - // Command: "/wire" + // Command: "/wire || /sendmoney" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { final var sendmoney = dispatcher.register(CommandManager.literal("wire") - .then(CommandManager.argument("newBalance", IntegerArgumentType.integer()) .then(CommandManager.argument("reason", StringArgumentType.string()) .then(CommandManager.argument("payment", LongArgumentType.longArg()) .then(CommandManager.argument("otherParty", StringArgumentType.string()) - //probably will remove time and otherParty from this agurment list not sure yet - .then(CommandManager.argument("time", IntegerArgumentType.integer()) .executes(context -> Wire( - IntegerArgumentType.getInteger(context, "newBalance"), StringArgumentType.getString(context, "reason"), LongArgumentType.getLong(context, "payment"), StringArgumentType.getString(context, "otherParty"), - IntegerArgumentType.getInteger(context, "time"), - context)))))))); + context)))))); - dispatcher.register(CommandManager.literal("resetbalance").redirect(sendmoney)); + dispatcher.register(CommandManager.literal("wire").redirect(sendmoney)); }); } @@ -115,58 +95,58 @@ public class BankCommands { return ret; } - //SetBalance will be a ServerCommand only - public Integer SetBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { + //SetBalance will be a ServerCommand only Perm level Op + public Integer SetBalance(Integer newBalance, String reason, String otherParty, CommandContext context) { Integer ret = -1; - if (context.getSource().isExecutedByPlayer()) { + if (context.getSource().hasPermissionLevel(1)) { ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); - playerBank.SetBalance(newBalance, reason, payment, otherParty, time); + playerBank.SetBalance(newBalance, reason, otherParty); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); } return ret; } - //AddMoney will be a ServerCommand Only - public Integer AddMoney(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { + //AddMoney will be a ServerCommand Only Perm level Op + public Integer AddMoney(String reason, long payment, String otherParty, CommandContext context) { Integer ret = -1; - if (context.getSource().isExecutedByPlayer()) { + if (context.getSource().hasPermissionLevel(1)) { ret = 0; ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); - playerBank.AddMoney(newBalance, reason, payment, otherParty, time); + playerBank.AddMoney(reason, payment, otherParty); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); } return ret; } - //SubtractBalance will be a ServerCommand only - public Integer SubtractBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { + //SubtractBalance will be a ServerCommand Perm leve Op + public Integer SubtractBalance(String reason, long payment, String otherParty, CommandContext context) { Integer ret = -1; - if (context.getSource().isExecutedByPlayer()) { + if (context.getSource().hasPermissionLevel(1)) { ret = 0; ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); - playerBank.SubtractBalance(newBalance, reason, payment, otherParty, time); + playerBank.SubtractBalance(reason, payment, otherParty); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); } return ret; } - public Integer Wire(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { + public Integer Wire(String reason, long payment, String otherParty, CommandContext context) { Integer ret = -1; if (context.getSource().isExecutedByPlayer()) { ret = 0; ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); - playerBank.Wire(newBalance, reason, payment, otherParty, time); + playerBank.Wire(reason, payment, otherParty); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); } diff --git a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java index 0698206..dd8110a 100644 --- a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java +++ b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java @@ -150,38 +150,6 @@ public class ConfigManager { } } - //NOTE: THIS APPENDS TO EXISITING JSON FILE - // public void AppendToJsonFile(String fileName, Object data) throws FILE_WRITE_EXCEPTION { - // Gson gson = new GsonBuilder().setPrettyPrinting().create(); - // File file = new File(fileName); - // if (!file.exists()) { - // WriteToJsonFile(fileName, data); - // } - // try { - // //read the json file and get the objects and store them in a array - // FileReader jsonParser = new FileReader(fileName); - // JsonArray jsonArray = new JsonArray(); - // jsonArray = JsonParser.parseReader(jsonParser).getAsJsonArray(); - // FileWriter writer = new FileWriter(fileName); - // jsonParser.close(); - - // //make the new json object here convert the map with gson and put in the array - // JsonObject createJsonObject = new JsonObject(); - // Gson mapper = new Gson(); - // createJsonObject = mapper.toJsonTree(data).getAsJsonObject(); - // jsonArray.add(createJsonObject); - - // //write to file - // gson.toJson(jsonArray, writer); - // writer.flush(); - // writer.close(); - // } - // catch (JsonIOException | IOException e) { - // System.out.println(ChatUtil.ColoredString("Could not successfully write to json file", CONSOLE_COLOR.RED)); - // throw new FILE_WRITE_EXCEPTION(); - // } - // } - // GetJsonStringFromFile // // Retrieves json file and converts to desired object. Returns JsonSyntaxException if file could not be fitted to class input