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 registeredBankName;
private static String CONFIG_LOCATION = "config/keeblarcraft/bank/";
// 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;
@ -69,7 +71,7 @@ public class IndividualBank {
boolean existingFile = false;
try {
// 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);
accounts = config.GetJsonObjectFromFile(accountsListDir + nameOfBank, Accounts.class);
existingFile = true;
@ -98,9 +100,9 @@ public class IndividualBank {
System.out.println(ChatUtil.ColoredString("Trying to create new file", CONSOLE_COLOR.BLUE));
try {
// 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
config.CreateDirectory("bank/" + routingNumber + "/accounts");
config.CreateDirectory(CONFIG_LOCATION + routingNumber + "/accounts");
// Flash initial account configuration file for this bank
FlashConfig("accounts");

View File

@ -27,22 +27,23 @@ public class NoteCommands {
/////////////////////////////////////////////////////////////////////////////
public NoteCommands() {
// Check if directory exists
if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) {
// Attempt to create the directory
try {
if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) {
System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success!
} 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
}
} catch (DIRECTORY_CREATE_EXCEPTION e) {
System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED));
}
} else {
System.out.println(ChatUtil.ColoredString("Notes directory already exists. Skipping creation...", CONSOLE_COLOR.BLUE)); //TODO: Success!
}
// if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) {
// // Attempt to create the directory
// try {
// if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) {
// System.out.println(ChatUtil.ColoredString("Created notes directory successfully!", CONSOLE_COLOR.BLUE)); //TODO: Success!
// } 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
// }
// } catch (DIRECTORY_CREATE_EXCEPTION e) {
// System.out.println(ChatUtil.ColoredString("Directory creation failed", CONSOLE_COLOR.RED));
// }
// } else {
// 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
///
@ -50,69 +51,69 @@ public class NoteCommands {
/////////////////////////////////////////////////////////////////////////////
public void RegisterNoteCommands() {
// 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) -> {
// dispatcher.register(CommandManager.literal("delnote")
// dispatcher.register(CommandManager.literal("addnote")
// .then(CommandManager.argument("value", StringArgumentType.greedyString())
// .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
// });
// Command: "/purgenotes"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("purgenotes")
.executes(context -> PurgeAllNotes(context)));
});
// // Command: "/delnote noteIdHere"
// // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// // dispatcher.register(CommandManager.literal("delnote")
// // .then(CommandManager.argument("value", StringArgumentType.greedyString())
// // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context))));
// // });
// 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: "/purgenotes"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// dispatcher.register(CommandManager.literal("purgenotes")
// .executes(context -> PurgeAllNotes(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"
// 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))));
// dispatcher.register(CommandManager.literal("editnote").redirect(mNote));
// });
// Alias redirects
dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd));
dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd));
});
// // Command Root: "/delnote noteIdHere"
// // 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))));
// Command Root: "/notegui"
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
dispatcher.register(CommandManager.literal("notegui")
.executes(context -> { OpenNoteGui(context);
return 0;
}));
});
// // Alias redirects
// dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd));
// dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd));
// });
// 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;
}));
// // Command Root: "/notegui"
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
// dispatcher.register(CommandManager.literal("notegui")
// .executes(context -> { OpenNoteGui(context);
// 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
public void WriteToJsonFile(String fileName, Object data) throws FILE_WRITE_EXCEPTION {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
fileName = "config/keeblarcraft/" + fileName;
try {
FileWriter writer = new FileWriter(fileName);
gson.toJson(data, writer);
@ -147,6 +148,7 @@ public class ConfigManager {
public <T> T GetJsonObjectFromFile(String fileName, Class<T> classToConvertTo) throws JsonSyntaxException {
Gson gson = new Gson();
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
// 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.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 net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@ -12,7 +18,38 @@ import net.minecraft.server.world.ServerWorld;
public class DimensionLoadingEvent {
// 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
// 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)) {
// Make sure player is in map. For now we only care about storing OVERWORLD inventory. We DO NOT care about
// the dimension inventory!
if (!inventories.containsKey(player.getUuidAsString())) {
if (!iw.inventories.containsKey(player.getUuidAsString())) {
PlayerInventory copyInv = new PlayerInventory(player);
copyInv.clone(player.getInventory());
inventories.put(player.getUuidAsString(), copyInv);
iw.inventories.put(player.getUuidAsString(), copyInv);
player.getInventory().clear();
} else {
System.out.println("Player in system. Ignoring");
}
} 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...");
player.getInventory().clone(inventories.get(player.getUuidAsString()));
inventories.remove(player.getUuidAsString());
player.getInventory().clone(iw.inventories.get(player.getUuidAsString()));
iw.inventories.remove(player.getUuidAsString());
} else {
System.out.println("Player not in system. Ignoring");
}
@ -44,12 +81,20 @@ public class DimensionLoadingEvent {
// needs to be tested
public static void ResetInventories() {
System.out.println("ResetInventories: inventory size: " + inventories.size());
for (Entry<String, PlayerInventory> entry : inventories.entrySet()) {
System.out.println("ResetInventories: inventory size: " + iw.inventories.size());
for (Entry<String, PlayerInventory> entry : iw.inventories.entrySet()) {
PlayerEntity player = entry.getValue().player;
System.out.println("Found PlayerEntity");
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;
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();
private static FactionManager static_inst;
@ -59,7 +59,7 @@ public class FactionManager {
if (!existingFile)
{
try {
config.CreateDirectory("bank/" + "factions.json");
config.CreateDirectory(FACTION_CFG_FILE);
FlashConfig();
} catch (Exception e) {
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
public final class Setup {
private static Setup static_inst;
private static String GLOBAL_CONFIG = "config/keeblarcraft/";
public Setup() {
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
private static final List<String> DIRECTORY_LIST = new ArrayList<String>() {{
add("notes"); // Expect 1 file per player!
add("factions"); // Expect 1 file per faction!
add("story"); // Expect 1 file per story chapter!
add("commands"); // Expect 1 file per command that's configurable!
add("events"); // Expect 1 file per event that is configurable!
add("bank");
add("attributes");
add(GLOBAL_CONFIG); // inside config dir
add(GLOBAL_CONFIG + "notes"); // Expect 1 file per player!
add(GLOBAL_CONFIG + "factions"); // Expect 1 file per faction!
add(GLOBAL_CONFIG + "story"); // Expect 1 file per story chapter!
add(GLOBAL_CONFIG + "commands"); // Expect 1 file per command that's configurable!
add(GLOBAL_CONFIG + "events"); // Expect 1 file per event that is configurable!
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
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("factions/general_factions_config.json"); // General configuration file for factions stuff
add("events/general_event_config.json"); // General configuration file for story events!
add("general.json"); // The super general configuration file! (May be removed)
add("attributes/general_attribute_config.json");
add(GLOBAL_CONFIG + "story/general_story_config.json"); // Big config file, determines when players can do certain things at different story levels
add(GLOBAL_CONFIG + "factions/general_factions_config.json"); // General configuration file for factions stuff
add(GLOBAL_CONFIG + "events/general_event_config.json"); // General configuration file for story events!
add(GLOBAL_CONFIG + "general.json"); // The super general configuration file! (May be removed)
add(GLOBAL_CONFIG + "attributes/general_attribute_config.json");
}};
// RunChecks()