11package world .bentobox .aoneblock ;
22
33import java .util .Objects ;
4+ import java .util .Set ;
45import java .util .TreeMap ;
6+ import java .util .stream .Collectors ;
7+
8+ import org .bukkit .Material ;
59
610import world .bentobox .aoneblock .dataobjects .OneBlockIslands ;
11+ import world .bentobox .bentobox .api .localization .TextVariables ;
712import world .bentobox .bentobox .api .user .User ;
813import world .bentobox .bentobox .database .objects .Island ;
14+ import world .bentobox .bentobox .hooks .LangUtilsHook ;
15+ import world .bentobox .bentobox .util .Util ;
916
1017public class AOneBlockPlaceholders {
1118
@@ -46,6 +53,53 @@ public AOneBlockPlaceholders(AOneBlock addon,
4653 // Since 1.10
4754 placeholdersManager .registerPlaceholder (addon , "visited_island_lifetime_count" , this ::getLifetimeByLocation );
4855 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 ("" );
49103 }
50104
51105 /**
@@ -68,7 +122,7 @@ public String getPhaseByLocation(User user) {
68122 * @return String of count
69123 */
70124 public String getCountByLocation (User user ) {
71- if (user == null || user .getUniqueId () == null )
125+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
72126 return "" ;
73127 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
74128 .map (addon ::getOneBlocksIsland ).map (OneBlockIslands ::getBlockNumber ).map (String ::valueOf ).orElse ("" );
@@ -107,7 +161,7 @@ public String getCount(User user) {
107161 * @return next phase
108162 */
109163 public String getNextPhaseByLocation (User user ) {
110- if (user == null || user .getUniqueId () == null )
164+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
111165 return "" ;
112166 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
113167 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhase ).orElse ("" );
@@ -133,7 +187,7 @@ public String getNextPhase(User user) {
133187 * @return string number of blocks
134188 */
135189 public String getNextPhaseBlocksByLocation (User user ) {
136- if (user == null || user .getUniqueId () == null )
190+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
137191 return "" ;
138192 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
139193 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhaseBlocks )
@@ -181,7 +235,7 @@ public String getPhaseBlocks(User user) {
181235 * @return string percentage
182236 */
183237 public String getPercentDoneByLocation (User user ) {
184- if (user == null || user .getUniqueId () == null )
238+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
185239 return "" ;
186240 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
187241 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -212,7 +266,7 @@ public String getPercentDone(User user) {
212266 * @return colored scale
213267 */
214268 public String getDoneScaleByLocation (User user ) {
215- if (user == null || user .getUniqueId () == null )
269+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
216270 return "" ;
217271 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
218272 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -259,7 +313,7 @@ public String getLifetime(User user) {
259313 * @return String of Lifetime
260314 */
261315 public String getLifetimeByLocation (User user ) {
262- if (user == null || user .getUniqueId () == null )
316+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
263317 return "" ;
264318
265319 return this .addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
0 commit comments