Search in sources :

Example 6 with PermissionMessageChannel

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

the class MuteListener method onChat.

private void onChat(MessageChannelEvent.Chat event, Player player) {
    boolean cancel = false;
    Optional<MuteData> omd = Util.testForEndTimestamp(handler.getPlayerMuteData(player), () -> handler.unmutePlayer(player));
    if (omd.isPresent()) {
        this.handler.onMute(omd.get(), player);
        MessageChannel.TO_CONSOLE.send(Text.builder().append(Text.of(player.getName() + " (")).append(plugin.getMessageProvider().getTextMessageWithFormat("standard.muted")).append(Text.of("): ")).append(event.getRawMessage()).build());
        cancel = true;
    }
    if (cancelOnGlobalMute(player, false)) {
        cancel = true;
    }
    if (cancel) {
        if (this.muteConfig.isShowMutedChat()) {
            // Send it to admins only.
            String m = this.muteConfig.getCancelledTag();
            if (!m.isEmpty()) {
                event.getFormatter().setHeader(Text.join(TextSerializers.FORMATTING_CODE.deserialize(m), event.getFormatter().getHeader().toText()));
            }
            new PermissionMessageChannel(MuteCommand.getMutedChatPermission()).send(player, event.getMessage(), ChatTypes.SYSTEM);
        }
        event.setCancelled(true);
    }
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) MuteData(io.github.nucleuspowered.nucleus.modules.mute.data.MuteData)

Example 7 with PermissionMessageChannel

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

the class NoteCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User user = args.<User>getOne(playerKey).get();
    String note = args.<String>getOne(noteKey).get();
    UUID noter = Util.consoleFakeUUID;
    if (src instanceof Player) {
        noter = ((Player) src).getUniqueId();
    }
    NoteData noteData = new NoteData(Instant.now(), noter, note);
    if (noteHandler.addNote(user, noteData)) {
        MutableMessageChannel messageChannel = new PermissionMessageChannel(notifyPermission).asMutable();
        messageChannel.addMember(src);
        messageChannel.send(plugin.getMessageProvider().getTextMessageWithFormat("command.note.success", src.getName(), noteData.getNote(), user.getName()));
        return CommandResult.success();
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warn.fail", user.getName()));
    return CommandResult.empty();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) UUID(java.util.UUID) NoteData(io.github.nucleuspowered.nucleus.modules.note.data.NoteData) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 8 with PermissionMessageChannel

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

the class HelpOpCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    String message = args.<String>getOne(messageKey).get();
    // that's that.
    if (Sponge.getEventManager().post(new InternalNucleusHelpOpEvent(src, message))) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("message.cancel"));
        return CommandResult.empty();
    }
    Text prefix = messageConfig.getHelpOpPrefix().getForCommandSource(src);
    new PermissionMessageChannel(permissions.getPermissionWithSuffix("receive")).send(src, TextParsingUtils.joinTextsWithColoursFlowing(prefix, Text.of(message)));
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.helpop.success"));
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) InternalNucleusHelpOpEvent(io.github.nucleuspowered.nucleus.modules.message.events.InternalNucleusHelpOpEvent) Text(org.spongepowered.api.text.Text)

Example 9 with PermissionMessageChannel

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

the class BanCommand method executeBan.

private CommandResult executeBan(CommandSource src, GameProfile u, String r) {
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    User user = uss.get(u).get();
    if (!user.isOnline() && !permissions.testSuffix(src, "offline")) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
        return CommandResult.empty();
    }
    if (service.isBanned(u)) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
        return CommandResult.empty();
    }
    // Create the ban.
    Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u).source(src).reason(TextSerializers.FORMATTING_CODE.deserialize(r)).build();
    service.addBan(bp);
    // Get the permission, "quickstart.ban.notify"
    MutableMessageChannel send = new PermissionMessageChannel(notifyPermission).asMutable();
    send.addMember(src);
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.applied", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), src.getName()));
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", r));
    if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
        Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(r));
    }
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) User(org.spongepowered.api.entity.living.player.User) BanService(org.spongepowered.api.service.ban.BanService) Ban(org.spongepowered.api.util.ban.Ban) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 10 with PermissionMessageChannel

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

the class JailCommand method onJail.

private CommandResult onJail(CommandSource src, CommandContext args, User user) throws ReturnMessageException {
    Optional<LocationData> owl = args.getOne(jailKey);
    if (!owl.isPresent()) {
        throw ReturnMessageException.fromKey("command.jail.jail.nojail");
    }
    // This might not be there.
    Optional<Long> duration = args.getOne(durationKey);
    String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("command.jail.reason"));
    JailData jd;
    Text message;
    Text messageTo;
    if (duration.isPresent()) {
        if (user.isOnline()) {
            jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().get().getLocation(), Instant.now().plusSeconds(duration.get()));
        } else {
            jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, null, Duration.of(duration.get(), ChronoUnit.SECONDS));
        }
        message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), jd.getJailName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
        messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedfor", owl.get().getName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
    } else {
        jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().map(Locatable::getLocation).orElse(null));
        message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), owl.get().getName(), src.getName());
        messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedperm", owl.get().getName(), src.getName());
    }
    if (handler.jailPlayer(user, jd)) {
        MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
        mc.addMember(src);
        mc.send(message);
        mc.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
        user.getPlayer().ifPresent(x -> {
            x.sendMessage(messageTo);
            x.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
        });
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.jail.error");
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) LocationData(io.github.nucleuspowered.nucleus.internal.LocationData) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Text(org.spongepowered.api.text.Text) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Aggregations

PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)12 MutableMessageChannel (org.spongepowered.api.text.channel.MutableMessageChannel)8 User (org.spongepowered.api.entity.living.player.User)5 UUID (java.util.UUID)4 Player (org.spongepowered.api.entity.living.player.Player)4 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)3 BanService (org.spongepowered.api.service.ban.BanService)3 Text (org.spongepowered.api.text.Text)3 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)2 MuteData (io.github.nucleuspowered.nucleus.modules.mute.data.MuteData)2 Instant (java.time.Instant)2 Ban (org.spongepowered.api.util.ban.Ban)2 Util (io.github.nucleuspowered.nucleus.Util)1 NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)1 TimespanArgument (io.github.nucleuspowered.nucleus.argumentparsers.TimespanArgument)1 LocationData (io.github.nucleuspowered.nucleus.internal.LocationData)1 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)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