From b4a58f5c884e4ea40082412eb6e1c16dc5a2f530 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 17:20:59 -0400 Subject: [PATCH] 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. --- .../mod_pocketDim/core/PocketManager.java | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 1882bba6..acb6ed98 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -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) + private static void deleteDimensionFiles(InnerDimData dimension) { - InnerDimData dimension = (InnerDimData) target; - if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) - { - 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; + // 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(); } - 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,10 +646,7 @@ public class PocketManager { return dimension.getLink(x, y, z); } - else - { - return null; - } + return null; } public static boolean isBlackListed(int dimensionID) @@ -715,9 +711,6 @@ public class PocketManager // Load compacted client-side dimension data load(); Compactor.readDimensions(input, new DimRegistrationCallback()); - - // Register pocket dimensions - DDProperties properties = DDProperties.instance(); isLoaded = true; isLoading = false;