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);
}
Aggregations