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));
}
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));
}
}
}
}
Aggregations