Search in sources :

Example 1 with ConversionException

use of org.cubeengine.converter.ConversionException in project modules-extra by CubeEngine.

the class MuteCommands method mute.

@Command(desc = "Mutes a player")
public void mute(CommandSource context, Player player, @Optional String duration) {
    Date muted = getMuted(player);
    if (muted != null && muted.getTime() > System.currentTimeMillis()) {
        i18n.send(context, NEUTRAL, "{user} was already muted!", player);
    }
    try {
        Integer.parseInt(duration);
        duration += "m";
    } catch (NumberFormatException ignored) {
    }
    Duration dura = module.getConfig().defaultMuteTime;
    if (duration != null) {
        try {
            dura = converter.fromNode(StringNode.of(duration), null, null);
        } catch (ConversionException e) {
            i18n.send(context, NEGATIVE, "Invalid duration format!");
            return;
        }
    }
    setMuted(player, new Date(System.currentTimeMillis() + (dura.toMillis() == 0 ? DAYS.toMillis(9001) : dura.toMillis())));
    Text timeString = dura.toMillis() == 0 ? i18n.translate(player, NONE, "ever") : Text.of(TimeUtil.format(player.getLocale(), dura.toMillis()));
    i18n.send(player, NEGATIVE, "You are now muted for {txt#amount}!", timeString);
    i18n.send(context, NEUTRAL, "You muted {user} globally for {txt#amount}!", player, timeString);
}
Also used : ConversionException(org.cubeengine.converter.ConversionException) Duration(java.time.Duration) Text(org.spongepowered.api.text.Text) Date(java.sql.Date) Command(org.cubeengine.butler.parametric.Command)

Aggregations

Date (java.sql.Date)1 Duration (java.time.Duration)1 Command (org.cubeengine.butler.parametric.Command)1 ConversionException (org.cubeengine.converter.ConversionException)1 Text (org.spongepowered.api.text.Text)1