Search in sources :

Example 1 with ServerboundPageOpenRequestPacket

use of com.almuradev.almura.feature.guide.network.ServerboundPageOpenRequestPacket in project Almura by AlmuraDev.

the class ClientPageManager method requestPage.

public void requestPage(String pageId) {
    checkNotNull(pageId);
    this.network.sendToServer(new ServerboundPageOpenRequestPacket(pageId));
}
Also used : ServerboundPageOpenRequestPacket(com.almuradev.almura.feature.guide.network.ServerboundPageOpenRequestPacket)

Example 2 with ServerboundPageOpenRequestPacket

use of com.almuradev.almura.feature.guide.network.ServerboundPageOpenRequestPacket in project Almura by AlmuraDev.

the class ServerboundPageOpenRequestPacketHandler method handleMessage.

@Override
public void handleMessage(ServerboundPageOpenRequestPacket message, RemoteConnection connection, Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && Sponge.isServerAvailable()) {
        final MinecraftServer server = (MinecraftServer) Sponge.getServer();
        if (PacketUtil.checkThreadAndEnqueue(server, message, this, connection, side)) {
            final Player player = ((PlayerConnection) connection).getPlayer();
            final Page page = this.manager.getPage(message.id).orElse(null);
            if (!player.hasPermission("almura.guide.page." + message.id) || page == null) {
                // We do not have permission for a page or it is null then we have a de-sync. Re-send all page names
                this.network.sendTo(player, new ClientboundPageListingsPacket(this.manager.getAvailablePagesFor(player).entrySet().stream().map(entry -> new PageListEntry(entry.getKey(), entry.getValue().getName())).collect(Collectors.toList()), null));
            } else {
                this.network.sendTo(player, new ClientboundPageOpenResponsePacket(page));
            }
        }
    }
}
Also used : Page(com.almuradev.almura.feature.guide.Page) RemoteConnection(org.spongepowered.api.network.RemoteConnection) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket) ServerPageManager(com.almuradev.almura.feature.guide.ServerPageManager) Scheduler(org.spongepowered.api.scheduler.Scheduler) Sponge(org.spongepowered.api.Sponge) ServerboundPageOpenRequestPacket(com.almuradev.almura.feature.guide.network.ServerboundPageOpenRequestPacket) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) MessageHandler(org.spongepowered.api.network.MessageHandler) Collectors(java.util.stream.Collectors) PlayerConnection(org.spongepowered.api.network.PlayerConnection) PageListEntry(com.almuradev.almura.feature.guide.PageListEntry) PacketUtil(com.almuradev.almura.shared.util.PacketUtil) Platform(org.spongepowered.api.Platform) ChannelBinding(org.spongepowered.api.network.ChannelBinding) Inject(javax.inject.Inject) MinecraftServer(net.minecraft.server.MinecraftServer) ChannelId(org.spongepowered.api.network.ChannelId) Player(org.spongepowered.api.entity.living.player.Player) ClientboundPageOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundPageOpenResponsePacket) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ClientboundPageOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundPageOpenResponsePacket) Player(org.spongepowered.api.entity.living.player.Player) Page(com.almuradev.almura.feature.guide.Page) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer) PageListEntry(com.almuradev.almura.feature.guide.PageListEntry)

Aggregations

ServerboundPageOpenRequestPacket (com.almuradev.almura.feature.guide.network.ServerboundPageOpenRequestPacket)2 Page (com.almuradev.almura.feature.guide.Page)1 PageListEntry (com.almuradev.almura.feature.guide.PageListEntry)1 ServerPageManager (com.almuradev.almura.feature.guide.ServerPageManager)1 ClientboundPageListingsPacket (com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket)1 ClientboundPageOpenResponsePacket (com.almuradev.almura.feature.guide.network.ClientboundPageOpenResponsePacket)1 NetworkConfig (com.almuradev.almura.shared.network.NetworkConfig)1 PacketUtil (com.almuradev.almura.shared.util.PacketUtil)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 Platform (org.spongepowered.api.Platform)1 Sponge (org.spongepowered.api.Sponge)1 Player (org.spongepowered.api.entity.living.player.Player)1 ChannelBinding (org.spongepowered.api.network.ChannelBinding)1 ChannelId (org.spongepowered.api.network.ChannelId)1 MessageHandler (org.spongepowered.api.network.MessageHandler)1 PlayerConnection (org.spongepowered.api.network.PlayerConnection)1 RemoteConnection (org.spongepowered.api.network.RemoteConnection)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1