Search in sources :

Example 1 with ServerListGeneralDataModule

use of io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule in project Nucleus by NucleusPowered.

the class ServerListCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Display current information
    if (args.hasAny("m")) {
        onMessage(src, slc.getMessages(), "command.serverlist.head.messages");
        return CommandResult.success();
    } else if (args.hasAny("w")) {
        onMessage(src, slc.getWhitelist(), "command.serverlist.head.whitelist");
        return CommandResult.success();
    }
    MessageProvider messageProvider = plugin.getMessageProvider();
    if (slc.isModifyServerList()) {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.true"));
        if (!slc.getMessages().isEmpty()) {
            src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.messages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -m")).toText());
        }
        if (!slc.getWhitelist().isEmpty()) {
            src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
        }
    } else if (slc.getModifyServerList() == ServerListConfig.ServerListSelection.WHITELIST) {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.whitelist"));
        if (!slc.getWhitelist().isEmpty()) {
            src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.whitelistmessages.click").toBuilder().onClick(TextActions.runCommand("/nucleus:serverlist -w")).toText());
        }
    } else {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.modify.false"));
    }
    ServerListGeneralDataModule ss = plugin.getGeneralService().get(ServerListGeneralDataModule.class);
    ss.getMessage().ifPresent(t -> {
        src.sendMessage(Util.SPACE);
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.tempheader"));
        src.sendMessage(t);
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.message.expiry", Util.getTimeToNow(ss.getExpiry().get())));
    });
    if (slc.isHidePlayerCount()) {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hideplayers"));
    } else if (slc.isHideVanishedPlayers()) {
        src.sendMessage(messageProvider.getTextMessageWithFormat("command.serverlist.hidevanished"));
    }
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule)

Example 2 with ServerListGeneralDataModule

use of io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule in project Nucleus by NucleusPowered.

the class TemporaryMessageCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Get the temporary message item.
    ServerListGeneralDataModule mod = plugin.getGeneralService().get(ServerListGeneralDataModule.class);
    if (args.hasAny("r")) {
        if (mod.getMessage().isPresent()) {
            // Remove
            mod.remove();
            // Send message.
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.removed"));
            return CommandResult.success();
        }
        throw ReturnMessageException.fromKey("command.serverlist.message.noremoved");
    }
    // Which line?
    boolean linetwo = args.<Integer>getOne(line).map(x -> x == 2).orElse(false);
    Optional<String> onMessage = args.getOne(this.message);
    if (!onMessage.isPresent()) {
        boolean isValid = mod.getExpiry().map(x -> x.isAfter(Instant.now())).orElse(false);
        if (!isValid) {
            throw ReturnMessageException.fromKey("command.serverlist.message.isempty");
        }
        if (linetwo) {
            mod.setLineTwo(null);
        } else {
            mod.setLineOne(null);
        }
        Optional<Text> newMessage = mod.getMessage();
        if (newMessage.isPresent()) {
            // Send message
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.set"));
            src.sendMessage(newMessage.get());
        } else {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.empty"));
        }
        return CommandResult.success();
    }
    String nMessage = onMessage.get();
    // If the expiry is null or before now, and there is no timespan, then it's an hour.
    Instant endTime = args.<Long>getOne(timespan).map(x -> Instant.now().plus(x, ChronoUnit.SECONDS)).orElseGet(() -> mod.getExpiry().map(x -> x.isBefore(Instant.now()) ? x.plusSeconds(3600) : x).orElseGet(() -> Instant.now().plusSeconds(3600)));
    // Set the expiry.
    mod.setExpiry(endTime);
    if (linetwo) {
        mod.setLineTwo(nMessage);
    } else {
        mod.setLineOne(nMessage);
    }
    Optional<Text> newMessage = mod.getMessage();
    if (newMessage.isPresent()) {
        // Send message
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.set"));
        src.sendMessage(newMessage.get());
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.serverlist.message.expiry", Util.getTimeToNow(endTime)));
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.serverlist.message.notset");
}
Also used : BoundedIntegerArgument(io.github.nucleuspowered.nucleus.argumentparsers.BoundedIntegerArgument) CommandResult(org.spongepowered.api.command.CommandResult) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) CommandSource(org.spongepowered.api.command.CommandSource) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Instant(java.time.Instant) CommandElement(org.spongepowered.api.command.args.CommandElement) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) ChronoUnit(java.time.temporal.ChronoUnit) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) TimespanArgument(io.github.nucleuspowered.nucleus.argumentparsers.TimespanArgument) Optional(java.util.Optional) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) Instant(java.time.Instant) ServerListGeneralDataModule(io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule) Text(org.spongepowered.api.text.Text)

Aggregations

ServerListGeneralDataModule (io.github.nucleuspowered.nucleus.modules.serverlist.datamodules.ServerListGeneralDataModule)2 Util (io.github.nucleuspowered.nucleus.Util)1 BoundedIntegerArgument (io.github.nucleuspowered.nucleus.argumentparsers.BoundedIntegerArgument)1 TimespanArgument (io.github.nucleuspowered.nucleus.argumentparsers.TimespanArgument)1 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Optional (java.util.Optional)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandSource (org.spongepowered.api.command.CommandSource)1 CommandContext (org.spongepowered.api.command.args.CommandContext)1 CommandElement (org.spongepowered.api.command.args.CommandElement)1 GenericArguments (org.spongepowered.api.command.args.GenericArguments)1 Text (org.spongepowered.api.text.Text)1 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)1