3838import com .mojang .brigadier .builder .RequiredArgumentBuilder ;
3939import com .mojang .brigadier .context .CommandContext ;
4040import com .mojang .brigadier .tree .LiteralCommandNode ;
41+ import de .bluecolored .bluemap .common .config .ConfigurationException ;
4142import de .bluecolored .bluemap .common .plugin .Plugin ;
4243import de .bluecolored .bluemap .common .plugin .PluginState ;
4344import de .bluecolored .bluemap .common .plugin .text .Text ;
4445import de .bluecolored .bluemap .common .plugin .text .TextColor ;
4546import de .bluecolored .bluemap .common .plugin .text .TextFormat ;
46- import de .bluecolored .bluemap .common .rendermanager .MapPurgeTask ;
47- import de .bluecolored .bluemap .common .rendermanager .MapUpdateTask ;
48- import de .bluecolored .bluemap .common .rendermanager .RenderTask ;
49- import de .bluecolored .bluemap .common .rendermanager .WorldRegionRenderTask ;
47+ import de .bluecolored .bluemap .common .rendermanager .*;
5048import de .bluecolored .bluemap .common .serverinterface .CommandSource ;
5149import de .bluecolored .bluemap .core .BlueMap ;
5250import de .bluecolored .bluemap .core .MinecraftVersion ;
5351import de .bluecolored .bluemap .core .debug .StateDumper ;
5452import de .bluecolored .bluemap .core .logger .Logger ;
5553import de .bluecolored .bluemap .core .map .BmMap ;
5654import de .bluecolored .bluemap .core .map .MapRenderState ;
55+ import de .bluecolored .bluemap .core .storage .Storage ;
5756import de .bluecolored .bluemap .core .world .Block ;
5857import de .bluecolored .bluemap .core .world .World ;
5958
6059import java .io .IOException ;
6160import java .nio .file .Path ;
62- import java .util .ArrayList ;
63- import java .util .Arrays ;
64- import java .util .List ;
65- import java .util .Optional ;
61+ import java .util .*;
6662import java .util .function .Function ;
6763import java .util .function .Predicate ;
6864
@@ -88,26 +84,22 @@ public Commands(Plugin plugin, CommandDispatcher<S> dispatcher, Function<S, Comm
8884
8985 public void init () {
9086 // commands
91- LiteralCommandNode <S > baseCommand =
92- literal ("bluemap" )
87+ LiteralCommandNode <S > baseCommand = literal ("bluemap" )
9388 .requires (requirementsUnloaded ("bluemap.status" ))
9489 .executes (this ::statusCommand )
9590 .build ();
9691
97- LiteralCommandNode <S > versionCommand =
98- literal ("version" )
92+ LiteralCommandNode <S > versionCommand = literal ("version" )
9993 .requires (requirementsUnloaded ("bluemap.version" ))
10094 .executes (this ::versionCommand )
10195 .build ();
10296
103- LiteralCommandNode <S > helpCommand =
104- literal ("help" )
97+ LiteralCommandNode <S > helpCommand = literal ("help" )
10598 .requires (requirementsUnloaded ("bluemap.help" ))
10699 .executes (this ::helpCommand )
107100 .build ();
108101
109- LiteralCommandNode <S > reloadCommand =
110- literal ("reload" )
102+ LiteralCommandNode <S > reloadCommand = literal ("reload" )
111103 .requires (requirementsUnloaded ("bluemap.reload" ))
112104 .executes (context -> this .reloadCommand (context , false ))
113105
@@ -116,8 +108,7 @@ public void init() {
116108
117109 .build ();
118110
119- LiteralCommandNode <S > debugCommand =
120- literal ("debug" )
111+ LiteralCommandNode <S > debugCommand = literal ("debug" )
121112 .requires (requirementsUnloaded ("bluemap.debug" ))
122113
123114 .then (literal ("block" )
@@ -147,31 +138,27 @@ public void init() {
147138
148139 .build ();
149140
150- LiteralCommandNode <S > stopCommand =
151- literal ("stop" )
141+ LiteralCommandNode <S > stopCommand = literal ("stop" )
152142 .requires (requirements ("bluemap.stop" ))
153143 .executes (this ::stopCommand )
154144 .build ();
155145
156- LiteralCommandNode <S > startCommand =
157- literal ("start" )
146+ LiteralCommandNode <S > startCommand = literal ("start" )
158147 .requires (requirements ("bluemap.start" ))
159148 .executes (this ::startCommand )
160149 .build ();
161150
162- LiteralCommandNode <S > freezeCommand =
163- literal ("freeze" )
151+ LiteralCommandNode <S > freezeCommand = literal ("freeze" )
164152 .requires (requirements ("bluemap.freeze" ))
165153 .then (argument ("map" , StringArgumentType .string ()).suggests (new MapSuggestionProvider <>(plugin ))
166154 .executes (this ::freezeCommand ))
167155 .build ();
168156
169- LiteralCommandNode <S > unfreezeCommand =
170- literal ("unfreeze" )
171- .requires (requirements ("bluemap.freeze" ))
172- .then (argument ("map" , StringArgumentType .string ()).suggests (new MapSuggestionProvider <>(plugin ))
173- .executes (this ::unfreezeCommand ))
174- .build ();
157+ LiteralCommandNode <S > unfreezeCommand = literal ("unfreeze" )
158+ .requires (requirements ("bluemap.freeze" ))
159+ .then (argument ("map" , StringArgumentType .string ()).suggests (new MapSuggestionProvider <>(plugin ))
160+ .executes (this ::unfreezeCommand ))
161+ .build ();
175162
176163 LiteralCommandNode <S > forceUpdateCommand =
177164 addRenderArguments (
@@ -187,33 +174,42 @@ public void init() {
187174 this ::updateCommand
188175 ).build ();
189176
190- LiteralCommandNode <S > purgeCommand =
191- literal ("purge" )
192- .requires (requirements ("bluemap.purge" ))
193- .then (argument ("map" , StringArgumentType .string ()).suggests (new MapSuggestionProvider <>(plugin ))
194- .executes (this ::purgeCommand ))
195- .build ();
177+ LiteralCommandNode <S > purgeCommand = literal ("purge" )
178+ .requires (requirements ("bluemap.purge" ))
179+ .then (argument ("map" , StringArgumentType .string ()).suggests (new MapSuggestionProvider <>(plugin ))
180+ .executes (this ::purgeCommand ))
181+ .build ();
196182
197- LiteralCommandNode <S > cancelCommand =
198- literal ("cancel" )
183+ LiteralCommandNode <S > cancelCommand = literal ("cancel" )
199184 .requires (requirements ("bluemap.cancel" ))
200185 .executes (this ::cancelCommand )
201186 .then (argument ("task-ref" , StringArgumentType .string ()).suggests (new TaskRefSuggestionProvider <>(helper ))
202187 .executes (this ::cancelCommand ))
203188 .build ();
204189
205- LiteralCommandNode <S > worldsCommand =
206- literal ("worlds" )
190+ LiteralCommandNode <S > worldsCommand = literal ("worlds" )
207191 .requires (requirements ("bluemap.status" ))
208192 .executes (this ::worldsCommand )
209193 .build ();
210194
211- LiteralCommandNode <S > mapsCommand =
212- literal ("maps" )
195+ LiteralCommandNode <S > mapsCommand = literal ("maps" )
213196 .requires (requirements ("bluemap.status" ))
214197 .executes (this ::mapsCommand )
215198 .build ();
216199
200+ LiteralCommandNode <S > storagesCommand = literal ("storages" )
201+ .requires (requirements ("bluemap.status" ))
202+ .executes (this ::storagesCommand )
203+
204+ .then (argument ("storage" , StringArgumentType .string ()).suggests (new StorageSuggestionProvider <>(plugin ))
205+ .executes (this ::storagesInfoCommand )
206+
207+ .then (literal ("delete" )
208+ .then (argument ("map" , StringArgumentType .string ())
209+ .executes (this ::storagesDeleteMapCommand ))))
210+
211+ .build ();
212+
217213 // command tree
218214 dispatcher .getRoot ().addChild (baseCommand );
219215 baseCommand .addChild (versionCommand );
@@ -230,6 +226,7 @@ public void init() {
230226 baseCommand .addChild (purgeCommand );
231227 baseCommand .addChild (worldsCommand );
232228 baseCommand .addChild (mapsCommand );
229+ baseCommand .addChild (storagesCommand );
233230 }
234231
235232 private <B extends ArgumentBuilder <S , B >> B addRenderArguments (B builder , Command <S > command ) {
@@ -862,4 +859,91 @@ public int mapsCommand(CommandContext<S> context) {
862859 return 1 ;
863860 }
864861
862+ public int storagesCommand (CommandContext <S > context ) {
863+ CommandSource source = commandSourceInterface .apply (context .getSource ());
864+
865+ source .sendMessage (Text .of (TextColor .BLUE , "Storages loaded by BlueMap:" ));
866+ for (var entry : plugin .getBlueMap ().getConfigs ().getStorageConfigs ().entrySet ()) {
867+ source .sendMessage (Text .of (TextColor .GRAY , " - " , TextColor .WHITE , entry .getKey ())
868+ .setHoverText (Text .of (entry .getValue ().getStorageType ().name ()))
869+ .setClickAction (Text .ClickAction .RUN_COMMAND , "/bluemap storages " + entry .getKey ())
870+ );
871+ }
872+
873+ return 1 ;
874+ }
875+
876+ public int storagesInfoCommand (CommandContext <S > context ) {
877+ CommandSource source = commandSourceInterface .apply (context .getSource ());
878+ String storageId = context .getArgument ("storage" , String .class );
879+
880+ Storage storage ;
881+ try {
882+ storage = plugin .getBlueMap ().getStorage (storageId );
883+ } catch (ConfigurationException ex ) {
884+ source .sendMessage (Text .of (TextColor .RED , ex .getMessage ()));
885+ return 0 ;
886+ }
887+
888+ Collection <String > mapIds ;
889+ try {
890+ mapIds = storage .collectMapIds ();
891+ } catch (IOException ex ) {
892+ source .sendMessage (Text .of (TextColor .RED , "There was an unexpected exception trying to access this storage. Please check the console for more details..." ));
893+ Logger .global .logError ("Unexpected exception trying to load mapId's from storage '" + storageId + "'!" , ex );
894+ return 0 ;
895+ }
896+
897+ source .sendMessage (Text .of (TextColor .BLUE , "Storage '" , storageId , "':" ));
898+ if (mapIds .isEmpty ()) {
899+ source .sendMessage (Text .of (TextColor .GRAY , " <empty storage>" ));
900+ } else {
901+ for (String mapId : mapIds ) {
902+ BmMap map = plugin .getMaps ().get (mapId );
903+ boolean isLoaded = map != null && map .getStorage ().equals (storage );
904+
905+ if (isLoaded ) {
906+ source .sendMessage (Text .of (TextColor .GRAY , " - " , TextColor .WHITE , mapId , TextColor .GREEN , TextFormat .ITALIC , " (loaded)" ));
907+ } else {
908+ source .sendMessage (Text .of (TextColor .GRAY , " - " , TextColor .WHITE , mapId , TextColor .DARK_GRAY , TextFormat .ITALIC , " (unloaded/static/remote)" ));
909+ }
910+ }
911+ }
912+
913+ return 1 ;
914+ }
915+
916+ public int storagesDeleteMapCommand (CommandContext <S > context ) {
917+ CommandSource source = commandSourceInterface .apply (context .getSource ());
918+ String storageId = context .getArgument ("storage" , String .class );
919+ String mapId = context .getArgument ("map" , String .class );
920+
921+ Storage storage ;
922+ try {
923+ storage = plugin .getBlueMap ().getStorage (storageId );
924+ } catch (ConfigurationException ex ) {
925+ source .sendMessage (Text .of (TextColor .RED , ex .getMessage ()));
926+ return 0 ;
927+ }
928+
929+ BmMap map = plugin .getMaps ().get (mapId );
930+ boolean isLoaded = map != null && map .getStorage ().equals (storage );
931+ if (isLoaded ) {
932+ Text purgeCommand = Text .of (TextColor .WHITE , "/bluemap purge " + mapId )
933+ .setClickAction (Text .ClickAction .SUGGEST_COMMAND , "/bluemap purge " + mapId );
934+ source .sendMessage (Text .of (TextColor .RED , "Can't delete a loaded map!\n " +
935+ "Unload the map by removing it's config-file first,\n " +
936+ "or use " , purgeCommand , " if you want to purge it." ));
937+ return 0 ;
938+ }
939+
940+ // delete map
941+ StorageDeleteTask deleteTask = new StorageDeleteTask (storage , mapId );
942+
943+ plugin .getRenderManager ().scheduleRenderTaskNext (deleteTask );
944+ source .sendMessage (Text .of (TextColor .GREEN , "Created new Task to delete map '" + mapId + "' from storage '" + storageId + "'" ));
945+
946+ return 1 ;
947+ }
948+
865949}
0 commit comments