From 7e4eb94248ac9e6cb5ccfa2c1f9ac8a73e076820 Mon Sep 17 00:00:00 2001 From: Walrus Date: Thu, 15 Aug 2024 20:04:34 -0400 Subject: [PATCH] fixed merge request issues --- src/main/java/jesse/CommonServerUtils.java | 17 ++++++ .../keeblarcraft/BankMgr/BankManager.java | 57 ++++++++----------- .../keeblarcraft/Commands/BankCommands.java | 16 +++--- .../keeblarcraft/ConfigMgr/ConfigManager.java | 11 ---- .../java/jesse/keeblarcraft/Keeblarcraft.java | 1 - .../keeblarcraft/ServerTickListener.java | 5 +- .../java/jesse/keeblarcraft/Utils/Setup.java | 2 - 7 files changed, 52 insertions(+), 57 deletions(-) create mode 100644 src/main/java/jesse/CommonServerUtils.java diff --git a/src/main/java/jesse/CommonServerUtils.java b/src/main/java/jesse/CommonServerUtils.java new file mode 100644 index 0000000..b241354 --- /dev/null +++ b/src/main/java/jesse/CommonServerUtils.java @@ -0,0 +1,17 @@ +package jesse; + +import net.minecraft.server.MinecraftServer; + +public class CommonServerUtils { +//the config is gonna hold the server instance change it if you want but dont reject my code cause its here +private static MinecraftServer server; + +public void SetServerInstance(MinecraftServer inputServer) { + server = inputServer; +} + +public static MinecraftServer GetServerInstance() { + return server; +} + +} diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java index ccb382b..af077ba 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java @@ -3,6 +3,7 @@ package jesse.keeblarcraft.BankMgr; import java.util.HashMap; import java.util.Map.Entry; +import jesse.CommonServerUtils; import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.Utils.ChatUtil; import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; @@ -12,13 +13,14 @@ import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; public class BankManager { - InnerBankManagerInfo bankInfo = new InnerBankManagerInfo(); // not sure why we make another one but i guess so we + BankManagerFile bankInfo = new BankManagerFile(); // not sure why we make another one but i guess so we ConfigManager config = new ConfigManager(); // for read and write privs + CommonServerUtils commonServerUtils = new CommonServerUtils(); public BankManager(String uuid) { Boolean existingFile = false; try { - bankInfo = config.GetJsonObjectFromFile("bank/" + uuid + ".json", InnerBankManagerInfo.class); + bankInfo = config.GetJsonObjectFromFile("bank/" + uuid + ".json", BankManagerFile.class); existingFile = true; } catch (Exception e) { // Do nothing. This means the file does not exist @@ -45,8 +47,9 @@ public class BankManager { } } - private class InnerBankManager { - public InnerBankManager(long money, String reason, long payment, String otherParty, Integer time) { + //this class is the structure for the hashmap in BankManagerFile + private class BankManagerMetaData { + public BankManagerMetaData(long money, String reason, long payment, String otherParty, Integer time) { this.balance = money; this.reason = reason; this.payment = payment; @@ -61,7 +64,8 @@ public class BankManager { Integer time; } - public class InnerBankManagerInfo { + // This is the general bank account of the read-in config for the player uuid ||| the class that gets converted into a json for the players file + public class BankManagerFile { // Players uuid is the name of the file String uuid; @@ -84,12 +88,12 @@ public class BankManager { * } * } */ - public HashMap bank = new HashMap(); + public HashMap bank = new HashMap(); } public long GetBalance() { long ret = 0; - for (Entry entry : bankInfo.bank.entrySet()) { + for (Entry entry : bankInfo.bank.entrySet()) { ret = entry.getValue().balance; } return ret; @@ -98,14 +102,14 @@ public class BankManager { public void SetBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { Integer transactionNumber = bankInfo.bank.size(); bankInfo.bank.put(transactionNumber.toString(), - new InnerBankManager(newBalance, reason, payment, otherParty, time)); + new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); FlashConfig(); } - public void AddBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { + public void AddMoney(Integer newBalance, String reason, long payment, String otherParty, Integer time) { if (bankInfo.bank.size() > 0) { - for (Entry entry : bankInfo.bank.entrySet()) { + for (Entry entry : bankInfo.bank.entrySet()) { entry.getValue().balance += newBalance; entry.getValue().reason = reason; entry.getValue().payment = payment; @@ -113,7 +117,7 @@ public class BankManager { entry.getValue().time = time; } } else { - bankInfo.bank.put(bankInfo.uuid, new InnerBankManager(newBalance, reason, payment, otherParty, time)); + bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); } FlashConfig(); @@ -121,7 +125,7 @@ public class BankManager { public void SubtractBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { if (bankInfo.bank.size() > 0) { - for (Entry entry : bankInfo.bank.entrySet()) { + for (Entry entry : bankInfo.bank.entrySet()) { entry.getValue().balance -= newBalance; entry.getValue().reason = reason; entry.getValue().payment = payment; @@ -129,16 +133,15 @@ public class BankManager { entry.getValue().time = time; } } else { - bankInfo.bank.put(bankInfo.uuid, new InnerBankManager(newBalance, reason, payment, otherParty, time)); + bankInfo.bank.put(bankInfo.uuid, new BankManagerMetaData(newBalance, reason, payment, otherParty, time)); } FlashConfig(); } - //WE NEED TO ADD A CHECK IF THE PLAYER HAS A ACCOUNT AS WELL TECHINCALLY even though they should never try to wire first public void Wire(Integer newBalance, String reason, long payment, String otherParty, Integer time) { if (bankInfo.bank.size() > 0) { - for (Entry entry : bankInfo.bank.entrySet()) { + for (Entry entry : bankInfo.bank.entrySet()) { entry.getValue().balance -= newBalance; entry.getValue().reason = reason; entry.getValue().payment = payment; @@ -151,7 +154,7 @@ public class BankManager { } } // make a server instance - MinecraftServer server = ConfigManager.GetServerInstance(); + MinecraftServer server = CommonServerUtils.GetServerInstance(); String[] playerList = server.getPlayerNames(); //NOT SURE IF THIS FOR LOOP IS ONE OFF COULD POSSIBLEY BE SO IF NO ONE IS GETTING MONEY DOUBLE CHECK FOR LOOP for (int i = 0; i < playerList.length; i++) { @@ -160,9 +163,9 @@ public class BankManager { 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") != null) { - InnerBankManagerInfo newBankInfo = new InnerBankManagerInfo(); - InnerBankManager newBank = new InnerBankManager(0, "Account Created", 0, "Server", 0); + 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); @@ -173,10 +176,10 @@ public class BankManager { } //since the other player has a account now and we have access to it we can start fucking around - InnerBankManagerInfo newBankInfo = new InnerBankManagerInfo(); - newBankInfo = config.GetJsonObjectFromFile("bank/" + GetUuidByName(server, otherParty) + ".json", InnerBankManagerInfo.class); + BankManagerFile newBankInfo = new BankManagerFile(); + 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()) { + for (Entry entry : newBankInfo.bank.entrySet()) { entry.getValue().balance += newBalance; entry.getValue().reason = reason; entry.getValue().payment = payment; @@ -219,15 +222,5 @@ public class BankManager { } catch (FILE_WRITE_EXCEPTION e) { System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED)); } - - // public void FlashConfigAppend() { - // try { - // config.WriteToJsonFile("bank/" + bankInfo.uuid.toString() + ".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 03eb660..b672424 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java @@ -1,7 +1,5 @@ package jesse.keeblarcraft.Commands; -import java.util.HashMap; - import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -17,7 +15,6 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; public class BankCommands { ConfigManager config = new ConfigManager(); - HashMap monopolyMan; public void RegisterCommands(){ // Command: "/getbalance" @@ -46,16 +43,16 @@ public class BankCommands { dispatcher.register(CommandManager.literal("resetbalance").redirect(rootSetBalance)); }); - // Command: "/addbalance" + // Command: "/AddMoney" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("addbalance") + 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 -> AddBalance( + .executes(context -> AddMoney( IntegerArgumentType.getInteger(context, "newBalance"), StringArgumentType.getString(context, "reason"), LongArgumentType.getLong(context, "payment"), @@ -112,6 +109,7 @@ public class BankCommands { ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); + return 0; } return ret; @@ -131,15 +129,15 @@ public class BankCommands { return ret; } - //AddBalance will be a ServerCommand Only - public Integer AddBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { + //AddMoney will be a ServerCommand Only + public Integer AddMoney(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext context) { Integer ret = -1; if (context.getSource().isExecutedByPlayer()) { ret = 0; ServerPlayerEntity player = context.getSource().getPlayer(); BankManager playerBank = new BankManager(player.getUuidAsString()); - playerBank.AddBalance(newBalance, reason, payment, otherParty, time); + playerBank.AddMoney(newBalance, reason, payment, otherParty, time); 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 a8815a4..0698206 100644 --- a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java +++ b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java @@ -281,15 +281,4 @@ public class ConfigManager { return ret; } - - //the config is gonna hold the server instance change it if you want but dont reject my code cause its here - private static MinecraftServer server; - - public void SetServerInstance(MinecraftServer inputServer) { - server = inputServer; - } - - public static MinecraftServer GetServerInstance() { - return server; - } } diff --git a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java index d2156a5..f981ba6 100644 --- a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java +++ b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java @@ -11,7 +11,6 @@ package jesse.keeblarcraft; import net.fabricmc.api.ModInitializer; // import net.minecraft.server.command.ServerCommandSource; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/jesse/keeblarcraft/ServerTickListener.java b/src/main/java/jesse/keeblarcraft/ServerTickListener.java index b95f73b..b31258a 100644 --- a/src/main/java/jesse/keeblarcraft/ServerTickListener.java +++ b/src/main/java/jesse/keeblarcraft/ServerTickListener.java @@ -1,11 +1,12 @@ package jesse.keeblarcraft; -import jesse.keeblarcraft.ConfigMgr.ConfigManager; +import jesse.CommonServerUtils; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.server.MinecraftServer; +//this lets get the MinecraftServer instance and also do stuff on the end of the tick if we wanted to public class ServerTickListener implements ServerTickEvents.EndTick { - ConfigManager config = new ConfigManager(); + CommonServerUtils config = new CommonServerUtils(); @Override public void onEndTick(MinecraftServer server) { //Code that runs on end of each tick yes this actually works and tested diff --git a/src/main/java/jesse/keeblarcraft/Utils/Setup.java b/src/main/java/jesse/keeblarcraft/Utils/Setup.java index 34415d6..a824252 100644 --- a/src/main/java/jesse/keeblarcraft/Utils/Setup.java +++ b/src/main/java/jesse/keeblarcraft/Utils/Setup.java @@ -24,8 +24,6 @@ import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_CREATE_EXCEPTION; import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_DELETE_EXCEPTION; import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_EXCEPTION; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; -import net.minecraft.server.MinecraftServer; // Singleton class is designed to help the mod set itself up and create all the important things. It does two things: //