Formatting change

Aformentioned merge wouldnt commit for some reason

PLEASE REVIEW THIS AND THE PREVIOUS COMMIT
This commit is contained in:
StevenRS11
2014-07-16 10:41:27 -05:00
parent 7c7129914a
commit 499c7d91d8

View File

@@ -29,21 +29,25 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
/** /**
* This class regulates all the operations involving the storage and manipulation of dimensions. * This class regulates all the operations involving the storage and
* It handles saving dim data, teleporting the player, and creating/registering new dimensions as * manipulation of dimensions. It handles saving dim data, teleporting the
* well as loading old dimensions on startup * player, and creating/registering new dimensions as well as loading old
* dimensions on startup
*/ */
public class PocketManager public class PocketManager
{ {
private static class InnerDimData extends NewDimData private static class InnerDimData extends NewDimData
{ {
// This class allows us to instantiate NewDimData indirectly without exposing // This class allows us to instantiate NewDimData indirectly without
// a public constructor from NewDimData. It's meant to stop us from constructing // exposing
// instances of NewDimData going through PocketManager. In turn, that enforces // a public constructor from NewDimData. It's meant to stop us from
// that any link destinations must be real dimensions controlled by PocketManager. // constructing
// instances of NewDimData going through PocketManager. In turn, that
// enforces
// that any link destinations must be real dimensions controlled by
// PocketManager.
public InnerDimData(int id, InnerDimData parent, DimensionType type, public InnerDimData(int id, InnerDimData parent, DimensionType type, IUpdateWatcher<ClientLinkData> linkWatcher)
IUpdateWatcher<ClientLinkData> linkWatcher)
{ {
super(id, parent, type, linkWatcher); super(id, parent, type, linkWatcher);
} }
@@ -108,9 +112,12 @@ public class PocketManager
private static class DimRegistrationCallback implements IDimRegistrationCallback private static class DimRegistrationCallback implements IDimRegistrationCallback
{ {
// We use this class to provide Compactor with the ability to send us dim data without // We use this class to provide Compactor with the ability to send us
// having to instantiate a bunch of data containers and without exposing an "unsafe" // dim data without
// creation method for anyone to call. Integrity protection for the win! It's like // having to instantiate a bunch of data containers and without exposing
// an "unsafe"
// creation method for anyone to call. Integrity protection for the win!
// It's like
// exposing a private constructor ONLY to a very specific trusted class. // exposing a private constructor ONLY to a very specific trusted class.
@Override @Override
@@ -133,9 +140,11 @@ public class PocketManager
private static final UpdateWatcherProxy<ClientDimData> dimWatcher = new UpdateWatcherProxy<ClientDimData>(); private static final UpdateWatcherProxy<ClientDimData> dimWatcher = new UpdateWatcherProxy<ClientDimData>();
private static ArrayList<NewDimData> rootDimensions = null; private static ArrayList<NewDimData> rootDimensions = null;
//HashMap that maps all the dimension IDs registered with DimDoors to their DD data. // HashMap that maps all the dimension IDs registered with DimDoors to their
// DD data.
private static HashMap<Integer, InnerDimData> dimensionData = null; private static HashMap<Integer, InnerDimData> dimensionData = null;
//ArrayList that stores the dimension IDs of any dimension that has been deleted. // ArrayList that stores the dimension IDs of any dimension that has been
// deleted.
private static ArrayList<Integer> dimensionIDBlackList = null; private static ArrayList<Integer> dimensionIDBlackList = null;
// Stores all the personal pocket mappings // Stores all the personal pocket mappings
@@ -147,7 +156,9 @@ public class PocketManager
} }
/** /**
* simple method called on startup to register all dims saved in the dim list. Only tries to register pocket dims, though. Also calls load() * simple method called on startup to register all dims saved in the dim
* list. Only tries to register pocket dims, though. Also calls load()
*
* @return * @return
*/ */
public static void load() public static void load()
@@ -167,7 +178,6 @@ public class PocketManager
dimensionIDBlackList = new ArrayList<Integer>(); dimensionIDBlackList = new ArrayList<Integer>();
personalPocketsMapping = new HashMap<String, NewDimData>(); personalPocketsMapping = new HashMap<String, NewDimData>();
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{ {
// Shouldnt try to load everything if we are a client // Shouldnt try to load everything if we are a client
@@ -180,7 +190,6 @@ public class PocketManager
DDProperties properties = DDProperties.instance(); DDProperties properties = DDProperties.instance();
registerDimension(properties.LimboDimensionID, null, DimensionType.ROOT); registerDimension(properties.LimboDimensionID, null, DimensionType.ROOT);
loadInternal(); loadInternal();
// Register pocket dimensions // Register pocket dimensions
@@ -210,7 +219,8 @@ public class PocketManager
PocketManager.rootDimensions.add(dimData); PocketManager.rootDimensions.add(dimData);
} }
else //register children else
// register children
{ {
InnerDimData test = PocketManager.dimensionData.get(packedData.ParentID); InnerDimData test = PocketManager.dimensionData.get(packedData.ParentID);
dimData = new InnerDimData(packedData.ID, test, type, linkWatcher); dimData = new InnerDimData(packedData.ID, test, type, linkWatcher);
@@ -232,8 +242,10 @@ public class PocketManager
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
// We cast to InnerDimData so that if anyone tries to be a smartass and create their // actually a pocket.
// We cast to InnerDimData so that if anyone tries to be a smartass and
// create their
// own version of NewDimData, this will throw an exception. // own version of NewDimData, this will throw an exception.
InnerDimData dimension = (InnerDimData) target; InnerDimData dimension = (InnerDimData) target;
if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null)
@@ -303,7 +315,8 @@ public class PocketManager
} }
catch (Exception e) catch (Exception e)
{ {
System.err.println("Could not register pocket dimension #" + dimension.id() + ". Probably caused by a version update/save data corruption/other mods."); System.err.println("Could not register pocket dimension #" + dimension.id()
+ ". Probably caused by a version update/save data corruption/other mods.");
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -342,7 +355,8 @@ public class PocketManager
} }
/** /**
* loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler * loads the dim data from the saved hashMap. Also handles compatibility
* with old saves, see OldSaveHandler
*/ */
private static void loadInternal() private static void loadInternal()
{ {
@@ -439,6 +453,7 @@ public class PocketManager
/** /**
* method to register a new pocket with DD and with forge. * method to register a new pocket with DD and with forge.
*
* @param parent * @param parent
* @param type * @param type
* @param playername * @param playername
@@ -467,7 +482,8 @@ public class PocketManager
return data; return data;
} }
else else
{ //register a pocket as personal if its parents are personal, but without a mapping. { // register a pocket as personal if its parents are personal, but
// without a mapping.
if (parent.type == DimensionType.PERSONAL) if (parent.type == DimensionType.PERSONAL)
{ {
DimensionManager.registerDimension(dimensionID, properties.PersonalPocketProviderID); DimensionManager.registerDimension(dimensionID, properties.PersonalPocketProviderID);
@@ -489,6 +505,7 @@ public class PocketManager
/** /**
* Registers a dimension with DD but NOT with forge. * Registers a dimension with DD but NOT with forge.
*
* @param dimensionID * @param dimensionID
* @param parent * @param parent
* @param isPocket * @param isPocket
@@ -524,7 +541,8 @@ public class PocketManager
// client side. createDimensionData() always handles root dimensions // client side. createDimensionData() always handles root dimensions
// properly, even if they weren't defined before. // properly, even if they weren't defined before.
// SenseiKiwi: I'm a little worried about how createDimensionData will raise // SenseiKiwi: I'm a little worried about how createDimensionData will
// raise
// an event when it creates any root dimensions... Needs checking later. // an event when it creates any root dimensions... Needs checking later.
InnerDimData root = (InnerDimData) createDimensionData(rootID); InnerDimData root = (InnerDimData) createDimensionData(rootID);
@@ -545,10 +563,13 @@ public class PocketManager
} }
if (dimension.isPocketDimension() && !DimensionManager.isDimensionRegistered(dimension.id())) if (dimension.isPocketDimension() && !DimensionManager.isDimensionRegistered(dimension.id()))
{ {
//Im registering pocket dims here. I *think* we can assume that if its a pocket and we are // Im registering pocket dims here. I *think* we can assume that if
// its a pocket and we are
// registering its dim data, we also need to register it with forge. // registering its dim data, we also need to register it with forge.
//New packet stuff prevents this from always being true, unfortuantly. I send the dimdata to the client when they teleport. // New packet stuff prevents this from always being true,
// unfortuantly. I send the dimdata to the client when they
// teleport.
// Steven // Steven
DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID); DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID);
} }
@@ -572,15 +593,19 @@ public class PocketManager
public static NewDimData createDimensionDataDangerously(int dimensionID) public static NewDimData createDimensionDataDangerously(int dimensionID)
{ {
// Same as createDimensionData(int), but public. Meant to discourage anyone from // Same as createDimensionData(int), but public. Meant to discourage
// using it unless absolutely needed! We'll probably phase this out eventually. // anyone from
// using it unless absolutely needed! We'll probably phase this out
// eventually.
return createDimensionData(dimensionID); return createDimensionData(dimensionID);
} }
protected static NewDimData createDimensionData(int dimensionID) protected static NewDimData createDimensionData(int dimensionID)
{ {
// Retrieve the data for a dimension. If we don't have a record for that dimension, // Retrieve the data for a dimension. If we don't have a record for that
// assume it's a non-pocket dimension that hasn't been initialized with us before // dimension,
// assume it's a non-pocket dimension that hasn't been initialized with
// us before
// and create a NewDimData instance for it. // and create a NewDimData instance for it.
NewDimData dimension = PocketManager.dimensionData.get(dimensionID); NewDimData dimension = PocketManager.dimensionData.get(dimensionID);
@@ -643,10 +668,12 @@ public class PocketManager
{ {
return PocketManager.dimensionIDBlackList.contains(dimensionID); return PocketManager.dimensionIDBlackList.contains(dimensionID);
} }
public static void registerDimWatcher(IUpdateWatcher<ClientDimData> watcher) public static void registerDimWatcher(IUpdateWatcher<ClientDimData> watcher)
{ {
getDimwatcher().registerReceiver(watcher); getDimwatcher().registerReceiver(watcher);
} }
public static boolean unregisterDimWatcher(IUpdateWatcher<ClientDimData> watcher) public static boolean unregisterDimWatcher(IUpdateWatcher<ClientDimData> watcher)
{ {
return getDimwatcher().unregisterReceiver(watcher); return getDimwatcher().unregisterReceiver(watcher);
@@ -669,7 +696,8 @@ public class PocketManager
public static void writePacket(DataOutputStream output) throws IOException public static void writePacket(DataOutputStream output) throws IOException
{ {
// Write a very compact description of our dimensions and links to be sent to a client // Write a very compact description of our dimensions and links to be
// sent to a client
Compactor.write(dimensionData.values(), output); Compactor.write(dimensionData.values(), output);
} }
@@ -687,6 +715,7 @@ public class PocketManager
DimensionManager.registerDimension(dimID, DDProperties.instance().PocketProviderID); DimensionManager.registerDimension(dimID, DDProperties.instance().PocketProviderID);
} }
} }
public static void readPacket(DataInputStream input) throws IOException public static void readPacket(DataInputStream input) throws IOException
{ {
// TODO- figure out why this is getting called so frequently // TODO- figure out why this is getting called so frequently