diff --git a/src/main/java/de/skate702/craftingkeys/config/Config.java b/src/main/java/de/skate702/craftingkeys/config/Config.java index 18ddccd..eaa78c8 100644 --- a/src/main/java/de/skate702/craftingkeys/config/Config.java +++ b/src/main/java/de/skate702/craftingkeys/config/Config.java @@ -20,10 +20,17 @@ public class Config { * Defines the config string for the other-category. */ protected static final String categoryOther = "other"; + + /** + * Standard Return Key if there is a problem reading the config. + */ + private static final int retDefKey = -1; + /** * Provides the Suggested Config File. */ protected static Configuration configFile = null; + /** * Defines all 11 Keys you can use with Crafting Keys. */ @@ -31,19 +38,62 @@ public class Config { keyCenterLeft, keyCenterCenter, keyCenterRight, keyLowerLeft, keyLowerCenter, keyLowerRight, keyStack, keyInteract, keyDrop; + /** * Defines, if NumPad is always active for crafting. */ private static Property enableNumPad; - public static boolean isNumPadEnabled() { - return enableNumPad.getBoolean(true); + public static int getKeyTopLeft() { + return keyTopLeft.getInt(retDefKey); } + public static int getkeyTopCenter() { + return keyTopCenter.getInt(retDefKey); + } - public static int getKeyCode(KeyType key) { - //return ((Property)(Config.class.getField((key.toString())))..getInt(-1); // TODO! - return 0; + public static int getKeyTopRight() { + return keyTopRight.getInt(retDefKey); + } + + public static int getKeyCenterLeft() { + return keyCenterLeft.getInt(retDefKey); + } + + public static int getKeyCenterCenter() { + return keyCenterCenter.getInt(retDefKey); + } + + public static int getKeyCenterRight() { + return keyCenterRight.getInt(retDefKey); + } + + public static int getKeyLowerLeft() { + return keyLowerLeft.getInt(retDefKey); + } + + public static int getKeyLowerCenter() { + return keyLowerCenter.getInt(retDefKey); + } + + public static int getKeyLowerRight() { + return keyLowerRight.getInt(retDefKey); + } + + public static int getKeyStack() { + return keyStack.getInt(retDefKey); + } + + public static int getKeyInteract() { + return keyInteract.getInt(retDefKey); + } + + public static int getKeyDrop() { + return keyDrop.getInt(retDefKey); + } + + public static boolean getEnableNumPad() { + return enableNumPad.getBoolean(true); } /** @@ -82,24 +132,18 @@ public class Config { /** * Generates comments for easier understanding of the categories. - * - * @param config Mod related Configuration File */ private static void genComments() { - configFile.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes"); configFile.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys"); - } /** * Loads all properties from the configFile file. - * - * @param config Mod related Configuration File */ private static void syncProperties() { - // Standart Keys + // Standard Keys keyTopLeft = configFile.get(categoryKeys, "1. Top Left", Keyboard.KEY_Q, "Top Left crafting key (key value)"); keyTopCenter = configFile.get(categoryKeys, "2. Top Center", Keyboard.KEY_W, "Top Center crafting key (key value)"); @@ -125,11 +169,4 @@ public class Config { } - public enum KeyType { - keyTopLeft, keyTopCenter, keyTopRight, - keyCenterLeft, keyCenterCenter, keyCenterRight, - keyLowerLeft, keyLowerCenter, keyLowerRight, - keyStack, keyInteract, keyDrop - } - } diff --git a/src/main/java/de/skate702/craftingkeys/util/Helper.java b/src/main/java/de/skate702/craftingkeys/util/Helper.java index 472afec..6db44a2 100644 --- a/src/main/java/de/skate702/craftingkeys/util/Helper.java +++ b/src/main/java/de/skate702/craftingkeys/util/Helper.java @@ -7,6 +7,7 @@ import org.lwjgl.input.Keyboard; * * @author sebastian */ +@Deprecated public class Helper { /** diff --git a/src/main/java/de/skate702/craftingkeys/util/Logger.java b/src/main/java/de/skate702/craftingkeys/util/Logger.java new file mode 100644 index 0000000..857d51e --- /dev/null +++ b/src/main/java/de/skate702/craftingkeys/util/Logger.java @@ -0,0 +1,91 @@ +package de.skate702.craftingkeys.util; + +import de.skate702.craftingkeys.CraftingKeys; + +/** + * Simple Logger Class for debug output. Thank you, compiler! + */ +public class Logger { + + + /** + * Static Final Level. Compiler optimizing will kill all other calls! + */ + private static final LevelOfDetail MODE = LevelOfDetail.INFO; + + /** + * Standard Output in front of every logger action. + */ + private static final String StdOutput = "[" + CraftingKeys.NAME + "/"; + + private static void print(String method, String message, LevelOfDetail in) { + System.out.println(StdOutput + in.toString() + "] " + method + ": " + message); + + + /** + * Prints a INFO-Message if allowed. + * + * @param method The calling method / method info + * @param message The message to print + */ + } + + public static void info(String method, String message) { + if (MODE.getLevel() <= 0) { + print(method, message, LevelOfDetail.INFO); + } + } + + /** + * Prints a DEBUG-Message if allowed. + * + * @param method The calling method / method info + * @param message The message to print + */ + public static void debug(String method, String message) { + if (MODE.getLevel() <= 1) { + print(method, message, LevelOfDetail.DEBUG); + } + } + + /** + * Prints a WARN-Message if allowed. + * + * @param method The calling method / method info + * @param message The message to print + */ + public static void warn(String method, String message) { + if (MODE.getLevel() <= 2) { + print(method, message, LevelOfDetail.WARN); + } + } + + /** + * Prints a ERROR-Message if allowed. + * + * @param method The calling method / method info + * @param message The message to print + */ + public static void error(String method, String message) { + if (MODE.getLevel() <= 3) { + print(method, message, LevelOfDetail.ERROR); + } + } + + /** + * Define Level Of Detail with fixed numbers. + */ + private enum LevelOfDetail { + INFO(0), DEBUG(1), WARN(2), ERROR(3), NONE(4); + + private final int level; + + LevelOfDetail(int level) { + this.level = level; + } + + public int getLevel() { + return level; + } + } +}