Fixed server crashes

This commit is contained in:
Frank 2021-08-06 22:26:56 +02:00
parent d4c9695e5c
commit c28a566c78
2 changed files with 14 additions and 8 deletions

View file

@ -29,9 +29,17 @@ public class DataExchangeAPI extends DataExchange {
* 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((api) -> new ConnectorClientside(api), (api) -> new ConnectorServerside(api)); super();
} }
@Environment(EnvType.CLIENT)
protected ConnectorClientside clientSupplier(DataExchange api) {
return new ConnectorClientside(api);
}
protected ConnectorServerside serverSupplier(DataExchange api) {
return new ConnectorServerside(api);
}
/** /**
* Register a mod to participate in the DataExchange. * Register a mod to participate in the DataExchange.

View file

@ -182,13 +182,11 @@ abstract public class DataExchange {
protected final Set<DataHandlerDescriptor> descriptors; protected final Set<DataHandlerDescriptor> descriptors;
protected final List<AutoFileSyncEntry> autoSyncFiles = new ArrayList<>(4); protected final List<AutoFileSyncEntry> autoSyncFiles = new ArrayList<>(4);
private final Function<DataExchange, ConnectorClientside> clientSupplier; abstract protected ConnectorClientside clientSupplier(DataExchange api);
private final Function<DataExchange, ConnectorServerside> serverSupplier; abstract protected ConnectorServerside serverSupplier(DataExchange api);
protected DataExchange(Function<DataExchange, ConnectorClientside> client, Function<DataExchange, ConnectorServerside> server){ protected DataExchange(){
descriptors = new HashSet<>(); descriptors = new HashSet<>();
this.clientSupplier = client;
this.serverSupplier = server;
} }
public Set<DataHandlerDescriptor> getDescriptors() { return descriptors; } public Set<DataHandlerDescriptor> getDescriptors() { return descriptors; }
@ -196,7 +194,7 @@ abstract public class DataExchange {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
protected void initClientside(){ protected void initClientside(){
if (client!=null) return; if (client!=null) return;
client = clientSupplier.apply(this); client = clientSupplier(this);
ClientLoginConnectionEvents.INIT.register((a, b) ->{ ClientLoginConnectionEvents.INIT.register((a, b) ->{
System.out.println("INIT"); System.out.println("INIT");
}); });
@ -210,7 +208,7 @@ abstract public class DataExchange {
protected void initServerSide(){ protected void initServerSide(){
if (server!=null) return; if (server!=null) return;
server = serverSupplier.apply(this); server = serverSupplier(this);
ServerPlayConnectionEvents.INIT.register(server::onPlayInit); ServerPlayConnectionEvents.INIT.register(server::onPlayInit);
ServerPlayConnectionEvents.JOIN.register(server::onPlayReady); ServerPlayConnectionEvents.JOIN.register(server::onPlayReady);