Search in sources :

Example 81 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class CoreListener method onGameReload.

@Listener
public void onGameReload(final GameReloadEvent event) {
    CommandSource requester = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
    if (plugin.reload()) {
        requester.sendMessage(Text.of(TextColors.YELLOW, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.one")));
        requester.sendMessage(Text.of(TextColors.YELLOW, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.two")));
    } else {
        requester.sendMessage(Text.of(TextColors.RED, "[Nucleus] ", plugin.getMessageProvider().getTextMessageWithFormat("command.reload.errorone")));
    }
    this.warnOnWildcard = this.plugin.getInternalServiceManager().getServiceUnchecked(CoreConfigAdapter.class).getNodeOrDefault().isCheckForWildcard();
}
Also used : CommandSource(org.spongepowered.api.command.CommandSource) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 82 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class ListHomeCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // args.getOne(subject);
    User user = this.getUserFromArgs(User.class, src, player, args);
    Text header;
    boolean other = src instanceof User && !((User) src).getUniqueId().equals(user.getUniqueId());
    if (other && user.hasPermission(this.exempt)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.listhome.exempt"));
    }
    List<Home> msw = homeHandler.getHomes(user);
    if (msw.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.nohomes"));
        return CommandResult.empty();
    }
    if (other) {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.name", user.getName());
    } else {
        header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.normal");
    }
    List<Text> lt = msw.stream().sorted(Comparator.comparing(NamedLocation::getName)).map(x -> {
        Optional<Location<World>> olw = x.getLocation();
        if (!olw.isPresent()) {
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphoverinvalid", x.getName()))).build()).build();
        } else {
            final Location<World> lw = olw.get();
            return Text.builder().append(Text.builder(x.getName()).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphover", x.getName()))).onClick(TextActions.runCommand(other ? "/homeother " + user.getName() + " " + x.getName() : "/home " + x.getName())).build()).append(plugin.getMessageProvider().getTextMessageWithFormat("home.location", lw.getExtent().getName(), String.valueOf(lw.getBlockX()), String.valueOf(lw.getBlockY()), String.valueOf(lw.getBlockZ()))).build();
        }
    }).collect(Collectors.toList());
    PaginationList.Builder pb = Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt);
    pb.sendTo(src);
    return CommandResult.success();
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) HashMap(java.util.HashMap) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) PaginationList(org.spongepowered.api.service.pagination.PaginationList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) SelectorWrapperArgument(io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) 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) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) NicknameArgument(io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) HomeHandler(io.github.nucleuspowered.nucleus.modules.home.handlers.HomeHandler) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) User(org.spongepowered.api.entity.living.player.User) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) PaginationList(org.spongepowered.api.service.pagination.PaginationList) Home(io.github.nucleuspowered.nucleus.api.nucleusdata.Home) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

Example 83 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class HatCommand method executeWithPlayer.

@Override
protected CommandResult executeWithPlayer(CommandSource player, Player pl, CommandContext args, boolean isSelf) throws Exception {
    Optional<ItemStack> helmetOptional = pl.getHelmet();
    ItemStack stack = pl.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> ReturnMessageException.fromKey("command.generalerror.handempty"));
    ItemStack hand = stack.copy();
    hand.setQuantity(1);
    pl.setHelmet(hand);
    Text itemName = hand.get(Keys.DISPLAY_NAME).orElseGet(() -> Text.of(stack));
    GameMode gameMode = pl.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET);
    if (gameMode != GameModes.CREATIVE) {
        if (stack.getQuantity() > 1) {
            stack.setQuantity(stack.getQuantity() - 1);
            pl.setItemInHand(HandTypes.MAIN_HAND, stack);
        } else {
            pl.setItemInHand(HandTypes.MAIN_HAND, null);
        }
    }
    // If the old item can't be placed back in the subject inventory, drop the item.
    helmetOptional.ifPresent(itemStack -> Util.getStandardInventory(pl).offer(itemStack.copy()).getRejectedItems().forEach(x -> Util.dropItemOnFloorAtLocation(x, pl.getWorld(), pl.getLocation().getPosition())));
    if (!isSelf) {
        player.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.success", plugin.getNameUtil().getName(pl), itemName));
    }
    pl.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.hat.successself", itemName));
    return CommandResult.success();
}
Also used : NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) Keys(org.spongepowered.api.data.key.Keys) CommandSource(org.spongepowered.api.command.CommandSource) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ItemStack(org.spongepowered.api.item.inventory.ItemStack) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) Util(io.github.nucleuspowered.nucleus.Util) Player(org.spongepowered.api.entity.living.player.Player) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 84 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class MessageHandler method sendMessage.

@Override
public boolean sendMessage(CommandSource sender, CommandSource receiver, String message) {
    // Message is about to be sent. Send the event out. If canceled, then that's that.
    boolean isBlocked = false;
    boolean isCancelled = Sponge.getEventManager().post(new InternalNucleusMessageEvent(sender, receiver, message));
    if (isCancelled) {
        sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("message.cancel"));
        // Only continue to show Social Spy messages if the subject is muted.
        if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
            return false;
        }
    }
    // What about msgtoggle?
    if (receiver instanceof Player && !sender.hasPermission(this.msgToggleBypass) && ucl.get((Player) receiver).map(x -> !x.get(MessageUserDataModule.class).isMsgToggle()).orElse(false)) {
        isCancelled = true;
        isBlocked = true;
        sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithTextFormat("message.blocked", Nucleus.getNucleus().getNameUtil().getName((Player) receiver)));
        if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
            return false;
        }
    }
    // Social Spies.
    final UUID uuidSender = getUUID(sender);
    final UUID uuidReceiver = getUUID(receiver);
    final Map<String, Object> variables = Maps.newHashMap();
    variables.put("from", sender);
    variables.put("to", receiver);
    // Create the tokens.
    Map<String, Function<CommandSource, Optional<Text>>> tokens = Maps.newHashMap();
    tokens.put("from", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToName));
    tokens.put("to", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToName));
    tokens.put("fromdisplay", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToDisplayName));
    tokens.put("todisplay", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToDisplayName));
    Text tm = useMessage(sender, message);
    if (!isCancelled) {
        sender.sendMessage(constructMessage(sender, tm, messageConfig.getMessageSenderPrefix(), tokens, variables));
        receiver.sendMessage(constructMessage(sender, tm, messageConfig.getMessageReceiverPrefix(), tokens, variables));
    }
    NucleusTextTemplateImpl prefix = messageConfig.getMessageSocialSpyPrefix();
    if (isBlocked) {
        prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getBlockedTag() + prefix.getRepresentation());
    }
    if (isCancelled) {
        prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getMutedTag() + prefix.getRepresentation());
    }
    MessageConfig.Targets targets = messageConfig.spyOn();
    if (sender instanceof Player && targets.isPlayer() || sender instanceof ConsoleSource && targets.isCustom() || targets.isCustom()) {
        Set<CommandSource> lm = onlinePlayersCanSpyOn(!uuidSender.equals(Util.consoleFakeUUID) && !uuidReceiver.equals(Util.consoleFakeUUID), sender, receiver);
        MessageChannel mc = MessageChannel.fixed(lm);
        if (!mc.getMembers().isEmpty()) {
            mc.send(constructMessage(sender, tm, prefix, tokens, variables));
        }
    }
    // Add the UUIDs to the reply list - the receiver will now reply to the sender.
    if (!isCancelled) {
        messagesReceived.put(uuidReceiver, uuidSender);
    }
    return !isCancelled;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) Text(org.spongepowered.api.text.Text) CommandSource(org.spongepowered.api.command.CommandSource) Function(java.util.function.Function) MessageConfig(io.github.nucleuspowered.nucleus.modules.message.config.MessageConfig) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageUserDataModule(io.github.nucleuspowered.nucleus.modules.message.datamodules.MessageUserDataModule) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) UUID(java.util.UUID) InternalNucleusMessageEvent(io.github.nucleuspowered.nucleus.modules.message.events.InternalNucleusMessageEvent)

Example 85 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class MessageHandler method getLastMessageFrom.

public Optional<CommandSource> getLastMessageFrom(UUID from) {
    Preconditions.checkNotNull(from);
    UUID to = messagesReceived.get(from);
    if (to == null) {
        return Optional.empty();
    }
    if (to.equals(Util.consoleFakeUUID)) {
        return Optional.of(Sponge.getServer().getConsole());
    }
    if (targets.containsKey(to)) {
        Optional<? extends CommandSource> om = targets.get(to).get();
        if (om.isPresent()) {
            return om.map(x -> x);
        }
    }
    return Sponge.getServer().getOnlinePlayers().stream().filter(x -> x.getUniqueId().equals(to)).map(y -> (CommandSource) y).findFirst();
}
Also used : Arrays(java.util.Arrays) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) MessageConfig(io.github.nucleuspowered.nucleus.modules.message.config.MessageConfig) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) SocialSpyCommand(io.github.nucleuspowered.nucleus.modules.message.commands.SocialSpyCommand) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Text(org.spongepowered.api.text.Text) Map(java.util.Map) Util(io.github.nucleuspowered.nucleus.Util) MsgToggleCommand(io.github.nucleuspowered.nucleus.modules.message.commands.MsgToggleCommand) Identifiable(org.spongepowered.api.util.Identifiable) Nullable(javax.annotation.Nullable) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) NucleusTextTemplateFactory(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateFactory) MessageCommand(io.github.nucleuspowered.nucleus.modules.message.commands.MessageCommand) InternalNucleusMessageEvent(io.github.nucleuspowered.nucleus.modules.message.events.InternalNucleusMessageEvent) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) ImmutableMap(com.google.common.collect.ImmutableMap) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) CommandSource(org.spongepowered.api.command.CommandSource) NucleusPrivateMessagingService(io.github.nucleuspowered.nucleus.api.service.NucleusPrivateMessagingService) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) MessageUserDataModule(io.github.nucleuspowered.nucleus.modules.message.datamodules.MessageUserDataModule) UUID(java.util.UUID) MessageConfigAdapter(io.github.nucleuspowered.nucleus.modules.message.config.MessageConfigAdapter) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Tristate(org.spongepowered.api.util.Tristate) MessageModule(io.github.nucleuspowered.nucleus.modules.message.MessageModule) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) List(java.util.List) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Player(org.spongepowered.api.entity.living.player.Player) NucleusTextTemplateImpl(io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl) UUID(java.util.UUID) CommandSource(org.spongepowered.api.command.CommandSource)

Aggregations

CommandSource (org.spongepowered.api.command.CommandSource)91 Text (org.spongepowered.api.text.Text)60 CommandResult (org.spongepowered.api.command.CommandResult)48 List (java.util.List)47 CommandContext (org.spongepowered.api.command.args.CommandContext)45 Collectors (java.util.stream.Collectors)37 Sponge (org.spongepowered.api.Sponge)37 Player (org.spongepowered.api.entity.living.player.Player)36 Optional (java.util.Optional)35 TextColors (org.spongepowered.api.text.format.TextColors)30 CommandElement (org.spongepowered.api.command.args.CommandElement)27 TextActions (org.spongepowered.api.text.action.TextActions)27 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)25 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)24 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)23 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)23 GenericArguments (org.spongepowered.api.command.args.GenericArguments)23 Util (io.github.nucleuspowered.nucleus.Util)20 Nullable (javax.annotation.Nullable)20 Map (java.util.Map)19