fixed merge request issues

This commit is contained in:
Walrus 2024-08-15 20:04:34 -04:00
parent 5b28fa4fc4
commit 7e4eb94248
7 changed files with 52 additions and 57 deletions

View File

@ -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;
}
}

View File

@ -3,6 +3,7 @@ package jesse.keeblarcraft.BankMgr;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import jesse.CommonServerUtils;
import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import jesse.keeblarcraft.Utils.ChatUtil; import jesse.keeblarcraft.Utils.ChatUtil;
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
@ -12,13 +13,14 @@ import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
public class BankManager { 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 ConfigManager config = new ConfigManager(); // for read and write privs
CommonServerUtils commonServerUtils = new CommonServerUtils();
public BankManager(String uuid) { public BankManager(String uuid) {
Boolean existingFile = false; Boolean existingFile = false;
try { try {
bankInfo = config.GetJsonObjectFromFile("bank/" + uuid + ".json", InnerBankManagerInfo.class); bankInfo = config.GetJsonObjectFromFile("bank/" + uuid + ".json", BankManagerFile.class);
existingFile = true; existingFile = true;
} catch (Exception e) { } catch (Exception e) {
// Do nothing. This means the file does not exist // Do nothing. This means the file does not exist
@ -45,8 +47,9 @@ public class BankManager {
} }
} }
private class InnerBankManager { //this class is the structure for the hashmap in BankManagerFile
public InnerBankManager(long money, String reason, long payment, String otherParty, Integer time) { private class BankManagerMetaData {
public BankManagerMetaData(long money, String reason, long payment, String otherParty, Integer time) {
this.balance = money; this.balance = money;
this.reason = reason; this.reason = reason;
this.payment = payment; this.payment = payment;
@ -61,7 +64,8 @@ public class BankManager {
Integer time; 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 // Players uuid is the name of the file
String uuid; String uuid;
@ -84,12 +88,12 @@ public class BankManager {
* } * }
* } * }
*/ */
public HashMap<String, InnerBankManager> bank = new HashMap<String, InnerBankManager>(); public HashMap<String, BankManagerMetaData> bank = new HashMap<String, BankManagerMetaData>();
} }
public long GetBalance() { public long GetBalance() {
long ret = 0; long ret = 0;
for (Entry<String, InnerBankManager> entry : bankInfo.bank.entrySet()) { for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
ret = entry.getValue().balance; ret = entry.getValue().balance;
} }
return ret; return ret;
@ -98,14 +102,14 @@ public class BankManager {
public void SetBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { public void SetBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) {
Integer transactionNumber = bankInfo.bank.size(); Integer transactionNumber = bankInfo.bank.size();
bankInfo.bank.put(transactionNumber.toString(), bankInfo.bank.put(transactionNumber.toString(),
new InnerBankManager(newBalance, reason, payment, otherParty, time)); new BankManagerMetaData(newBalance, reason, payment, otherParty, time));
FlashConfig(); 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) { if (bankInfo.bank.size() > 0) {
for (Entry<String, InnerBankManager> entry : bankInfo.bank.entrySet()) { for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
entry.getValue().balance += newBalance; entry.getValue().balance += newBalance;
entry.getValue().reason = reason; entry.getValue().reason = reason;
entry.getValue().payment = payment; entry.getValue().payment = payment;
@ -113,7 +117,7 @@ public class BankManager {
entry.getValue().time = time; entry.getValue().time = time;
} }
} else { } 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(); FlashConfig();
@ -121,7 +125,7 @@ public class BankManager {
public void SubtractBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) { public void SubtractBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time) {
if (bankInfo.bank.size() > 0) { if (bankInfo.bank.size() > 0) {
for (Entry<String, InnerBankManager> entry : bankInfo.bank.entrySet()) { for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
entry.getValue().balance -= newBalance; entry.getValue().balance -= newBalance;
entry.getValue().reason = reason; entry.getValue().reason = reason;
entry.getValue().payment = payment; entry.getValue().payment = payment;
@ -129,16 +133,15 @@ public class BankManager {
entry.getValue().time = time; entry.getValue().time = time;
} }
} else { } 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(); 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) { public void Wire(Integer newBalance, String reason, long payment, String otherParty, Integer time) {
if (bankInfo.bank.size() > 0) { if (bankInfo.bank.size() > 0) {
for (Entry<String, InnerBankManager> entry : bankInfo.bank.entrySet()) { for (Entry<String, BankManagerMetaData> entry : bankInfo.bank.entrySet()) {
entry.getValue().balance -= newBalance; entry.getValue().balance -= newBalance;
entry.getValue().reason = reason; entry.getValue().reason = reason;
entry.getValue().payment = payment; entry.getValue().payment = payment;
@ -151,7 +154,7 @@ public class BankManager {
} }
} }
// make a server instance // make a server instance
MinecraftServer server = ConfigManager.GetServerInstance(); MinecraftServer server = CommonServerUtils.GetServerInstance();
String[] playerList = server.getPlayerNames(); 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 //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++) { 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)); 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 // 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 // MAKE THEM A BANK FIRST IF THEY DONT HAVE ONE fortnite forever
if (config.GetFile("bank/" + GetUuidByName(server, otherParty) + ".json") != null) { if (config.GetFile("bank/" + GetUuidByName(server, otherParty) + ".json").size() < 1) {
InnerBankManagerInfo newBankInfo = new InnerBankManagerInfo(); BankManagerFile newBankInfo = new BankManagerFile();
InnerBankManager newBank = new InnerBankManager(0, "Account Created", 0, "Server", 0); BankManagerMetaData newBank = new BankManagerMetaData(0, "Account Created", 0, "Server", 0);
newBankInfo.bank.put(GetUuidByName(server, otherParty).toString(), newBank); newBankInfo.bank.put(GetUuidByName(server, otherParty).toString(), newBank);
try { try {
config.WriteToJsonFile("bank/" + newBankInfo.uuid + ".json", newBankInfo); 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 //since the other player has a account now and we have access to it we can start fucking around
InnerBankManagerInfo newBankInfo = new InnerBankManagerInfo(); BankManagerFile newBankInfo = new BankManagerFile();
newBankInfo = config.GetJsonObjectFromFile("bank/" + GetUuidByName(server, otherParty) + ".json", InnerBankManagerInfo.class); 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 now we will only use adding valance and not subtracting since that dosent make any sense
for (Entry<String, InnerBankManager> entry : newBankInfo.bank.entrySet()) { for (Entry<String, BankManagerMetaData> entry : newBankInfo.bank.entrySet()) {
entry.getValue().balance += newBalance; entry.getValue().balance += newBalance;
entry.getValue().reason = reason; entry.getValue().reason = reason;
entry.getValue().payment = payment; entry.getValue().payment = payment;
@ -219,15 +222,5 @@ public class BankManager {
} catch (FILE_WRITE_EXCEPTION e) { } catch (FILE_WRITE_EXCEPTION e) {
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED)); 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));
// }
// }
} }
} }

View File

@ -1,7 +1,5 @@
package jesse.keeblarcraft.Commands; package jesse.keeblarcraft.Commands;
import java.util.HashMap;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.LongArgumentType; import com.mojang.brigadier.arguments.LongArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
@ -17,7 +15,6 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
public class BankCommands { public class BankCommands {
ConfigManager config = new ConfigManager(); ConfigManager config = new ConfigManager();
HashMap<String, Integer> monopolyMan;
public void RegisterCommands(){ public void RegisterCommands(){
// Command: "/getbalance" // Command: "/getbalance"
@ -46,16 +43,16 @@ public class BankCommands {
dispatcher.register(CommandManager.literal("resetbalance").redirect(rootSetBalance)); dispatcher.register(CommandManager.literal("resetbalance").redirect(rootSetBalance));
}); });
// Command: "/addbalance" // Command: "/AddMoney"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { 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("newBalance", IntegerArgumentType.integer())
.then(CommandManager.argument("reason", StringArgumentType.string()) .then(CommandManager.argument("reason", StringArgumentType.string())
.then(CommandManager.argument("payment", LongArgumentType.longArg()) .then(CommandManager.argument("payment", LongArgumentType.longArg())
.then(CommandManager.argument("otherParty", StringArgumentType.string()) .then(CommandManager.argument("otherParty", StringArgumentType.string())
//probably will remove time and otherParty from this agurment list not sure yet //probably will remove time and otherParty from this agurment list not sure yet
.then(CommandManager.argument("time", IntegerArgumentType.integer()) .then(CommandManager.argument("time", IntegerArgumentType.integer())
.executes(context -> AddBalance( .executes(context -> AddMoney(
IntegerArgumentType.getInteger(context, "newBalance"), IntegerArgumentType.getInteger(context, "newBalance"),
StringArgumentType.getString(context, "reason"), StringArgumentType.getString(context, "reason"),
LongArgumentType.getLong(context, "payment"), LongArgumentType.getLong(context, "payment"),
@ -112,6 +109,7 @@ public class BankCommands {
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
BankManager playerBank = new BankManager(player.getUuidAsString()); BankManager playerBank = new BankManager(player.getUuidAsString());
player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance()))); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
return 0;
} }
return ret; return ret;
@ -131,15 +129,15 @@ public class BankCommands {
return ret; return ret;
} }
//AddBalance will be a ServerCommand Only //AddMoney will be a ServerCommand Only
public Integer AddBalance(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext<ServerCommandSource> context) { public Integer AddMoney(Integer newBalance, String reason, long payment, String otherParty, Integer time, CommandContext<ServerCommandSource> context) {
Integer ret = -1; Integer ret = -1;
if (context.getSource().isExecutedByPlayer()) { if (context.getSource().isExecutedByPlayer()) {
ret = 0; ret = 0;
ServerPlayerEntity player = context.getSource().getPlayer(); ServerPlayerEntity player = context.getSource().getPlayer();
BankManager playerBank = new BankManager(player.getUuidAsString()); 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()))); player.sendMessage(Text.literal(String.valueOf(playerBank.GetBalance())));
} }

View File

@ -281,15 +281,4 @@ public class ConfigManager {
return ret; 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;
}
} }

View File

@ -11,7 +11,6 @@ package jesse.keeblarcraft;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
// import net.minecraft.server.command.ServerCommandSource; // import net.minecraft.server.command.ServerCommandSource;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -1,11 +1,12 @@
package jesse.keeblarcraft; package jesse.keeblarcraft;
import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.CommonServerUtils;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer; 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 { public class ServerTickListener implements ServerTickEvents.EndTick {
ConfigManager config = new ConfigManager(); CommonServerUtils config = new CommonServerUtils();
@Override @Override
public void onEndTick(MinecraftServer server) { public void onEndTick(MinecraftServer server) {
//Code that runs on end of each tick yes this actually works and tested //Code that runs on end of each tick yes this actually works and tested

View File

@ -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_CREATE_EXCEPTION;
import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_DELETE_EXCEPTION; import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_DELETE_EXCEPTION;
import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_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: // Singleton class is designed to help the mod set itself up and create all the important things. It does two things:
// //