use of io.github.nucleuspowered.nucleus.modules.note.data.NoteData in project Nucleus by NucleusPowered.
the class NoteArgument method parseValue.
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
Optional<String> optPlayer = args.nextIfPresent();
if (!optPlayer.isPresent()) {
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.nouserarg"));
}
String player = optPlayer.get();
Optional<User> optUser = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(player);
if (!optUser.isPresent()) {
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.nouser", player));
}
User user = optUser.get();
Optional<String> optIndex = args.nextIfPresent();
if (!optIndex.isPresent()) {
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.noindex", user.getName()));
}
List<NoteData> noteData = handler.getNotesInternal(user);
int index;
try {
index = Integer.parseInt(optIndex.get()) - 1;
if (index >= noteData.size() || index < 0) {
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.nonotedata", optIndex.get(), user.getName()));
}
} catch (NumberFormatException ex) {
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.indexnotnumber"));
}
if (!noteData.isEmpty()) {
return new Result(user, noteData.get(index));
}
throw args.createError(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("args.note.nousernotes", user.getName()));
}
use of io.github.nucleuspowered.nucleus.modules.note.data.NoteData in project Nucleus by NucleusPowered.
the class CheckNotesCommand method createMessage.
private Text createMessage(NoteData note, User user) {
String name;
if (note.getNoterInternal().equals(Util.consoleFakeUUID)) {
name = Sponge.getServer().getConsole().getName();
} else {
Optional<User> ou = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(note.getNoterInternal());
name = ou.map(User::getName).orElseGet(() -> plugin.getMessageProvider().getMessageWithFormat("standard.unknown"));
}
// Get the ID of the note, its index in the users List<NoteData>. Add one to start with an ID of 1.
int id = handler.getNotesInternal(user).indexOf(note) + 1;
// Action buttons, this should look like 'Action > [Delete] - [Return] <'
Text.Builder actions = plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.action").toBuilder();
// Add separation between the word 'Action' and action buttons
actions.append(Text.of(TextColors.GOLD, " > "));
// Add the delete button [Delete]
actions.append(Text.builder().append(Text.of(TextColors.RED, plugin.getMessageProvider().getMessageWithFormat("standard.action.delete"))).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.hover.delete"))).onClick(TextActions.runCommand("/removenote " + user.getName() + " " + id)).build());
// Add a - to separate it from the next action button
actions.append(Text.of(TextColors.GOLD, " - "));
// Add the return button [Return]
actions.append(Text.builder().append(Text.of(TextColors.GREEN, plugin.getMessageProvider().getMessageWithFormat("standard.action.return"))).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.hover.return"))).onClick(TextActions.runCommand("/checknotes " + user.getName())).build());
// Add a < to end the actions button list
actions.append(Text.of(TextColors.GOLD, " < "));
// Get and format the date of the warning
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MMM dd, yyyy").withZone(ZoneId.systemDefault());
String date = dtf.format(note.getDate());
// Create a clickable name providing more information about the warning
Text.Builder information = Text.builder(name).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.hover.check"))).onClick(TextActions.executeCallback(commandSource -> {
commandSource.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.id", String.valueOf(id)));
commandSource.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.date", date));
commandSource.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.noter", name));
commandSource.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.note", note.getNote()));
commandSource.sendMessage(actions.build());
}));
// Create the warning message
Text.Builder message = Text.builder().append(Text.of(TextColors.GREEN, information.build())).append(Text.of(": ")).append(Text.of(TextColors.YELLOW, note.getNote()));
return message.build();
}
use of io.github.nucleuspowered.nucleus.modules.note.data.NoteData in project Nucleus by NucleusPowered.
the class NoteCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
String note = args.<String>getOne(noteKey).get();
UUID noter = Util.consoleFakeUUID;
if (src instanceof Player) {
noter = ((Player) src).getUniqueId();
}
NoteData noteData = new NoteData(Instant.now(), noter, note);
if (noteHandler.addNote(user, noteData)) {
MutableMessageChannel messageChannel = new PermissionMessageChannel(notifyPermission).asMutable();
messageChannel.addMember(src);
messageChannel.send(plugin.getMessageProvider().getTextMessageWithFormat("command.note.success", src.getName(), noteData.getNote(), user.getName()));
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warn.fail", user.getName()));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.modules.note.data.NoteData in project Nucleus by NucleusPowered.
the class RemoveNoteCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
NoteArgument.Result result = args.<NoteArgument.Result>getOne(noteKey).get();
User user = result.user;
List<NoteData> notes = handler.getNotesInternal(user);
if (notes.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkwarnings.none", user.getName()));
return CommandResult.success();
}
if (handler.removeNote(user, result.noteData)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.removenote.success", user.getName()));
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.removenote.failure", user.getName()));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.modules.note.data.NoteData in project Nucleus by NucleusPowered.
the class CheckNotesCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
List<NoteData> notes = handler.getNotesInternal(user);
if (notes.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.none", user.getName()));
return CommandResult.success();
}
List<Text> messages = notes.stream().sorted(Comparator.comparing(NoteData::getDate)).map(x -> createMessage(x, user)).collect(Collectors.toList());
messages.add(0, plugin.getMessageProvider().getTextMessageWithFormat("command.checknotes.info"));
PaginationService paginationService = Sponge.getGame().getServiceManager().provideUnchecked(PaginationService.class);
paginationService.builder().title(Text.builder().color(TextColors.GOLD).append(Text.of(plugin.getMessageProvider().getMessageWithFormat("command.checknotes.header", user.getName()))).build()).padding(Text.builder().color(TextColors.YELLOW).append(Text.of("=")).build()).contents(messages).sendTo(src);
return CommandResult.success();
}
Aggregations