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 .aoneblock .panels .PhasesPanel ;
12+ import world .bentobox .bentobox .api .localization .TextVariables ;
713import world .bentobox .bentobox .api .user .User ;
814import world .bentobox .bentobox .database .objects .Island ;
15+ import world .bentobox .bentobox .hooks .LangUtilsHook ;
16+ import world .bentobox .bentobox .util .Util ;
917
1018public class AOneBlockPlaceholders {
1119
@@ -46,6 +54,54 @@ public AOneBlockPlaceholders(AOneBlock addon,
4654 // Since 1.10
4755 placeholdersManager .registerPlaceholder (addon , "visited_island_lifetime_count" , this ::getLifetimeByLocation );
4856 placeholdersManager .registerPlaceholder (addon , "my_island_lifetime_count" , this ::getLifetime );
57+
58+ placeholdersManager .registerPlaceholder (addon , "visited_island_phase_block_list" ,
59+ this ::getPhaseBlocksNamesByLocation );
60+ placeholdersManager .registerPlaceholder (addon , "my_island_phase_block_list" , this ::getPhaseBlocksNames );
61+
62+ }
63+
64+ public String getPhaseBlocksNames (User user ) {
65+ if (user == null || user .getUniqueId () == null )
66+ return "" ;
67+ Island i = addon .getIslands ().getIsland (addon .getOverWorld (), user );
68+ if (i == null ) {
69+ return "" ;
70+ }
71+ return getPhaseBlocksForIsland (user , i );
72+ }
73+
74+ private String getPhaseBlocksForIsland (User user , Island i ) {
75+ String phaseName = addon .getOneBlocksIsland (i ).getPhaseName ();
76+ Set <Material > set = addon .getOneBlockManager ().getPhase (phaseName ).map (phase -> phase .getBlocks ().keySet ())
77+ .orElse (null );
78+ if (set == null ) {
79+ return "" ;
80+ }
81+
82+ String result = set .stream ().map (m -> getMaterialName (user , m ))
83+ .map (string -> user .getTranslation (PhasesPanel .REFERENCE + "blocks" , TextVariables .NAME ,
84+ string ))
85+ .collect (Collectors .joining ());
86+ // Removing the last newline character or comma if it exists
87+ result = result .trim ();
88+ if (result .endsWith ("\n " ) || result .endsWith ("," )) {
89+ result = result .substring (0 , result .length () - 1 );
90+ }
91+
92+ return result ;
93+
94+ }
95+
96+ private String getMaterialName (User user , Material m ) {
97+ return addon .getPlugin ().getHooks ().getHook ("LangUtils" ).map (hook -> LangUtilsHook .getMaterialName (m , user ))
98+ .orElse (Util .prettifyText (m .name ()));
99+ }
100+
101+ public String getPhaseBlocksNamesByLocation (User user ) {
102+ if (user == null || user .getUniqueId () == null || !addon .inWorld (user .getWorld ()))
103+ return "" ;
104+ return addon .getIslands ().getIslandAt (user .getLocation ()).map (i -> getPhaseBlocksForIsland (user , i )).orElse ("" );
49105 }
50106
51107 /**
@@ -68,7 +124,7 @@ public String getPhaseByLocation(User user) {
68124 * @return String of count
69125 */
70126 public String getCountByLocation (User user ) {
71- if (user == null || user .getUniqueId () == null )
127+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
72128 return "" ;
73129 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
74130 .map (addon ::getOneBlocksIsland ).map (OneBlockIslands ::getBlockNumber ).map (String ::valueOf ).orElse ("" );
@@ -107,7 +163,7 @@ public String getCount(User user) {
107163 * @return next phase
108164 */
109165 public String getNextPhaseByLocation (User user ) {
110- if (user == null || user .getUniqueId () == null )
166+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
111167 return "" ;
112168 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
113169 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhase ).orElse ("" );
@@ -133,7 +189,7 @@ public String getNextPhase(User user) {
133189 * @return string number of blocks
134190 */
135191 public String getNextPhaseBlocksByLocation (User user ) {
136- if (user == null || user .getUniqueId () == null )
192+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
137193 return "" ;
138194 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
139195 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getNextPhaseBlocks )
@@ -181,7 +237,7 @@ public String getPhaseBlocks(User user) {
181237 * @return string percentage
182238 */
183239 public String getPercentDoneByLocation (User user ) {
184- if (user == null || user .getUniqueId () == null )
240+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
185241 return "" ;
186242 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
187243 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -212,7 +268,7 @@ public String getPercentDone(User user) {
212268 * @return colored scale
213269 */
214270 public String getDoneScaleByLocation (User user ) {
215- if (user == null || user .getUniqueId () == null )
271+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
216272 return "" ;
217273 return addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
218274 .map (addon ::getOneBlocksIsland ).map (addon .getOneBlockManager ()::getPercentageDone )
@@ -259,7 +315,7 @@ public String getLifetime(User user) {
259315 * @return String of Lifetime
260316 */
261317 public String getLifetimeByLocation (User user ) {
262- if (user == null || user .getUniqueId () == null )
318+ if (user == null || user .getUniqueId () == null || ! addon . inWorld ( user . getWorld ()) )
263319 return "" ;
264320
265321 return this .addon .getIslands ().getProtectedIslandAt (Objects .requireNonNull (user .getLocation ()))
0 commit comments