Api cleanup

This commit is contained in:
Frank 2021-08-06 23:29:41 +02:00
parent 3438c86de2
commit 4d3f7aa34b

View file

@ -52,26 +52,29 @@ public class DataExchangeAPI extends DataExchange {
/** /**
* Returns the IDs of all registered Mods. * Returns the IDs of all registered Mods.
*
* @return List of modIDs * @return List of modIDs
*/ */
public static List<String> registeredMods(){ public static List<String> registeredMods() {
return MODS; return MODS;
} }
/** /**
* Add a new Descriptor for a {@link DataHandler}. * Add a new Descriptor for a {@link DataHandler}.
*
* @param desc The Descriptor you want to add. * @param desc The Descriptor you want to add.
*/ */
public static void registerDescriptor(DataHandlerDescriptor desc){ public static void registerDescriptor(DataHandlerDescriptor desc) {
DataExchange api = DataExchange.getInstance(); DataExchange api = DataExchange.getInstance();
api.getDescriptors().add(desc); api.getDescriptors().add(desc);
} }
/** /**
* Bulk-Add a Descriptors for your {@link DataHandler}-Objects. * Bulk-Add a Descriptors for your {@link DataHandler}-Objects.
*
* @param desc The Descriptors you want to add. * @param desc The Descriptors you want to add.
*/ */
public static void registerDescriptors(List<DataHandlerDescriptor> desc){ public static void registerDescriptors(List<DataHandlerDescriptor> desc) {
DataExchange api = DataExchange.getInstance(); DataExchange api = DataExchange.getInstance();
api.getDescriptors().addAll(desc); api.getDescriptors().addAll(desc);
} }
@ -84,10 +87,11 @@ public class DataExchangeAPI extends DataExchange {
* <p> * <p>
* The method {@link DataHandler#serializeData(FriendlyByteBuf)} is called just before the data is sent. You should * The method {@link DataHandler#serializeData(FriendlyByteBuf)} is called just before the data is sent. You should
* use this method to add the Data you need to the communication. * use this method to add the Data you need to the communication.
*
* @param h The Data that you want to send * @param h The Data that you want to send
*/ */
public static void send(DataHandler h){ public static void send(DataHandler h) {
if (h.getOriginatesOnServer()){ if (h.getOriginatesOnServer()) {
DataExchangeAPI.getInstance().server.sendToClient(h); DataExchangeAPI.getInstance().server.sendToClient(h);
} else { } else {
DataExchangeAPI.getInstance().client.sendToServer(h); DataExchangeAPI.getInstance().client.sendToServer(h);
@ -100,55 +104,60 @@ public class DataExchangeAPI extends DataExchange {
* @param modID The ID of the calling Mod * @param modID The ID of the calling Mod
* @param fileName The name of the File * @param fileName The name of the File
*/ */
public static void addAutoSyncFile(String modID, File fileName){ public static void addAutoSyncFile(String modID, File fileName) {
getInstance().addAutoSyncFileData(modID, fileName, false, FileHash.NEED_TRANSFER); getInstance().addAutoSyncFileData(modID, fileName, false, FileHash.NEED_TRANSFER);
} }
/** /**
* Registers a File for automatic client syncing. * Registers a File for automatic client syncing.
* <p>
* The file is synced of the {@link FileHash} on client and server are not equal. This method will not copy the
* configs content from the client to the server.
* *
* @param modID The ID of the calling Mod * @param modID The ID of the calling Mod
* @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for * @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
* Details * Details
* @param fileName The name of the File * @param fileName The name of the File
*/ */
public static void addAutoSyncFile(String modID, String uniqueID, File fileName){ public static void addAutoSyncFile(String modID, String uniqueID, File fileName) {
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, false, FileHash.NEED_TRANSFER); getInstance().addAutoSyncFileData(modID, uniqueID, fileName, false, FileHash.NEED_TRANSFER);
} }
/** /**
* Registers a File for automatic client syncing. * Registers a File for automatic client syncing.
* * <p>
* @param modID The ID of the calling Mod * The content of the file is requested for comparison. This will copy the
* @param fileName The name of the File
* @param requestContent When {@code true} the content of the file is requested for comparison. This will copy the
* entire file from the client to the server. * entire file from the client to the server.
* <p> * <p>
* You should only use this option, if you need to compare parts of the file in order to decide * You should only use this option, if you need to compare parts of the file in order to decide
* If the File needs to be copied. Normally using the {@link ru.bclib.api.dataexchange.FileHash} * if the File needs to be copied. Normally using the {@link ru.bclib.api.dataexchange.FileHash}
* for comparison is sufficient. * for comparison is sufficient.
*
* @param modID The ID of the calling Mod
* @param fileName The name of the File
* @param needTransfer If the predicate returns true, the file needs to get copied to the server. * @param needTransfer If the predicate returns true, the file needs to get copied to the server.
*/ */
public static void addAutoSyncFile(String modID, File fileName, boolean requestContent, NeedTransferPredicate needTransfer){ public static void addAutoSyncFile(String modID, File fileName, NeedTransferPredicate needTransfer) {
getInstance().addAutoSyncFileData(modID, fileName, requestContent, needTransfer); getInstance().addAutoSyncFileData(modID, fileName, true, needTransfer);
} }
/** /**
* Registers a File for automatic client syncing. * Registers a File for automatic client syncing.
* <p>
* The content of the file is requested for comparison. This will copy the
* entire file from the client to the server.
* <p>
* You should only use this option, if you need to compare parts of the file in order to decide
* if the File needs to be copied. Normally using the {@link ru.bclib.api.dataexchange.FileHash}
* for comparison is sufficient.
* *
* @param modID The ID of the calling Mod * @param modID The ID of the calling Mod
* @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for * @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
* Details * Details
* @param fileName The name of the File * @param fileName The name of the File
* @param requestContent When {@code true} the content of the file is requested for comparison. This will copy the
* entire file from the client to the server.
* <p>
* You should only use this option, if you need to compare parts of the file in order to decide
* If the File needs to be copied. Normally using the {@link ru.bclib.api.dataexchange.FileHash}
* for comparison is sufficient.
* @param needTransfer If the predicate returns true, the file needs to get copied to the server. * @param needTransfer If the predicate returns true, the file needs to get copied to the server.
*/ */
public static void addAutoSyncFile(String modID, String uniqueID, File fileName, boolean requestContent, NeedTransferPredicate needTransfer){ public static void addAutoSyncFile(String modID, String uniqueID, File fileName, NeedTransferPredicate needTransfer) {
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, requestContent, needTransfer); getInstance().addAutoSyncFileData(modID, uniqueID, fileName, true, needTransfer);
} }
} }