diff options
author | Namikon <namikon@gmx.net> | 2015-07-02 16:09:32 +0200 |
---|---|---|
committer | Namikon <namikon@gmx.net> | 2015-07-02 16:09:32 +0200 |
commit | 753cc02b152c83dc1067847684ddc17011ddd283 (patch) | |
tree | c35ceb6bd8c1e52670dfc829cc7820fdbac9aad9 /src/main/java/bloodasp/galacticgreg/auxiliary | |
parent | af7f6d249ece39c0767672a2f3098fed0ffa7cee (diff) | |
download | GT5-Unofficial-753cc02b152c83dc1067847684ddc17011ddd283.tar.gz GT5-Unofficial-753cc02b152c83dc1067847684ddc17011ddd283.tar.bz2 GT5-Unofficial-753cc02b152c83dc1067847684ddc17011ddd283.zip |
Moved from Bitbucket to Github. We're open source, yaay
Diffstat (limited to 'src/main/java/bloodasp/galacticgreg/auxiliary')
6 files changed, 680 insertions, 0 deletions
diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java new file mode 100644 index 0000000000..9f337f945e --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ConfigManager.java @@ -0,0 +1,81 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.io.File; + +import bloodasp.galacticgreg.GalacticGreg; +import net.minecraftforge.common.config.Configuration; + +/** + * 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 diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java new file mode 100644 index 0000000000..e59c22e102 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GTOreGroup.java @@ -0,0 +1,19 @@ +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; + } +} diff --git a/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java new file mode 100644 index 0000000000..f640f61193 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/GalacticGregConfig.java @@ -0,0 +1,128 @@ +package bloodasp.galacticgreg.auxiliary; + +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 RegisterVanillaDim; + public boolean RegisterGalacticCraftCore; + public boolean RegisterGalacticCraftPlanets; + public boolean RegisterGalaxySpace; + public boolean LootChestsEnabled; + public boolean EnableAEExportCommand; + public boolean SchematicsEnabled; + public boolean ProperConfigured; + public String LootChestItemOverride; + public boolean QuietMode; + + public BlockMetaComb CustomLootChest; + + @Override + protected void PreInit() { + ProfileOreGen = false; + ReportOreGenFailures = false; + PrintDebugMessagesToFMLLog = false; + PrintTraceMessagesToFMLLog = false; + + LootChestsEnabled = true; + + RegisterVanillaDim = true; + RegisterGalacticCraftCore = true; + RegisterGalacticCraftPlanets = true; + RegisterGalaxySpace = true; + + // Default false, as it is WiP + EnableAEExportCommand = false; + SchematicsEnabled = false; + + ProperConfigured = 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"); + + RegisterVanillaDim = _mainConfig.getBoolean("RegisterVanillaDim", "BuildInMods", RegisterVanillaDim, "Enable to register the build-in dimension definition for TheEnd - Asteroids"); + RegisterGalacticCraftCore = _mainConfig.getBoolean("RegisterGalacticCraftCore", "BuildInMods", RegisterGalacticCraftCore, "Enable to register the build-in dimension definition for GalacticCraft Core (The moon)"); + RegisterGalacticCraftPlanets = _mainConfig.getBoolean("RegisterGalacticCraftPlanets", "BuildInMods", RegisterGalacticCraftPlanets, "Enable to register the build-in dimension definition for GalacticCraft Planets (Mars, asteroids)"); + RegisterGalaxySpace = _mainConfig.getBoolean("RegisterGalaxySpace", "BuildInMods", RegisterGalaxySpace, "Enable to register the build-in dimension definition for GalaxySpace by BlesseNtumble"); + + 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"); + ProperConfigured = _mainConfig.getBoolean("IHaveConfiguredEverything", "main", ProperConfigured, "Set this to true to confirm that you've read the warnings about the massive change in WorldConfig.cfg and you backed-up / configured everything properly"); + 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 new file mode 100644 index 0000000000..4f6166e3eb --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/LogHelper.java @@ -0,0 +1,250 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.ArrayList; + +import org.apache.logging.log4j.Level; + +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<String>(); + 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<String>(); + } + + /** + * 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 new file mode 100644 index 0000000000..07b6e58deb --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/PlayerChatHelper.java @@ -0,0 +1,115 @@ +package bloodasp.galacticgreg.auxiliary; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +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 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 new file mode 100644 index 0000000000..192fb07262 --- /dev/null +++ b/src/main/java/bloodasp/galacticgreg/auxiliary/ProfilingStorage.java @@ -0,0 +1,87 @@ +package bloodasp.galacticgreg.auxiliary; + +import java.util.HashMap; +import java.util.Iterator; +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 + */ +public class ProfilingStorage { + private Map<String, List<Long>> mProfilingMap; + + public ProfilingStorage() + { + mProfilingMap = new HashMap<String, List<Long>>(); + } + + /** + * Add a new time to the list of pDimension. Will be ignored it tTotalTime == 0 + * @param pDimension + * @param tTotalTime + */ + public void AddTimeToList(ModDimensionDef pDimension, long pTotalTime) + { + try + { + if (pTotalTime == 0) + return; + + if(!mProfilingMap.containsKey(pDimension.getDimIdentifier())) + mProfilingMap.put(pDimension.getDimIdentifier(), new LinkedList<Long>()); + + 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 ll = (LinkedList) mProfilingMap.get(pDimension.getDimIdentifier()); + + if(ll != null) + { + Iterator<Long> qItr = ll.iterator(); + while(qItr.hasNext()) + { + tAverage += qItr.next(); + tTotalVal++; + } + + tReturnVal = (long)((float)(tAverage / tTotalVal)); + } + return tReturnVal; + } + catch (Exception e) + { + return -1; + } + } +} |