1
1
package world .bentobox .aoneblock ;
2
2
3
3
import java .util .Objects ;
4
+ import java .util .Set ;
4
5
import java .util .TreeMap ;
6
+ import java .util .stream .Collectors ;
7
+
8
+ import org .bukkit .Material ;
5
9
6
10
import world .bentobox .aoneblock .dataobjects .OneBlockIslands ;
11
+ import world .bentobox .bentobox .api .localization .TextVariables ;
7
12
import world .bentobox .bentobox .api .user .User ;
8
13
import world .bentobox .bentobox .database .objects .Island ;
14
+ import world .bentobox .bentobox .hooks .LangUtilsHook ;
15
+ import world .bentobox .bentobox .util .Util ;
9
16
10
17
public class AOneBlockPlaceholders {
11
18
@@ -46,6 +53,53 @@ public AOneBlockPlaceholders(AOneBlock addon,
46
53
// Since 1.10
47
54
placeholdersManager .registerPlaceholder (addon , "visited_island_lifetime_count" , this ::getLifetimeByLocation );
48
55
placeholdersManager .registerPlaceholder (addon , "my_island_lifetime_count" , this ::getLifetime );
56
+
57
+ placeholdersManager .registerPlaceholder (addon , "visited_island_phase_block_list" ,
58
+ this ::getPhaseBlocksNamesByLocation );
59
+ placeholdersManager .registerPlaceholder (addon , "my_island_phase_block_list" , this ::getPhaseBlocksNames );
60
+
61
+ }
62
+
63
+ public String getPhaseBlocksNames (User user ) {
64
+ if (user == null || user .getUniqueId () == null )
65
+ return "" ;
66
+ Island i = addon .getIslands ().getIsland (addon .getOverWorld (), user );
67
+ if (i == null ) {
68
+ return "" ;
69
+ }
70
+ return getPhaseBlocksForIsland (user , i );
71
+ }
72
+
73
+ private String getPhaseBlocksForIsland (User user , Island i ) {
74
+ String phaseName = addon .getOneBlocksIsland (i ).getPhaseName ();
75
+ Set <Material > set = addon .getOneBlockManager ().getPhase (phaseName ).map (phase -> phase .getBlocks ().keySet ())
76
+ .orElse (null );
77
+ if (set == null ) {
78
+ return "" ;
79
+ }
80
+
81
+ String result = set .stream ().map (m -> getMaterialName (user , m ))
82
+ .map (string -> user .getTranslation ("aoneblock.placeholders.block-list-format" , TextVariables .NAME ,
83
+ string ))
84
+ .collect (Collectors .joining ());
85
+ // Removing the last newline character or comma if it exists
86
+ if (result .endsWith ("\n " ) || result .endsWith ("," )) {
87
+ result = result .substring (0 , result .length () - 1 );
88
+ }
89
+
90
+ return result ;
91
+
92
+ }
93
+
94
+ private String getMaterialName (User user , Material m ) {
95
+ return addon .getPlugin ().getHooks ().getHook ("LangUtils" ).map (hook -> LangUtilsHook .getMaterialName (m , user ))
96
+ .orElse (Util .prettifyText (m .name ()));
97
+ }
98
+
99
+ public String getPhaseBlocksNamesByLocation (User user ) {
100
+ if (user == null || user .getUniqueId () == null || !addon .inWorld (user .getWorld ()))
101
+ return "" ;
102
+ return addon .getIslands ().getIslandAt (user .getLocation ()).map (i -> getPhaseBlocksForIsland (user , i )).orElse ("" );
49
103
}
50
104
51
105
/**
@@ -68,7 +122,7 @@ public String getPhaseByLocation(User user) {
68
122
* @return String of count
69
123
*/
70
124
public String getCountByLocation (User user ) {
71
- if (user == null || user .getUniqueId () == null )
125
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
72
126
return "" ;
73
127
return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
74
128
.map (addon ::getOneBlocksIsland ).map (OneBlockIslands ::getBlockNumber ).map (String ::valueOf ).orElse ("" );
@@ -107,7 +161,7 @@ public String getCount(User user) {
107
161
* @return next phase
108
162
*/
109
163
public String getNextPhaseByLocation (User user ) {
110
- if (user == null || user .getUniqueId () == null )
164
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
111
165
return "" ;
112
166
return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
113
167
.map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhase ).orElse ("" );
@@ -133,7 +187,7 @@ public String getNextPhase(User user) {
133
187
* @return string number of blocks
134
188
*/
135
189
public String getNextPhaseBlocksByLocation (User user ) {
136
- if (user == null || user .getUniqueId () == null )
190
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
137
191
return "" ;
138
192
return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
139
193
.map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhaseBlocks )
@@ -181,7 +235,7 @@ public String getPhaseBlocks(User user) {
181
235
* @return string percentage
182
236
*/
183
237
public String getPercentDoneByLocation (User user ) {
184
- if (user == null || user .getUniqueId () == null )
238
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
185
239
return "" ;
186
240
return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
187
241
.map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -212,7 +266,7 @@ public String getPercentDone(User user) {
212
266
* @return colored scale
213
267
*/
214
268
public String getDoneScaleByLocation (User user ) {
215
- if (user == null || user .getUniqueId () == null )
269
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
216
270
return "" ;
217
271
return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
218
272
.map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -259,7 +313,7 @@ public String getLifetime(User user) {
259
313
* @return String of Lifetime
260
314
*/
261
315
public String getLifetimeByLocation (User user ) {
262
- if (user == null || user .getUniqueId () == null )
316
+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
263
317
return "" ;
264
318
265
319
return this .addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
0 commit comments