66package org .royaldev .royalcommands .rcommands ;
77
88import org .bukkit .Material ;
9- import org .bukkit .World ;
10- import org .bukkit .command .Command ;
119import org .bukkit .command .CommandSender ;
1210import org .bukkit .entity .Player ;
1311import org .bukkit .inventory .ItemStack ;
1412import org .bukkit .inventory .meta .MapMeta ;
1513import org .bukkit .map .MapView ;
16- import org .bukkit .map .MapView .Scale ;
1714import org .royaldev .royalcommands .MessageColor ;
18- import org .royaldev .royalcommands .RUtils ;
1915import org .royaldev .royalcommands .RoyalCommands ;
20-
21- import java .util .ArrayList ;
22- import java .util .Arrays ;
23- import java .util .List ;
16+ import org .royaldev .royalcommands .rcommands .map .SCmdInfo ;
17+ import org .royaldev .royalcommands .rcommands .map .SCmdLock ;
18+ import org .royaldev .royalcommands .rcommands .map .SCmdPosition ;
19+ import org .royaldev .royalcommands .rcommands .map .SCmdScale ;
20+ import org .royaldev .royalcommands .rcommands .map .SCmdTrack ;
21+ import org .royaldev .royalcommands .rcommands .map .SCmdUnlimited ;
22+ import org .royaldev .royalcommands .rcommands .map .SCmdWorld ;
2423
2524@ ReflectCommand
26- public class CmdMap extends TabCommand {
25+ public class CmdMap extends ParentCommand {
2726
2827 public CmdMap (final RoyalCommands instance , final String name ) {
29- super (instance , name , true , new Short []{CompletionType .LIST .getShort (), CompletionType .CUSTOM .getShort ()});
30- }
31-
32- @ Override
33- protected List <String > customList (final CommandSender cs , final Command cmd , final String label , final String [] args , final String arg ) {
34- return new ArrayList <>(Arrays .asList (
35- "setlock" , "locked" , "lock" ,
36- "scale" , "scaling" , "setscale" , "setscaling" ,
37- "track" , "tracking" ,
38- "unlimited" , "unlimit" ,
39- "reposition" , "position" , "pos" , "repos" , "setposition" , "setpos" , "coords" , "coordinates" , "setcoords" , "setcoordinates" ,
40- "world" , "setworld" ,
41- "info" ,
42- "help" , "?"
43- ));
28+ super (instance , name , true );
29+ this .addSubCommand (new SCmdScale (this .plugin , this ));
30+ this .addSubCommand (new SCmdInfo (this .plugin , this ));
31+ this .addSubCommand (new SCmdLock (this .plugin , this ));
32+ this .addSubCommand (new SCmdPosition (this .plugin , this ));
33+ this .addSubCommand (new SCmdTrack (this .plugin , this ));
34+ this .addSubCommand (new SCmdUnlimited (this .plugin , this ));
35+ this .addSubCommand (new SCmdWorld (this .plugin , this ));
4436 }
4537
46- @ Override
47- protected Scale [] customEnum (final CommandSender cs , final Command cmd , final String label , final String [] args , final String arg ) {
48- return Scale .values ();
49- }
50-
51- @ Override
52- protected List <String > getCustomCompletions (final CommandSender cs , final Command cmd , final String label , final String [] args , final String arg ) {
53- if (cs instanceof Player ) {
54- Player p = (Player ) cs ;
55- /**
56- * TODO: Depending on the first parameter, either show numbers, the user's current coordinates, or a list of worlds
57- */
58- switch (args [0 ]) {
59- case "scale" :
60- case "scaling" :
61- case "setscale" :
62- case "setscaling" :
63- return getCompletionsFor (cs , cmd , label , args , CompletionType .ENUM );
64- case "reposition" :
65- case "position" :
66- case "pos" :
67- case "repos" :
68- case "setposition" :
69- case "setpos" :
70- case "coords" :
71- case "coordinates" :
72- case "setcoords" :
73- case "setcoordinates" :
74- return new ArrayList <>(Arrays .asList (
75- p .getLocation ().getBlockX () + " " + p .getLocation ().getBlockZ (),
76- p .getWorld ().getSpawnLocation ().getBlockX () + " " + p .getWorld ().getSpawnLocation ().getBlockZ ()
77- ));
78- case "world" :
79- case "setworld" :
80- return getCompletionsFor (cs , cmd , label , args , CompletionType .WORLD );
81- }
82- return new ArrayList <>();
83- }
84- return new ArrayList <>();
85- }
86-
87- private String combineEnums (Enum [] es ) {
38+ public String combineEnums (Enum [] es ) {
8839 StringBuilder sb = new StringBuilder ();
8940 for (Enum e : es ) {
9041 sb .append (MessageColor .NEUTRAL );
@@ -95,154 +46,27 @@ private String combineEnums(Enum[] es) {
9546 return sb .substring (0 , sb .length () - 4 );
9647 }
9748
98- private boolean subcommandMatches (String subcommand , String ... matchAgainst ) {
99- for (String aMatchAgainst : matchAgainst ) if (subcommand .equalsIgnoreCase (aMatchAgainst )) return true ;
100- return false ;
101- }
102-
103- private void updateMap (Player p , MapView mv ) {
49+ public void updateMap (Player p , MapView mv ) {
10450 p .sendMap (mv );
10551 }
10652
107- @ Override
108- public boolean runCommand (final CommandSender cs , final Command cmd , final String label , final String [] args , CommandArguments ca ) {
53+ public ItemStack isMap (final CommandSender cs ) {
10954 if (!(cs instanceof Player )) {
11055 cs .sendMessage (MessageColor .NEGATIVE + "This command is only available to players!" );
111- return true ;
56+ return null ;
11257 }
11358 Player p = (Player ) cs ;
114- if (args .length < 1 ) {
115- cs .sendMessage (cmd .getDescription ());
116- return false ;
117- }
118- String subcommand = args [0 ].toLowerCase ();
119- if (subcommandMatches (subcommand , "help" , "?" )) {
120- cs .sendMessage (MessageColor .NEUTRAL + "/" + label + MessageColor .POSITIVE + " help:" );
121- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " scale [scaletype]" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Sets the scale of the map in hand." );
122- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " position [x] [z]" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Sets the center position of the map in hand." );
123- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " lock" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Sets the lock status of the map in hand." );
124- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " tracking" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Sets if tracking should be used on the map in hand." );
125- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " unlimited" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Sets if unlimited tracking should be used on the map in hand." );
126- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " world [world]" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Changes the world displayed by the map in hand." );
127- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " info" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Displays information about the map in hand." );
128- cs .sendMessage (" " + MessageColor .POSITIVE + "/" + label + MessageColor .NEUTRAL + " help" + MessageColor .POSITIVE + " - " + MessageColor .NEUTRAL + "Displays this help." );
129- //cs.sendMessage(" " + MessageColor.POSITIVE + "/" + label + MessageColor.NEUTRAL + " subcommand" + MessageColor.POSITIVE + " - " + MessageColor.NEUTRAL + "Description");
130- return true ;
131- }
13259 ItemStack hand = p .getInventory ().getItemInMainHand ();
13360 if (hand == null || hand .getType () != Material .FILLED_MAP ) {
134- cs .sendMessage (MessageColor .NEGATIVE + "You must be holding a filled map to use this subcommand !" );
135- return true ;
61+ cs .sendMessage (MessageColor .NEGATIVE + "You must be holding a filled map!" );
62+ return null ;
13663 }
13764 MapMeta mapMeta = (MapMeta ) hand .getItemMeta ();
13865 MapView mv = mapMeta .getMapView ();
13966 if (mv == null ) {
14067 cs .sendMessage (MessageColor .NEGATIVE + "This map seems to be corrupted/invalid." );
141- return true ;
142- }
143- if (subcommandMatches (subcommand , "scale" , "scaling" , "setscale" , "setscaling" )) {
144- if (args .length < 2 ) {
145- cs .sendMessage (combineEnums (Scale .values ()));
146- cs .sendMessage (MessageColor .NEGATIVE + "Please specify a scale." );
147- return true ;
148- }
149- String sscale = args [1 ].toUpperCase ();
150- Scale mvs ;
151- try {
152- mvs = Scale .valueOf (sscale );
153- } catch (IllegalArgumentException e ) {
154- cs .sendMessage (combineEnums (Scale .values ()));
155- cs .sendMessage (MessageColor .NEGATIVE + "Invalid scale type." );
156- return true ;
157- }
158- mv .setScale (mvs );
159- updateMap (p , mv );
160- p .getInventory ().setItemInMainHand (hand );
161- cs .sendMessage (MessageColor .POSITIVE + "Set the scale of map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " to " + MessageColor .NEUTRAL + mvs .name ().toLowerCase ().replace ("_" , " " ) + MessageColor .POSITIVE + "." );
162- return true ;
163- } else if (subcommandMatches (subcommand , "reposition" , "position" , "pos" , "repos" , "setposition" , "setpos" , "coords" , "coordinates" , "setcoords" , "setcoordinates" )) {
164- if (args .length < 3 ) {
165- cs .sendMessage (MessageColor .NEGATIVE + "Please specify the new X and Z coordinates for the center of the map." );
166- return true ;
167- }
168- int x , z ;
169- try {
170- x = Integer .parseInt (args [1 ]);
171- z = Integer .parseInt (args [2 ]);
172- } catch (NumberFormatException e ) {
173- cs .sendMessage (MessageColor .NEGATIVE + "Those coordinates were invalid!" );
174- return true ;
175- }
176- mv .setCenterX (x );
177- mv .setCenterZ (z );
178- updateMap (p , mv );
179- p .getInventory ().setItemInMainHand (hand );
180- cs .sendMessage (MessageColor .POSITIVE + "Set the center of map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " to " + MessageColor .NEUTRAL + x + MessageColor .POSITIVE + ", " + MessageColor .NEUTRAL + z + MessageColor .POSITIVE + "." );
181- return true ;
182- } else if (subcommandMatches (subcommand , "world" , "setworld" )) {
183- if (args .length < 2 ) {
184- cs .sendMessage (MessageColor .NEGATIVE + "Specify the world to set this map to." );
185- return true ;
186- }
187- String sworld = args [1 ];
188- World w = this .plugin .getServer ().getWorld (sworld );
189- if (w == null ) {
190- cs .sendMessage (MessageColor .NEGATIVE + "No such world!" );
191- return true ;
192- }
193- mv .setWorld (w );
194- updateMap (p , mv );
195- p .getInventory ().setItemInMainHand (hand );
196- cs .sendMessage (MessageColor .POSITIVE + "Set the world of map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " to " + MessageColor .NEUTRAL + RUtils .getMVWorldName (w ) + MessageColor .POSITIVE + "." );
197- return true ;
198- } else if (subcommandMatches (subcommand , "info" , "getinfo" , "information" , "getinformation" )) {
199- cs .sendMessage (MessageColor .POSITIVE + "Information about map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + ":" );
200- cs .sendMessage (" " + MessageColor .POSITIVE + "Center coordinates: " + MessageColor .NEUTRAL + mv .getCenterX () + MessageColor .POSITIVE + ", " + MessageColor .NEUTRAL + mv .getCenterZ ());
201- cs .sendMessage (" " + MessageColor .POSITIVE + "World: " + MessageColor .NEUTRAL + RUtils .getMVWorldName (mv .getWorld ()));
202- cs .sendMessage (" " + MessageColor .POSITIVE + "Scale: " + MessageColor .NEUTRAL + RUtils .getFriendlyEnumName (mv .getScale ()));
203- cs .sendMessage (" " + MessageColor .POSITIVE + "Lock: " + MessageColor .NEUTRAL + mv .isLocked ());
204- cs .sendMessage (" " + MessageColor .POSITIVE + "Tracking: " + MessageColor .NEUTRAL + mv .isTrackingPosition ());
205- cs .sendMessage (" " + MessageColor .POSITIVE + "Unlimited Tracking: " + MessageColor .NEUTRAL + mv .isUnlimitedTracking ());
206- //cs.sendMessage(" " + MessageColor.POSITIVE + "Char: " + MessageColor.NEUTRAL + "stuff");
207- return true ;
208- } else if (subcommandMatches (subcommand , "render" , "fullrender" )) {
209- return true ;
210- } else if (subcommandMatches (subcommand , "lock" , "locked" , "setlock" )) {
211- if (!mv .isLocked ()) {
212- mv .setLocked (true );
213- cs .sendMessage (MessageColor .POSITIVE + "Map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " set to locked." );
214- } else {
215- mv .setLocked (false );
216- cs .sendMessage (MessageColor .POSITIVE + "Map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " set to unlocked." );
217- }
218- updateMap (p , mv );
219- p .getInventory ().setItemInMainHand (hand );
220- return true ;
221- } else if (subcommandMatches (subcommand , "track" , "tracking" )) {
222- if (!mv .isTrackingPosition ()) {
223- mv .setTrackingPosition (true );
224- cs .sendMessage (MessageColor .POSITIVE + "Tracking for map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " enabled." );
225- } else {
226- mv .setTrackingPosition (false );
227- cs .sendMessage (MessageColor .POSITIVE + "Tracking for map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " disabled" );
228- }
229- updateMap (p , mv );
230- p .getInventory ().setItemInMainHand (hand );
231- return true ;
232- } else if (subcommandMatches (subcommand , "unlimit" , "unlimited" )) {
233- if (!mv .isUnlimitedTracking ()) {
234- mv .setUnlimitedTracking (true );
235- cs .sendMessage (MessageColor .POSITIVE + "Unlimited tracking for map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " enabled." );
236- } else {
237- mv .setUnlimitedTracking (false );
238- cs .sendMessage (MessageColor .POSITIVE + "Unlimited tracking for map " + MessageColor .NEUTRAL + mv .getId () + MessageColor .POSITIVE + " disabled." );
239- }
240- updateMap (p , mv );
241- p .getInventory ().setItemInMainHand (hand );
242- return true ;
243- } else {
244- cs .sendMessage (MessageColor .NEGATIVE + "Unknown subcommand. Try " + MessageColor .NEUTRAL + "/" + label + " help" + MessageColor .NEGATIVE + "." );
245- return true ;
68+ return null ;
24669 }
70+ return hand ;
24771 }
24872}
0 commit comments