Send out a packet when the server is available to libzontreck
This commit is contained in:
parent
c8136451e0
commit
adceccc275
4 changed files with 58 additions and 0 deletions
|
@ -56,6 +56,8 @@ public class LibZontreck {
|
||||||
public static final String PLAYER_SKIN_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
public static final String PLAYER_SKIN_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
public static final UUID NULL_ID;
|
public static final UUID NULL_ID;
|
||||||
|
|
||||||
|
public static boolean LIBZONTRECK_SERVER_AVAILABLE=false;
|
||||||
|
|
||||||
|
|
||||||
public static LogicalSide CURRENT_SIDE;
|
public static LogicalSide CURRENT_SIDE;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import dev.zontreck.libzontreck.LibZontreck;
|
||||||
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
|
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
|
||||||
import dev.zontreck.libzontreck.memory.PlayerContainer;
|
import dev.zontreck.libzontreck.memory.PlayerContainer;
|
||||||
import dev.zontreck.libzontreck.networking.ModMessages;
|
import dev.zontreck.libzontreck.networking.ModMessages;
|
||||||
|
import dev.zontreck.libzontreck.networking.packets.S2CServerAvailable;
|
||||||
import dev.zontreck.libzontreck.networking.packets.S2CWalletInitialSyncPacket;
|
import dev.zontreck.libzontreck.networking.packets.S2CWalletInitialSyncPacket;
|
||||||
import dev.zontreck.libzontreck.profiles.Profile;
|
import dev.zontreck.libzontreck.profiles.Profile;
|
||||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||||
|
@ -56,6 +57,9 @@ public class ForgeEventHandlers {
|
||||||
public void run() {
|
public void run() {
|
||||||
// Check player wallet, then send wallet to client
|
// Check player wallet, then send wallet to client
|
||||||
//ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player);
|
//ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player);
|
||||||
|
|
||||||
|
S2CServerAvailable avail = new S2CServerAvailable();
|
||||||
|
avail.send(player);
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +67,7 @@ public class ForgeEventHandlers {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev)
|
public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev)
|
||||||
{
|
{
|
||||||
|
LibZontreck.LIBZONTRECK_SERVER_AVAILABLE=false; // Yes do this even on the client!
|
||||||
if(ev.getEntity().level().isClientSide)return;
|
if(ev.getEntity().level().isClientSide)return;
|
||||||
// Get player profile, send disconnect alert, then commit profile and remove it from memory
|
// Get player profile, send disconnect alert, then commit profile and remove it from memory
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import dev.zontreck.libzontreck.events.RegisterPacketsEvent;
|
||||||
import dev.zontreck.libzontreck.networking.packets.IPacket;
|
import dev.zontreck.libzontreck.networking.packets.IPacket;
|
||||||
import dev.zontreck.libzontreck.networking.packets.S2CCloseChestGUI;
|
import dev.zontreck.libzontreck.networking.packets.S2CCloseChestGUI;
|
||||||
import dev.zontreck.libzontreck.networking.packets.S2CPlaySoundPacket;
|
import dev.zontreck.libzontreck.networking.packets.S2CPlaySoundPacket;
|
||||||
|
import dev.zontreck.libzontreck.networking.packets.S2CServerAvailable;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -58,6 +59,13 @@ public class ModMessages {
|
||||||
.consumerMainThread(S2CCloseChestGUI::handle)
|
.consumerMainThread(S2CCloseChestGUI::handle)
|
||||||
.add();
|
.add();
|
||||||
|
|
||||||
|
net.messageBuilder(S2CServerAvailable.class, PACKET_ID.getAndIncrement(),
|
||||||
|
NetworkDirection.PLAY_TO_CLIENT)
|
||||||
|
.decoder(S2CServerAvailable::new)
|
||||||
|
.encoder(S2CServerAvailable::toBytes)
|
||||||
|
.consumerMainThread(S2CServerAvailable::handle)
|
||||||
|
.add();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package dev.zontreck.libzontreck.networking.packets;
|
||||||
|
|
||||||
|
import dev.zontreck.libzontreck.LibZontreck;
|
||||||
|
import dev.zontreck.libzontreck.networking.ModMessages;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class S2CServerAvailable
|
||||||
|
{
|
||||||
|
public S2CServerAvailable(FriendlyByteBuf buf)
|
||||||
|
{
|
||||||
|
// nothing!
|
||||||
|
}
|
||||||
|
|
||||||
|
public S2CServerAvailable()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toBytes(FriendlyByteBuf buf)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Supplier<NetworkEvent.Context> supplier)
|
||||||
|
{
|
||||||
|
NetworkEvent.Context context = supplier.get();
|
||||||
|
|
||||||
|
context.enqueueWork(()->{
|
||||||
|
// We are now on the client
|
||||||
|
|
||||||
|
LibZontreck.LIBZONTRECK_SERVER_AVAILABLE = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(ServerPlayer player)
|
||||||
|
{
|
||||||
|
ModMessages.sendToPlayer(this, player);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue