Now when a pre-assigned value is set via command line, the next time the server starts it will regen the values of everything and save the new values to disk (tl;dr - set a pre-assigned value via command and then restart server for the changes to take effect)
This commit is contained in:
parent
b36ea50c70
commit
a97fa3fb49
6 changed files with 61 additions and 29 deletions
|
@ -3,10 +3,7 @@ package com.pahimar.ee3;
|
|||
import com.pahimar.ee3.command.CommandSetValue;
|
||||
import com.pahimar.ee3.command.CommandSyncValues;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.handler.ConfigurationHandler;
|
||||
import com.pahimar.ee3.handler.CraftingHandler;
|
||||
import com.pahimar.ee3.handler.FuelHandler;
|
||||
import com.pahimar.ee3.handler.GuiHandler;
|
||||
import com.pahimar.ee3.handler.*;
|
||||
import com.pahimar.ee3.init.*;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.proxy.IProxy;
|
||||
|
@ -17,6 +14,7 @@ import com.pahimar.ee3.reference.Reference;
|
|||
import com.pahimar.ee3.skill.SkillRegistry;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
|
@ -25,6 +23,8 @@ import cpw.mods.fml.common.event.*;
|
|||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, certificateFingerprint = Reference.FINGERPRINT, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY_CLASS)
|
||||
public class EquivalentExchange3
|
||||
{
|
||||
|
@ -37,8 +37,6 @@ public class EquivalentExchange3
|
|||
@EventHandler
|
||||
public void invalidFingerprint(FMLFingerprintViolationEvent event)
|
||||
{
|
||||
// Report (log) to the user that the version of Equivalent Exchange 3
|
||||
// they are using has been changed/tampered with
|
||||
if (Reference.FINGERPRINT.equals("@FINGERPRINT@"))
|
||||
{
|
||||
LogHelper.info(Messages.NO_FINGERPRINT_MESSAGE);
|
||||
|
@ -106,7 +104,22 @@ public class EquivalentExchange3
|
|||
@EventHandler
|
||||
public void onServerStopping(FMLServerStoppingEvent event)
|
||||
{
|
||||
SerializationHelper.writeEnergyValueRegistryToFile();
|
||||
if (EnergyValueRegistry.getInstance().getShouldRegenNextRestart())
|
||||
{
|
||||
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + "ee3");
|
||||
File energyValueRegistryFile = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
|
||||
|
||||
if (energyValueRegistryFile.exists())
|
||||
{
|
||||
energyValueRegistryFile.delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SerializationHelper.writeEnergyValueRegistryToFile(SerializationHelper.getModListMD5() + ".ee3");
|
||||
}
|
||||
|
||||
WorldEventHandler.hasInitilialized = false;
|
||||
}
|
||||
|
||||
public EnergyValueRegistry getEnergyValueRegistry()
|
||||
|
|
|
@ -88,10 +88,10 @@ public class CommandSetValue extends CommandBase
|
|||
{
|
||||
if (args[0].equalsIgnoreCase("pre"))
|
||||
{
|
||||
// TODO Mark that the server needs to regen values on next startup
|
||||
Map<WrappedStack, EnergyValue> preAssignedValues = SerializationHelper.readEnergyValueStackMapFromJsonFile(Files.PRE_ASSIGNED_ENERGY_VALUES);
|
||||
preAssignedValues.put(wrappedStack, newEnergyValue);
|
||||
SerializationHelper.writeEnergyValueStackMapToJsonFile(Files.PRE_ASSIGNED_ENERGY_VALUES, preAssignedValues);
|
||||
EnergyValueRegistry.getInstance().setShouldRegenNextRestart(true);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("post"))
|
||||
{
|
||||
|
|
|
@ -16,10 +16,6 @@ public class DynamicEnergyValueInitThread implements Runnable
|
|||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
EnergyValueRegistry.getInstance().init();
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
if (duration > 10)
|
||||
{
|
||||
LogHelper.info(String.format("DynamicEV system initialized after %s ms", duration));
|
||||
}
|
||||
LogHelper.info(String.format("DynamicEV system initialized after %s ms", System.currentTimeMillis() - startTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.*;
|
|||
|
||||
public class EnergyValueRegistry implements INBTTaggable
|
||||
{
|
||||
private boolean shouldRegenNextRestart = false;
|
||||
private static EnergyValueRegistry energyValueRegistry = null;
|
||||
private static Map<WrappedStack, EnergyValue> preAssignedMappings;
|
||||
private static Map<WrappedStack, EnergyValue> postAssignedMappings;
|
||||
|
@ -345,14 +346,26 @@ public class EnergyValueRegistry implements INBTTaggable
|
|||
|
||||
protected final void init()
|
||||
{
|
||||
if (!SerializationHelper.energyValueRegistryFileExist())
|
||||
String fileName = SerializationHelper.getModListMD5() + ".ee3";
|
||||
|
||||
if (!SerializationHelper.dataFileExist(fileName))
|
||||
{
|
||||
runDynamicEnergyValueResolution();
|
||||
}
|
||||
else
|
||||
{
|
||||
SerializationHelper.readEnergyValueRegistryFromFile();
|
||||
NBTTagCompound nbtEnergyValueRegistry = SerializationHelper.readEnergyValueRegistryFromFile(fileName);
|
||||
if (nbtEnergyValueRegistry != null)
|
||||
{
|
||||
energyValueRegistry.readFromNBT(nbtEnergyValueRegistry);
|
||||
}
|
||||
else
|
||||
{
|
||||
runDynamicEnergyValueResolution();
|
||||
}
|
||||
}
|
||||
|
||||
this.shouldRegenNextRestart = false;
|
||||
}
|
||||
|
||||
private void runDynamicEnergyValueResolution()
|
||||
|
@ -482,7 +495,7 @@ public class EnergyValueRegistry implements INBTTaggable
|
|||
valueMappings = ImmutableSortedMap.copyOf(tempValueMappings);
|
||||
|
||||
// Serialize values to disk
|
||||
SerializationHelper.writeEnergyValueRegistryToFile();
|
||||
SerializationHelper.writeEnergyValueRegistryToFile(SerializationHelper.getModListMD5() + ".ee3");
|
||||
}
|
||||
|
||||
private Map<WrappedStack, EnergyValue> computeStackMappings()
|
||||
|
@ -720,4 +733,14 @@ public class EnergyValueRegistry implements INBTTaggable
|
|||
valueMappings = ImmutableSortedMap.copyOf(tempValueMappings);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getShouldRegenNextRestart()
|
||||
{
|
||||
return shouldRegenNextRestart;
|
||||
}
|
||||
|
||||
public void setShouldRegenNextRestart(boolean shouldRegenNextRestart)
|
||||
{
|
||||
this.shouldRegenNextRestart = shouldRegenNextRestart;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraftforge.event.world.WorldEvent;
|
|||
|
||||
public class WorldEventHandler
|
||||
{
|
||||
private static boolean hasInitilialized = false;
|
||||
public static boolean hasInitilialized = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoadEvent(WorldEvent.Load event)
|
||||
|
|
|
@ -42,7 +42,7 @@ public class SerializationHelper
|
|||
return DigestUtils.md5Hex(modListString.toString());
|
||||
}
|
||||
|
||||
public static boolean energyValueRegistryFileExist()
|
||||
public static boolean dataFileExist(String fileName)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null)
|
||||
{
|
||||
|
@ -59,12 +59,12 @@ public class SerializationHelper
|
|||
return false;
|
||||
}
|
||||
|
||||
File file = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
|
||||
File file = new File(dataDirectory, fileName);
|
||||
|
||||
return file.exists() && file.isFile();
|
||||
}
|
||||
|
||||
public static void writeEnergyValueRegistryToFile()
|
||||
public static void writeEnergyValueRegistryToFile(String fileName)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getMinecraftServerInstance() != null)
|
||||
{
|
||||
|
@ -79,8 +79,8 @@ public class SerializationHelper
|
|||
|
||||
try
|
||||
{
|
||||
File file1 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3.tmp");
|
||||
File file2 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
|
||||
File file1 = new File(dataDirectory, fileName + ".tmp");
|
||||
File file2 = new File(dataDirectory, fileName);
|
||||
CompressedStreamTools.writeCompressed(energyValueRegistryNBT, new FileOutputStream(file1));
|
||||
|
||||
if (file2.exists())
|
||||
|
@ -90,7 +90,7 @@ public class SerializationHelper
|
|||
|
||||
file1.renameTo(file2);
|
||||
|
||||
LogHelper.info("Successfully saved EnergyValues to file: " + file2.getAbsolutePath());
|
||||
LogHelper.info("Successfully saved EnergyValueRegistry to file: " + file2.getPath());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@ -99,22 +99,24 @@ public class SerializationHelper
|
|||
}
|
||||
}
|
||||
|
||||
public static void readEnergyValueRegistryFromFile()
|
||||
public static NBTTagCompound readEnergyValueRegistryFromFile(String fileName)
|
||||
{
|
||||
if (energyValueRegistryFileExist())
|
||||
if (dataFileExist(fileName))
|
||||
{
|
||||
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + "ee3");
|
||||
File energyValueRegistryFile = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
|
||||
File energyValueRegistryFile = new File(dataDirectory, fileName);
|
||||
|
||||
try
|
||||
{
|
||||
EnergyValueRegistry.getInstance().readFromNBT(CompressedStreamTools.readCompressed(new FileInputStream(energyValueRegistryFile)));
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(energyValueRegistryFile));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<WrappedStack, EnergyValue> readEnergyValueStackMapFromJsonFile(String fileName)
|
||||
|
@ -141,8 +143,6 @@ public class SerializationHelper
|
|||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// TODO More intelligent log message
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue