Skip to content

Commit

Permalink
PlaceholderManager#setPlaceholders now accepts a string list
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTriassic committed Oct 20, 2024
1 parent 0eb229b commit 5645a11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.stream.Collectors;

public class BossBarDisplay extends Display {

Expand All @@ -29,9 +28,7 @@ public BossBarDisplay(GeyserDebugInfo instance, @NotNull GeyserSession session)
@Override
public void updateDisplay() {
List<String> displayFormat = instance.getConfig().get().getDisplay().getBossBar().getText();
String displayText = displayFormat.stream()
.map(line -> PlaceholderManager.setPlaceholders(session, line))
.collect(Collectors.joining("\n"));
String displayText = String.join("\n", PlaceholderManager.setPlaceholders(session, displayFormat));

bossBar.updateTitle(Component.text(displayText));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.geysermc.geyser.session.GeyserSession;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class PlaceholderManager {

Expand All @@ -20,7 +22,10 @@ public class PlaceholderManager {
* @return The text with placeholders resolved to their respective values.
*/
@NotNull
public static String setPlaceholders(final GeyserSession session, final @NotNull String text) {
public static String setPlaceholders(
final GeyserSession session,
final @NotNull String text
) {
StringBuilder finalResult = new StringBuilder();
int cursor = 0;

Expand Down Expand Up @@ -71,6 +76,22 @@ public static String setPlaceholders(final GeyserSession session, final @NotNull
return finalResult.toString();
}

/**
* Resolves placeholders in the given text based on the provided Geyser session.
* Placeholders should be formatted as %provider_placeholder%.
*
* @param session The Geyser session to retrieve context-specific placeholder values.
* @param text The text containing placeholders to resolve.
* @return The text with placeholders resolved to their respective values.
*/
@NotNull
public static List<String> setPlaceholders(
final GeyserSession session,
final @NotNull List<String> text
) {
return text.stream().map(line -> setPlaceholders(session, line)).collect(Collectors.toList());
}

public void register(PlaceholderProvider provider) {
providers.put(provider.getIdentifier(), provider);
}
Expand Down

0 comments on commit 5645a11

Please sign in to comment.