Skip to content

Commit

Permalink
current state of update
Browse files Browse the repository at this point in the history
  • Loading branch information
Innokenty committed Jun 25, 2024
1 parent e26d30f commit dc7b0a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.singularitynet.Client;

import io.singularitynet.MessagePayloadC2S;
import io.singularitynet.MessagePayloadS2C;
import io.singularitynet.MissionHandlers.MissionBehaviour;
import io.singularitynet.SidesMessageHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/singularitynet/MessagePayloadS2C.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public void encode(PacketByteBuf buf, VereyaMessage message) {
}
};

public static final Id<MessagePayloadC2S> ID = new Id<>(NetworkConstants.SERVER2CLIENT);
public static final CustomPayload.Id<MessagePayloadC2S> ID = new CustomPayload.Id<>(NetworkConstants.SERVER2CLIENT);
public static final PacketCodec<RegistryByteBuf, MessagePayloadC2S> CODEC = PacketCodec.tuple(PACKET_CODEC, MessagePayloadC2S::msg, MessagePayloadC2S::new);

@Override
public Id<? extends CustomPayload> getId() {
public CustomPayload.Id<? extends CustomPayload> getId() {
return ID;
}
}
5 changes: 3 additions & 2 deletions src/main/java/io/singularitynet/Server/VereyaModServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.jmx.Server;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -59,8 +60,8 @@ public void onInitialize() {
instance = this;
PayloadTypeRegistry.playC2S().register(MessagePayloadC2S.ID, MessagePayloadC2S.CODEC);
// register the instance for messages from Client to the Server
ServerPlayNetworking.registerGlobalReceiver(MessagePayloadS2C.ID, (payload, context) -> {
SidesMessageHandler.onMessage(payload, context);
ServerPlayNetworking.registerGlobalReceiver(MessagePayloadC2S.ID, (payload, context) -> {
SidesMessageHandler.client2server.onMessage(payload, context);
});
ServerLifecycleEvents.SERVER_STARTED.register((MinecraftServer server) -> {
Logger LOGGER = LogManager.getLogger();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/singularitynet/SidesMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ public static void onMessage(MessagePayloadC2S payload, ServerPlayNetworking.Con
final VereyaMessage message = payload.msg();
final List<IVereyaMessageListener> interestedParties = getMessageListeners(message);
if (interestedParties == null) return;
context.player().server.execute(() -> {
context.server().execute(() -> {
for (IVereyaMessageListener l : interestedParties)
{
// If the message's uid is set (ie non-zero), then use it to ensure that only the matching listener receives this message.
// Otherwise, let all listeners who are interested get a look.
// if (message.uid == 0 || System.identityHashCode(l) == message.uid)
// l.onMessage(message.messageType, message.data);
l.onMessage(message.getMessageType(), message.getData());
l.onMessage(message.getMessageType(), message.getData(), context.player());
}
});
}

public void onMessage(MessagePayloadC2S payload, ClientPlayNetworking.Context context) {
public void onMessage(MessagePayloadS2C payload, ClientPlayNetworking.Context context) {
final VereyaMessage message = payload.msg();
final List<IVereyaMessageListener> interestedParties = getMessageListeners(message);
if (interestedParties == null) return;
Expand Down

0 comments on commit dc7b0a5

Please sign in to comment.