Search in sources :

Example 6 with ClientboundTitlesRegistryPacket

use of com.almuradev.almura.feature.title.network.ClientboundTitlesRegistryPacket in project Almura by AlmuraDev.

the class ServerTitleManager method deleteTitle.

public void deleteTitle(final Player player, final String id) {
    checkNotNull(player);
    checkNotNull(id);
    if (!this.getTitle(id).isPresent()) {
        // TODO Dockter, we're in a desync...either send them a notification that title deletion failed as it doesn't exist or remove this TODO
        this.network.sendTo(player, new ClientboundTitlesRegistryPacket(this.titles.values().stream().filter(title -> {
            if (!title.isHidden()) {
                return true;
            }
            return player.hasPermission(Almura.ID + ".title.admin");
        }).collect(Collectors.toSet())));
    } else {
        this.scheduler.createTaskBuilder().async().execute(() -> {
            try (final DSLContext context = this.databaseManager.createContext(true)) {
                final int result = TitleQueries.createDeleteTitle(id).build(context).keepStatement(false).execute();
                final Runnable runnable;
                if (result == 0) {
                    runnable = () -> {
                    // TODO Dockter, send a notification down to the player that deletion failed
                    };
                } else {
                    runnable = this::loadTitles;
                }
                this.scheduler.createTaskBuilder().execute(runnable).submit(this.container);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }).submit(this.container);
    }
}
Also used : Almura(com.almuradev.almura.Almura) Results(org.jooq.Results) Getter(org.spongepowered.api.event.filter.Getter) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DatabaseManager(com.almuradev.almura.shared.database.DatabaseManager) ClientboundSelectedTitlePacket(com.almuradev.almura.feature.title.network.ClientboundSelectedTitlePacket) SQLException(java.sql.SQLException) Text(org.spongepowered.api.text.Text) Map(java.util.Map) DSLContext(org.jooq.DSLContext) GameState(org.spongepowered.api.GameState) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Nullable(javax.annotation.Nullable) Record(org.jooq.Record) Logger(org.slf4j.Logger) ClientboundTitlesRegistryPacket(com.almuradev.almura.feature.title.network.ClientboundTitlesRegistryPacket) Timestamp(java.sql.Timestamp) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Scheduler(org.spongepowered.api.scheduler.Scheduler) ServerNotificationManager(com.almuradev.almura.feature.notification.ServerNotificationManager) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) ClientboundSelectedTitleBulkPacket(com.almuradev.almura.feature.title.network.ClientboundSelectedTitleBulkPacket) Collectors(java.util.stream.Collectors) TitleSelectRecord(com.almuradev.generated.title.tables.records.TitleSelectRecord) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) SerializationUtil(com.almuradev.almura.shared.util.SerializationUtil) TitleQueries(com.almuradev.almura.feature.title.database.TitleQueries) Witness(com.almuradev.core.event.Witness) ChannelId(org.spongepowered.api.network.ChannelId) Optional(java.util.Optional) ClientboundAvailableTitlesResponsePacket(com.almuradev.almura.feature.title.network.ClientboundAvailableTitlesResponsePacket) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) SQLException(java.sql.SQLException) DSLContext(org.jooq.DSLContext) ClientboundTitlesRegistryPacket(com.almuradev.almura.feature.title.network.ClientboundTitlesRegistryPacket)

Aggregations

ClientboundAvailableTitlesResponsePacket (com.almuradev.almura.feature.title.network.ClientboundAvailableTitlesResponsePacket)6 ClientboundSelectedTitlePacket (com.almuradev.almura.feature.title.network.ClientboundSelectedTitlePacket)6 ClientboundTitlesRegistryPacket (com.almuradev.almura.feature.title.network.ClientboundTitlesRegistryPacket)6 SQLException (java.sql.SQLException)6 HashSet (java.util.HashSet)6 DSLContext (org.jooq.DSLContext)6 Almura (com.almuradev.almura.Almura)5 ServerNotificationManager (com.almuradev.almura.feature.notification.ServerNotificationManager)5 TitleQueries (com.almuradev.almura.feature.title.database.TitleQueries)5 ClientboundSelectedTitleBulkPacket (com.almuradev.almura.feature.title.network.ClientboundSelectedTitleBulkPacket)5 DatabaseManager (com.almuradev.almura.shared.database.DatabaseManager)5 NetworkConfig (com.almuradev.almura.shared.network.NetworkConfig)5 SerializationUtil (com.almuradev.almura.shared.util.SerializationUtil)5 Witness (com.almuradev.core.event.Witness)5 TitleSelectRecord (com.almuradev.generated.title.tables.records.TitleSelectRecord)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 Timestamp (java.sql.Timestamp)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Optional (java.util.Optional)5