Simplified PocketManager

1. Rewrote or removed a few bits that were causing minor warnings.
2. Rewrote deleteDimensionFiles() and deleteDimensionData() to remove
unnecessary casts and checks. We can confirm that those checks are
unnecessary because those functions are only used inside PocketManager.
If they were ever exposed externally, then we would need to add checks
again.
This commit is contained in:
SenseiKiwi 2014-07-03 17:20:59 -04:00
parent 80bb87dac6
commit b4a58f5c88

View file

@ -315,44 +315,43 @@ public class PocketManager
{
if (deleteFolder)
{
deleteDimensionFiles(target);
deleteDimensionFiles(dimension);
}
dimensionIDBlackList.add(dimension.id);
deleteDimensionData(dimension.id);
deleteDimensionData(dimension);
return true;
}
return false;
}
private static boolean deleteDimensionFiles(NewDimData target)
{
InnerDimData dimension = (InnerDimData) target;
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
private static void deleteDimensionFiles(InnerDimData dimension)
{
// We assume that the caller checks if the dimension is loaded, for the
// sake of efficiency. Don't call this on a loaded dimension or bad
// things will happen!
String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath();
File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id());
DeleteFolder.deleteFolder(saveDirectory);
File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt");
dataFile.delete();
return true;
}
return false;
}
private static boolean deleteDimensionData(int dimensionID)
private static void deleteDimensionData(InnerDimData dimension)
{
if (dimensionData.containsKey(dimensionID) && DimensionManager.getWorld(dimensionID) == null)
// We assume that the caller checks if the dimension is loaded, for the
// sake of efficiency. Don't call this on a loaded dimension or bad
// things will happen!
if (dimensionData.remove(dimension.id()) != null)
{
NewDimData target = PocketManager.getDimensionData(dimensionID);
InnerDimData dimension = (InnerDimData) target;
dimensionData.remove(dimensionID);
// Raise the dim deleted event
getDimwatcher().onDeleted(new ClientDimData(dimension));
dimension.clear();
return true;
}
return false;
else
{
// This should never happen. A simple sanity check.
throw new IllegalArgumentException("The specified dimension is not listed with PocketManager.");
}
}
private static void registerPockets(DDProperties properties)
@ -647,11 +646,8 @@ public class PocketManager
{
return dimension.getLink(x, y, z);
}
else
{
return null;
}
}
public static boolean isBlackListed(int dimensionID)
{
@ -716,9 +712,6 @@ public class PocketManager
load();
Compactor.readDimensions(input, new DimRegistrationCallback());
// Register pocket dimensions
DDProperties properties = DDProperties.instance();
isLoaded = true;
isLoading = false;
isConnected = true;