use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class KitInfoCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
MessageProvider mp = this.plugin.getMessageProvider();
Util.getPaginationBuilder(src).title(mp.getTextMessageWithFormat("command.kit.info.title", kit.getName())).contents(addViewHover(mp, kit), addCommandHover(mp, kit), mp.getTextMessageWithFormat("command.kit.info.sep"), mp.getTextMessageWithFormat("command.kit.info.firstjoin", yesno(mp, kit.isFirstJoinKit())), mp.getTextMessageWithFormat("command.kit.info.cost", String.valueOf(kit.getCost())), mp.getTextMessageWithFormat("command.kit.info.cooldown", kit.getCooldown().map(x -> Util.getTimeStringFromSeconds(x.getSeconds())).orElse(mp.getMessageWithFormat("standard.none"))), mp.getTextMessageWithFormat("command.kit.info.onetime", yesno(mp, kit.isOneTime())), mp.getTextMessageWithFormat("command.kit.info.autoredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.hidden", yesno(mp, kit.isHiddenFromList())), mp.getTextMessageWithFormat("command.kit.info.displayredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.ignoresperm", yesno(mp, kit.ignoresPermission()))).sendTo(src);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class CheckJailCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
Optional<JailData> jail = handler.getPlayerJailDataInternal(user);
MessageProvider mp = this.plugin.getMessageProvider();
if (!jail.isPresent()) {
throw ReturnMessageException.fromKey("command.checkjail.nojail", user.getName());
}
JailData md = jail.get();
String name;
if (md.getJailerInternal().equals(Util.consoleFakeUUID)) {
name = Sponge.getServer().getConsole().getName();
} else {
name = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(md.getJailerInternal()).map(User::getName).orElseGet(() -> mp.getMessageWithFormat("standard.unknown"));
}
if (md.getRemainingTime().isPresent()) {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), md.getJailName(), name, Util.getTimeStringFromSeconds(md.getRemainingTime().get().getSeconds())));
} else {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), md.getJailName(), name));
}
if (md.getCreationTime() > 0) {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", Util.FULL_TIME_FORMATTER.withLocale(src.getLocale()).format(Instant.ofEpochSecond(md.getCreationTime()))));
} else {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", mp.getMessageWithFormat("standard.unknown")));
}
src.sendMessage(mp.getTextMessageWithFormat("standard.reasoncoloured", md.getReason()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class CheckJailedCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Using the cache, tell us who is jailed.
MessageProvider provider = plugin.getMessageProvider();
Optional<NamedLocation> jail = args.getOne(jailNameKey);
List<UUID> usersInJail = jail.map(x -> plugin.getUserCacheService().getJailedIn(x.getName())).orElseGet(() -> plugin.getUserCacheService().getJailed());
String jailName = jail.map(NamedLocation::getName).orElseGet(() -> provider.getMessageWithFormat("standard.alljails"));
if (usersInJail.isEmpty()) {
src.sendMessage(provider.getTextMessageWithFormat("command.checkjailed.none", jailName));
return CommandResult.success();
}
// Get the users in this jail, or all jails
Util.getPaginationBuilder(src).title(provider.getTextMessageWithFormat("command.checkjailed.header", jailName)).contents(usersInJail.stream().map(x -> {
Text name = plugin.getNameUtil().getName(x).orElseGet(() -> Text.of("unknown: ", x.toString()));
return name.toBuilder().onHover(TextActions.showText(provider.getTextMessageWithFormat("command.checkjailed.hover"))).onClick(TextActions.runCommand("/nucleus:checkjail " + x.toString())).build();
}).collect(Collectors.toList())).sendTo(src);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class ItemNameSetCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
MessageProvider provider = Nucleus.getNucleus().getMessageProvider();
if (!src.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
throw ReturnMessageException.fromKey("command.itemname.set.noitem");
}
ItemStack stack = src.getItemInHand(HandTypes.MAIN_HAND).get();
Text name = TextSerializers.FORMATTING_CODE.deserialize(args.<String>getOne(nameKey).get());
if (stack.offer(Keys.DISPLAY_NAME, name).isSuccessful()) {
src.setItemInHand(HandTypes.MAIN_HAND, stack);
src.sendMessage(provider.getTextMessageWithFormat("command.itemname.set.success"));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.itemname.set.fail");
}
use of io.github.nucleuspowered.nucleus.internal.messages.MessageProvider in project Nucleus by NucleusPowered.
the class Util method getTimeStringFromSeconds.
public static String getTimeStringFromSeconds(long time) {
time = Math.abs(time);
long sec = time % 60;
long min = (time / 60) % 60;
long hour = (time / 3600) % 24;
long day = time / 86400;
MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
if (time == 0) {
return messageProvider.getMessageWithFormat("standard.inamoment");
}
StringBuilder sb = new StringBuilder();
if (day > 0) {
sb.append(day).append(" ");
if (day > 1) {
sb.append(messageProvider.getMessageWithFormat("standard.days"));
} else {
sb.append(messageProvider.getMessageWithFormat("standard.day"));
}
}
if (hour > 0) {
appendComma(sb);
sb.append(hour).append(" ");
if (hour > 1) {
sb.append(messageProvider.getMessageWithFormat("standard.hours"));
} else {
sb.append(messageProvider.getMessageWithFormat("standard.hour"));
}
}
if (min > 0) {
appendComma(sb);
sb.append(min).append(" ");
if (min > 1) {
sb.append(messageProvider.getMessageWithFormat("standard.minutes"));
} else {
sb.append(messageProvider.getMessageWithFormat("standard.minute"));
}
}
if (sec > 0) {
appendComma(sb);
sb.append(sec).append(" ");
if (sec > 1) {
sb.append(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.seconds"));
} else {
sb.append(Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.second"));
}
}
if (sb.length() > 0) {
return sb.toString();
} else {
return messageProvider.getMessageWithFormat("standard.unknown");
}
}
Aggregations