Search in sources :

Example 1 with MutableMessageChannel

use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.

the class TempBanCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User u = args.<User>getOne(user).get();
    Long time = args.<Long>getOne(duration).get();
    String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("ban.defaultreason"));
    if (permissions.testSuffix(u, "exempt.target", src, false)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.exempt", u.getName()));
    }
    if (!u.isOnline() && !permissions.testSuffix(src, "offline")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.offline.noperms"));
    }
    if (time > banConfig.getMaximumTempBanLength() && banConfig.getMaximumTempBanLength() != -1 && !permissions.testSuffix(src, "exempt.length")) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.length.toolong", Util.getTimeStringFromSeconds(this.banConfig.getMaximumTempBanLength())));
        return CommandResult.success();
    }
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    if (service.isBanned(u.getProfile())) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName()));
        return CommandResult.empty();
    }
    // Expiration date
    Instant date = Instant.now().plus(time, ChronoUnit.SECONDS);
    // Create the ban.
    Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u.getProfile()).source(src).expirationDate(date).reason(TextSerializers.FORMATTING_CODE.deserialize(reason)).build();
    service.addBan(bp);
    MutableMessageChannel send = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
    send.addMember(src);
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.tempban.applied", u.getName(), Util.getTimeStringFromSeconds(time), src.getName()));
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
    if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
        Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(reason));
    }
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) User(org.spongepowered.api.entity.living.player.User) Instant(java.time.Instant) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) BanService(org.spongepowered.api.service.ban.BanService) Ban(org.spongepowered.api.util.ban.Ban) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 2 with MutableMessageChannel

use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.

the class UnbanCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    GameProfile gp;
    if (args.hasAny(key)) {
        gp = args.<GameProfile>getOne(key).get();
    } else {
        gp = args.<GameProfile>getOne(key2).get();
    }
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    Optional<Ban.Profile> obp = service.getBanFor(gp);
    if (!obp.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.notset", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
        return CommandResult.empty();
    }
    service.removeBan(obp.get());
    MutableMessageChannel notify = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
    notify.addMember(src);
    notify.send(plugin.getMessageProvider().getTextMessageWithFormat("command.unban.success", obp.get().getProfile().getName().orElse("standard.unknown"), src.getName()));
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) GameProfile(org.spongepowered.api.profile.GameProfile) BanService(org.spongepowered.api.service.ban.BanService) GameProfile(org.spongepowered.api.profile.GameProfile) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 3 with MutableMessageChannel

use of org.spongepowered.api.text.channel.MutableMessageChannel 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 MutableMessageChannel

use of org.spongepowered.api.text.channel.MutableMessageChannel in project Nucleus by NucleusPowered.

the class VoiceCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    if (!muteHandler.isGlobalMuteEnabled()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.globaloff"));
        return CommandResult.empty();
    }
    Player pl = args.<Player>getOne(player).get();
    if (permissions.testSuffix(pl, "auto")) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.autovoice", pl.getName()));
        return CommandResult.empty();
    }
    boolean turnOn = args.<Boolean>getOne(on).orElse(!muteHandler.isVoiced(pl.getUniqueId()));
    UUID voice = pl.getUniqueId();
    if (turnOn == muteHandler.isVoiced(voice)) {
        if (turnOn) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.alreadyvoiced", pl.getName()));
        } else {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.alreadynotvoiced", pl.getName()));
        }
        return CommandResult.empty();
    }
    MutableMessageChannel mmc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
    mmc.addMember(src);
    if (turnOn) {
        muteHandler.addVoice(pl.getUniqueId());
        mmc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.source", pl.getName()));
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.target"));
    } else {
        muteHandler.removeVoice(pl.getUniqueId());
        mmc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.source", pl.getName()));
        pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.voice.voiced.target"));
    }
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) Player(org.spongepowered.api.entity.living.player.Player) UUID(java.util.UUID) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 5 with MutableMessageChannel

use of org.spongepowered.api.text.channel.MutableMessageChannel 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)

Aggregations

MutableMessageChannel (org.spongepowered.api.text.channel.MutableMessageChannel)11 PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)8 User (org.spongepowered.api.entity.living.player.User)5 UUID (java.util.UUID)4 Player (org.spongepowered.api.entity.living.player.Player)3 Text (org.spongepowered.api.text.Text)3 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)2 Instant (java.time.Instant)2 Sponge (org.spongepowered.api.Sponge)2 CommandSource (org.spongepowered.api.command.CommandSource)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 BanService (org.spongepowered.api.service.ban.BanService)2 PostFormatChatMessageEvent (br.net.fabiozumbi12.UltimateChat.Sponge.API.PostFormatChatMessageEvent)1 SendChannelMessageEvent (br.net.fabiozumbi12.UltimateChat.Sponge.API.SendChannelMessageEvent)1 UCLogger.timingType (br.net.fabiozumbi12.UltimateChat.Sponge.UCLogger.timingType)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 Util (io.github.nucleuspowered.nucleus.Util)1 NucleusAPI (io.github.nucleuspowered.nucleus.api.NucleusAPI)1 TimespanArgument (io.github.nucleuspowered.nucleus.argumentparsers.TimespanArgument)1 LocationData (io.github.nucleuspowered.nucleus.internal.LocationData)1