Skip to content

Commit 3f577d0

Browse files
authored
feat: add placeholder for multiple owners (#4711)
- closes #4695
1 parent 4d2e4a3 commit 3f577d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
import java.util.Collections;
5050
import java.util.Locale;
5151
import java.util.Map;
52+
import java.util.Set;
5253
import java.util.TimeZone;
5354
import java.util.UUID;
5455
import java.util.concurrent.TimeUnit;
5556
import java.util.function.BiFunction;
57+
import java.util.stream.Collectors;
5658

5759
/**
5860
* Registry that contains {@link Placeholder placeholders}
@@ -127,6 +129,22 @@ private void registerDefault() {
127129
}
128130
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
129131
});
132+
this.createPlaceholder("currentplot_owners", (player, plot) -> {
133+
if (plot.getFlag(ServerPlotFlag.class)) {
134+
return legacyComponent(TranslatableCaption.of("info.server"), player);
135+
}
136+
final Set<UUID> plotOwners = plot.getOwners();
137+
if (plotOwners.isEmpty()) {
138+
return legacyComponent(TranslatableCaption.of("generic.generic_unowned"), player);
139+
}
140+
return plotOwners.stream().map(PlotSquared.platform().playerManager()::getUsernameCaption).map(f -> {
141+
try {
142+
return f.get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS).getComponent(player);
143+
} catch (final Exception ignored) {
144+
return legacyComponent(TranslatableCaption.of("info.unknown"), player);
145+
}
146+
}).collect(Collectors.joining(", "));
147+
});
130148
this.createPlaceholder("currentplot_members", (player, plot) -> {
131149
if (plot.getMembers().isEmpty() && plot.getTrusted().isEmpty()) {
132150
return legacyComponent(TranslatableCaption.of("info.none"), player);

0 commit comments

Comments
 (0)