Search in sources :

Example 1 with GuideOpenType

use of com.almuradev.almura.feature.guide.network.GuideOpenType 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()));
        }
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) Game(org.spongepowered.api.Game) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) Order(org.spongepowered.api.event.Order) Map(java.util.Map) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Path(java.nio.file.Path) GuideOpenType(com.almuradev.almura.feature.guide.network.GuideOpenType) FileVisitor(java.nio.file.FileVisitor) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket) MalisisCore(net.malisis.core.MalisisCore) Set(java.util.Set) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) ChannelId(org.spongepowered.api.network.ChannelId) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) ConfigurationOptions(ninja.leaping.configurate.ConfigurationOptions) Getter(org.spongepowered.api.event.filter.Getter) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) TextUtil(com.almuradev.almura.shared.util.TextUtil) UchatUtil(com.almuradev.almura.shared.util.UchatUtil) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Text(org.spongepowered.api.text.Text) Task(org.spongepowered.api.scheduler.Task) GameState(org.spongepowered.api.GameState) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Logger(org.slf4j.Logger) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) Files(java.nio.file.Files) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ClientboundGuideOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) ConfigDir(org.spongepowered.api.config.ConfigDir) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ConfigRenderOptions(com.typesafe.config.ConfigRenderOptions) Witness(com.almuradev.core.event.Witness) Listener(org.spongepowered.api.event.Listener) Comparator(java.util.Comparator) ClientboundGuideOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket)

Aggregations

ClientboundGuideOpenResponsePacket (com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket)1 ClientboundPageListingsPacket (com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket)1 GuideOpenType (com.almuradev.almura.feature.guide.network.GuideOpenType)1 ServerNotificationManager (com.almuradev.almura.feature.notification.ServerNotificationManager)1 NetworkConfig (com.almuradev.almura.shared.network.NetworkConfig)1 TextUtil (com.almuradev.almura.shared.util.TextUtil)1 UchatUtil (com.almuradev.almura.shared.util.UchatUtil)1 Witness (com.almuradev.core.event.Witness)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ConfigRenderOptions (com.typesafe.config.ConfigRenderOptions)1 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Instant (java.time.Instant)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1