Search in sources :

Example 16 with MessageProvider

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

the class MessageModule method performEnableTasks.

@Override
public void performEnableTasks() {
    createSeenModule(SocialSpyCommand.class, (cs, user) -> {
        MessageHandler handler = Nucleus.getNucleus().getInternalServiceManager().getServiceUnchecked(MessageHandler.class);
        boolean socialSpy = handler.isSocialSpy(user);
        boolean msgToggle = Nucleus.getNucleus().getUserDataManager().get(user).map(y -> y.get(MessageUserDataModule.class).isMsgToggle()).orElse(true);
        MessageProvider mp = plugin.getMessageProvider();
        List<Text> lt = Lists.newArrayList(mp.getTextMessageWithFormat("seen.socialspy", mp.getMessageWithFormat("standard.yesno." + Boolean.toString(socialSpy).toLowerCase())));
        getConfigAdapter().ifPresent(x -> lt.add(mp.getTextMessageWithFormat("seen.socialspylevel", String.valueOf(Util.getPositiveIntOptionFromSubject(user, MessageHandler.socialSpyOption).orElse(0)))));
        lt.add(mp.getTextMessageWithFormat("seen.msgtoggle", mp.getMessageWithFormat("standard.yesno." + Boolean.toString(msgToggle).toLowerCase())));
        return lt;
    });
}
Also used : Nucleus(io.github.nucleuspowered.nucleus.Nucleus) NucleusPrivateMessagingService(io.github.nucleuspowered.nucleus.api.service.NucleusPrivateMessagingService) Sponge(org.spongepowered.api.Sponge) SocialSpyCommand(io.github.nucleuspowered.nucleus.modules.message.commands.SocialSpyCommand) MessageUserDataModule(io.github.nucleuspowered.nucleus.modules.message.datamodules.MessageUserDataModule) MessageConfigAdapter(io.github.nucleuspowered.nucleus.modules.message.config.MessageConfigAdapter) ConfigurableModule(io.github.nucleuspowered.nucleus.internal.qsml.module.ConfigurableModule) List(java.util.List) Lists(com.google.common.collect.Lists) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) MessageHandler(io.github.nucleuspowered.nucleus.modules.message.handlers.MessageHandler) Text(org.spongepowered.api.text.Text) RegisterService(io.github.nucleuspowered.nucleus.internal.annotations.RegisterService) Util(io.github.nucleuspowered.nucleus.Util) ModuleData(uk.co.drnaylor.quickstart.annotations.ModuleData) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) MessageHandler(io.github.nucleuspowered.nucleus.modules.message.handlers.MessageHandler) MessageUserDataModule(io.github.nucleuspowered.nucleus.modules.message.datamodules.MessageUserDataModule) Text(org.spongepowered.api.text.Text)

Example 17 with MessageProvider

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

the class SpawnMobCommand method executeWithPlayer.

@Override
public CommandResult executeWithPlayer(CommandSource src, Player pl, CommandContext args, boolean isSelf) throws Exception {
    // Get the amount
    int amount = args.<Integer>getOne(amountKey).get();
    EntityType et = args.<EntityType>getOne(mobTypeKey).get();
    if (!Living.class.isAssignableFrom(et.getEntityClass())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.livingonly", et.getTranslation().get()));
    }
    String id = et.getId().toLowerCase();
    if (this.mobConfig.isPerMobPermission() && !permissions.testSuffix(src, "mob." + id.replace(":", "."))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.mobnoperm", et.getTranslation().get()));
    }
    Optional<BlockSpawnsConfig> config = this.mobConfig.getBlockSpawnsConfigForWorld(pl.getWorld());
    if (config.isPresent() && (config.get().isBlockVanillaMobs() && id.startsWith("minecraft:") || config.get().getIdsToBlock().contains(id))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.blockedinconfig", et.getTranslation().get()));
    }
    Location<World> loc = pl.getLocation();
    World w = loc.getExtent();
    MessageProvider mp = plugin.getMessageProvider();
    // Count the number of entities spawned.
    int i = 0;
    Entity entityone = null;
    do {
        Entity e = w.createEntity(et, loc.getPosition());
        if (!w.spawnEntity(e)) {
            throw ReturnMessageException.fromKeyText("command.spawnmob.fail", Text.of(e));
        }
        if (entityone == null) {
            entityone = e;
        }
        i++;
    } while (i < Math.min(amount, this.mobConfig.getMaxMobsToSpawn()));
    if (amount > this.mobConfig.getMaxMobsToSpawn()) {
        src.sendMessage(mp.getTextMessageWithFormat("command.spawnmob.limit", String.valueOf(this.mobConfig.getMaxMobsToSpawn())));
    }
    if (i == 0) {
        throw ReturnMessageException.fromKey("command.spawnmob.fail", et.getTranslation().get());
    }
    if (i == 1) {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.singular", Text.of(i), Text.of(entityone)));
    } else {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.plural", Text.of(i), Text.of(entityone)));
    }
    return CommandResult.success();
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Living(org.spongepowered.api.entity.living.Living) BlockSpawnsConfig(io.github.nucleuspowered.nucleus.modules.mob.config.BlockSpawnsConfig) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 18 with MessageProvider

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

the class SeenCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User user = args.<User>getOne(uuid).isPresent() ? args.<User>getOne(uuid).get() : args.<User>getOne(playerKey).get();
    if (user.isOnline()) {
        // Get the player in case the User is displaying the wrong name.
        user = user.getPlayer().get();
    }
    ModularUserService iqsu = Nucleus.getNucleus().getUserDataManager().getUnchecked(user);
    CoreUserDataModule coreUserDataModule = iqsu.get(CoreUserDataModule.class);
    List<Text> messages = new ArrayList<>();
    final MessageProvider messageProvider = plugin.getMessageProvider();
    // Everyone gets the last online time.
    if (user.isOnline()) {
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.online", user.getName()));
        coreUserDataModule.getLastLogin().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedon", Util.getTimeToNow(x))));
    } else {
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.offline", user.getName()));
        coreUserDataModule.getLastLogout().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedoff", Util.getTimeToNow(x))));
    }
    messages.add(messageProvider.getTextMessageWithFormat("command.seen.displayname", TextSerializers.FORMATTING_CODE.serialize(plugin.getNameUtil().getName(user))));
    if (permissions.testSuffix(src, EXTENDED_SUFFIX)) {
        messages.add(notEmpty);
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.uuid", user.getUniqueId().toString()));
        if (user.isOnline()) {
            Player pl = user.getPlayer().get();
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.ipaddress", pl.getConnection().getAddress().getAddress().toString()));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(pl.getJoinData().firstPlayed().get())));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.walk", String.valueOf(Math.round(pl.get(Keys.WALKING_SPEED).orElse(0.1d) * SpeedCommand.multiplier))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.fly", String.valueOf(Math.round(pl.get(Keys.FLYING_SPEED).orElse(0.05d) * SpeedCommand.multiplier))));
            messages.add(getLocationString("command.seen.currentlocation", pl.getLocation(), src));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.canfly", getYesNo(pl.get(Keys.CAN_FLY).orElse(false))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.isflying", getYesNo(pl.get(Keys.IS_FLYING).orElse(false))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.gamemode", pl.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).getName()));
        } else {
            coreUserDataModule.getLastIp().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.lastipaddress", x)));
            Optional<Instant> i = user.get(Keys.FIRST_DATE_PLAYED);
            if (!i.isPresent()) {
                i = coreUserDataModule.getFirstJoin();
            }
            i.ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(x))));
            Optional<Location<World>> olw = coreUserDataModule.getLogoutLocation();
            olw.ifPresent(worldLocation -> messages.add(getLocationString("command.seen.lastlocation", worldLocation, src)));
            user.get(JoinData.class).ifPresent(x -> {
                Optional<Instant> oi = x.firstPlayed().getDirect();
                oi.ifPresent(instant -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(instant))));
            });
        }
    }
    // Add the extra module information.
    messages.addAll(seenHandler.buildInformation(src, user));
    PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    ps.builder().contents(messages).padding(Text.of(TextColors.GREEN, "-")).title(messageProvider.getTextMessageWithFormat("command.seen.title", user.getName())).sendTo(src);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) JoinData(org.spongepowered.api.data.manipulator.mutable.entity.JoinData) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Location(org.spongepowered.api.world.Location)

Example 19 with MessageProvider

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

the class WorthCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    CatalogType type = getCatalogTypeFromHandOrArgs(src, item, args);
    String id = type.getId();
    // Get the item from the system.
    ItemDataNode node = itemDataService.getDataForItem(id);
    // Get the current item worth.
    MessageProvider provider = plugin.getMessageProvider();
    if (!econHelper.economyServiceExists()) {
        src.sendMessage(provider.getTextMessageWithFormat("command.setworth.noeconservice"));
    }
    double buyPrice = node.getServerBuyPrice();
    double sellPrice = node.getServerSellPrice();
    StringBuilder stringBuilder = new StringBuilder();
    if (buyPrice >= 0) {
        stringBuilder.append(provider.getMessageWithFormat("command.worth.buy", econHelper.getCurrencySymbol(node.getServerBuyPrice())));
    }
    if (sellPrice >= 0) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append(" - ");
        }
        stringBuilder.append(provider.getMessageWithFormat("command.worth.sell", econHelper.getCurrencySymbol(node.getServerSellPrice())));
    }
    if (stringBuilder.length() == 0) {
        src.sendMessage(provider.getTextMessageWithFormat("command.worth.nothing", Util.getTranslatableIfPresentOnCatalogType(type)));
    } else {
        src.sendMessage(provider.getTextMessageWithFormat("command.worth.something", Util.getTranslatableIfPresentOnCatalogType(type), stringBuilder.toString()));
    }
    return CommandResult.success();
}
Also used : CatalogType(org.spongepowered.api.CatalogType) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) ItemDataNode(io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode)

Example 20 with MessageProvider

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

Aggregations

MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)33 Text (org.spongepowered.api.text.Text)18 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)10 List (java.util.List)10 Util (io.github.nucleuspowered.nucleus.Util)8 Collectors (java.util.stream.Collectors)8 CommandSource (org.spongepowered.api.command.CommandSource)8 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)7 Nullable (javax.annotation.Nullable)7 CommandResult (org.spongepowered.api.command.CommandResult)7 CommandContext (org.spongepowered.api.command.args.CommandContext)7 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)7 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)6 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)6 Optional (java.util.Optional)6 Sponge (org.spongepowered.api.Sponge)6 User (org.spongepowered.api.entity.living.player.User)6 TextActions (org.spongepowered.api.text.action.TextActions)6 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)5 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5