Search in sources :

Example 1 with PermissionMessageChannel

use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel 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 PermissionMessageChannel

use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel 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 PermissionMessageChannel

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

the class JailListener method onPlayerLogin.

@Listener
public void onPlayerLogin(final NucleusOnLoginEvent event, @Getter("getTargetUser") User user, @Getter("getUserService") ModularUserService qs) {
    JailUserDataModule userDataModule = qs.get(JailUserDataModule.class);
    // Jailing the subject if we need to.
    if (userDataModule.jailOnNextLogin() && userDataModule.getJailData().isPresent()) {
        Optional<NamedLocation> owl = handler.getWarpLocation(user);
        if (!owl.isPresent()) {
            new PermissionMessageChannel(notify).send(Text.of(TextColors.RED, "WARNING: No jail is defined. Jailed players are going free!"));
            handler.unjailPlayer(user);
            return;
        }
        JailData jd = userDataModule.getJailData().get();
        jd.setPreviousLocation(event.getFrom().getLocation());
        userDataModule.setJailData(jd);
        event.setTo(owl.get().getTransform().get());
    }
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) Listener(org.spongepowered.api.event.Listener)

Example 4 with PermissionMessageChannel

use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel 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 5 with PermissionMessageChannel

use of io.github.nucleuspowered.nucleus.util.PermissionMessageChannel 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)

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