Created new packet for sending the player state to the client.
This commit is contained in:
@ -0,0 +1,34 @@
|
|||||||
|
package dev.micle.loginprotection.network;
|
||||||
|
|
||||||
|
import dev.micle.loginprotection.data.ProtectedPlayer;
|
||||||
|
import dev.micle.loginprotection.proxy.Proxy;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ServerPlayerStatePacket {
|
||||||
|
private final ProtectedPlayer.State state;
|
||||||
|
|
||||||
|
public ServerPlayerStatePacket(ProtectedPlayer.State state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void encode(final ServerPlayerStatePacket packet, final FriendlyByteBuf buffer) {
|
||||||
|
NetworkManager.writeVersionInfo(buffer, true);
|
||||||
|
buffer.writeUtf(packet.state.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerPlayerStatePacket decode(final FriendlyByteBuf buffer) {
|
||||||
|
NetworkManager.checkVersion(buffer);
|
||||||
|
return new ServerPlayerStatePacket(ProtectedPlayer.State.valueOf(buffer.readUtf()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handle(final ServerPlayerStatePacket packet, final Supplier<NetworkEvent.Context> contextSupplier) {
|
||||||
|
final NetworkEvent.Context context = contextSupplier.get();
|
||||||
|
context.enqueueWork(() -> {
|
||||||
|
Proxy.Client.setPlayerState(packet.state);
|
||||||
|
});
|
||||||
|
context.setPacketHandled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user