Skip to content

Commit 4e092a9

Browse files
Add support for short world notation in placeholders (#4819)
1 parent e33e0ef commit 4e092a9

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/PAPIPlaceholders.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public String onPlaceholderRequest(Player p, String identifier) {
7171
return "";
7272
}
7373

74+
if (identifier.equals("this")) {
75+
identifier = pl.getLocation().getWorldName();
76+
}
77+
7478
return pl.getPlotCount(identifier) > 0 ?
7579
PlaceholderAPIPlugin.booleanTrue() :
7680
PlaceholderAPIPlugin.booleanFalse();
@@ -82,6 +86,10 @@ public String onPlaceholderRequest(Player p, String identifier) {
8286
return "";
8387
}
8488

89+
if (identifier.equals("this")) {
90+
identifier = pl.getLocation().getWorldName();
91+
}
92+
8593
return String.valueOf(pl.getPlotCount(identifier));
8694
}
8795

@@ -91,6 +99,10 @@ public String onPlaceholderRequest(Player p, String identifier) {
9199
return "";
92100
}
93101

102+
if (identifier.equals("this")) {
103+
identifier = pl.getLocation().getWorldName();
104+
}
105+
94106
return String.valueOf(PlotQuery.newQuery()
95107
.ownedBy(pl)
96108
.inWorld(identifier)
@@ -99,6 +111,39 @@ public String onPlaceholderRequest(Player p, String identifier) {
99111
.count());
100112
}
101113

114+
if (identifier.startsWith("server_plot_count_")) {
115+
identifier = identifier.substring("server_plot_count_".length());
116+
if (identifier.isEmpty()) {
117+
return "";
118+
}
119+
120+
if (identifier.equals("this")) {
121+
identifier = pl.getLocation().getWorldName();
122+
}
123+
124+
return String.valueOf(PlotQuery.newQuery()
125+
.allPlots()
126+
.inWorld(identifier)
127+
.count());
128+
}
129+
130+
if (identifier.startsWith("server_base_plot_count_")) {
131+
identifier = identifier.substring("server_base_plot_count_".length());
132+
if (identifier.isEmpty()) {
133+
return "";
134+
}
135+
136+
if (identifier.equals("this")) {
137+
identifier = pl.getLocation().getWorldName();
138+
}
139+
140+
return String.valueOf(PlotQuery.newQuery()
141+
.allPlots()
142+
.inWorld(identifier)
143+
.whereBasePlot()
144+
.count());
145+
}
146+
102147
// PlotSquared placeholders
103148
return PlotSquared.platform().placeholderRegistry().getPlaceholderValue(identifier, pl);
104149
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ private void registerDefault() {
225225
return Integer.toString(metaDataAccess.get().orElse(0));
226226
}
227227
});
228+
this.createPlaceholder("server_plot_count", player -> Integer.toString(PlotQuery.newQuery()
229+
.allPlots()
230+
.count())
231+
);
232+
this.createPlaceholder("server_base_plot_count", player -> Integer.toString(PlotQuery.newQuery()
233+
.allPlots()
234+
.whereBasePlot()
235+
.count())
236+
);
228237
}
229238

230239
/**

0 commit comments

Comments
 (0)