예제 #1
0
  @SuppressWarnings({"unchecked", "ConstantConditions"})
  @Command(
      aliases = "pm",
      desc = "Send private message to target player.",
      usage = "/pm <target player> <message>")
  public void sendPm(@Sender EntityPlayer sender, String target, @Text String message) {

    try {
      UserId userId = profileService.findUserId(target);
      if (!Objects.equals(sender.getDisplayName(), userId.getEntityPlayer().getDisplayName())) {
        userId
            .getEntityPlayer()
            .addChatMessage(
                new ChatComponentText(
                    String.format(
                        "%s(%s - Message from %s%s: %s)",
                        EnumChatFormatting.GRAY,
                        formattedDate,
                        sender.getDisplayName(),
                        EnumChatFormatting.GRAY,
                        message.trim())));
        recipients.put(sender.getUniqueID(), profileService.findUserId(target));
      }
      if (Objects.equals(sender.getDisplayName(), userId.getEntityPlayer().getDisplayName())) {
        sender.addChatMessage(Messages.error(tr("whisper.pm.same-player.error")));
      }
    } catch (ProfileNotFoundException | NullPointerException e) {
      sender.addChatMessage(Messages.error(tr("whisper.pm.no-such-player.error")));
    } catch (ProfileLookupException ignored) {
    }
  }
예제 #2
0
 @Command(
     aliases = "r",
     desc = "Reply to the person, that sent you the last message.",
     usage = "/r <message>")
 public void replyToPm(@Sender EntityPlayer sender, @Text String message) {
   try {
     UserId target = (UserId) recipients.get(sender.getUniqueID());
     if (target.getEntityPlayer() != null) {
       target
           .getEntityPlayer()
           .addChatMessage(
               new ChatComponentText(
                   String.format(
                       "%s(%s - Message from %s%s: %s)",
                       EnumChatFormatting.GRAY,
                       formattedDate,
                       sender.getDisplayName(),
                       EnumChatFormatting.GRAY,
                       message.trim())));
     }
   } catch (NullPointerException e) {
     sender.addChatMessage(Messages.error(tr("whisper.r.nobody-to-reply-to")));
   }
 }