Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Individual Hologram player #12

Closed
mateusneresrb opened this issue Jun 14, 2022 · 1 comment
Closed

Individual Hologram player #12

mateusneresrb opened this issue Jun 14, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@mateusneresrb
Copy link

Hello, I am setting up a ranking and need to make holograms in individual for each player, the player will be able to switch the ranking depending on types and because of this I need the hologram to be unique.

I tested the placeholders and it seems to be very complex to use them for this case, could you show me an example of how to do this ?

@unldenis
Copy link
Owner

unldenis commented Jun 14, 2022

When a hologram is shown to a player, placeholders are 'called' if present.

This example is quite explanatory, since Java 8 with Lambdas it saves you a lot of boilderplate code.
The AbstractLine#update() method is available to update a hologram line from 1.2.6.

      Hologram hologram = Hologram.builder()
              .location(location)
              .addLine("Statistics", false)
              .addLine("Name: %name%", false)
              .addLine("Kills: %kills%", false)
              .addLine("Points: %points%", false)
              .addPlaceholder("%name%", Player::getName)
              .addPlaceholder("%kills%", player -> {
                  // get player's kills
                  return "0";
              })
              .addPlaceholder("%points%", new Function<Player, String>() {
                  @Override
                  public String apply(Player player) {
                      if(player.getName().equals("Mateus"))
                          return "1K";
                      return "0";
                  }
              })
              .build(hologramPool);

@unldenis unldenis added the documentation Improvements or additions to documentation label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants