Added Step to handler that allows users to stop the message from beeing sent and prepare some data.

This commit is contained in:
Frank 2021-08-17 09:52:48 +02:00
parent 132623419d
commit 742ea56e34
5 changed files with 58 additions and 25 deletions

View file

@ -44,6 +44,12 @@ public class HelloClient extends DataHandler {
super(DESCRIPTOR.IDENTIFIER, true);
}
public static ModContainer getModContainer(String modID) {
Optional<ModContainer> optional = FabricLoader.getInstance()
.getModContainer(modID);
return optional.orElse(null);
}
public static String getModVersion(String modID) {
Optional<ModContainer> optional = FabricLoader.getInstance()
.getModContainer(modID);
@ -61,7 +67,18 @@ public class HelloClient extends DataHandler {
}
@Override
protected void serializeData(FriendlyByteBuf buf) {
protected boolean prepareData(boolean isClient) {
if (!Configs.MAIN_CONFIG.getBoolean(Configs.MAIN_SYNC_CATEGORY, "enabled", true)) {
BCLib.LOGGER.info("Auto-Sync was disabled on the server.");
return false;
}
DataExchange.getInstance().loadSyncFolder();
return true;
}
@Override
protected void serializeData(FriendlyByteBuf buf, boolean isClient) {
final String vbclib = getBCLibVersion();
BCLib.LOGGER.info("Sending Hello to Client. (server=" + vbclib + ")");
final List<String> mods = DataExchangeAPI.registeredMods();

View file

@ -62,9 +62,19 @@ public class HelloServer extends DataHandler {
public HelloServer() {
super(DESCRIPTOR.IDENTIFIER, false);
}
@Override
protected void serializeData(FriendlyByteBuf buf) {
protected boolean prepareData(boolean isClient) {
if (!Configs.CLIENT_CONFIG.getBoolean(Configs.MAIN_SYNC_CATEGORY, "enabled", true)) {
BCLib.LOGGER.info("Auto-Sync was disabled on the client.");
return false;
}
return true;
}
@Override
protected void serializeData(FriendlyByteBuf buf, boolean isClient) {
BCLib.LOGGER.info("Sending hello to server.");
buf.writeInt(DataFixerAPI.getModVersion(HelloClient.getBCLibVersion()));
}
@ -84,12 +94,6 @@ public class HelloServer extends DataHandler {
return;
}
if (Configs.MAIN_CONFIG.getBoolean(Configs.MAIN_SYNC_CATEGORY, "enabled", true)) {
reply(new HelloClient(), server);
} else {
BCLib.LOGGER.info("Auto-Sync was disabled on the server.");
}
DataExchange.getInstance().loadSyncFolder();
reply(new HelloClient(), server);
}
}

View file

@ -29,7 +29,7 @@ public class RequestFiles extends DataHandler {
}
@Override
protected void serializeData(FriendlyByteBuf buf) {
protected void serializeData(FriendlyByteBuf buf, boolean isClient) {
newToken();
writeString(buf, currentToken);

View file

@ -43,7 +43,7 @@ public class SendFiles extends DataHandler {
}
@Override
protected void serializeData(FriendlyByteBuf buf) {
protected void serializeData(FriendlyByteBuf buf, boolean isClient) {
List<AutoFileSyncEntry> existingFiles = files.stream().filter(e -> e.fileName.exists()).collect(Collectors.toList());
/*
//this will try to send a file that was not registered or requested by the client