Skip to content

Commit f5696b7

Browse files
authored
feat: add a placeholder to provide the absolute plot's x/y (#4741)
1 parent 9ed0c7f commit f5696b7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ private void registerDefault() {
204204
this.createPlaceholder("currentplot_x", (player, plot) -> Integer.toString(plot.getId().getX()));
205205
this.createPlaceholder("currentplot_y", (player, plot) -> Integer.toString(plot.getId().getY()));
206206
this.createPlaceholder("currentplot_xy", (player, plot) -> plot.getId().toString());
207+
this.createPlaceholder("currentplot_abs_x", (player, plot) -> Integer.toString(plot.getId().getX()), true);
208+
this.createPlaceholder("currentplot_abs_y", (player, plot) -> Integer.toString(plot.getId().getY()), true);
209+
this.createPlaceholder("currentplot_abs_xy", (player, plot) -> plot.getId().toString(), true);
207210
this.createPlaceholder("currentplot_rating", (player, plot) -> {
208211
if (Double.isNaN(plot.getAverageRating())) {
209212
return legacyComponent(TranslatableCaption.of("placeholder.nan"), player);
@@ -253,7 +256,23 @@ public void createPlaceholder(
253256
final @NonNull String key,
254257
final @NonNull BiFunction<PlotPlayer<?>, Plot, String> placeholderFunction
255258
) {
256-
this.registerPlaceholder(new PlotSpecificPlaceholder(key) {
259+
this.createPlaceholder(key, placeholderFunction, false);
260+
}
261+
262+
/**
263+
* Create a functional placeholder
264+
*
265+
* @param key Placeholder key
266+
* @param placeholderFunction Placeholder generator. Cannot return null
267+
* @param requireAbsolute If the plot given to the placeholder should be the absolute (not base) plot
268+
* @since TODO
269+
*/
270+
public void createPlaceholder(
271+
final @NonNull String key,
272+
final @NonNull BiFunction<PlotPlayer<?>, Plot, String> placeholderFunction,
273+
final boolean requireAbsolute
274+
) {
275+
this.registerPlaceholder(new PlotSpecificPlaceholder(key, requireAbsolute) {
257276
@Override
258277
public @NonNull String getValue(final @NonNull PlotPlayer<?> player, final @NonNull Plot plot) {
259278
return placeholderFunction.apply(player, plot);

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,28 @@
2727
*/
2828
public abstract class PlotSpecificPlaceholder extends Placeholder {
2929

30+
private final boolean requireAbsolute;
31+
3032
public PlotSpecificPlaceholder(final @NonNull String key) {
33+
this(key, false);
34+
}
35+
36+
/**
37+
* Create a functional placeholder
38+
*
39+
* @param key Placeholder key
40+
* @param requireAbsolute If the plot given to the placeholder should be the absolute (not base) plot
41+
* @since TODO
42+
*/
43+
public PlotSpecificPlaceholder(final @NonNull String key, final boolean requireAbsolute) {
3144
super(key);
45+
this.requireAbsolute = requireAbsolute;
3246
}
3347

3448
@Override
3549
public @NonNull
3650
final String getValue(final @NonNull PlotPlayer<?> player) {
37-
final Plot plot = player.getCurrentPlot();
51+
final Plot plot = requireAbsolute ? player.getLocation().getPlotAbs() : player.getCurrentPlot();
3852
if (plot == null) {
3953
return "";
4054
}

0 commit comments

Comments
 (0)