diff options
Diffstat (limited to 'src/main/java/bloodasp/galacticgreg/auxiliary')
6 files changed, 619 insertions, 592 deletions
diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java index 9f337f945e..34f7a5cc8b 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java @@ -2,80 +2,78 @@ package bloodasp.galacticgreg.auxiliary; import java.io.File; -import bloodasp.galacticgreg.GalacticGreg; import net.minecraftforge.common.config.Configuration; +import bloodasp.galacticgreg.GalacticGreg; + /** * config class to read/setup config files and folders + * * @author Namikon */ public abstract class ConfigManager { - private File _mainconfigDir = null; - private File _blocksconfigDir = null; - private String _mModCollection = ""; - private String _mModID = ""; - - protected Configuration _mainConfig = null; - - protected File _mConfigBaseDirectory; - public boolean DoDebugMessages = false; - - protected abstract void PreInit(); - protected abstract void Init(); - protected abstract void PostInit(); - - - public ConfigManager(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) - { - _mModCollection = pModCollectionDirectory; - _mModID = pModID; - _mConfigBaseDirectory = pConfigBaseDirectory; - } - - /** - * Load/init the config file - * @return true/false if the load/init was successful or not - */ - public boolean LoadConfig() - { - try - { - InitConfigDirs(); - if (_mainConfig == null) - return false; - - PreInit(); - _mainConfig.load(); - Init(); - _mainConfig.save(); - PostInit(); - - return true; - } - catch (Exception e) - { - GalacticGreg.Logger.error("Unable to init config file"); - e.printStackTrace(); - return false; - } - } - - /** - * Search for required config-directory / file and create them if they can't be found - */ - private void InitConfigDirs() - { - GalacticGreg.Logger.debug("Checking/creating config folders"); - - _mainconfigDir = new File(String.format("%s%s%s", _mConfigBaseDirectory, File.separator, _mModCollection)); - - if(!_mainconfigDir.exists()) { - GalacticGreg.Logger.info("Config folder not found. Creating..."); - _mainconfigDir.mkdir(); - } - - File tRealConfigFile = new File(String.format("%s%s%s%s", _mainconfigDir, File.separator, _mModID, ".cfg")); - - _mainConfig = new Configuration(tRealConfigFile); - } -}
\ No newline at end of file + + private File _mainconfigDir = null; + private File _blocksconfigDir = null; + private String _mModCollection = ""; + private String _mModID = ""; + + protected Configuration _mainConfig = null; + + protected File _mConfigBaseDirectory; + public boolean DoDebugMessages = false; + + protected abstract void PreInit(); + + protected abstract void Init(); + + protected abstract void PostInit(); + + public ConfigManager(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) { + _mModCollection = pModCollectionDirectory; + _mModID = pModID; + _mConfigBaseDirectory = pConfigBaseDirectory; + } + + /** + * Load/init the config file + * + * @return true/false if the load/init was successful or not + */ + public boolean LoadConfig() { + try { + InitConfigDirs(); + if (_mainConfig == null) return false; + + PreInit(); + _mainConfig.load(); + Init(); + _mainConfig.save(); + PostInit(); + + return true; + } catch (Exception e) { + GalacticGreg.Logger.error("Unable to init config file"); + e.printStackTrace(); + return false; + } + } + + /** + * Search for required config-directory / file and create them if they can't be found + */ + private void InitConfigDirs() { + GalacticGreg.Logger.debug("Checking/creating config folders"); + + _mainconfigDir = new File(String.format("%s%s%s", _mConfigBaseDirectory, File.separator, _mModCollection)); + + if (!_mainconfigDir.exists()) { + GalacticGreg.Logger.info("Config folder not found. Creating..."); + _mainconfigDir.mkdir(); + } + + File tRealConfigFile = new File(String.format("%s%s%s%s", _mainconfigDir, File.separator, _mModID, ".cfg")); + + _mainConfig = new Configuration(tRealConfigFile); + } +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java index e59c22e102..8361a2bda9 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java @@ -2,18 +2,18 @@ package bloodasp.galacticgreg.auxiliary; /** * Just a simple container to wrap 4 GT Ore-Meta ids into one var - */ + */ public class GTOreGroup { - public short PrimaryMeta; - public short SecondaryMeta; - public short SporadicBetweenMeta; - public short SporadicAroundMeta; - - public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) - { - PrimaryMeta = pPrimaryMeta; - SecondaryMeta = pSecondaryMeta; - SporadicBetweenMeta = pSporadicBetweenMeta; - SporadicAroundMeta = pSporadicAroundMeta; - } + + public short PrimaryMeta; + public short SecondaryMeta; + public short SporadicBetweenMeta; + public short SporadicAroundMeta; + + public GTOreGroup(short pPrimaryMeta, short pSecondaryMeta, short pSporadicBetweenMeta, short pSporadicAroundMeta) { + PrimaryMeta = pPrimaryMeta; + SecondaryMeta = pSecondaryMeta; + SporadicBetweenMeta = pSporadicBetweenMeta; + SporadicAroundMeta = pSporadicAroundMeta; + } } diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java index 54d20f395f..f932941c7e 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java @@ -4,108 +4,138 @@ import java.io.File; import net.minecraft.block.Block; import net.minecraft.init.Blocks; + import bloodasp.galacticgreg.GalacticGreg; import bloodasp.galacticgreg.api.BlockMetaComb; import cpw.mods.fml.common.registry.GameRegistry; public class GalacticGregConfig extends ConfigManager { - - public GalacticGregConfig(File pConfigBaseDirectory, - String pModCollectionDirectory, String pModID) { - super(pConfigBaseDirectory, pModCollectionDirectory, pModID); - - } - - public boolean ProfileOreGen; - public boolean ReportOreGenFailures; - public boolean PrintDebugMessagesToFMLLog; - public boolean PrintTraceMessagesToFMLLog; - - public boolean LootChestsEnabled; - public boolean EnableAEExportCommand; - public boolean SchematicsEnabled; - public String LootChestItemOverride; - public boolean QuietMode; - - public BlockMetaComb CustomLootChest; - - @Override - protected void PreInit() { - ProfileOreGen = false; - ReportOreGenFailures = false; - PrintDebugMessagesToFMLLog = false; - PrintTraceMessagesToFMLLog = false; - - LootChestsEnabled = true; - - // Default false, as it is WiP - EnableAEExportCommand = false; - SchematicsEnabled = false; - - LootChestItemOverride = ""; - QuietMode = false; - } - - @Override - protected void Init() { - ProfileOreGen = _mainConfig.getBoolean("ProfileOreGen", "Debug", ProfileOreGen, "Enable to profile oregen and register the ingame command ggregprofiler"); - ReportOreGenFailures = _mainConfig.getBoolean("ReportOreGenFailures", "Debug", ReportOreGenFailures, "Report if a ore tileentity could not be placed"); - PrintDebugMessagesToFMLLog = _mainConfig.getBoolean("PrintDebugMessagesToFMLLog", "Debug", PrintDebugMessagesToFMLLog, "Enable debug output, not recommended for servers"); - PrintTraceMessagesToFMLLog = _mainConfig.getBoolean("PrintTraceMessagesToFMLLog", "Debug", PrintTraceMessagesToFMLLog, "Enable trace output. Warning: This will produce gazillions of log entries"); - QuietMode = _mainConfig.getBoolean("QuietMode", "Debug", QuietMode, "In quiet-mode only errors, warnings and fatals will be printed to the logfile/console"); - - LootChestsEnabled = _mainConfig.getBoolean("LootChestsEnabled", "Extras", LootChestsEnabled, "Enables/disables the dungeon-chest generator system for asteroids. New config values will be generated if set to true"); - EnableAEExportCommand = _mainConfig.getBoolean("EnableAEExportCommand", "Extras", EnableAEExportCommand, "If set to true, you can export any structure stored on a AE2 spatial storage disk. (Can't be spawned yet, WiP). Requires SchematicsEnabled to be true"); - SchematicsEnabled = _mainConfig.getBoolean("SchematicsEnabled", "Extras", SchematicsEnabled, "Enable the experimental Schematics-handler to spawn exported schematics in dimensions. This is WiP, use at own risk"); - LootChestItemOverride = _mainConfig.getString("CustomLootChest", "Extras", LootChestItemOverride, "Define the chest you wish to use as LootChest. use the <ModID>:<Name>:<meta> format or leave empty for the default Minecraft Chest"); - - GalacticGreg.Logger.setDebugOutput(PrintDebugMessagesToFMLLog); - GalacticGreg.Logger.setTraceOutput(PrintTraceMessagesToFMLLog); - GalacticGreg.Logger.setQuietMode(QuietMode); - } - - @Override - protected void PostInit() { - - } - - public boolean serverPostInit() - { - CustomLootChest = new BlockMetaComb(Blocks.chest); - try - { - if (LootChestItemOverride != "") - { - String[] args = LootChestItemOverride.split(":"); - String tMod; - String tName; - int tMeta; - - if (args.length >= 2) - { - tMod = args[0]; - tName = args[1]; - if (args.length == 3) - tMeta = Integer.parseInt(args[2]); - else - tMeta = 0; - - Block tBlock = GameRegistry.findBlock(tMod, tName); - if (tBlock != null) - { - GalacticGreg.Logger.debug("Found valid ChestOverride: %s. LootChest replaced", LootChestItemOverride); - CustomLootChest = new BlockMetaComb(tBlock, tMeta); - } - } - } - - return true; - } - catch (Exception e) - { - GalacticGreg.Logger.error("Unable to find custom chest override %s. Make sure item exists. Defaulting to Minecraft:chest", LootChestItemOverride); - e.printStackTrace(); - return false; - } - } + + public GalacticGregConfig(File pConfigBaseDirectory, String pModCollectionDirectory, String pModID) { + super(pConfigBaseDirectory, pModCollectionDirectory, pModID); + + } + + public boolean ProfileOreGen; + public boolean ReportOreGenFailures; + public boolean PrintDebugMessagesToFMLLog; + public boolean PrintTraceMessagesToFMLLog; + + public boolean LootChestsEnabled; + public boolean EnableAEExportCommand; + public boolean SchematicsEnabled; + public String LootChestItemOverride; + public boolean QuietMode; + + public BlockMetaComb CustomLootChest; + + @Override + protected void PreInit() { + ProfileOreGen = false; + ReportOreGenFailures = false; + PrintDebugMessagesToFMLLog = false; + PrintTraceMessagesToFMLLog = false; + + LootChestsEnabled = true; + + // Default false, as it is WiP + EnableAEExportCommand = false; + SchematicsEnabled = false; + + LootChestItemOverride = ""; + QuietMode = false; + } + + @Override + protected void Init() { + ProfileOreGen = _mainConfig.getBoolean( + "ProfileOreGen", + "Debug", + ProfileOreGen, + "Enable to profile oregen and register the ingame command ggregprofiler"); + ReportOreGenFailures = _mainConfig.getBoolean( + "ReportOreGenFailures", + "Debug", + ReportOreGenFailures, + "Report if a ore tileentity could not be placed"); + PrintDebugMessagesToFMLLog = _mainConfig.getBoolean( + "PrintDebugMessagesToFMLLog", + "Debug", + PrintDebugMessagesToFMLLog, + "Enable debug output, not recommended for servers"); + PrintTraceMessagesToFMLLog = _mainConfig.getBoolean( + "PrintTraceMessagesToFMLLog", + "Debug", + PrintTraceMessagesToFMLLog, + "Enable trace output. Warning: This will produce gazillions of log entries"); + QuietMode = _mainConfig.getBoolean( + "QuietMode", + "Debug", + QuietMode, + "In quiet-mode only errors, warnings and fatals will be printed to the logfile/console"); + + LootChestsEnabled = _mainConfig.getBoolean( + "LootChestsEnabled", + "Extras", + LootChestsEnabled, + "Enables/disables the dungeon-chest generator system for asteroids. New config values will be generated if set to true"); + EnableAEExportCommand = _mainConfig.getBoolean( + "EnableAEExportCommand", + "Extras", + EnableAEExportCommand, + "If set to true, you can export any structure stored on a AE2 spatial storage disk. (Can't be spawned yet, WiP). Requires SchematicsEnabled to be true"); + SchematicsEnabled = _mainConfig.getBoolean( + "SchematicsEnabled", + "Extras", + SchematicsEnabled, + "Enable the experimental Schematics-handler to spawn exported schematics in dimensions. This is WiP, use at own risk"); + LootChestItemOverride = _mainConfig.getString( + "CustomLootChest", + "Extras", + LootChestItemOverride, + "Define the chest you wish to use as LootChest. use the <ModID>:<Name>:<meta> format or leave empty for the default Minecraft Chest"); + + GalacticGreg.Logger.setDebugOutput(PrintDebugMessagesToFMLLog); + GalacticGreg.Logger.setTraceOutput(PrintTraceMessagesToFMLLog); + GalacticGreg.Logger.setQuietMode(QuietMode); + } + + @Override + protected void PostInit() { + + } + + public boolean serverPostInit() { + CustomLootChest = new BlockMetaComb(Blocks.chest); + try { + if (LootChestItemOverride != "") { + String[] args = LootChestItemOverride.split(":"); + String tMod; + String tName; + int tMeta; + + if (args.length >= 2) { + tMod = args[0]; + tName = args[1]; + if (args.length == 3) tMeta = Integer.parseInt(args[2]); + else tMeta = 0; + + Block tBlock = GameRegistry.findBlock(tMod, tName); + if (tBlock != null) { + GalacticGreg.Logger + .debug("Found valid ChestOverride: %s. LootChest replaced", LootChestItemOverride); + CustomLootChest = new BlockMetaComb(tBlock, tMeta); + } + } + } + + return true; + } catch (Exception e) { + GalacticGreg.Logger.error( + "Unable to find custom chest override %s. Make sure item exists. Defaulting to Minecraft:chest", + LootChestItemOverride); + e.printStackTrace(); + return false; + } + } } diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java b/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java index eb3db77060..c8b450c27a 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java @@ -1,249 +1,267 @@ package bloodasp.galacticgreg.auxiliary; -import cpw.mods.fml.common.FMLLog; +import java.util.ArrayList; + import org.apache.logging.log4j.Level; -import java.util.ArrayList; +import cpw.mods.fml.common.FMLLog; /** * Generic LogHelper to print stuff to the console + * * @author Namikon */ public final class LogHelper { - private ArrayList<String> _mReportedCategories = new ArrayList<>(); - private boolean doDebugLogs = false; - private boolean doTraceLogs = false; - private boolean quietMode = false; - private String _mModID = ""; - - private final static String STR_NOCAT = "ihaznocathegory"; - private final static String STR_TOKEN_ONETIMEMESSAGE = " OTM"; - - public LogHelper(String pModID) - { - _mModID = pModID; - } - - /** If true, only error/fatal/warn messages will be printed - * @param pEnabled - */ - public void setQuietMode(boolean pEnabled) { - quietMode = pEnabled; - } - - - /** - * Enable/Disable debug logs - * @param pEnabled - */ - public void setDebugOutput(boolean pEnabled) - { - doDebugLogs = pEnabled; - } - - /** - * Enable/Disable trace logs - * @param pEnabled - */ - public void setTraceOutput(boolean pEnabled) - { - doTraceLogs = pEnabled; - } - - /** - * Resets all One-Time categories, so they will be displayed again - */ - public void ResetCategories() - { - _mReportedCategories = new ArrayList<>(); - } - - /** - * Print a log-message with built-in String.format(x) support. This message will only appear once. usefull for - * error/warnings within loops - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param pLogLevel The logLevel for this message - * @param pMessage The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void log(String pCategory, Level pLogLevel, String pMessage, Object... args) - { - if (pLogLevel == Level.DEBUG && !doDebugLogs) - return; - - if (pLogLevel == Level.TRACE && !doTraceLogs) - return; - - if (pLogLevel != Level.ERROR && pLogLevel != Level.FATAL && pLogLevel != Level.WARN) - if (quietMode) - return; - - - String tt = ""; - if (!pCategory.equals(STR_NOCAT)) - { - tt = STR_TOKEN_ONETIMEMESSAGE; - if (_mReportedCategories.contains(pCategory)) - return; - else - { - _mReportedCategories.add(pCategory); - } - } - - FMLLog.log(_mModID.toUpperCase() + tt, pLogLevel, pMessage, args); - } - - - /** Prints a one-time message with Category ALL - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_all(String pCategory, String object, Object... args) - { - log(pCategory, Level.ALL, object, args); - } - - /** Prints a one-time message with Category DEBUG - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_debug(String pCategory, String object, Object... args) - { - log(pCategory, Level.DEBUG, object, args); - } - - /** Prints a one-time message with Category ERROR - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_error(String pCategory, String object, Object... args) - { - log(pCategory, Level.ERROR, object, args); - } - - /** Prints a one-time message with Category FATAL - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_fatal(String pCategory, String object, Object... args) - { - log(pCategory, Level.FATAL, object, args); - } - - /** Prints a one-time message with Category INFO - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_info(String pCategory, String object, Object... args) - { - log(pCategory, Level.INFO, object, args); - } - - /** Prints a one-time message with Category OFF - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_off(String pCategory, String object, Object... args) - { - log(pCategory, Level.OFF, object, args); - } - - /** Prints a one-time message with Category TRACE - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_trace(String pCategory, String object, Object... args) - { - log(pCategory, Level.TRACE, object, args); - } - - /** Prints a one-time message with Category WARN - * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will never be displayed - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void ot_warn(String pCategory, String object, Object... args) - { - log(pCategory, Level.WARN, object, args); - } - - /** Prints a message with Category ALL - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void all(String object, Object... args) - { - log(STR_NOCAT, Level.ALL, object, args); - } - - /** Prints a message with Category DEBUG - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void debug(String object, Object... args) - { - log(STR_NOCAT, Level.DEBUG, object, args); - } - - /** Prints a message with Category ERROR - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void error(String object, Object... args) - { - log(STR_NOCAT, Level.ERROR, object, args); - } - - /** Prints a message with Category FATAL - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void fatal(String object, Object... args) - { - log(STR_NOCAT, Level.FATAL, object, args); - } - - /** Prints a message with Category INFO - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void info(String object, Object... args) - { - log(STR_NOCAT, Level.INFO, object, args); - } - - /** Prints a message with Category OFF - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void off(String object, Object... args) - { - log(STR_NOCAT, Level.OFF, object, args); - } - - /** Prints a message with Category TRACE - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void trace(String object, Object... args) - { - log(STR_NOCAT, Level.TRACE, object, args); - } - - /** Prints a message with Category WARN - * @param object The log message - * @param args Optional args, if you've used format-specifier in pMessage - */ - public void warn(String object, Object... args) - { - log(STR_NOCAT, Level.WARN, object, args); - } + + private ArrayList<String> _mReportedCategories = new ArrayList<>(); + private boolean doDebugLogs = false; + private boolean doTraceLogs = false; + private boolean quietMode = false; + private String _mModID = ""; + + private final static String STR_NOCAT = "ihaznocathegory"; + private final static String STR_TOKEN_ONETIMEMESSAGE = " OTM"; + + public LogHelper(String pModID) { + _mModID = pModID; + } + + /** + * If true, only error/fatal/warn messages will be printed + * + * @param pEnabled + */ + public void setQuietMode(boolean pEnabled) { + quietMode = pEnabled; + } + + /** + * Enable/Disable debug logs + * + * @param pEnabled + */ + public void setDebugOutput(boolean pEnabled) { + doDebugLogs = pEnabled; + } + + /** + * Enable/Disable trace logs + * + * @param pEnabled + */ + public void setTraceOutput(boolean pEnabled) { + doTraceLogs = pEnabled; + } + + /** + * Resets all One-Time categories, so they will be displayed again + */ + public void ResetCategories() { + _mReportedCategories = new ArrayList<>(); + } + + /** + * Print a log-message with built-in String.format(x) support. This message will only appear once. usefull for + * error/warnings within loops + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param pLogLevel The logLevel for this message + * @param pMessage The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void log(String pCategory, Level pLogLevel, String pMessage, Object... args) { + if (pLogLevel == Level.DEBUG && !doDebugLogs) return; + + if (pLogLevel == Level.TRACE && !doTraceLogs) return; + + if (pLogLevel != Level.ERROR && pLogLevel != Level.FATAL && pLogLevel != Level.WARN) if (quietMode) return; + + String tt = ""; + if (!pCategory.equals(STR_NOCAT)) { + tt = STR_TOKEN_ONETIMEMESSAGE; + if (_mReportedCategories.contains(pCategory)) return; + else { + _mReportedCategories.add(pCategory); + } + } + + FMLLog.log(_mModID.toUpperCase() + tt, pLogLevel, pMessage, args); + } + + /** + * Prints a one-time message with Category ALL + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_all(String pCategory, String object, Object... args) { + log(pCategory, Level.ALL, object, args); + } + + /** + * Prints a one-time message with Category DEBUG + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_debug(String pCategory, String object, Object... args) { + log(pCategory, Level.DEBUG, object, args); + } + + /** + * Prints a one-time message with Category ERROR + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_error(String pCategory, String object, Object... args) { + log(pCategory, Level.ERROR, object, args); + } + + /** + * Prints a one-time message with Category FATAL + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_fatal(String pCategory, String object, Object... args) { + log(pCategory, Level.FATAL, object, args); + } + + /** + * Prints a one-time message with Category INFO + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_info(String pCategory, String object, Object... args) { + log(pCategory, Level.INFO, object, args); + } + + /** + * Prints a one-time message with Category OFF + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_off(String pCategory, String object, Object... args) { + log(pCategory, Level.OFF, object, args); + } + + /** + * Prints a one-time message with Category TRACE + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_trace(String pCategory, String object, Object... args) { + log(pCategory, Level.TRACE, object, args); + } + + /** + * Prints a one-time message with Category WARN + * + * @param pCategory The category for this message. Used to identify the function, use an easy to memorize name. Will + * never be displayed + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void ot_warn(String pCategory, String object, Object... args) { + log(pCategory, Level.WARN, object, args); + } + + /** + * Prints a message with Category ALL + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void all(String object, Object... args) { + log(STR_NOCAT, Level.ALL, object, args); + } + + /** + * Prints a message with Category DEBUG + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void debug(String object, Object... args) { + log(STR_NOCAT, Level.DEBUG, object, args); + } + + /** + * Prints a message with Category ERROR + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void error(String object, Object... args) { + log(STR_NOCAT, Level.ERROR, object, args); + } + + /** + * Prints a message with Category FATAL + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void fatal(String object, Object... args) { + log(STR_NOCAT, Level.FATAL, object, args); + } + + /** + * Prints a message with Category INFO + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void info(String object, Object... args) { + log(STR_NOCAT, Level.INFO, object, args); + } + + /** + * Prints a message with Category OFF + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void off(String object, Object... args) { + log(STR_NOCAT, Level.OFF, object, args); + } + + /** + * Prints a message with Category TRACE + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void trace(String object, Object... args) { + log(STR_NOCAT, Level.TRACE, object, args); + } + + /** + * Prints a message with Category WARN + * + * @param object The log message + * @param args Optional args, if you've used format-specifier in pMessage + */ + public void warn(String object, Object... args) { + log(STR_NOCAT, Level.WARN, object, args); + } } diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java b/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java index 07b6e58deb..409775ea1a 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java @@ -7,109 +7,100 @@ import net.minecraft.util.EnumChatFormatting; /** * Method to easily send chat-messages to EntityPlayer + * * @author Namikon * */ public class PlayerChatHelper { - /** - * Meant for notifications that are being send to an admin/op - * Color will be GREEN - * @param pPlayer - * @param pMessage - */ - public static void SendInfo(ICommandSender pCommandSender, String pMessage) - { - pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); - } - /** - * Meant for notifications that are being send to an admin/op - * Color will be RED - * @param pPlayer - * @param pMessage - */ - public static void SendError(ICommandSender pCommandSender, String pMessage) - { - pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); - } - - /** - * Meant for notifications that are being send to an admin/op - * Color will be YELLOW - * @param pPlayer - * @param pMessage - */ - public static void SendWarn(ICommandSender pCommandSender, String pMessage) - { - pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); - } - - - /** - * Meant for notifications that are being send to an admin/op - * Color will be GREEN - * @param pPlayer - * @param pMessage - */ - public static void SendInfo(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); - } - - /** - * Meant for notifications that are being send to an admin/op - * Color will be RED - * @param pPlayer - * @param pMessage - */ - public static void SendError(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); - } - - /** - * Meant for notifications that are being send to an admin/op - * Color will be YELLOW - * @param pPlayer - * @param pMessage - */ - public static void SendWarn(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); - } - - /** - * Meant for ingame notifications that are being send to a player, not an admin/op - * Color will be DARK_GREEN - * @param pPlayer - * @param pMessage - */ - public static void SendNotifyPositive(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_GREEN + pMessage)); - } + /** + * Meant for notifications that are being send to an admin/op Color will be GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be RED + * + * @param pPlayer + * @param pMessage + */ + public static void SendError(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be YELLOW + * + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(ICommandSender pCommandSender, String pMessage) { + pCommandSender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendInfo(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be RED + * + * @param pPlayer + * @param pMessage + */ + public static void SendError(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + pMessage)); + } + + /** + * Meant for notifications that are being send to an admin/op Color will be YELLOW + * + * @param pPlayer + * @param pMessage + */ + public static void SendWarn(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be DARK_GREEN + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyPositive(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_GREEN + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be AQUA + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyNormal(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + pMessage)); + } + + /** + * Meant for ingame notifications that are being send to a player, not an admin/op Color will be DARK_PURPLE + * + * @param pPlayer + * @param pMessage + */ + public static void SendNotifyWarning(EntityPlayer pPlayer, String pMessage) { + pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + pMessage)); + } - /** - * Meant for ingame notifications that are being send to a player, not an admin/op - * Color will be AQUA - * @param pPlayer - * @param pMessage - */ - public static void SendNotifyNormal(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + pMessage)); - } - - /** - * Meant for ingame notifications that are being send to a player, not an admin/op - * Color will be DARK_PURPLE - * @param pPlayer - * @param pMessage - */ - public static void SendNotifyWarning(EntityPlayer pPlayer, String pMessage) - { - pPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + pMessage)); - } - - } diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java b/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java index dafa1e628e..3510c31341 100644 --- a/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java @@ -1,84 +1,74 @@ package bloodasp.galacticgreg.auxiliary; -import bloodasp.galacticgreg.api.ModDimensionDef; - import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import bloodasp.galacticgreg.api.ModDimensionDef; + /** - * A simple FIFO-storage for Long-values - * Will keep 50 values for each dimension in memory - * Doesn't need to be changed when adding new planets/mods + * A simple FIFO-storage for Long-values Will keep 50 values for each dimension in memory Doesn't need to be changed + * when adding new planets/mods */ public class ProfilingStorage { - private Map<String, List<Long>> mProfilingMap; - - public ProfilingStorage() - { - mProfilingMap = new HashMap<>(); - } - - /** - * Add a new time to the list of pDimension. Will be ignored it tTotalTime == 0 - * @param pDimension - * @param pTotalTime - */ - public void AddTimeToList(ModDimensionDef pDimension, long pTotalTime) - { - try - { - if (pTotalTime == 0) - return; - - if(!mProfilingMap.containsKey(pDimension.getDimIdentifier())) - mProfilingMap.put(pDimension.getDimIdentifier(), new LinkedList<>()); - - LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); - - ll.addLast(pTotalTime); - - while(ll.size() > 50) - ll.removeFirst(); - } catch (Exception e) - { - // Just do nothing. profiling is for debug purposes only anyways... - } - } - - /** - * Return the average time required to execute the oregen in Dimension pDimension - * @param pDimension The DimensionType in question - * @return - */ - public long GetAverageTime(ModDimensionDef pDimension) - { - try - { - if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) - return -1; - - int tTotalVal = 0; - long tAverage = 0; - long tReturnVal = 0; - - LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); - - if(ll != null) - { - for (Long aLong : ll) { - tAverage += aLong; - tTotalVal++; - } - - tReturnVal = (long)((float)(tAverage / tTotalVal)); - } - return tReturnVal; - } - catch (Exception e) - { - return -1; - } - } + + private Map<String, List<Long>> mProfilingMap; + + public ProfilingStorage() { + mProfilingMap = new HashMap<>(); + } + + /** + * Add a new time to the list of pDimension. Will be ignored it tTotalTime == 0 + * + * @param pDimension + * @param pTotalTime + */ + public void AddTimeToList(ModDimensionDef pDimension, long pTotalTime) { + try { + if (pTotalTime == 0) return; + + if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) + mProfilingMap.put(pDimension.getDimIdentifier(), new LinkedList<>()); + + LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); + + ll.addLast(pTotalTime); + + while (ll.size() > 50) ll.removeFirst(); + } catch (Exception e) { + // Just do nothing. profiling is for debug purposes only anyways... + } + } + + /** + * Return the average time required to execute the oregen in Dimension pDimension + * + * @param pDimension The DimensionType in question + * @return + */ + public long GetAverageTime(ModDimensionDef pDimension) { + try { + if (!mProfilingMap.containsKey(pDimension.getDimIdentifier())) return -1; + + int tTotalVal = 0; + long tAverage = 0; + long tReturnVal = 0; + + LinkedList<Long> ll = (LinkedList<Long>) mProfilingMap.get(pDimension.getDimIdentifier()); + + if (ll != null) { + for (Long aLong : ll) { + tAverage += aLong; + tTotalVal++; + } + + tReturnVal = (long) ((float) (tAverage / tTotalVal)); + } + return tReturnVal; + } catch (Exception e) { + return -1; + } + } } |