normalized config files to keeblarcraft config dir inside config
Some checks failed
build / build (21) (push) Has been cancelled

This commit is contained in:
Jkibbels 2024-11-24 15:06:34 -05:00
parent b048e34eda
commit b4234d4b6b
7 changed files with 143 additions and 93 deletions

View File

@ -1,3 +0,0 @@
// 1.20 2024-11-23T21:42:28.919839077 keeblarcraft/Keeblarcraft World Generation
afc3340283d1101601bd4d2ca96341a58eceaf83 data/keeblarcraft/dimension_type/keeblarcraftdim_type.json
4398eda2b0c28b2c754c45f5805534bf1921b243 data/keeblarcraft/worldgen/biome/test_biome.json

View File

@ -32,6 +32,8 @@ public class IndividualBank {
private String bankFourLetterIdentifier; private String bankFourLetterIdentifier;
private String registeredBankName; private String registeredBankName;
private static String CONFIG_LOCATION = "config/keeblarcraft/bank/";
// Think FDIC but from the servers account (keeblarcraft insurance corporation) // 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. // 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 Integer kbicInsuredAmount;
@ -69,7 +71,7 @@ public class IndividualBank {
boolean existingFile = false; boolean existingFile = false;
try { try {
// Read in the global accounts list // Read in the global accounts list
String accountsListDir = "bank/" + routingNumber.toString() + "/accounts/"; String accountsListDir = CONFIG_LOCATION + routingNumber.toString() + "/accounts/";
System.out.println("accountsListDir + bankName is " + accountsListDir + nameOfBank); System.out.println("accountsListDir + bankName is " + accountsListDir + nameOfBank);
accounts = config.GetJsonObjectFromFile(accountsListDir + nameOfBank, Accounts.class); accounts = config.GetJsonObjectFromFile(accountsListDir + nameOfBank, Accounts.class);
existingFile = true; existingFile = true;
@ -98,9 +100,9 @@ public class IndividualBank {
System.out.println(ChatUtil.ColoredString("Trying to create new file", CONSOLE_COLOR.BLUE)); System.out.println(ChatUtil.ColoredString("Trying to create new file", CONSOLE_COLOR.BLUE));
try { try {
// We assume the bank dir is created by server. Create this banks dir // We assume the bank dir is created by server. Create this banks dir
config.CreateDirectory("bank/" + routingNumber); // config.CreateDirectory("bank/" + routingNumber);
// Create this banks initial accounts dir // Create this banks initial accounts dir
config.CreateDirectory("bank/" + routingNumber + "/accounts"); config.CreateDirectory(CONFIG_LOCATION + routingNumber + "/accounts");
// Flash initial account configuration file for this bank // Flash initial account configuration file for this bank
FlashConfig("accounts"); FlashConfig("accounts");

View File

@ -27,22 +27,23 @@ public class NoteCommands {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public NoteCommands() { public NoteCommands() {
// Check if directory exists // Check if directory exists
if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) { // if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) {
// Attempt to create the directory // // Attempt to create the directory
try { // try {
if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) { // if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) {
System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success! // System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success!
} else { // } else {
System.out.println(ChatUtil.ColoredString("ERROR: Notes directory FAILED to create!! Either the directory already exists or we are missing permissions!", CONSOLE_COLOR.RED)); //TODO: Critical failure --not specfic enough to mark it as a red or blue // System.out.println(ChatUtil.ColoredString("ERROR: Notes directory FAILED to create!! Either the directory already exists or we are missing permissions!", CONSOLE_COLOR.RED)); //TODO: Critical failure --not specfic enough to mark it as a red or blue
} // }
} catch (DIRECTORY_CREATE_EXCEPTION e) { // } catch (DIRECTORY_CREATE_EXCEPTION e) {
System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED)); // System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED));
} // }
} else { // } else {
System.out.println(ChatUtil.ColoredString("Notes directory already exists. Skipping creation...", CONSOLE_COLOR.BLUE)); //TODO: Success! // System.out.println(ChatUtil.ColoredString("Notes directory already exists. Skipping creation...", CONSOLE_COLOR.BLUE)); //TODO: Success!
} // }
} }
//TODO: Rework note commands upon story mode release
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/// @fn RegisterNoteCommands /// @fn RegisterNoteCommands
/// ///
@ -50,69 +51,69 @@ public class NoteCommands {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public void RegisterNoteCommands() { public void RegisterNoteCommands() {
// Command: "/addnote note goes here" // Command: "/addnote note goes here"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("addnote")
.then(CommandManager.argument("value", StringArgumentType.greedyString())
.executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
});
// Command: "/delnote noteIdHere"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// dispatcher.register(CommandManager.literal("delnote") // dispatcher.register(CommandManager.literal("addnote")
// .then(CommandManager.argument("value", StringArgumentType.greedyString()) // .then(CommandManager.argument("value", StringArgumentType.greedyString())
// .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context)))); // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
// }); // });
// Command: "/purgenotes" // // Command: "/delnote noteIdHere"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("purgenotes") // // dispatcher.register(CommandManager.literal("delnote")
.executes(context -> PurgeAllNotes(context))); // // .then(CommandManager.argument("value", StringArgumentType.greedyString())
}); // // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
// // });
// Command: "/modifynote noteIdHere new_note_string_here" // // Command: "/purgenotes"
// Alises: "/editnote" // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // dispatcher.register(CommandManager.literal("purgenotes")
final var mNote = dispatcher.register(CommandManager.literal("editnote") // .executes(context -> PurgeAllNotes(context)));
.then(CommandManager.argument("note_id", IntegerArgumentType.integer()) // });
.then(CommandManager.argument("new_note", StringArgumentType.string())
.executes(context -> ModifyNote(
IntegerArgumentType.getInteger(context, "note_id"),
StringArgumentType.getString(context, "new_note"),
context)))));
dispatcher.register(CommandManager.literal("editnote").redirect(mNote)); // // Command: "/modifynote noteIdHere new_note_string_here"
}); // // Alises: "/editnote"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// final var mNote = dispatcher.register(CommandManager.literal("editnote")
// .then(CommandManager.argument("note_id", IntegerArgumentType.integer())
// .then(CommandManager.argument("new_note", StringArgumentType.string())
// .executes(context -> ModifyNote(
// IntegerArgumentType.getInteger(context, "note_id"),
// StringArgumentType.getString(context, "new_note"),
// context)))));
// Command Root: "/delnote noteIdHere" // dispatcher.register(CommandManager.literal("editnote").redirect(mNote));
// Aliases: "/rmnote", "/deletenote" // });
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
final var rootDeleteCmd = dispatcher.register(CommandManager.literal("delnote")
.then(CommandManager.argument("value", IntegerArgumentType.integer())
.executes(context -> DeleteNote(IntegerArgumentType.getInteger(context, "value"), context))));
// Alias redirects // // Command Root: "/delnote noteIdHere"
dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd)); // // Aliases: "/rmnote", "/deletenote"
dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd)); // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
}); // final var rootDeleteCmd = dispatcher.register(CommandManager.literal("delnote")
// .then(CommandManager.argument("value", IntegerArgumentType.integer())
// .executes(context -> DeleteNote(IntegerArgumentType.getInteger(context, "value"), context))));
// Command Root: "/notegui" // // Alias redirects
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd));
dispatcher.register(CommandManager.literal("notegui") // dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd));
.executes(context -> { OpenNoteGui(context); // });
return 0;
}));
});
// Command Root: "/notelist" // // Command Root: "/notegui"
// Aliases: "/listnotes" // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // dispatcher.register(CommandManager.literal("notegui")
final var rootListNotes = dispatcher.register(CommandManager.literal("notelist") // .executes(context -> { OpenNoteGui(context);
.executes(context -> { ListNotes(context); // return 0;
return 0; // }));
})); // });
dispatcher.register(CommandManager.literal("listnotes").redirect(rootListNotes)); // // Command Root: "/notelist"
}); // // Aliases: "/listnotes"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// final var rootListNotes = dispatcher.register(CommandManager.literal("notelist")
// .executes(context -> { ListNotes(context);
// return 0;
// }));
// dispatcher.register(CommandManager.literal("listnotes").redirect(rootListNotes));
// });
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -130,6 +130,7 @@ public class ConfigManager {
// NOTE: THIS DOES NOT SAFE UPDATE THE KEY OBJECT. PRE-EXISTING DATA WILL BE DELETED FOREVER // NOTE: THIS DOES NOT SAFE UPDATE THE KEY OBJECT. PRE-EXISTING DATA WILL BE DELETED FOREVER
public void WriteToJsonFile(String fileName, Object data) throws FILE_WRITE_EXCEPTION { public void WriteToJsonFile(String fileName, Object data) throws FILE_WRITE_EXCEPTION {
Gson gson = new GsonBuilder().setPrettyPrinting().create(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
fileName = "config/keeblarcraft/" + fileName;
try { try {
FileWriter writer = new FileWriter(fileName); FileWriter writer = new FileWriter(fileName);
gson.toJson(data, writer); gson.toJson(data, writer);
@ -147,6 +148,7 @@ public class ConfigManager {
public <T> T GetJsonObjectFromFile(String fileName, Class<T> classToConvertTo) throws JsonSyntaxException { public <T> T GetJsonObjectFromFile(String fileName, Class<T> classToConvertTo) throws JsonSyntaxException {
Gson gson = new Gson(); Gson gson = new Gson();
String ret = ""; String ret = "";
fileName = "config/keeblarcraft/" + fileName;
// hot fix: Not sure how to return "false" for invalid conversion when I'm forced to convert or just catch... Look into a better // hot fix: Not sure how to return "false" for invalid conversion when I'm forced to convert or just catch... Look into a better
// return value in the future - but for now throw JsonSyntaxException no matter what exception is caught // return value in the future - but for now throw JsonSyntaxException no matter what exception is caught

View File

@ -3,6 +3,12 @@ package jesse.keeblarcraft.EventMgr;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.naming.InvalidNameException;
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
import jesse.keeblarcraft.Utils.ChatUtil;
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
import jesse.keeblarcraft.Utils.CustomExceptions.FILE_WRITE_EXCEPTION;
import jesse.keeblarcraft.world.dimension.ModDimensions; import jesse.keeblarcraft.world.dimension.ModDimensions;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -12,7 +18,38 @@ import net.minecraft.server.world.ServerWorld;
public class DimensionLoadingEvent { public class DimensionLoadingEvent {
// private static List<Inventory> inventories = new ArrayList<Inventory>(); // private static List<Inventory> inventories = new ArrayList<Inventory>();
public static HashMap<String, PlayerInventory> inventories = new HashMap<String, PlayerInventory>(); private static class InventoryWrapper {
public HashMap<String, PlayerInventory> inventories = new HashMap<String, PlayerInventory>();
}
private static InventoryWrapper iw = new InventoryWrapper();
private static String CONFIG_LOCATION = "misc/dimension_inventories_cached.json";
ConfigManager config = new ConfigManager();
public DimensionLoadingEvent() {
// read config
Boolean existingFile = false;
try {
iw = config.GetJsonObjectFromFile(CONFIG_LOCATION, InventoryWrapper.class);
existingFile = true;
} catch (Exception e) {
// Do nothing. This means the file does not exist
}
// In the event the above code failed out, this means a new file has to be created for the player's uuid
if (!existingFile)
{
System.out.println(ChatUtil.ColoredString("Trying to create new file", CONSOLE_COLOR.BLUE));
try {
FlashConfig();
} catch (Exception e) {
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));
}
} else {
System.out.println(ChatUtil.ColoredString("Moving on", CONSOLE_COLOR.BLUE));
}
}
// TODO: In the future when the attribute system is more complete this will need to filter a whitelist of items // TODO: In the future when the attribute system is more complete this will need to filter a whitelist of items
// from the that system + story mode because some items will be able to transcend dimensions! // from the that system + story mode because some items will be able to transcend dimensions!
@ -20,19 +57,19 @@ public class DimensionLoadingEvent {
if (destination.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) { if (destination.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) {
// Make sure player is in map. For now we only care about storing OVERWORLD inventory. We DO NOT care about // Make sure player is in map. For now we only care about storing OVERWORLD inventory. We DO NOT care about
// the dimension inventory! // the dimension inventory!
if (!inventories.containsKey(player.getUuidAsString())) { if (!iw.inventories.containsKey(player.getUuidAsString())) {
PlayerInventory copyInv = new PlayerInventory(player); PlayerInventory copyInv = new PlayerInventory(player);
copyInv.clone(player.getInventory()); copyInv.clone(player.getInventory());
inventories.put(player.getUuidAsString(), copyInv); iw.inventories.put(player.getUuidAsString(), copyInv);
player.getInventory().clear(); player.getInventory().clear();
} else { } else {
System.out.println("Player in system. Ignoring"); System.out.println("Player in system. Ignoring");
} }
} else if (origin.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) { } else if (origin.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) {
if (inventories.containsKey(player.getUuidAsString())) { if (iw.inventories.containsKey(player.getUuidAsString())) {
System.out.println("Player is in map. Cloning our inventory back to them..."); System.out.println("Player is in map. Cloning our inventory back to them...");
player.getInventory().clone(inventories.get(player.getUuidAsString())); player.getInventory().clone(iw.inventories.get(player.getUuidAsString()));
inventories.remove(player.getUuidAsString()); iw.inventories.remove(player.getUuidAsString());
} else { } else {
System.out.println("Player not in system. Ignoring"); System.out.println("Player not in system. Ignoring");
} }
@ -44,12 +81,20 @@ public class DimensionLoadingEvent {
// needs to be tested // needs to be tested
public static void ResetInventories() { public static void ResetInventories() {
System.out.println("ResetInventories: inventory size: " + inventories.size()); System.out.println("ResetInventories: inventory size: " + iw.inventories.size());
for (Entry<String, PlayerInventory> entry : inventories.entrySet()) { for (Entry<String, PlayerInventory> entry : iw.inventories.entrySet()) {
PlayerEntity player = entry.getValue().player; PlayerEntity player = entry.getValue().player;
System.out.println("Found PlayerEntity"); System.out.println("Found PlayerEntity");
player.getInventory().clone(entry.getValue()); player.getInventory().clone(entry.getValue());
} }
} }
public void FlashConfig() {
try {
config.WriteToJsonFile(CONFIG_LOCATION, iw.inventories);
} catch (FILE_WRITE_EXCEPTION e) {
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
}
}
} }

View File

@ -19,7 +19,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class FactionManager { public class FactionManager {
private static String FACTION_CFG_FILE = "factions/factions.json"; private static String FACTION_CFG_FILE = "config/keeblarcraft/factions/factions.json";
ConfigManager config = new ConfigManager(); ConfigManager config = new ConfigManager();
private static FactionManager static_inst; private static FactionManager static_inst;
@ -59,7 +59,7 @@ public class FactionManager {
if (!existingFile) if (!existingFile)
{ {
try { try {
config.CreateDirectory("bank/" + "factions.json"); config.CreateDirectory(FACTION_CFG_FILE);
FlashConfig(); FlashConfig();
} catch (Exception e) { } catch (Exception e) {
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED)); System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));

View File

@ -30,6 +30,7 @@ import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_EXCEPTION;
// If we do not have these, or only partial - then functionality may be disabled for runtime performance // If we do not have these, or only partial - then functionality may be disabled for runtime performance
public final class Setup { public final class Setup {
private static Setup static_inst; private static Setup static_inst;
private static String GLOBAL_CONFIG = "config/keeblarcraft/";
public Setup() { public Setup() {
System.out.println(ChatUtil.ColoredString("Running system setup and checks...", CONSOLE_COLOR.BLUE)); System.out.println(ChatUtil.ColoredString("Running system setup and checks...", CONSOLE_COLOR.BLUE));
@ -50,22 +51,24 @@ public final class Setup {
// First time setup variables // First time setup variables
private static final List<String> DIRECTORY_LIST = new ArrayList<String>() {{ private static final List<String> DIRECTORY_LIST = new ArrayList<String>() {{
add("notes"); // Expect 1 file per player! add(GLOBAL_CONFIG); // inside config dir
add("factions"); // Expect 1 file per faction! add(GLOBAL_CONFIG + "notes"); // Expect 1 file per player!
add("story"); // Expect 1 file per story chapter! add(GLOBAL_CONFIG + "factions"); // Expect 1 file per faction!
add("commands"); // Expect 1 file per command that's configurable! add(GLOBAL_CONFIG + "story"); // Expect 1 file per story chapter!
add("events"); // Expect 1 file per event that is configurable! add(GLOBAL_CONFIG + "commands"); // Expect 1 file per command that's configurable!
add("bank"); add(GLOBAL_CONFIG + "events"); // Expect 1 file per event that is configurable!
add("attributes"); add(GLOBAL_CONFIG + "bank");
add(GLOBAL_CONFIG + "attributes");
add(GLOBAL_CONFIG + "misc");
}}; }};
// These will be top-level config files above the directories this mod creates // These will be top-level config files above the directories this mod creates
private static final List<String> FILE_LIST = new ArrayList<String>() {{ private static final List<String> FILE_LIST = new ArrayList<String>() {{
add("story/general_story_config.json"); // Big config file, determines when players can do certain things at different story levels add(GLOBAL_CONFIG + "story/general_story_config.json"); // Big config file, determines when players can do certain things at different story levels
add("factions/general_factions_config.json"); // General configuration file for factions stuff add(GLOBAL_CONFIG + "factions/general_factions_config.json"); // General configuration file for factions stuff
add("events/general_event_config.json"); // General configuration file for story events! add(GLOBAL_CONFIG + "events/general_event_config.json"); // General configuration file for story events!
add("general.json"); // The super general configuration file! (May be removed) add(GLOBAL_CONFIG + "general.json"); // The super general configuration file! (May be removed)
add("attributes/general_attribute_config.json"); add(GLOBAL_CONFIG + "attributes/general_attribute_config.json");
}}; }};
// RunChecks() // RunChecks()