use of com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket in project Almura by AlmuraDev.
the class ServerboundGuideOpenRequestPacketHandler method handleMessage.
@Override
public void handleMessage(ServerboundGuideOpenRequestPacket 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();
if (!player.hasPermission("almura.guide.open") || player.hasPermission("almura.singleplayer") && MalisisCore.isObfEnv) {
player.sendMessage(Text.of(TextColors.WHITE, "Access denied, missing permission: ", TextColors.AQUA, "almura.guide.open", TextColors.WHITE, "."));
return;
}
// Open the GUI
this.network.sendTo(player, new ClientboundGuideOpenResponsePacket(GuideOpenType.PLAYER_INVOKED_KEYBIND, player.hasPermission("almura.guide.add"), player.hasPermission("almura.guide.remove"), player.hasPermission("almura.guide.modify"), true));
final Map<String, Page> pagesToSend = this.manager.getAvailablePagesFor(player);
if (pagesToSend.size() > 0) {
final List<PageListEntry> playerListings = pagesToSend.entrySet().stream().map(entry -> new PageListEntry(entry.getKey(), entry.getValue().getName())).collect(Collectors.toList());
final PageListEntry switchToPageEntry = playerListings.stream().findFirst().orElse(null);
// Send the list of pages
this.network.sendTo(player, new ClientboundPageListingsPacket(playerListings, switchToPageEntry == null ? null : switchToPageEntry.getId()));
}
}
}
}
use of com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket in project Almura by AlmuraDev.
the class ServerPageManager method openGuideForPlayer.
public void openGuideForPlayer(Player player, GuideOpenType type, String pageName) {
this.network.sendTo(player, new ClientboundGuideOpenResponsePacket(// Specifies what called the open request.
type, player.hasPermission("almura.guide.add"), player.hasPermission("almura.guide.remove"), player.hasPermission("almura.guide.modify"), false));
final Map<String, Page> pagesToSend = this.getAvailablePagesFor(player);
if (pagesToSend.size() > 0) {
final List<PageListEntry> playerListings = pagesToSend.entrySet().stream().map(entry -> new PageListEntry(entry.getKey(), entry.getValue().getName())).collect(Collectors.toList());
final PageListEntry allPages = playerListings.stream().findFirst().orElse(null);
if (pageName != null) {
final Page page = getPage(pageName).orElse(null);
this.network.sendTo(player, new ClientboundPageListingsPacket(playerListings, page == null ? allPages.getId() : page.getId()));
} else {
this.network.sendTo(player, new ClientboundPageListingsPacket(playerListings, allPages == null ? null : allPages.getId()));
}
}
}
Aggregations