Search in sources :

Example 1 with NucleusFirstJoinEvent

use of io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent in project Nucleus by NucleusPowered.

the class CoreListener method onPlayerJoinLast.

@Listener
public void onPlayerJoinLast(final ClientConnectionEvent.Join event, @Getter("getTargetEntity") final Player player) {
    if (Nucleus.getNucleus().getUserDataManager().get(player).map(x -> x.get(CoreUserDataModule.class).isFirstPlay()).orElse(true)) {
        NucleusFirstJoinEvent firstJoinEvent = new OnFirstLoginEvent(event.getCause(), player, event.getOriginalChannel(), event.getChannel().orElse(null), event.getOriginalMessage(), event.isMessageCancelled(), event.getFormatter());
        Sponge.getEventManager().post(firstJoinEvent);
        event.setChannel(firstJoinEvent.getChannel().get());
        event.setMessageCancelled(firstJoinEvent.isMessageCancelled());
        Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(CoreUserDataModule.class).setStartedFirstJoin(false);
    }
    // Warn about wildcard.
    if (!ServiceChangeListener.isOpOnly() && player.hasPermission("nucleus")) {
        MessageProvider provider = this.plugin.getMessageProvider();
        Nucleus.getNucleus().getLogger().warn("The player " + player.getName() + " has got either the nucleus wildcard or the * wildcard " + "permission. This may cause unintended side effects.");
        if (this.warnOnWildcard) {
            // warn
            List<Text> text = Lists.newArrayList();
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard2"));
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard3"));
            if (this.url != null) {
                text.add(provider.getTextMessageWithFormat("core.permission.wildcard4").toBuilder().onClick(TextActions.openUrl(this.url)).build());
            }
            text.add(provider.getTextMessageWithFormat("core.permission.wildcard5"));
            Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().title(provider.getTextMessageWithFormat("core.permission.wildcard")).contents(text).padding(Text.of(TextColors.GOLD, "-")).sendTo(player);
        }
    }
}
Also used : Getter(org.spongepowered.api.event.filter.Getter) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) URL(java.net.URL) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) InetAddress(java.net.InetAddress) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) Order(org.spongepowered.api.event.Order) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) IsCancelled(org.spongepowered.api.event.filter.IsCancelled) Task(org.spongepowered.api.scheduler.Task) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) GameProfile(org.spongepowered.api.profile.GameProfile) Util(io.github.nucleuspowered.nucleus.Util) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) NucleusOnLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.NucleusOnLoginEvent) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) Iterator(java.util.Iterator) CommandSource(org.spongepowered.api.command.CommandSource) MalformedURLException(java.net.MalformedURLException) UniqueUserCountTransientModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Instant(java.time.Instant) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) List(java.util.List) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) NucleusFirstJoinEvent(io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) OnFirstLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.OnFirstLoginEvent) Listener(org.spongepowered.api.event.Listener) OnFirstLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.OnFirstLoginEvent) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) NucleusFirstJoinEvent(io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Aggregations

Lists (com.google.common.collect.Lists)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 Util (io.github.nucleuspowered.nucleus.Util)1 NucleusFirstJoinEvent (io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent)1 NucleusTextTemplate (io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate)1 ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)1 ListenerBase (io.github.nucleuspowered.nucleus.internal.ListenerBase)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)1 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)1 CoreConfig (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig)1 CoreConfigAdapter (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)1 CoreUserDataModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)1 UniqueUserCountTransientModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule)1 NucleusOnLoginEvent (io.github.nucleuspowered.nucleus.modules.core.events.NucleusOnLoginEvent)1 OnFirstLoginEvent (io.github.nucleuspowered.nucleus.modules.core.events.OnFirstLoginEvent)1 CauseStackHelper (io.github.nucleuspowered.nucleus.util.CauseStackHelper)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1