Api cleanup
This commit is contained in:
parent
3438c86de2
commit
4d3f7aa34b
1 changed files with 127 additions and 118 deletions
|
@ -23,132 +23,141 @@ import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class DataExchangeAPI extends DataExchange {
|
public class DataExchangeAPI extends DataExchange {
|
||||||
private final static List<String> MODS = Lists.newArrayList();
|
private final static List<String> MODS = Lists.newArrayList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You should never need to create a custom instance of this Object.
|
* You should never need to create a custom instance of this Object.
|
||||||
*/
|
*/
|
||||||
public DataExchangeAPI() {
|
public DataExchangeAPI() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
protected ConnectorClientside clientSupplier(DataExchange api) {
|
protected ConnectorClientside clientSupplier(DataExchange api) {
|
||||||
return new ConnectorClientside(api);
|
return new ConnectorClientside(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConnectorServerside serverSupplier(DataExchange api) {
|
protected ConnectorServerside serverSupplier(DataExchange api) {
|
||||||
return new ConnectorServerside(api);
|
return new ConnectorServerside(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a mod to participate in the DataExchange.
|
* Register a mod to participate in the DataExchange.
|
||||||
*
|
*
|
||||||
* @param modID - {@link String} modID.
|
* @param modID - {@link String} modID.
|
||||||
*/
|
*/
|
||||||
public static void registerMod(String modID) {
|
public static void registerMod(String modID) {
|
||||||
MODS.add(modID);
|
MODS.add(modID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the IDs of all registered Mods.
|
|
||||||
* @return List of modIDs
|
|
||||||
*/
|
|
||||||
public static List<String> registeredMods(){
|
|
||||||
return MODS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new Descriptor for a {@link DataHandler}.
|
|
||||||
* @param desc The Descriptor you want to add.
|
|
||||||
*/
|
|
||||||
public static void registerDescriptor(DataHandlerDescriptor desc){
|
|
||||||
DataExchange api = DataExchange.getInstance();
|
|
||||||
api.getDescriptors().add(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk-Add a Descriptors for your {@link DataHandler}-Objects.
|
* Returns the IDs of all registered Mods.
|
||||||
* @param desc The Descriptors you want to add.
|
*
|
||||||
*/
|
* @return List of modIDs
|
||||||
public static void registerDescriptors(List<DataHandlerDescriptor> desc){
|
*/
|
||||||
DataExchange api = DataExchange.getInstance();
|
public static List<String> registeredMods() {
|
||||||
api.getDescriptors().addAll(desc);
|
return MODS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the Handler.
|
* Add a new Descriptor for a {@link DataHandler}.
|
||||||
* <p>
|
*
|
||||||
* Depending on what the result of {@link DataHandler#getOriginatesOnServer()}, the Data is sent from the server
|
* @param desc The Descriptor you want to add.
|
||||||
* to the client (if {@code true}) or the other way around.
|
*/
|
||||||
* <p>
|
public static void registerDescriptor(DataHandlerDescriptor desc) {
|
||||||
* The method {@link DataHandler#serializeData(FriendlyByteBuf)} is called just before the data is sent. You should
|
DataExchange api = DataExchange.getInstance();
|
||||||
* use this method to add the Data you need to the communication.
|
api.getDescriptors().add(desc);
|
||||||
* @param h The Data that you want to send
|
}
|
||||||
*/
|
|
||||||
public static void send(DataHandler h){
|
|
||||||
if (h.getOriginatesOnServer()){
|
|
||||||
DataExchangeAPI.getInstance().server.sendToClient(h);
|
|
||||||
} else {
|
|
||||||
DataExchangeAPI.getInstance().client.sendToServer(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a File for automatic client syncing.
|
* Bulk-Add a Descriptors for your {@link DataHandler}-Objects.
|
||||||
*
|
*
|
||||||
* @param modID The ID of the calling Mod
|
* @param desc The Descriptors you want to add.
|
||||||
* @param fileName The name of the File
|
*/
|
||||||
*/
|
public static void registerDescriptors(List<DataHandlerDescriptor> desc) {
|
||||||
public static void addAutoSyncFile(String modID, File fileName){
|
DataExchange api = DataExchange.getInstance();
|
||||||
getInstance().addAutoSyncFileData(modID, fileName, false, FileHash.NEED_TRANSFER);
|
api.getDescriptors().addAll(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a File for automatic client syncing.
|
* Sends the Handler.
|
||||||
*
|
* <p>
|
||||||
* @param modID The ID of the calling Mod
|
* Depending on what the result of {@link DataHandler#getOriginatesOnServer()}, the Data is sent from the server
|
||||||
* @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
|
* to the client (if {@code true}) or the other way around.
|
||||||
* Details
|
* <p>
|
||||||
* @param fileName The name of the File
|
* 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.
|
||||||
public static void addAutoSyncFile(String modID, String uniqueID, File fileName){
|
*
|
||||||
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, false, FileHash.NEED_TRANSFER);
|
* @param h The Data that you want to send
|
||||||
}
|
*/
|
||||||
|
public static void send(DataHandler h) {
|
||||||
|
if (h.getOriginatesOnServer()) {
|
||||||
|
DataExchangeAPI.getInstance().server.sendToClient(h);
|
||||||
|
} else {
|
||||||
|
DataExchangeAPI.getInstance().client.sendToServer(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a File for automatic client syncing.
|
* Registers a File for automatic client syncing.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
* @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.
|
public static void addAutoSyncFile(String modID, File fileName) {
|
||||||
* <p>
|
getInstance().addAutoSyncFileData(modID, fileName, false, FileHash.NEED_TRANSFER);
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public static void addAutoSyncFile(String modID, File fileName, boolean requestContent, NeedTransferPredicate needTransfer){
|
|
||||||
getInstance().addAutoSyncFileData(modID, fileName, requestContent, needTransfer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a File for automatic client syncing.
|
* Registers a File for automatic client syncing.
|
||||||
*
|
* <p>
|
||||||
* @param modID The ID of the calling Mod
|
* The file is synced of the {@link FileHash} on client and server are not equal. This method will not copy the
|
||||||
* @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
|
* configs content from the client to the server.
|
||||||
* Details
|
*
|
||||||
* @param fileName The name of the File
|
* @param modID The ID of the calling Mod
|
||||||
* @param requestContent When {@code true} the content of the file is requested for comparison. This will copy the
|
* @param uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
|
||||||
* entire file from the client to the server.
|
* Details
|
||||||
* <p>
|
* @param fileName The name of the File
|
||||||
* 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}
|
public static void addAutoSyncFile(String modID, String uniqueID, File fileName) {
|
||||||
* for comparison is sufficient.
|
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, false, FileHash.NEED_TRANSFER);
|
||||||
* @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){
|
/**
|
||||||
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, requestContent, needTransfer);
|
* 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 fileName The name of the File
|
||||||
|
* @param needTransfer If the predicate returns true, the file needs to get copied to the server.
|
||||||
|
*/
|
||||||
|
public static void addAutoSyncFile(String modID, File fileName, NeedTransferPredicate needTransfer) {
|
||||||
|
getInstance().addAutoSyncFileData(modID, fileName, true, needTransfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 uniqueID A unique Identifier for the File. (see {@link ru.bclib.api.dataexchange.FileHash#uniqueID} for
|
||||||
|
* Details
|
||||||
|
* @param fileName The name of the File
|
||||||
|
* @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, NeedTransferPredicate needTransfer) {
|
||||||
|
getInstance().addAutoSyncFileData(modID, uniqueID, fileName, true, needTransfer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue