@Listener
 public void onPlayerChat(MessageChannelEvent.Chat event) {
   Optional<Player> playerOptional = event.getCause().first(Player.class);
   if (!playerOptional.isPresent()) return;
   Player player = playerOptional.get();
   if (JobsLite.optionEnabled("chatPrefixes")) {
     String uuid = player.getUniqueId().toString();
     if (playerManager.playerExists(uuid)) {
       String currentJob = playerManager.getCurrentJob(uuid).trim();
       if (!currentJob.isEmpty()) {
         String displayName = jobManager.getDisplayName(currentJob);
         if (!displayName.isEmpty()) {
           if (JobsLite.optionEnabled("displayLevel")) {
             event.setMessage(
                 TextUtils.chatMessage(
                     player.getName(),
                     displayName,
                     playerManager.getCurrentLevel(uuid, currentJob),
                     jobManager.getColor(currentJob),
                     event.getRawMessage().toPlain()));
           } else {
             event.setMessage(
                 TextUtils.chatMessage(
                     player.getName(),
                     displayName,
                     jobManager.getColor(currentJob),
                     event.getRawMessage().toPlain()));
           }
         }
       }
     }
   }
 }
Beispiel #2
0
  @Listener(order = Order.LATE)
  public void onMessageChannelEventChat(MessageChannelEvent.Chat event, @First Player player) {
    Builder playerTag = Text.builder().onHover(TextActions.showText(Text.of(player.getName())));

    Optional<PlayerTag> optionalPlayerTag = PlayerTag.get(player);

    if (!optionalPlayerTag.isPresent()) {
      playerTag.append(PlayerTag.getDefault(player));
    } else {
      playerTag.append(optionalPlayerTag.get().getTag());
    }

    Text worldTag = Text.EMPTY;

    Optional<WorldTag> optionalWorldTag = WorldTag.get(player.getWorld().getProperties());

    if (optionalWorldTag.isPresent()) {
      worldTag = optionalWorldTag.get().getTag();
    }

    Builder groupTagBuilder = Text.builder();

    for (Entry<Set<Context>, List<Subject>> parent :
        player.getSubjectData().getAllParents().entrySet()) {
      for (Subject subject : parent.getValue()) {
        String group = subject.getIdentifier();

        if (group.equalsIgnoreCase("op_0")
            || group.equalsIgnoreCase("op_1")
            || group.equalsIgnoreCase("op_2")
            || group.equalsIgnoreCase("op_3")
            || group.equalsIgnoreCase("op_4")) {
          group = "op";
        }

        Optional<GroupTag> optionalGroupTag = GroupTag.get(group);

        if (optionalGroupTag.isPresent()) {
          groupTagBuilder.append(optionalGroupTag.get().getTag());
        }
      }
    }

    MessageFormatter formatter = event.getFormatter();

    String oldStr = TextSerializers.FORMATTING_CODE.serialize(formatter.getHeader().toText());

    String name = oldStr.substring(oldStr.indexOf("<"), oldStr.lastIndexOf(">") + 1);

    Text old = TextSerializers.FORMATTING_CODE.deserialize(oldStr.replace(name, ""));

    formatter.setHeader(
        TextTemplate.of(
            worldTag, groupTagBuilder.build(), playerTag.build(), old, TextColors.RESET));
  }
Beispiel #3
0
 @Listener(order = Order.FIRST)
 public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
   String message = event.getRawMessage().toPlain();
   if (player.getUniqueId().equals(uuid)) {
     if (message.equalsIgnoreCase("[cancel]")) {
       // Cancel the creation
       cancel();
       player.sendMessage(messages.getMessage("creation.cancelled"));
     }
   }
 }