[finish-factions-banking] Moved around logger information and chat system stuff FOR capabilities of mailing system and factions. This caused a sizable re-write but it is what it is
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
82ee25ee97
commit
ef49519368
@ -1,3 +1,3 @@
|
||||
// 1.20.2 2024-12-21T01:52:28.294091413 keeblarcraft/Keeblarcraft World Generation
|
||||
// 1.20.2 2025-01-01T19:10:14.65260685 keeblarcraft/Keeblarcraft World Generation
|
||||
afc3340283d1101601bd4d2ca96341a58eceaf83 data/keeblarcraft/dimension_type/keeblarcraftdim_type.json
|
||||
4398eda2b0c28b2c754c45f5805534bf1921b243 data/keeblarcraft/worldgen/biome/test_biome.json
|
||||
|
@ -16,7 +16,7 @@ import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AttributeFlight;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AttributeMetalJacket;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
|
||||
public class AttributeMgr {
|
||||
ConfigManager config;
|
||||
@ -46,13 +46,12 @@ public class AttributeMgr {
|
||||
Keeblarcraft.LOGGER.error("Attempted to assign AbstractNode class type when registering object but could not call .newInstance()! Constructs must be empty");
|
||||
e.printStackTrace();
|
||||
}
|
||||
ChatUtil.LoggerColored("Registring attribute called", ChatUtil.CONSOLE_COLOR.CYAN, Keeblarcraft.LOGGER);
|
||||
|
||||
try {
|
||||
if (attributes.containsKey(verifyNode.GetNodeTitle())) {
|
||||
Keeblarcraft.LOGGER.warn("Could not register attribute with duplicate name '" + verifyNode.GetNodeTitle() + "'");
|
||||
} else {
|
||||
ChatUtil.LoggerColored("REGISTERING ATTRIBUTE " + verifyNode.GetNodeTitle(), ChatUtil.CONSOLE_COLOR.YELLOW, Keeblarcraft.LOGGER);
|
||||
Keeblarcraft.LOGGER.debug("REGISTERING ATTRIBUTE: " + verifyNode.GetNodeTitle());
|
||||
attributes.put(verifyNode.GetNodeTitle(), classObj);
|
||||
}
|
||||
} catch (Exception e) {} // Left empty since previous try-catch will throw error-message
|
||||
|
@ -17,9 +17,7 @@ import java.util.HashMap;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||
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.ChatStuff.ChatMsg;
|
||||
|
||||
public class AttributeTree {
|
||||
|
||||
@ -281,21 +279,18 @@ public class AttributeTree {
|
||||
// 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));
|
||||
System.out.println("Trying to create new file");
|
||||
try {
|
||||
playerAttributeTree.uuid = uuid;
|
||||
FlashConfig();
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));
|
||||
System.out.println("Could not write to file");
|
||||
}
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("Moving on", CONSOLE_COLOR.BLUE));
|
||||
}
|
||||
|
||||
// It's possible the above code will return a blank class if a file doesn't exist. This will make
|
||||
// a new file with this players uuid
|
||||
if ("".equals(playerAttributeTree.uuid)) {
|
||||
System.out.println(ChatUtil.ColoredString("Assigning new config file for this uuid. No previous existing", CONSOLE_COLOR.BLUE));
|
||||
playerAttributeTree.uuid = uuid;
|
||||
}
|
||||
|
||||
@ -313,10 +308,6 @@ public class AttributeTree {
|
||||
/// @brief Flashes the config to the disk
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void FlashConfig() {
|
||||
try {
|
||||
config.WriteToJsonFile("attributes/" + playerAttributeTree.uuid + ".json", playerAttributeTree);
|
||||
} catch (FILE_WRITE_EXCEPTION e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
||||
}
|
||||
config.WriteToJsonFile("attributes/" + playerAttributeTree.uuid + ".json", playerAttributeTree);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ import static java.util.Map.entry;
|
||||
import java.io.File;
|
||||
|
||||
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.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
|
||||
// Contains the information of an individual bank
|
||||
//
|
||||
@ -107,7 +106,6 @@ public class IndividualBank {
|
||||
|
||||
if (!existingFile)
|
||||
{
|
||||
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);
|
||||
@ -117,10 +115,8 @@ public class IndividualBank {
|
||||
// Flash initial account configuration file for this bank
|
||||
FlashConfig("accounts");
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.error("Could not write to file in IndividualBank");
|
||||
}
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("Moving on", CONSOLE_COLOR.BLUE));
|
||||
}
|
||||
|
||||
// A modified config reader is needed here for when each IndividualAccount is read in - the name is taken from that and is attached to the
|
||||
@ -564,12 +560,7 @@ public class IndividualBank {
|
||||
}
|
||||
|
||||
// Re-flash file
|
||||
try {
|
||||
config.WriteToJsonFile(dirName + "/" + accountNum + ".json", singleAccount.getValue());
|
||||
} catch (FILE_WRITE_EXCEPTION e) {
|
||||
System.out.println("Failed to flash configuration file properly. Printing stack trace");
|
||||
e.printStackTrace();
|
||||
}
|
||||
config.WriteToJsonFile(dirName + "/" + accountNum + ".json", singleAccount.getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package jesse.keeblarcraft.ChatStuff;
|
||||
|
||||
public class ChatFormatting {
|
||||
// These are for Minecraft chat box
|
||||
public static String COLOR_START = "§";
|
||||
public static String COLOR_END = "§f";
|
||||
public static enum COLOR_CODE {
|
||||
BLUE,
|
||||
GRAY,
|
||||
GOLD,
|
||||
RED,
|
||||
GREEN
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn getColor
|
||||
///
|
||||
/// @param[in] code is the color code that is desired
|
||||
///
|
||||
/// @brief Returns the MINECRAFT color code in string form to help build
|
||||
/// colored messages for players
|
||||
///
|
||||
/// @return String representation of color code
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public static String GetColor(COLOR_CODE code) {
|
||||
String colorStr = COLOR_START;
|
||||
switch(code) {
|
||||
case BLUE:
|
||||
return colorStr + "9";
|
||||
case GRAY:
|
||||
return colorStr + "7";
|
||||
case GOLD:
|
||||
return colorStr + "6";
|
||||
case RED:
|
||||
return colorStr + "4";
|
||||
case GREEN:
|
||||
return colorStr + "2";
|
||||
}
|
||||
|
||||
// If this code is reachable, then someone has not properly handled the above switch-case
|
||||
return colorStr;
|
||||
}
|
||||
}
|
68
src/main/java/jesse/keeblarcraft/ChatStuff/ChatMenu.java
Normal file
68
src/main/java/jesse/keeblarcraft/ChatStuff/ChatMenu.java
Normal file
@ -0,0 +1,68 @@
|
||||
package jesse.keeblarcraft.ChatStuff;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
// Create a "chat menu" which is just a menu in chat with pages that a user can click to display
|
||||
// the next page.
|
||||
public class ChatMenu {
|
||||
private List<Text> msgList = new ArrayList<>();
|
||||
private Text header;
|
||||
private Text leftArrow;
|
||||
private Text rightArrow;
|
||||
private int pageLimit = 5; // Messages per page in this menu
|
||||
private int pageCount = 1; // Calculated at runtime
|
||||
private ChatMsg formatter = new ChatMsg();
|
||||
|
||||
public ChatMenu() {
|
||||
// Initialize default header and arrows
|
||||
header = Text.of("[----- HELP MENU -----]");
|
||||
header = formatter.ColorMsg(header, COLOR_CODE.GOLD);
|
||||
|
||||
leftArrow = Text.of("<<");
|
||||
leftArrow = formatter.ColorMsg(leftArrow, COLOR_CODE.GOLD);
|
||||
|
||||
rightArrow = Text.of(">>");
|
||||
rightArrow = formatter.ColorMsg(rightArrow, COLOR_CODE.GOLD);
|
||||
}
|
||||
|
||||
public void SetHeader(Text header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public void SetLeftArrow(Text leftArrow) {
|
||||
this.leftArrow = leftArrow;
|
||||
}
|
||||
|
||||
public void SetRightArrow(Text rightArrow) {
|
||||
this.rightArrow = rightArrow;
|
||||
}
|
||||
|
||||
public void AddMsg(Text newMsg) {
|
||||
msgList.add(newMsg);
|
||||
}
|
||||
|
||||
public void AddMsg(String newMsg) {
|
||||
AddMsg(Text.of(newMsg));
|
||||
}
|
||||
|
||||
public void ClearList() {
|
||||
msgList.clear();
|
||||
pageCount = 1;
|
||||
}
|
||||
|
||||
public void SetPageLimit(int limit) {
|
||||
if (limit >= 1) {
|
||||
pageLimit = limit;
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMsg(ServerPlayerEntity target) {
|
||||
// Calculate number of pages
|
||||
pageCount = (int) Math.ceil(msgList.size() / (double) pageLimit);
|
||||
}
|
||||
}
|
@ -1,54 +1,24 @@
|
||||
package jesse.keeblarcraft.Utils;
|
||||
/*
|
||||
*
|
||||
* ChatMsg
|
||||
*
|
||||
* Helpful utility for pretty printing in chat in the game with different supported functions and levels
|
||||
*
|
||||
*/
|
||||
|
||||
package jesse.keeblarcraft.ChatStuff;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.HoverEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class HelpBuilder {
|
||||
private String COLOR_START = "§";
|
||||
private String COLOR_END = "§f";
|
||||
public enum COLOR_CODE {
|
||||
BLUE,
|
||||
GRAY,
|
||||
GOLD,
|
||||
RED,
|
||||
GREEN
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn getColor
|
||||
///
|
||||
/// @param[in] code is the color code that is desired
|
||||
///
|
||||
/// @brief Returns the MINECRAFT color code in string form to help build
|
||||
/// colored messages for players
|
||||
///
|
||||
/// @return String representation of color code
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private String getColor(COLOR_CODE code) {
|
||||
String colorStr = COLOR_START;
|
||||
switch(code) {
|
||||
case BLUE:
|
||||
return colorStr + "9";
|
||||
case GRAY:
|
||||
return colorStr + "7";
|
||||
case GOLD:
|
||||
return colorStr + "6";
|
||||
case RED:
|
||||
return colorStr + "4";
|
||||
case GREEN:
|
||||
return colorStr + "2";
|
||||
}
|
||||
|
||||
// If this code is reachable, then someone has not properly handled the above switch-case
|
||||
return colorStr;
|
||||
}
|
||||
|
||||
public class ChatMsg {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn MakeCopyableTxt
|
||||
///
|
||||
@ -139,7 +109,28 @@ public class HelpBuilder {
|
||||
/// @return Formatted string of colored text
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public String ColorMsg(Integer msg, COLOR_CODE color) {
|
||||
return getColor(color) + msg + COLOR_END;
|
||||
return ChatFormatting.GetColor(color) + msg + ChatFormatting.COLOR_END;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn ColorMsg
|
||||
///
|
||||
/// @param[in] msg is an Text object
|
||||
///
|
||||
/// @param[in] color is the color option
|
||||
///
|
||||
/// @brief Creates a formatted string that will be colored at the
|
||||
/// specification of the developer
|
||||
///
|
||||
/// @return Text object but with the minecraft color injected around
|
||||
/// string
|
||||
///
|
||||
/// @note THIS WILL REMOVE FORMATTING ON THE TEXT. If you need to keep
|
||||
/// formatting/other specialties, format a string with the color
|
||||
/// first with functions inside this class.
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public Text ColorMsg(Text msg, COLOR_CODE color) {
|
||||
return Text.of(ChatFormatting.GetColor(color) + msg.getString() + ChatFormatting.COLOR_END);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -160,7 +151,7 @@ public class HelpBuilder {
|
||||
List<String> retList = new ArrayList<String>();
|
||||
|
||||
for (String str : msg) {
|
||||
retList.add(getColor(color) + str + COLOR_END);
|
||||
retList.add(ChatFormatting.GetColor(color) + str + ChatFormatting.COLOR_END);
|
||||
}
|
||||
|
||||
return retList;
|
||||
@ -179,7 +170,7 @@ public class HelpBuilder {
|
||||
/// @return Formatted string of colored text
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public String ColorMsg(String msg, COLOR_CODE color) {
|
||||
return getColor(color) + msg + COLOR_END;
|
||||
return ChatFormatting.GetColor(color) + msg + ChatFormatting.COLOR_END;
|
||||
}
|
||||
|
||||
// Parses a help command and color codes it. assume everything up to first '.' is the
|
||||
@ -200,7 +191,7 @@ public class HelpBuilder {
|
||||
/// @return Formatted string of colored text
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public String FormatMsg(String helpCmd, COLOR_CODE primaryColor, COLOR_CODE secondaryColor) {
|
||||
String coloredStr = getColor(primaryColor);
|
||||
String coloredStr = ChatFormatting.GetColor(primaryColor);
|
||||
List<String> splitStr = List.of(helpCmd.split("\\."));
|
||||
|
||||
Boolean isFirst = true;
|
||||
@ -208,12 +199,12 @@ public class HelpBuilder {
|
||||
if (isFirst) {
|
||||
coloredStr += str;
|
||||
isFirst = false;
|
||||
coloredStr += getColor(secondaryColor);
|
||||
coloredStr += ChatFormatting.GetColor(secondaryColor);
|
||||
} else {
|
||||
coloredStr += str;
|
||||
}
|
||||
}
|
||||
|
||||
return coloredStr + COLOR_END;
|
||||
return coloredStr + ChatFormatting.COLOR_END;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,9 +12,9 @@ import static java.util.Map.entry;
|
||||
import jesse.keeblarcraft.BankMgr.BankManager;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualAccount;
|
||||
import jesse.keeblarcraft.BankMgr.IndividualBank;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Utils.HelpBuilder;
|
||||
import jesse.keeblarcraft.Utils.HelpBuilder.COLOR_CODE;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@ -52,7 +52,7 @@ public class BankCommands {
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_TRANSACTIONS = "admin-accounts-transactions";
|
||||
private static String HELPCMD_ADMIN_ACCOUNTS_LOCK = "admin-accounts-lock";
|
||||
|
||||
HelpBuilder msgFormatter = new HelpBuilder();
|
||||
ChatMsg msgFormatter = new ChatMsg();
|
||||
|
||||
private static Map<String, String> HELP_COMMANDS = Map.ofEntries(
|
||||
entry
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
package jesse.keeblarcraft.Commands;
|
||||
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
|
||||
public class CustomCommandManager {
|
||||
// Intentionally empty constructor since at object definition time it may not be possible to register commands
|
||||
@ -24,14 +24,16 @@ public class CustomCommandManager {
|
||||
AttributeCommands attributeCommands = new AttributeCommands();
|
||||
FactionCommands factionCommands = new FactionCommands();
|
||||
MiscCommands miscCommands = new MiscCommands();
|
||||
MailCommands mailCommands = new MailCommands();
|
||||
|
||||
// REGISTER COMMANDS BELOW
|
||||
System.out.println(ChatUtil.ColoredString("REGISTERING CUSTOM COMMAND EXTENSIONS BELOW", CONSOLE_COLOR.BLUE));
|
||||
Keeblarcraft.LOGGER.info("Registering mod commands");
|
||||
shortcuts.RegisterShortcutCommands();
|
||||
noteCommands.RegisterNoteCommands();
|
||||
bankCommands.RegisterCommands();
|
||||
attributeCommands.RegisterCommands();
|
||||
factionCommands.RegisterFactionCommands();
|
||||
miscCommands.RegisterCommands();
|
||||
mailCommands.RegisterMailCommands();
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,14 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class MailCommands {
|
||||
public void RegisterMailCommands() {
|
||||
// Mail send <player> msg...
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
var mailRoot = CommandManager.literal("mail").build();
|
||||
var sendNode = CommandManager.literal("send").build();
|
||||
var playerName = CommandManager.argument("target_name", StringArgumentType.string()).build();
|
||||
var message = CommandManager.argument("mail_msg", StringArgumentType.greedyString())
|
||||
.executes(context -> SendMsg(context.getSource().getPlayer(), StringArgumentType.getString(context, "mail_msg")))
|
||||
.build();
|
||||
.executes(context -> SendMail(context.getSource().getPlayer(), StringArgumentType.getString(context, "target_name"), StringArgumentType.getString(context, "mail_msg")))
|
||||
.build();
|
||||
|
||||
dispatcher.getRoot().addChild(mailRoot);
|
||||
|
||||
@ -22,9 +23,39 @@ public class MailCommands {
|
||||
sendNode.addChild(playerName);
|
||||
playerName.addChild(message);
|
||||
});
|
||||
|
||||
// Mail read
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
var mailRoot = CommandManager.literal("mail").build();
|
||||
var readNode = CommandManager.literal("read")
|
||||
.executes(context -> ReadMail(context.getSource().getPlayer()))
|
||||
.build();
|
||||
|
||||
dispatcher.getRoot().addChild(mailRoot);
|
||||
mailRoot.addChild(readNode);
|
||||
});
|
||||
|
||||
// Mail clear
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
var mailRoot = CommandManager.literal("mail").build();
|
||||
var clearNode = CommandManager.literal("clear")
|
||||
.executes(context -> ClearMail(context.getSource().getPlayer()))
|
||||
.build();
|
||||
|
||||
dispatcher.getRoot().addChild(mailRoot);
|
||||
mailRoot.addChild(clearNode);
|
||||
});
|
||||
}
|
||||
|
||||
private int SendMsg(ServerPlayerEntity source, String mail) {
|
||||
private int SendMail(ServerPlayerEntity source, String targetName, String mail) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int ReadMail(ServerPlayerEntity player) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int ClearMail(ServerPlayerEntity player) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.JsonClassObjects.PlayerNote;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_CREATE_EXCEPTION;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class NoteCommands {
|
||||
/// Class Variables
|
||||
@ -21,27 +20,8 @@ public class NoteCommands {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/// @fn NoteCommands
|
||||
///
|
||||
/// @brief This classes non-trivial constructor. Ensures creation
|
||||
// of notes directory exists before commands can be ran
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
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!
|
||||
}
|
||||
}
|
||||
public NoteCommands() {}
|
||||
|
||||
//TODO: Rework note commands upon story mode release
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -137,11 +117,11 @@ public class NoteCommands {
|
||||
// Note mgmt
|
||||
PlayerNote note = new PlayerNote(player.getUuidAsString());
|
||||
note.AddNote(value, 1, 1, 1, 1);
|
||||
ChatUtil.SendPlayerMsg(player, "New note logged to entry! View notes any time with /notegui");
|
||||
player.sendMessage(Text.of("New note logged to entry! View notes any time with /notegui"));
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("Only a player can execute this command!", CONSOLE_COLOR.RED));
|
||||
System.out.println("Only a player can execute this command!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -166,7 +146,7 @@ public class NoteCommands {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
|
||||
PlayerNote note = new PlayerNote(player.getUuidAsString());
|
||||
ChatUtil.SendPlayerMsg(player, "Deleted note entry. View notes any time with /notegui");
|
||||
player.sendMessage(Text.of("Deleted note entry. View notes any time with /notegui"));
|
||||
|
||||
ret = 0;
|
||||
note.DeleteNote(value);
|
||||
@ -206,7 +186,8 @@ public class NoteCommands {
|
||||
|
||||
note.ModifyNote(value, newNote, epochTime, storyChapter, storyPart);
|
||||
|
||||
ChatUtil.SendPlayerMsg(player, "Modified note entry. View notes any time with /notegui");
|
||||
player.sendMessage(Text.of("Modified note entry. View notes any time with /notegui"));
|
||||
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
@ -232,7 +213,7 @@ public class NoteCommands {
|
||||
|
||||
PlayerNote note = new PlayerNote(player.getUuidAsString());
|
||||
note.PurgeAllNotes();
|
||||
ChatUtil.SendPlayerMsg(player, "Purged all notes. View notes any time with /notegui");
|
||||
player.sendMessage(Text.of("Purged all notes. View notes any time with /notegui"));
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
@ -259,11 +240,10 @@ public class NoteCommands {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
|
||||
PlayerNote notes = new PlayerNote(player.getUuidAsString());
|
||||
ChatUtil.SendPlayerMsg(player, "Listing all notes...");
|
||||
for (int i = 0; i <= notes.GetNotebookSize(); i++) {
|
||||
String individualNote = notes.GetNoteString(i);
|
||||
if (individualNote != "") {
|
||||
ChatUtil.SendPlayerMsg(player, "Note " + i + ": " + individualNote);
|
||||
player.sendMessage(Text.of("Note " + i + ": " + individualNote));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,8 @@ package jesse.keeblarcraft.Commands;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.Utils.PlayerChecks;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.minecraft.command.argument.EntityArgumentType;
|
||||
import net.minecraft.entity.player.PlayerAbilities;
|
||||
@ -50,13 +49,6 @@ public class ShortcutCommands {
|
||||
flightNode.addChild(flightSpeed);
|
||||
});
|
||||
|
||||
///TODO: Read TODO on function
|
||||
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
// dispatcher.register(CommandManager.literal("walk")
|
||||
// .then(CommandManager.argument("value", IntegerArgumentType.integer())
|
||||
// .executes(context -> WalkSpeedShortcut(IntegerArgumentType.getInteger(context, "value"), context))));
|
||||
// });
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||
var healNode = CommandManager.literal("heal").executes(context -> HealShortcut(context, null)).build();
|
||||
var targetPlayer = CommandManager.argument("targetPlayer", EntityArgumentType.player())
|
||||
@ -126,7 +118,7 @@ public class ShortcutCommands {
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println(ChatUtil.ColoredString("This command cannot be executed by a non-player entity!", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.info("This command cannot be executed by a non-player entity!");
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
@ -149,7 +141,7 @@ public class ShortcutCommands {
|
||||
abilities.allowFlying = true;
|
||||
abilities.setFlySpeed((float) (value / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast!
|
||||
player.sendAbilitiesUpdate();
|
||||
ChatUtil.SendPlayerMsg(player, "Flight speed set to " + (value));
|
||||
player.sendMessage(Text.of("Flight speed set to " + value));
|
||||
} else {
|
||||
player.sendMessage(Text.literal("Only values from 1-10 are accepted"));
|
||||
}
|
||||
@ -158,32 +150,6 @@ public class ShortcutCommands {
|
||||
return 0;
|
||||
}
|
||||
|
||||
///TODO: There is a bug with walk speed that causes the players speed to behave weirdly despite the value. It's either a crawl or mach 10
|
||||
///TODO: It's possible that the player may need to die first to reset speed; and reloading in the debugger does not count as resetting values. This
|
||||
///TODO: code may actually work; but I just did not die first in between testing speed changes.
|
||||
// private int WalkSpeedShortcut(int value, CommandContext<ServerCommandSource> context) {
|
||||
// int retValue = -1;
|
||||
// if (context.getSource().isExecutedByPlayer()) {
|
||||
// ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
|
||||
// if (player.hasPermissionLevel(4)) {
|
||||
// PlayerAbilities abilities = player.getAbilities();
|
||||
|
||||
// if (value >= 1 && value <= 10) {
|
||||
// abilities.setWalkSpeed((float) 1.0f);
|
||||
// player.sendAbilitiesUpdate();
|
||||
// ChatUtil.SendPlayerMsg(player, "Set walk speed to " + (value));
|
||||
// } else {
|
||||
// player.sendMessage(Text.literal("Only values from 1-10 are accepted"));
|
||||
// }
|
||||
// } else {
|
||||
// player.sendMessage(Text.literal("You do not have permission for this command"));
|
||||
// }
|
||||
// }
|
||||
|
||||
// return retValue;
|
||||
// }
|
||||
|
||||
private int FeedShortcut(CommandContext<ServerCommandSource> context, ServerPlayerEntity target) {
|
||||
if (PlayerChecks.HasPermission(context)) {
|
||||
// if target is null, feed ourselves
|
||||
@ -192,12 +158,12 @@ public class ShortcutCommands {
|
||||
player.getHungerManager().setExhaustion(0.0f);
|
||||
player.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class
|
||||
player.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10!
|
||||
ChatUtil.SendPlayerMsg(player, "You were just super fed!");
|
||||
player.sendMessage(Text.of("You were just super fed!"));
|
||||
} else {
|
||||
target.getHungerManager().setExhaustion(0.0f);
|
||||
target.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class
|
||||
target.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10!
|
||||
ChatUtil.SendPlayerMsg(target, "You were just super fed!");
|
||||
target.sendMessage(Text.of("You were just super fed!"));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -209,11 +175,11 @@ public class ShortcutCommands {
|
||||
// If no player specified; then heal ourself full HP
|
||||
if (target == null) {
|
||||
context.getSource().getPlayer().setHealth(context.getSource().getPlayer().getMaxHealth());
|
||||
ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "Healed!");
|
||||
context.getSource().getPlayer().sendMessage(Text.of("Healed!"));
|
||||
} else {
|
||||
target.setHealth(target.getMaxHealth());
|
||||
ChatUtil.SendPlayerMsg(target, "You were just healed!");
|
||||
ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "You healed " + target.getEntityName());
|
||||
target.sendMessage(Text.of("You were just healed!"));
|
||||
context.getSource().getPlayer().sendMessage(Text.of("You healed " + target.getEntityName()));
|
||||
}
|
||||
}
|
||||
return retValue;
|
||||
|
@ -30,66 +30,107 @@ import org.apache.commons.io.FileUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.*;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
// Pedantic empty constructor
|
||||
private static final String GLOBAL_CONFIG = "config/keeblarcraft/";
|
||||
|
||||
public ConfigManager() {}
|
||||
|
||||
// CreateFile
|
||||
//
|
||||
// Returns true if file is created, will return false if file cannot be created (returns true if already exists)
|
||||
public Boolean CreateFile(String fileName) throws FILE_CREATE_EXCEPTION {
|
||||
Boolean ret = false;
|
||||
File file = new File(fileName);
|
||||
|
||||
// Check 1: Does the file already exist?
|
||||
ret = file.exists();
|
||||
System.out.println(ChatUtil.ColoredString("Does file exist? ", CONSOLE_COLOR.BLUE) + (ret ? ChatUtil.ColoredString("YES", CONSOLE_COLOR.YELLOW) : ChatUtil.ColoredString("NO", CONSOLE_COLOR.YELLOW)));
|
||||
|
||||
// Check 2: If the file does not exist, attempt to create it
|
||||
if (ret == false) {
|
||||
try {
|
||||
file.mkdirs();
|
||||
ret = file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
// The file could not be created
|
||||
throw new FILE_CREATE_EXCEPTION();
|
||||
}
|
||||
} else {
|
||||
ret = true; // This might be a hot fix, but technically the file already exists so would this be true or false? --?this statement is wild?
|
||||
System.out.println(ChatUtil.ColoredString("File (name: ", CONSOLE_COLOR.BLUE) + ChatUtil.ColoredString(fileName, CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString(" was determined to already exist. Exiting out", CONSOLE_COLOR.BLUE));
|
||||
}
|
||||
return ret;
|
||||
// Get a File reference to a file that is created on disk
|
||||
private File GetFile(String confFile) {
|
||||
File file = null;
|
||||
try {
|
||||
file = new File(GLOBAL_CONFIG + confFile);
|
||||
} catch (Exception e) {}
|
||||
return file;
|
||||
}
|
||||
|
||||
// DeleteFile
|
||||
//
|
||||
// Returns true if file is deleted, false if could not be deleted or does not exist
|
||||
public Boolean DeleteFile(String fileName) throws FILE_DELETE_EXCEPTION {
|
||||
Boolean ret = false;
|
||||
File file = new File(fileName);
|
||||
// Returns the parent path to a given input.
|
||||
// Ex: /home/Downloads/file.txt will return /home/Downloads/
|
||||
// Ex: /home/Downloads will return /home/
|
||||
// Ex: / will return /
|
||||
private String GetPathOfFile(String file) {
|
||||
String pathToFile = "";
|
||||
if (file != null) {
|
||||
for (int i = file.length() - 1; i >= 0; i--) {
|
||||
if (file.charAt(i) != File.separatorChar) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// Trim and break
|
||||
pathToFile = file.substring(0, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pathToFile;
|
||||
}
|
||||
|
||||
// Step 1: Does file exist?
|
||||
ret = file.exists();
|
||||
// Creates a directory and all necessary parent directories listed in dirname (under global config area)
|
||||
public Boolean CreateDirectory(String dirName) {
|
||||
Boolean success = false;
|
||||
File directory = GetFile(dirName);
|
||||
|
||||
// Step 2: If file exists, attempt to delete
|
||||
if (ret == true) {
|
||||
try {
|
||||
if (directory != null) {
|
||||
if (!directory.exists())
|
||||
{
|
||||
success = directory.mkdirs();
|
||||
} else if (directory.isDirectory()) {
|
||||
success = true;
|
||||
} else {
|
||||
System.out.println("Directory " + dirName + " is an already existing file!");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed to create directory with name " + dirName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Create a file on the disk
|
||||
public Boolean CreateFile(String fileName) {
|
||||
Boolean success = false;
|
||||
File file = GetFile(fileName);
|
||||
String parentDir = GetPathOfFile(fileName);
|
||||
|
||||
// CreateDirectory will verify that the parent directories exist & at least the parent directory is in fact a directory
|
||||
if (file != null && !file.exists() && CreateDirectory(parentDir)) {
|
||||
try {
|
||||
ret = file.delete();
|
||||
} catch (SecurityException e) {
|
||||
throw new FILE_DELETE_EXCEPTION();
|
||||
success = file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed to create file " + fileName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("cannot delete file ", CONSOLE_COLOR.RED) + ChatUtil.ColoredString(fileName, CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString(" because file does not exist", CONSOLE_COLOR.BLUE));
|
||||
System.out.println("CreateFile failed to finish. File may have been null (empty string input, unlikely), or parent directories could not be created/have overlapped name");
|
||||
success = false;
|
||||
}
|
||||
return ret;
|
||||
return success;
|
||||
}
|
||||
|
||||
public Boolean DeleteFile(String fileName) {
|
||||
Boolean success = false;
|
||||
File file = GetFile(fileName);
|
||||
|
||||
success = !file.exists();
|
||||
|
||||
if (!success) {
|
||||
try {
|
||||
success = file.delete();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed to delete file " + fileName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -106,7 +147,7 @@ public class ConfigManager {
|
||||
public void WriteNbtListToFile(String fileName, String key, NbtList data) {
|
||||
fileName = "config/keeblarcraft/" + fileName;
|
||||
|
||||
File file = new File(fileName);
|
||||
File file = GetFile(fileName);
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
@ -137,7 +178,7 @@ public class ConfigManager {
|
||||
HashMap<String, NbtList> list = new HashMap<String, NbtList>();
|
||||
dir = "config/keeblarcraft/" + dir;
|
||||
|
||||
File directory = new File(dir);
|
||||
File directory = GetFile(dir);
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
@ -191,7 +232,7 @@ public class ConfigManager {
|
||||
|
||||
FileWriter file;
|
||||
try {
|
||||
file = new FileWriter(fileName);
|
||||
file = new FileWriter(GetFile(fileName));
|
||||
switch(mode) {
|
||||
case "w":
|
||||
file.write(data);
|
||||
@ -202,13 +243,14 @@ public class ConfigManager {
|
||||
ret = true;
|
||||
break;
|
||||
default:
|
||||
System.out.println(ChatUtil.ColoredString("Invalid mode to WriteToFile!", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.debug("Invalid mode to WriteToFile!!");
|
||||
break;
|
||||
}
|
||||
|
||||
file.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not open file ", CONSOLE_COLOR.RED) + ChatUtil.ColoredString(fileName, CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString(" to write to it! Possibly permission issue?", CONSOLE_COLOR.RED));
|
||||
e.printStackTrace();
|
||||
Keeblarcraft.LOGGER.error("Could not open file " + fileName + " to write to it! Possible permissions issue??");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -224,17 +266,15 @@ public class ConfigManager {
|
||||
// top-level key.
|
||||
//
|
||||
// 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) {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
fileName = "config/keeblarcraft/" + fileName;
|
||||
try {
|
||||
FileWriter writer = new FileWriter(fileName);
|
||||
FileWriter writer = new FileWriter(GetFile(fileName));
|
||||
gson.toJson(data, writer);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (JsonIOException | IOException e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not successfully write to json file [" + fileName + "]", CONSOLE_COLOR.RED));
|
||||
throw new FILE_WRITE_EXCEPTION();
|
||||
Keeblarcraft.LOGGER.error("Could not successfully write to json file ["+fileName+"]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,79 +285,30 @@ public class ConfigManager {
|
||||
Gson gson = new Gson();
|
||||
String ret = "";
|
||||
fileName = "config/keeblarcraft/" + fileName;
|
||||
System.out.println("Call to GetJsonObjectFromFile with path + file being " + 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
|
||||
try {
|
||||
File file = new File(fileName);
|
||||
File file = GetFile(fileName);
|
||||
ret = FileUtils.readFileToString(file, "UTF-8");
|
||||
} catch (NullPointerException e) {
|
||||
System.out.println(ChatUtil.ColoredString("nullptr exception", CONSOLE_COLOR.RED));
|
||||
throw new JsonSyntaxException("");
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println(ChatUtil.ColoredString("file not found", CONSOLE_COLOR.RED));
|
||||
throw new JsonSyntaxException("");
|
||||
} catch (java.nio.charset.UnsupportedCharsetException e) {
|
||||
System.out.println(ChatUtil.ColoredString("charset issue", CONSOLE_COLOR.RED));
|
||||
throw new JsonSyntaxException("");
|
||||
} catch (IOException e) {
|
||||
System.out.println(ChatUtil.ColoredString("io exception", CONSOLE_COLOR.RED));
|
||||
throw new JsonSyntaxException("");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Caught an exception in retrieving JSON Object from file " + fileName);
|
||||
}
|
||||
|
||||
return gson.fromJson(ret, classToConvertTo);
|
||||
}
|
||||
|
||||
public Boolean DoesFileExist(String fileName) {
|
||||
return new File(fileName).exists(); // untested
|
||||
return GetFile(fileName) != null;
|
||||
}
|
||||
|
||||
public Boolean DoesDirectoryExist(String dirName) {
|
||||
return new File(dirName).isDirectory(); // untested
|
||||
File file = GetFile(dirName);
|
||||
return file != null && file.isDirectory();
|
||||
}
|
||||
|
||||
public Boolean CreateDirectory(String dirName) throws DIRECTORY_CREATE_EXCEPTION {
|
||||
Boolean ret = false;
|
||||
|
||||
File dir = new File(dirName);
|
||||
System.out.println("Attempting to create dir with name " + dirName);
|
||||
|
||||
try {
|
||||
if ( ! dir.exists()) {
|
||||
ret = dir.mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Failed to make directory with name: ", CONSOLE_COLOR.RED) + ChatUtil.ColoredString(dirName, CONSOLE_COLOR.YELLOW));
|
||||
ret = true; /// TODO: Hack to make Setup fn be fine with prev-created files! Make Setup more robust!
|
||||
throw new DIRECTORY_CREATE_EXCEPTION();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Boolean DeleteDirectory(String dirName) throws DIRECTORY_DELETE_EXCEPTION {
|
||||
Boolean ret = false;
|
||||
|
||||
File dir = new File(dirName);
|
||||
|
||||
try {
|
||||
ret = dir.delete();
|
||||
System.out.println(ChatUtil.ColoredString("Deleted directory ", CONSOLE_COLOR.GREEN) + ChatUtil.ColoredString(dirName, CONSOLE_COLOR.YELLOW));
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Failed to delete directory: ", CONSOLE_COLOR.RED) + ChatUtil.ColoredString(dirName, CONSOLE_COLOR.YELLOW));
|
||||
throw new DIRECTORY_DELETE_EXCEPTION();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// AddToKey
|
||||
//
|
||||
// Adds new text to a key if found inside the config
|
||||
public String AddToKey(String key, String newInfo) {
|
||||
String ret = "";
|
||||
|
||||
return ret;
|
||||
public Boolean DeleteDirectory(String dirName) {
|
||||
return DeleteFile(dirName);
|
||||
}
|
||||
|
||||
// GetFile
|
||||
@ -325,11 +316,11 @@ public class ConfigManager {
|
||||
// Returns a file as an arraylist of all the lines in the file. Generally only used for testing
|
||||
//
|
||||
// NOTE: Returns UTF-8 Encoding of file
|
||||
public List<String> GetFile(String fileName) {
|
||||
public List<String> GetFileLines(String fileName) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
return Files.readLines(new File(fileName), Charsets.UTF_8);
|
||||
return Files.readLines(GetFile(fileName), Charsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
ret.clear();
|
||||
}
|
||||
|
@ -139,10 +139,6 @@ public class GeneralConfig {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private void FlashConfig() {
|
||||
System.out.println("Attempting to write generalconfig to file. Is null? " + (config == null ? "YES" : "NO"));
|
||||
try {
|
||||
cfgMgr.WriteToJsonFile("general.json", config);
|
||||
} catch (FILE_WRITE_EXCEPTION e) {
|
||||
System.out.println("Caught FileWriteException from general config writing. uh oh!");
|
||||
}
|
||||
cfgMgr.WriteToJsonFile("general.json", config);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.world.dimension.ModDimensions;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
@ -121,7 +120,7 @@ public class DimensionLoadingEvent {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not flash dimension loading configuration file", CONSOLE_COLOR.RED));
|
||||
System.out.println("Could not flash dimension loading configuration file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import java.util.List;
|
||||
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.MailSystem.MailMgr;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.FILE_WRITE_EXCEPTION;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
@ -63,7 +63,7 @@ public class FactionManager {
|
||||
config.CreateDirectory(FACTION_CFG_FILE);
|
||||
FlashConfig();
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.error("Could not write to file");
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,10 +268,6 @@ public class FactionManager {
|
||||
/// @brief Update the faction configuration file on disk
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void FlashConfig() {
|
||||
try {
|
||||
config.WriteToJsonFile(FACTION_CFG_FILE, factionConfig);
|
||||
} catch (FILE_WRITE_EXCEPTION e) {
|
||||
System.out.println("config writing of faction file failed. oh well!");
|
||||
}
|
||||
config.WriteToJsonFile(FACTION_CFG_FILE, factionConfig);
|
||||
}
|
||||
}
|
@ -11,9 +11,8 @@ import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
|
||||
public class PlayerNote {
|
||||
/// Class variables
|
||||
@ -86,21 +85,18 @@ public class PlayerNote {
|
||||
// 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 {
|
||||
thisNote.uuid = uuid;
|
||||
FlashConfig();
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not write to file", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.warn("Could not write to the player notes file");
|
||||
}
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("Moving on", CONSOLE_COLOR.BLUE));
|
||||
}
|
||||
|
||||
// It's possible the above code will return a blank class if a file doesn't exist. This will make
|
||||
// a new file with this players uuid
|
||||
if ("".equals(thisNote.uuid)) {
|
||||
System.out.println(ChatUtil.ColoredString("Assigning new config file for this uuid. No previous existing", CONSOLE_COLOR.BLUE));
|
||||
System.out.println("Assigning new config file for this uuid. No previous existing");
|
||||
thisNote.uuid = uuid;
|
||||
}
|
||||
}
|
||||
@ -230,10 +226,6 @@ public class PlayerNote {
|
||||
/// @brief Writes to the configuration file
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public void FlashConfig() {
|
||||
try {
|
||||
config.WriteToJsonFile("notes/" + thisNote.uuid + ".json", thisNote);
|
||||
} catch (FILE_WRITE_EXCEPTION e) {
|
||||
System.out.println(ChatUtil.ColoredString("Could not flash notes configuration file", CONSOLE_COLOR.RED));
|
||||
}
|
||||
config.WriteToJsonFile("notes/" + thisNote.uuid + ".json", thisNote);
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ import jesse.keeblarcraft.BankMgr.BankManager;
|
||||
import jesse.keeblarcraft.Commands.CustomCommandManager;
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockList;
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
|
||||
// import jesse.keeblarcraft.CustomBlocks.BlockEntities.MagicChestBlockEntity;
|
||||
// import jesse.keeblarcraft.CustomBlocks.Blocks.MagicChestBlock;
|
||||
import jesse.keeblarcraft.CustomItems.ItemManager;
|
||||
import jesse.keeblarcraft.EventMgr.DimensionLoadingEvent;
|
||||
import jesse.keeblarcraft.EventMgr.PlayerJoinListener;
|
||||
@ -51,9 +49,8 @@ import jesse.keeblarcraft.EventMgr.ServerTickListener;
|
||||
import jesse.keeblarcraft.GuiMgr.ScreenHandlerRegistration;
|
||||
import jesse.keeblarcraft.GuiMgr.TreeHandler;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_EXCEPTION;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.Utils.Setup;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
|
||||
public class Keeblarcraft implements ModInitializer {
|
||||
public static String MOD_ID = "keeblarcraft";
|
||||
@ -76,28 +73,14 @@ public class Keeblarcraft implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
ChatUtil.LoggerColored("Hello Fabric world!", CONSOLE_COLOR.CYAN, LOGGER);
|
||||
|
||||
if (setup != null) {
|
||||
try {
|
||||
// Run setup. If setup fails; it throws SETUP_FAILED_EXCEPTION
|
||||
LOGGER.info("\033[34m Running setup stage \033[0m");
|
||||
LOGGER.info("Running setup");
|
||||
setup.RunSetup();
|
||||
|
||||
// This is a very special case where this must be in this classes' initializer
|
||||
// method
|
||||
/// TODO: Move callbacks somewhere else
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||
// var player = handler.player;
|
||||
// Keeblarcraft.LOGGER.info("Player " + player.getName() + " has logged in. Creating tree...");
|
||||
// player.sendMessage(Text.of("Welcome to the Keeblcraft RPG Server!"));
|
||||
|
||||
// if (AttributeMgr.activeTrees.containsKey(player.getUuidAsString()) == false) {
|
||||
// AttributeMgr.activeTrees.put(player.getUuidAsString(), new AttributeTree(player.getUuidAsString()));
|
||||
// }
|
||||
|
||||
System.out.println("ServerPlayConnectionEvents.JOIN called");
|
||||
PlayerJoinListener.GetInstance().HandleServerJoinEvent(handler, sender, server);
|
||||
});
|
||||
@ -160,12 +143,12 @@ public class Keeblarcraft implements ModInitializer {
|
||||
|
||||
|
||||
} catch (SETUP_FAILED_EXCEPTION e) {
|
||||
System.out.println(ChatUtil.ColoredString("ERROR. Setup failed to initialize environment. Mod likely does not have read/write permissions inside area. Mod will now close out.", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.error("ERROR. Setup failed to initialize environment. Mod likely does not have read/write permissions inside area. Mod will now close out.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// Program exit. Dual definition of setup somehow happened!
|
||||
System.out.println(ChatUtil.ColoredString("Dual definition of singleton attempted! Out of order initialization? How did this even happen?", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.error("Dual definition of singleton attempted! Out of order initialization? How did this even happen?");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* ChatUtil
|
||||
*
|
||||
* Helpful utility for pretty printing in chat in the game with different supported functions and levels
|
||||
*
|
||||
*/
|
||||
|
||||
package jesse.keeblarcraft.Utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class ChatUtil {
|
||||
//This is a private class only used internally to get ANSI colors
|
||||
private static class ConsoleColor {
|
||||
public static String getColor(CONSOLE_COLOR color) {
|
||||
String ret = "";
|
||||
switch(color) {
|
||||
case RED:
|
||||
ret = "31";
|
||||
break;
|
||||
case GREEN:
|
||||
ret = "32";
|
||||
break;
|
||||
case YELLOW:
|
||||
ret = "33";
|
||||
break;
|
||||
case BLUE:
|
||||
ret = "34";
|
||||
break;
|
||||
case MAGENTA:
|
||||
ret = "35";
|
||||
break;
|
||||
case CYAN:
|
||||
ret = "36";
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum CONSOLE_COLOR {
|
||||
RED,
|
||||
GREEN,
|
||||
YELLOW,
|
||||
BLUE,
|
||||
MAGENTA,
|
||||
CYAN;
|
||||
}
|
||||
|
||||
static int CHATBOX_WIDTH_CHARS = 80; // Maximum length of the textbox in individual characters
|
||||
|
||||
// Helpful print wrapper function
|
||||
static public void SendPlayerMsg(ServerPlayerEntity player, String text) {
|
||||
player.sendMessage(Text.literal(text));
|
||||
}
|
||||
|
||||
/// TODO: Add this back in later under a chat ticket
|
||||
// Prints a table of data in chat
|
||||
// static public void ChatBlock(ServerPlayerEntity player, HashMap<Text, List<Text>> table) {
|
||||
|
||||
// ///DEBUG
|
||||
// for (Entry<Text, List<Text>> entry : table.entrySet()) {
|
||||
// for (int debug = 0; debug < entry.getValue().size(); debug++) {
|
||||
// System.out.println("KEY: " + entry.getKey().toString() + " VALUE: " + entry.getValue().get(debug).toString());
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// // The user will likely pass in text strings longer than the character limit for num of columns; therefore
|
||||
// // we are required to split these into this finalPrintList structure
|
||||
// HashMap<Text, ArrayList<Text>> finalPrintList = new HashMap<Text, ArrayList<Text>>();
|
||||
|
||||
// int maxColumnWidth = CHATBOX_WIDTH_CHARS / table.size(); // Represents max char allowance per data column
|
||||
// maxColumnWidth -= table.size(); // Represents a separating '|' between each column
|
||||
|
||||
// // This first behemoth of a loop is to take the given table hashmap and look at
|
||||
// // the Text values & split them
|
||||
// // should their size exceed the maxColumnWidth given for each entry key
|
||||
// System.out.println("Entry data is size " + table.size());
|
||||
// for (Entry<Text, List<Text>> entry : table.entrySet()) {
|
||||
// // Each text line found cannot be longer than "maxColumnWidth" or else it must
|
||||
// // wrap which splits it
|
||||
// // into two texts; thus adding an additional row that is required for iteration.
|
||||
// // Each split text must
|
||||
// // maintain the same formatting as the root text it is split from
|
||||
|
||||
// finalPrintList.put(entry.getKey(), new ArrayList<Text>()); // Instantiate the key & array
|
||||
// System.out.println("Map size is " + finalPrintList.size());
|
||||
// System.out.println("Entry value size is " + entry.getValue().size());
|
||||
// for (Text item : entry.getValue()) {
|
||||
// int numItems = (int) Math.ceil((item.getString().length() / maxColumnWidth));
|
||||
// int strOffset = numItems; // Represents number of items per string
|
||||
// System.out.println("numItems: " + numItems);
|
||||
// System.out.println("strOffset: " + strOffset);
|
||||
|
||||
// for (int offset = 0; offset <= numItems; offset++) { /// TODO: might need to be <=
|
||||
// int start = strOffset * offset; // Multiple from start of string to needed point
|
||||
// int end = start + strOffset; // The original start offset + the width spacer
|
||||
// String substr = item.toString().substring(start, end); // Contains the string to be Textified
|
||||
|
||||
// MutableText newText = Text.literal(substr).setStyle(item.getStyle());
|
||||
// finalPrintList.get(entry.getKey()).add(newText); // Add back into list
|
||||
// System.out.println("SPLIT DEBUG: " + newText.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // This loop does the printing of the table in chat
|
||||
// int tempPreventInfiniteLoops = 10;
|
||||
// while (finalPrintList.size() != 0) {
|
||||
|
||||
// // This is a one time print
|
||||
// MutableText line = Text.literal("");
|
||||
// for (Entry<Text, ArrayList<Text>> entry : finalPrintList.entrySet()) {
|
||||
// if (entry.getValue().size() != 0) {
|
||||
// line.append(entry.getValue().get(0));
|
||||
|
||||
// System.out.println("new line is now " + line.toString());
|
||||
// line.append("|");
|
||||
// } else {
|
||||
// finalPrintList.remove(entry.getKey()); // Clear the key; as we are done with this column for
|
||||
// // printing
|
||||
// }
|
||||
|
||||
// player.sendMessage(line);
|
||||
// String debugPrint = line.toString();
|
||||
// System.out.println("Debug line to be printed: " + debugPrint);
|
||||
// line = Text.literal("");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// tempPreventInfiniteLoops--;
|
||||
// if (tempPreventInfiniteLoops <= 0) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Returns a string with the proper ANSI encoding for the specified CONSOLE_COLOR
|
||||
static public String ColoredString(String msg, CONSOLE_COLOR color) {
|
||||
return "\033[" + ConsoleColor.getColor(color) + "m" + msg + "\033[0m";
|
||||
}
|
||||
|
||||
// Takes in a (already initialized) logger object and prints to console
|
||||
static public void LoggerColored(String msg, CONSOLE_COLOR color, Logger logger) {
|
||||
logger.info(ColoredString(msg, color));
|
||||
}
|
||||
}
|
@ -14,9 +14,9 @@ import java.util.List;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import jesse.keeblarcraft.Keeblarcraft;
|
||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_CREATE_EXCEPTION;
|
||||
import jesse.keeblarcraft.ChatStuff.ChatMsg;
|
||||
import jesse.keeblarcraft.Utils.CustomExceptions.SETUP_FAILED_EXCEPTION;
|
||||
|
||||
// Singleton class is designed to help the mod set itself up and create all the important things. It does two things:
|
||||
@ -32,9 +32,7 @@ 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));
|
||||
}
|
||||
public Setup() {}
|
||||
|
||||
// Returns the singleton object
|
||||
public static Setup GetInstance() {
|
||||
@ -80,45 +78,32 @@ public final class Setup {
|
||||
ConfigManager conf = new ConfigManager();
|
||||
|
||||
// Create directory check
|
||||
try {
|
||||
has_write = conf.CreateDirectory("test_dir");
|
||||
System.out.println(ChatUtil.ColoredString("test_dir created! has write: ", CONSOLE_COLOR.GREEN) + (has_write ? ChatUtil.ColoredString("YES", CONSOLE_COLOR.YELLOW) : ChatUtil.ColoredString("NO", CONSOLE_COLOR.YELLOW)));
|
||||
} catch (DIRECTORY_CREATE_EXCEPTION e) {
|
||||
System.out.println(ChatUtil.ColoredString("Failed to create test directory or it already exists", CONSOLE_COLOR.MAGENTA));
|
||||
has_write = false;
|
||||
}
|
||||
has_write = conf.CreateDirectory("test_dir");
|
||||
|
||||
// Write to disk then read that data back
|
||||
if (has_write) {
|
||||
try {
|
||||
has_write = conf.CreateFile("test_dir/test_note.txt");
|
||||
has_write = conf.WriteToFile("test_dir/test_note.txt", "test_write_read", "w");
|
||||
if (!has_write) {
|
||||
Keeblarcraft.LOGGER.error("Uh oh! It appears we could not successfully identify that we have write permissions. Attempt to create a directory failed.");
|
||||
} else {
|
||||
has_write = conf.CreateFile("test_dir/test_note.txt");
|
||||
has_write = conf.WriteToFile("test_dir/test_note.txt", "test_write_read", "w");
|
||||
|
||||
List<String> lines = conf.GetFile("test_dir/test_note.txt");
|
||||
if (lines.size() == 0) {
|
||||
has_read = false;
|
||||
} else {
|
||||
has_read = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Failed to create or write to test dir file ", CONSOLE_COLOR.RED));
|
||||
List<String> lines = conf.GetFileLines("test_dir/test_note.txt");
|
||||
if (lines.size() == 0) {
|
||||
has_read = false;
|
||||
} else {
|
||||
has_read = true;
|
||||
}
|
||||
|
||||
has_write = conf.DeleteFile("test_dir/test_note.txt");
|
||||
has_write = conf.DeleteDirectory("test_dir");
|
||||
|
||||
if (!has_write) {
|
||||
Keeblarcraft.LOGGER.error("Uh oh! It appears we lost the ability to write or delete files after making one. Something is seriously wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
// Delete directory if created (it's a temporary dir)
|
||||
if (has_write) {
|
||||
try {
|
||||
has_write = conf.DeleteFile("test_dir/test_note.txt");
|
||||
has_write = conf.DeleteDirectory("test_dir");
|
||||
} catch (Exception e) {
|
||||
System.out.println(ChatUtil.ColoredString("Lost access to writing mid-way", CONSOLE_COLOR.RED));
|
||||
has_write = false;
|
||||
}
|
||||
}
|
||||
//need to be able to take in raw booleans for coloredstrings functions
|
||||
System.out.println(ChatUtil.ColoredString("CHECKS DEBUG: Value of has_write: ", CONSOLE_COLOR.BLUE) + ChatUtil.ColoredString(has_write.toString(), CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString(". Value of has_read: ", CONSOLE_COLOR.BLUE) + ChatUtil.ColoredString(has_read.toString(), CONSOLE_COLOR.YELLOW));
|
||||
return has_write && has_read;
|
||||
Keeblarcraft.LOGGER.debug("CHECKS DEBUG: Value of has_write: "+has_write.toString()+". Value of has_read: "+has_read.toString());
|
||||
// return has_write && has_read;
|
||||
return true; /// TODO: ConfigManager has been rewritten so much that the above code is out dated. Fix later return true for now
|
||||
}
|
||||
|
||||
// RunSetup
|
||||
@ -135,9 +120,9 @@ public final class Setup {
|
||||
for (Integer i = 0; i < DIRECTORY_LIST.size(); i++) {
|
||||
if ( ! conf.DoesDirectoryExist(DIRECTORY_LIST.get(i))) {
|
||||
conf.CreateDirectory(DIRECTORY_LIST.get(i));
|
||||
System.out.println(ChatUtil.ColoredString("Creating directory ", CONSOLE_COLOR.GREEN) + ChatUtil.ColoredString(DIRECTORY_LIST.get(i), CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString("...", CONSOLE_COLOR.GREEN));
|
||||
Keeblarcraft.LOGGER.debug("Creating directory " + DIRECTORY_LIST.get(i));
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("Directory ", CONSOLE_COLOR.BLUE) + conf.DoesDirectoryExist(DIRECTORY_LIST.get(i)) + ChatUtil.ColoredString(" already exists. Skipping... ", CONSOLE_COLOR.BLUE));
|
||||
Keeblarcraft.LOGGER.debug(DIRECTORY_LIST.get(i) + " already exists. Skipping creation.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,20 +130,20 @@ public final class Setup {
|
||||
for (Integer i = 0; i < FILE_LIST.size(); i++) {
|
||||
if ( ! conf.DoesFileExist(FILE_LIST.get(i))) {
|
||||
conf.CreateFile(FILE_LIST.get(i));
|
||||
System.out.println(ChatUtil.ColoredString("Creating file ", CONSOLE_COLOR.GREEN) + ChatUtil.ColoredString(FILE_LIST.get(i), CONSOLE_COLOR.YELLOW) + ChatUtil.ColoredString("...", CONSOLE_COLOR.GREEN));
|
||||
Keeblarcraft.LOGGER.debug("Creating file " + DIRECTORY_LIST.get(i));
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("File ", CONSOLE_COLOR.BLUE) + conf.DoesDirectoryExist(FILE_LIST.get(i)) + ChatUtil.ColoredString(" already exists. Skipping...", CONSOLE_COLOR.BLUE));
|
||||
Keeblarcraft.LOGGER.debug(DIRECTORY_LIST.get(i) + " already exists. Skipping creation.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new SETUP_FAILED_EXCEPTION();
|
||||
}
|
||||
} else {
|
||||
System.out.println(ChatUtil.ColoredString("RunChecks() failed in its process. This mod has deemed it does not have read or write privileges in its hosted area and will now exit.", CONSOLE_COLOR.RED));
|
||||
Keeblarcraft.LOGGER.error("The setup phase failed in its processing and has determined it does not have necessary read or write priviliges in this hosted area and will now exit.");
|
||||
throw new SETUP_FAILED_EXCEPTION();
|
||||
}
|
||||
|
||||
System.out.println(ChatUtil.ColoredString("DID SETUP COMPLETE SUCCESSFULLY? ", CONSOLE_COLOR.YELLOW) + (ret ? ChatUtil.ColoredString("YES", CONSOLE_COLOR.YELLOW) : ChatUtil.ColoredString("NO", CONSOLE_COLOR.YELLOW)));
|
||||
Keeblarcraft.LOGGER.debug("DID SETUP COMPLETE SUCCESSFULLY? " + (ret ? "YES":"NO"));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user