Search in sources :

Example 1 with MuteData

use of io.github.nucleuspowered.nucleus.modules.mute.data.MuteData in project Nucleus by NucleusPowered.

the class MuteModule method performEnableTasks.

@Override
public void performEnableTasks() {
    createSeenModule(CheckMuteCommand.class, (c, u) -> {
        // If we have a ban service, then check for a ban.
        MuteHandler jh = plugin.getInternalServiceManager().getServiceUnchecked(MuteHandler.class);
        if (jh.isMuted(u)) {
            MuteData jd = jh.getPlayerMuteData(u).get();
            // Lightweight checkban.
            Text.Builder m;
            if (jd.getRemainingTime().isPresent()) {
                m = plugin.getMessageProvider().getTextMessageWithFormat("seen.ismuted.temp", Util.getTimeToNow(jd.getEndTimestamp().get())).toBuilder();
            } else {
                m = plugin.getMessageProvider().getTextMessageWithFormat("seen.ismuted.perm").toBuilder();
            }
            return Lists.newArrayList(m.onClick(TextActions.runCommand("/checkmute " + u.getName())).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("standard.clicktoseemore"))).build(), plugin.getMessageProvider().getTextMessageWithFormat("standard.reason", jd.getReason()));
        }
        return Lists.newArrayList(plugin.getMessageProvider().getTextMessageWithFormat("seen.notmuted"));
    });
}
Also used : MuteHandler(io.github.nucleuspowered.nucleus.modules.mute.handler.MuteHandler) MuteData(io.github.nucleuspowered.nucleus.modules.mute.data.MuteData) Text(org.spongepowered.api.text.Text)

Example 2 with MuteData

use of io.github.nucleuspowered.nucleus.modules.mute.data.MuteData in project Nucleus by NucleusPowered.

the class CheckMuteCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Get the user.
    User user = args.<User>getOne(playerKey).get();
    Optional<MuteData> omd = handler.getPlayerMuteData(user);
    if (!omd.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkmute.none", user.getName()));
        return CommandResult.success();
    }
    // Muted, get information.
    MuteData md = omd.get();
    String name;
    if (!md.getMuter().isPresent()) {
        name = Sponge.getServer().getConsole().getName();
    } else {
        name = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(md.getMuter().get()).map(User::getName).orElseGet(() -> plugin.getMessageProvider().getMessageWithFormat("standard.unknown"));
    }
    if (md.getRemainingTime().isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkmute.mutedfor", user.getName(), name, Util.getTimeStringFromSeconds(md.getRemainingTime().get().getSeconds())));
    } else {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkmute.mutedperm", user.getName(), name));
    }
    if (md.getCreationTime() > 0) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkmute.created", Util.FULL_TIME_FORMATTER.withLocale(src.getLocale()).format(Instant.ofEpochSecond(md.getCreationTime()))));
    } else {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkmute.created", plugin.getMessageProvider().getMessageWithFormat("standard.unknown")));
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", md.getReason()));
    return CommandResult.success();
}
Also used : User(org.spongepowered.api.entity.living.player.User) MuteData(io.github.nucleuspowered.nucleus.modules.mute.data.MuteData)

Example 3 with MuteData

use of io.github.nucleuspowered.nucleus.modules.mute.data.MuteData in project Nucleus by NucleusPowered.

the class MuteCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Get the user.
    User user = args.<User>getOne(playerArgument).get();
    Optional<Long> time = args.getOne(timespanArgument);
    Optional<MuteData> omd = handler.getPlayerMuteData(user);
    Optional<String> reas = args.getOne(reason);
    if (permissions.testSuffix(user, "exempt.target", src, false)) {
        throw ReturnMessageException.fromKey("command.mute.exempt", user.getName());
    }
    // No time, no reason, but is muted, unmute
    if (omd.isPresent() && !time.isPresent() && !reas.isPresent()) {
        if (!this.requireUnmutePermission || this.permissions.testSuffix(src, "unmute")) {
            // Unmute.
            this.handler.unmutePlayer(user, CauseStackHelper.createCause(src), false);
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.unmute.success", user.getName(), src.getName()));
            return CommandResult.success();
        }
        throw ReturnMessageException.fromKey("command.unmute.perm");
    }
    // Do we have a reason?
    String rs = reas.orElse(plugin.getMessageProvider().getMessageWithFormat("command.mute.defaultreason"));
    UUID ua = Util.consoleFakeUUID;
    if (src instanceof Player) {
        ua = ((Player) src).getUniqueId();
    }
    if (this.maxMute > 0 && time.orElse(Long.MAX_VALUE) > this.maxMute && !permissions.testSuffix(src, "exempt.length")) {
        throw ReturnMessageException.fromKey("command.mute.length.toolong", Util.getTimeStringFromSeconds(this.maxMute));
    }
    MuteData data;
    if (time.isPresent()) {
        if (!user.isOnline()) {
            data = new MuteData(ua, rs, Duration.ofSeconds(time.get()));
        } else {
            data = new MuteData(ua, rs, Instant.now().plus(time.get(), ChronoUnit.SECONDS));
        }
    } else {
        data = new MuteData(ua, rs);
    }
    if (handler.mutePlayer(user, data)) {
        // Success.
        MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
        mc.addMember(src);
        if (time.isPresent()) {
            timedMute(src, user, data, time.get(), mc);
        } else {
            permMute(src, user, data, mc);
        }
        return CommandResult.success();
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.mute.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) MuteData(io.github.nucleuspowered.nucleus.modules.mute.data.MuteData) UUID(java.util.UUID) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 4 with MuteData

use of io.github.nucleuspowered.nucleus.modules.mute.data.MuteData 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 5 with MuteData

use of io.github.nucleuspowered.nucleus.modules.mute.data.MuteData in project Nucleus by NucleusPowered.

the class MuteListener method onPlayerMessage.

@Listener
public void onPlayerMessage(NucleusMessageEvent event) {
    if (!(event.getSender() instanceof Player)) {
        return;
    }
    boolean isCancelled = false;
    Player user = (Player) event.getSender();
    Optional<MuteData> omd = Util.testForEndTimestamp(handler.getPlayerMuteData(user), () -> handler.unmutePlayer(user));
    if (omd.isPresent()) {
        if (user.isOnline()) {
            this.handler.onMute(omd.get(), user.getPlayer().get());
        }
        isCancelled = true;
    }
    if (cancelOnGlobalMute(user, isCancelled)) {
        isCancelled = true;
    }
    event.setCancelled(isCancelled);
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MuteData(io.github.nucleuspowered.nucleus.modules.mute.data.MuteData) Listener(org.spongepowered.api.event.Listener)

Aggregations

MuteData (io.github.nucleuspowered.nucleus.modules.mute.data.MuteData)5 PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)2 Player (org.spongepowered.api.entity.living.player.Player)2 User (org.spongepowered.api.entity.living.player.User)2 MuteHandler (io.github.nucleuspowered.nucleus.modules.mute.handler.MuteHandler)1 UUID (java.util.UUID)1 Listener (org.spongepowered.api.event.Listener)1 Text (org.spongepowered.api.text.Text)1 MutableMessageChannel (org.spongepowered.api.text.channel.MutableMessageChannel)1