Search in sources :

Example 1 with Nucleus

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

the class CoreTask method accept.

@Override
public void accept(Task task) {
    Nucleus plugin = Nucleus.getNucleus();
    plugin.getUserDataManager().removeOfflinePlayers();
    if (this.printSave || Nucleus.getNucleus().isDebugMode()) {
        plugin.getLogger().info(plugin.getMessageProvider().getMessageWithFormat("core.savetask.starting"));
    }
    plugin.saveData();
    if (this.printSave || Nucleus.getNucleus().isDebugMode()) {
        plugin.getLogger().info(plugin.getMessageProvider().getMessageWithFormat("core.savetask.complete"));
    }
}
Also used : Nucleus(io.github.nucleuspowered.nucleus.Nucleus)

Example 2 with Nucleus

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

the class TextParsingUtils method getTextForUrl.

private static Text getTextForUrl(String url, String msg, String whiteSpace, StyleTuple st, @Nullable String optionString) {
    String toParse = TextSerializers.FORMATTING_CODE.stripCodes(url);
    Nucleus plugin = Nucleus.getNucleus();
    try {
        URL urlObj;
        if (!toParse.startsWith("http://") && !toParse.startsWith("https://")) {
            urlObj = new URL("http://" + toParse);
        } else {
            urlObj = new URL(toParse);
        }
        Text.Builder textBuilder = Text.builder(msg).color(st.colour).style(st.style).onClick(TextActions.openUrl(urlObj));
        if (optionString == null || !optionString.contains("h")) {
            textBuilder.onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("chat.url.click", url)));
        }
        if (!whiteSpace.isEmpty()) {
            return Text.builder(whiteSpace).append(textBuilder.build()).build();
        }
        return textBuilder.build();
    } catch (MalformedURLException e) {
        // URL parsing failed, just put the original text in here.
        plugin.getLogger().warn(plugin.getMessageProvider().getMessageWithFormat("chat.url.malformed", url));
        if (Nucleus.getNucleus().isDebugMode()) {
            e.printStackTrace();
        }
        Text ret = Text.builder(url).color(st.colour).style(st.style).build();
        if (!whiteSpace.isEmpty()) {
            return Text.builder(whiteSpace).append(ret).build();
        }
        return ret;
    }
}
Also used : Nucleus(io.github.nucleuspowered.nucleus.Nucleus) MalformedURLException(java.net.MalformedURLException) Text(org.spongepowered.api.text.Text) URL(java.net.URL)

Example 3 with Nucleus

use of io.github.nucleuspowered.nucleus.Nucleus 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)

Example 4 with Nucleus

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

the class JailModule method performPreTasks.

@Override
protected void performPreTasks() throws Exception {
    try {
        Nucleus nucleus = Nucleus.getNucleus();
        JailHandler jh = new JailHandler(nucleus);
        Sponge.getServiceManager().setProvider(nucleus, NucleusJailService.class, jh);
        serviceManager.registerService(JailHandler.class, jh);
        // Context
        Sponge.getServiceManager().provide(PermissionService.class).ifPresent(x -> x.registerContextCalculator(jh));
    } catch (Exception ex) {
        Nucleus.getNucleus().getLogger().warn("Could not load the jail module for the reason below.");
        ex.printStackTrace();
        throw ex;
    }
}
Also used : PermissionService(org.spongepowered.api.service.permission.PermissionService) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) JailHandler(io.github.nucleuspowered.nucleus.modules.jail.handlers.JailHandler)

Example 5 with Nucleus

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

the class ListWorldCommand method getWorldInfo.

static void getWorldInfo(List<Text> listContent, WorldProperties x, boolean canSeeSeeds) {
    Nucleus plugin = Nucleus.getNucleus();
    // Name of world
    if (!listContent.isEmpty()) {
        listContent.add(SPACE);
    }
    listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.worlditem", x.getWorldName()));
    // As requested by Pixelmon for use in their config.
    x.getAdditionalProperties().getInt(DataQuery.of("SpongeData", "dimensionId")).ifPresent(i -> listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.dimensionid", String.valueOf(i))));
    Vector3i spawnPosition = x.getSpawnPosition();
    listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.spawnpoint", String.valueOf(spawnPosition.getX()), String.valueOf(spawnPosition.getY()), String.valueOf(spawnPosition.getZ())));
    listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.uuid", x.getUniqueId().toString()));
    if (x.isEnabled()) {
        boolean worldLoaded = Sponge.getServer().getWorld(x.getUniqueId()).isPresent();
        String message = (worldLoaded ? "&a" : "&c") + plugin.getMessageProvider().getMessageWithFormat(worldLoaded ? "standard.true" : "standard.false");
        listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.enabled", message));
    } else {
        listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.disabled"));
    }
    if (canSeeSeeds) {
        listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.seed", String.valueOf(x.getSeed())));
    }
    listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.params", x.getDimensionType().getName(), x.getGeneratorType().getName(), CreateWorldCommand.modifierString(x.getGeneratorModifiers()), x.getGameMode().getName(), x.getDifficulty().getName()));
    listContent.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.list.params2", String.valueOf(x.isHardcore()), String.valueOf(x.loadOnStartup()), String.valueOf(x.isPVPEnabled()), String.valueOf(x.doesKeepSpawnLoaded())));
}
Also used : Nucleus(io.github.nucleuspowered.nucleus.Nucleus) Vector3i(com.flowpowered.math.vector.Vector3i)

Aggregations

Nucleus (io.github.nucleuspowered.nucleus.Nucleus)5 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 Lists (com.google.common.collect.Lists)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 JailHandler (io.github.nucleuspowered.nucleus.modules.jail.handlers.JailHandler)1