3737import de .bluecolored .bluemap .common .rendermanager .StorageDeleteTask ;
3838import de .bluecolored .bluemap .common .serverinterface .CommandSource ;
3939import de .bluecolored .bluemap .core .map .BmMap ;
40- import de .bluecolored .bluemap .core .storage .MapStorage ;
4140import de .bluecolored .bluemap .core .storage .Storage ;
4241import de .bluecolored .bluemap .core .storage .file .FileStorage ;
4342import lombok .RequiredArgsConstructor ;
4443import net .kyori .adventure .text .Component ;
45- import net .kyori .adventure .text .event .ClickEvent ;
46- import net .kyori .adventure .text .format .TextDecoration ;
4744
4845import java .io .IOException ;
4946import java .util .LinkedList ;
@@ -84,14 +81,8 @@ private Component formatStorageEntry(String id, StorageConfig storage, boolean l
8481 public Component storage (CommandSource source , @ Argument ("storage" ) @ Parser ("storage-id" ) String storageId )
8582 throws ConfigurationException , InterruptedException , IOException {
8683
87- Map <String , Storage > loadedStorages = plugin .getBlueMap ().getLoadedStorages ();
88- Storage storage = loadedStorages .get (storageId );
8984 StorageConfig storageConfig = plugin .getBlueMap ().getConfig ().getStorageConfigs ().get (storageId );
90-
91- if (storage == null ) {
92- source .sendMessage (format ("Initializing storage '%'..." , storageId ).color (BASE_COLOR ));
93- storage = plugin .getBlueMap ().getOrLoadStorage (storageId );
94- }
85+ Storage storage = getOrLoadStorage (storageId , source );
9586
9687 List <Component > lines = new LinkedList <>();
9788
@@ -124,41 +115,22 @@ public Component storage(CommandSource source, @Argument("storage") @Parser("sto
124115 lines .add (text ("Maps:" ).color (BASE_COLOR ));
125116 storage .mapIds ()
126117 .limit (20 )
127- .map (this :: formatMapEntry )
118+ .map (mapId -> formatMapEntry ( mapId , storage ) )
128119 .forEach (lines ::add );
129120
130121 return paragraph ("Storage '%s'" .formatted (storageId ), lines (lines ));
131122 }
132123
133- private Component formatMapEntry (String id ) {
134- BmMap map = plugin .getBlueMap ().getMaps ().get (id );
135-
136- Component loadedIcon = map != null ?
137- text ("✔" ).color (POSITIVE_COLOR ):
138- text ("❌" ).color (BASE_COLOR );
139-
140- return format ("% %" ,
141- loadedIcon ,
142- text (id ).color (HIGHLIGHT_COLOR )
143- ).color (BASE_COLOR );
144- }
145-
146124 @ Command ("storages <storage> delete <map>" )
147125 @ Permission ("bluemap.storages.delete" )
148126 public void deleteMap (
149127 CommandSource source ,
150128 @ Argument ("storage" ) @ Parser ("storage-id" ) String storageId ,
151129 @ Argument ("map" ) String mapId
152130 ) throws ConfigurationException , InterruptedException {
153- Map <String , Storage > loadedStorages = plugin .getBlueMap ().getLoadedStorages ();
154- Storage storage = loadedStorages .get (storageId );
155-
156- if (storage == null ) {
157- source .sendMessage (format ("Initializing storage %..." , storageId ).color (BASE_COLOR ));
158- storage = plugin .getBlueMap ().getOrLoadStorage (storageId );
159- }
131+ Storage storage = getOrLoadStorage (storageId , source );
160132
161- if (plugin . getBlueMap (). getMaps (). containsKey ( mapId )) {
133+ if (isMapLoaded ( mapId , storage )) {
162134 source .sendMessage (text ("Can't delete a loaded map!" ).color (NEGATIVE_COLOR )
163135 .append (format ("""
164136 Unload the map by removing it's config-file first,
@@ -183,4 +155,29 @@ public void deleteMap(
183155 ));
184156 }
185157
158+ private Storage getOrLoadStorage (String storageId , CommandSource source ) throws ConfigurationException , InterruptedException {
159+ Map <String , Storage > loadedStorages = plugin .getBlueMap ().getLoadedStorages ();
160+ Storage storage = loadedStorages .get (storageId );
161+ if (storage != null ) return storage ;
162+
163+ source .sendMessage (format ("Initializing storage '%'..." , storageId ).color (BASE_COLOR ));
164+ return plugin .getBlueMap ().getOrLoadStorage (storageId );
165+ }
166+
167+ private boolean isMapLoaded (String mapId , Storage storage ) {
168+ BmMap map = plugin .getBlueMap ().getMaps ().get (mapId );
169+ return map != null && map .getStorage ().equals (storage .map (mapId ));
170+ }
171+
172+ private Component formatMapEntry (String id , Storage storage ) {
173+ Component loadedIcon = isMapLoaded (id , storage ) ?
174+ text ("✔" ).color (POSITIVE_COLOR ):
175+ text ("❌" ).color (BASE_COLOR );
176+
177+ return format ("% %" ,
178+ loadedIcon ,
179+ text (id ).color (HIGHLIGHT_COLOR )
180+ ).color (BASE_COLOR );
181+ }
182+
186183}
0 commit comments