I HATE YOU GITHUB
This commit is contained in:
@@ -33,7 +33,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||||||
|
|
||||||
public class EventHookContainer
|
public class EventHookContainer
|
||||||
{
|
{
|
||||||
private final DDProperties properties;
|
private final DDProperties properties;
|
||||||
|
|
||||||
public EventHookContainer(DDProperties properties)
|
public EventHookContainer(DDProperties properties)
|
||||||
{
|
{
|
||||||
@@ -44,9 +44,8 @@ public class EventHookContainer
|
|||||||
public void onInitMapGen(InitMapGenEvent event)
|
public void onInitMapGen(InitMapGenEvent event)
|
||||||
{
|
{
|
||||||
// Replace the Nether fortress generator with our own only if any
|
// Replace the Nether fortress generator with our own only if any
|
||||||
// gateways would ever generate.
|
// gateways would ever generate. This allows admins to disable our
|
||||||
// This allows admins to disable our fortress overriding without
|
// fortress overriding without disabling all gateways.
|
||||||
// disabling all gateways.
|
|
||||||
/*
|
/*
|
||||||
* if (properties.FortressGatewayGenerationChance > 0 &&
|
* if (properties.FortressGatewayGenerationChance > 0 &&
|
||||||
* properties.WorldRiftGenerationEnabled && event.type ==
|
* properties.WorldRiftGenerationEnabled && event.type ==
|
||||||
@@ -88,15 +87,13 @@ public class EventHookContainer
|
|||||||
|
|
||||||
World world = event.entity.worldObj;
|
World world = event.entity.worldObj;
|
||||||
ItemStack stack = event.entityPlayer.inventory.getCurrentItem();
|
ItemStack stack = event.entityPlayer.inventory.getCurrentItem();
|
||||||
if (stack != null)
|
if (stack != null && stack.getItem() instanceof ItemDoor)
|
||||||
{
|
{
|
||||||
if (stack.getItem() instanceof ItemDoor)
|
if (mod_pocketDim.itemDimensionalDoor.tryToPlaceDoor(stack, event.entityPlayer, world,
|
||||||
|
event.x, event.y, event.z, event.face))
|
||||||
{
|
{
|
||||||
if(mod_pocketDim.itemDimensionalDoor.tryToPlaceDoor(stack, event.entityPlayer, world, event.x, event.y, event.z, event.face))
|
// Cancel the event so that we don't get two doors from vanilla doors
|
||||||
{
|
event.setCanceled(true);
|
||||||
//cancel the event so we dont get two doors from vanilla doors
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,11 +102,9 @@ public class EventHookContainer
|
|||||||
public void onWorldLoad(WorldEvent.Load event)
|
public void onWorldLoad(WorldEvent.Load event)
|
||||||
{
|
{
|
||||||
// We need to initialize PocketManager here because onServerAboutToStart
|
// We need to initialize PocketManager here because onServerAboutToStart
|
||||||
// fires before we can
|
// fires before we can use DimensionManager and onServerStarting fires
|
||||||
// use DimensionManager and onServerStarting fires after the game tries
|
// after the game tries to generate terrain. If a gateway tries to
|
||||||
// to generate terrain.
|
// generate before PocketManager has initialized, we get a crash.
|
||||||
// If a gateway tries to generate before PocketManager has initialized,
|
|
||||||
// we get a crash.
|
|
||||||
if (!PocketManager.isLoaded())
|
if (!PocketManager.isLoaded())
|
||||||
{
|
{
|
||||||
PocketManager.load();
|
PocketManager.load();
|
||||||
@@ -131,16 +126,14 @@ public class EventHookContainer
|
|||||||
public boolean onDeathWithHighPriority(LivingDeathEvent event)
|
public boolean onDeathWithHighPriority(LivingDeathEvent event)
|
||||||
{
|
{
|
||||||
// Teleport the entity to Limbo if it's a player in a pocket dimension
|
// Teleport the entity to Limbo if it's a player in a pocket dimension
|
||||||
// and
|
// and if Limbo preserves player inventories. We'll check again in a
|
||||||
// if Limbo preserves player inventories. We'll check again in a
|
// low-priority event handler to give other mods a chance to save the
|
||||||
// low-priority event handler
|
// player if Limbo does _not_ preserve inventories.
|
||||||
// to give other mods a chance to save the player if Limbo does _not_
|
|
||||||
// preserve inventories.
|
|
||||||
|
|
||||||
Entity entity = event.entity;
|
Entity entity = event.entity;
|
||||||
|
|
||||||
if (entity instanceof EntityPlayer && properties.LimboEnabled && entity.worldObj.provider instanceof PocketProvider
|
if (properties.LimboEnabled && properties.LimboReturnsInventoryEnabled &&
|
||||||
&& properties.LimboReturnsInventoryEnabled)
|
entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider)
|
||||||
{
|
{
|
||||||
EntityPlayer player = (EntityPlayer) entity;
|
EntityPlayer player = (EntityPlayer) entity;
|
||||||
mod_pocketDim.deathTracker.addUsername(player.username);
|
mod_pocketDim.deathTracker.addUsername(player.username);
|
||||||
@@ -155,11 +148,10 @@ public class EventHookContainer
|
|||||||
public boolean onDeathWithLowPriority(LivingDeathEvent event)
|
public boolean onDeathWithLowPriority(LivingDeathEvent event)
|
||||||
{
|
{
|
||||||
// This low-priority handler gives mods a chance to save a player from
|
// This low-priority handler gives mods a chance to save a player from
|
||||||
// death before we apply
|
// death before we apply teleporting them to Limbo _without_ preserving
|
||||||
// teleporting them to Limbo _without_ preserving their inventory. We
|
// their inventory. We also check if the player died in a pocket
|
||||||
// also check if the player
|
// dimension and record it, regardless of whether the player will be
|
||||||
// died in a pocket dimension and record it, regardless of whether the
|
// sent to Limbo.
|
||||||
// player will be sent to Limbo.
|
|
||||||
|
|
||||||
Entity entity = event.entity;
|
Entity entity = event.entity;
|
||||||
|
|
||||||
@@ -209,9 +201,8 @@ public class EventHookContainer
|
|||||||
SoundManager sndManager = FMLClientHandler.instance().getClient().sndManager;
|
SoundManager sndManager = FMLClientHandler.instance().getClient().sndManager;
|
||||||
|
|
||||||
// SenseiKiwi: I've added the following check as a quick fix for a
|
// SenseiKiwi: I've added the following check as a quick fix for a
|
||||||
// reported crash.
|
// reported crash. This needs to work without a hitch or we have to
|
||||||
// This needs to work without a hitch or we have to stop trying to
|
// stop trying to replace the background music...
|
||||||
// replace the background music...
|
|
||||||
if (sndManager != null && sndManager.sndSystem != null)
|
if (sndManager != null && sndManager.sndSystem != null)
|
||||||
{
|
{
|
||||||
if (world.provider instanceof LimboProvider)
|
if (world.provider instanceof LimboProvider)
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ public class PocketManager
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
||||||
{
|
{
|
||||||
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
||||||
@@ -314,7 +315,7 @@ public class PocketManager
|
|||||||
{
|
{
|
||||||
if (deleteFolder)
|
if (deleteFolder)
|
||||||
{
|
{
|
||||||
deleteDimensionFolder(target);
|
deleteDimensionFiles(target);
|
||||||
}
|
}
|
||||||
dimensionIDBlackList.add(dimension.id);
|
dimensionIDBlackList.add(dimension.id);
|
||||||
deleteDimensionData(dimension.id);
|
deleteDimensionData(dimension.id);
|
||||||
@@ -322,20 +323,25 @@ public class PocketManager
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private static boolean deleteDimensionFolder(NewDimData target)
|
|
||||||
|
private static boolean deleteDimensionFiles(NewDimData target)
|
||||||
{
|
{
|
||||||
InnerDimData dimension = (InnerDimData) target;
|
InnerDimData dimension = (InnerDimData) target;
|
||||||
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
|
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
|
||||||
{
|
{
|
||||||
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id());
|
String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath();
|
||||||
|
File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id());
|
||||||
DeleteFolder.deleteFolder(saveDirectory);
|
DeleteFolder.deleteFolder(saveDirectory);
|
||||||
|
File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt");
|
||||||
|
dataFile.delete();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean deleteDimensionData(int dimensionID)
|
private static boolean deleteDimensionData(int dimensionID)
|
||||||
{
|
{
|
||||||
if(dimensionData.containsKey(dimensionID)&& DimensionManager.getWorld(dimensionID) == null)
|
if (dimensionData.containsKey(dimensionID) && DimensionManager.getWorld(dimensionID) == null)
|
||||||
{
|
{
|
||||||
NewDimData target = PocketManager.getDimensionData(dimensionID);
|
NewDimData target = PocketManager.getDimensionData(dimensionID);
|
||||||
InnerDimData dimension = (InnerDimData) target;
|
InnerDimData dimension = (InnerDimData) target;
|
||||||
|
|||||||
@@ -244,58 +244,35 @@ public class DDSaveHandler
|
|||||||
// Create the data directory for our dimensions
|
// Create the data directory for our dimensions
|
||||||
// Don't catch exceptions here. If we can't create this folder,
|
// Don't catch exceptions here. If we can't create this folder,
|
||||||
// the mod should crash to let the user know early on.
|
// the mod should crash to let the user know early on.
|
||||||
|
|
||||||
//I still dont think that this is the best way to do this, but atleast it is better than
|
|
||||||
//risking deleting everything. I delete files afterwards that I did not modify.
|
|
||||||
|
|
||||||
//get the save directory path
|
// Get the save directory path
|
||||||
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/data/");
|
File saveDirectory = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/data/");
|
||||||
|
String savePath = saveDirectory.getAbsolutePath();
|
||||||
|
|
||||||
//create the save directory
|
// Create the save directory
|
||||||
Files.createParentDirs(saveDirectory);
|
Files.createParentDirs(saveDirectory);
|
||||||
saveDirectory.mkdir();
|
saveDirectory.mkdir();
|
||||||
|
|
||||||
//create and write the blackList
|
// Create and write the blackList
|
||||||
BlacklistProcessor blacklistReader = new BlacklistProcessor();
|
writeBlacklist(blacklist, savePath);
|
||||||
writeBlacklist(blacklist, blacklistReader,saveDirectory);
|
|
||||||
|
|
||||||
FileFilter dataFileFilter = new FileFilters.RegexFileFilter("dim_-?\\d+\\.txt");
|
|
||||||
|
|
||||||
//Take the list of all dimData files already saved in the save Directory, and map them according to ID.
|
|
||||||
File[] dataFiles = saveDirectory.listFiles(dataFileFilter);
|
|
||||||
HashMap<Integer,File> unsavedDimData = new HashMap<Integer,File>();
|
|
||||||
for (File dataFile : dataFiles)
|
|
||||||
{
|
|
||||||
unsavedDimData.put(Integer.parseInt(dataFile.getName().split("[.]")[0].substring(4)), dataFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Write the dimension save data, and remove the ones we save from the mapping
|
||||||
boolean succeeded = true;
|
boolean succeeded = true;
|
||||||
|
|
||||||
//write the dimension save data, and remove the ones we save from the mapping
|
|
||||||
DimDataProcessor writer = new DimDataProcessor();
|
DimDataProcessor writer = new DimDataProcessor();
|
||||||
for (IPackable<PackedDimData> dimension : dimensions)
|
for (IPackable<PackedDimData> dimension : dimensions)
|
||||||
{
|
{
|
||||||
succeeded &= writeDimension(dimension, writer, saveDirectory.getAbsolutePath()+"/dim_");
|
succeeded &= writeDimension(dimension, writer, savePath + "/dim_");
|
||||||
unsavedDimData.remove(Integer.parseInt(dimension.name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//once we have finished saving, delete the files from the save directory that where not saved
|
|
||||||
if(succeeded)
|
|
||||||
{
|
|
||||||
for (File dataFile : unsavedDimData.values())
|
|
||||||
{
|
|
||||||
dataFile.delete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return succeeded;
|
return succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean writeBlacklist(List<Integer> blacklist, BlacklistProcessor writer, File saveDirectory)
|
private static boolean writeBlacklist(List<Integer> blacklist, String savePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File tempFile = new File(saveDirectory.getAbsolutePath() + "blacklist.tmp");
|
BlacklistProcessor writer = new BlacklistProcessor();
|
||||||
File saveFile = new File(saveDirectory.getAbsolutePath() + "blacklist.txt");
|
File tempFile = new File(savePath + "/blacklist.tmp");
|
||||||
|
File saveFile = new File(savePath + "/blacklist.txt");
|
||||||
writer.writeToFile(tempFile, blacklist);
|
writer.writeToFile(tempFile, blacklist);
|
||||||
saveFile.delete();
|
saveFile.delete();
|
||||||
tempFile.renameTo(saveFile);
|
tempFile.renameTo(saveFile);
|
||||||
@@ -306,9 +283,9 @@ public class DDSaveHandler
|
|||||||
System.err.println("Could not save blacklist. The following error occurred:");
|
System.err.println("Could not save blacklist. The following error occurred:");
|
||||||
printException(e, true);
|
printException(e, true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean writeDimension(IPackable<PackedDimData> dimension, DimDataProcessor writer, String basePath)
|
private static boolean writeDimension(IPackable<PackedDimData> dimension, DimDataProcessor writer, String basePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user