Search in sources :

Example 1 with LocationData

use of io.github.nucleuspowered.nucleus.internal.LocationData in project Nucleus by NucleusPowered.

the class DeleteJailCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    LocationData wl = args.<LocationData>getOne(jailKey).get();
    if (handler.removeJail(wl.getName())) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.del.success", wl.getName()));
        return CommandResult.success();
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.del.error", wl.getName()));
    return CommandResult.empty();
}
Also used : LocationData(io.github.nucleuspowered.nucleus.internal.LocationData)

Example 2 with LocationData

use of io.github.nucleuspowered.nucleus.internal.LocationData 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

LocationData (io.github.nucleuspowered.nucleus.internal.LocationData)2 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)1 PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)1 Text (org.spongepowered.api.text.Text)1 MutableMessageChannel (org.spongepowered.api.text.channel.MutableMessageChannel)1