3333
3434import org .mvplugins .multiverse .core .anchor .AnchorManager ;
3535import org .mvplugins .multiverse .core .anchor .MultiverseAnchor ;
36+ import org .mvplugins .multiverse .core .command .context .issueraware .IssuerAwareValue ;
37+ import org .mvplugins .multiverse .core .command .context .issueraware .MultiverseWorldValue ;
38+ import org .mvplugins .multiverse .core .command .context .issueraware .PlayerArrayValue ;
3639import org .mvplugins .multiverse .core .config .CoreConfig ;
3740import org .mvplugins .multiverse .core .config .node .functions .DefaultSuggesterProvider ;
3841import org .mvplugins .multiverse .core .config .handle .PropertyModifyAction ;
3942import org .mvplugins .multiverse .core .destination .DestinationInstance ;
43+ import org .mvplugins .multiverse .core .destination .DestinationSuggestionPacket ;
4044import org .mvplugins .multiverse .core .destination .DestinationsProvider ;
41- import org .mvplugins .multiverse .core .destination .core .WorldDestination ;
4245import org .mvplugins .multiverse .core .permissions .CorePermissionsChecker ;
4346import org .mvplugins .multiverse .core .utils .REPatterns ;
4447import org .mvplugins .multiverse .core .utils .StringFormatter ;
@@ -129,6 +132,22 @@ private Collection<String> completeWithPreconditions(
129132 if (context .hasConfig ("playerOnly" ) && !context .getIssuer ().isPlayer ()) {
130133 return Collections .emptyList ();
131134 }
135+ if (context .hasConfig ("byIssuerForArg" )) {
136+ Boolean byIssuerForArg = Try .of (() -> context .getContextValueByName (IssuerAwareValue .class , context .getConfig ("byIssuerForArg" )))
137+ .map (IssuerAwareValue ::isByIssuer )
138+ .getOrElse (false );
139+ if (!byIssuerForArg ) {
140+ return Collections .emptyList ();
141+ }
142+ }
143+ if (context .hasConfig ("notByIssuerForArg" )) {
144+ Boolean byIssuerForArg = Try .of (() -> context .getContextValueByName (IssuerAwareValue .class , context .getConfig ("notByIssuerForArg" )))
145+ .map (IssuerAwareValue ::isByIssuer )
146+ .getOrElse (false );
147+ if (byIssuerForArg ) {
148+ return Collections .emptyList ();
149+ }
150+ }
132151 if (context .hasConfig ("resolveUntil" )) {
133152 if (!Try .run (() -> context .getContextValueByName (Object .class , context .getConfig ("resolveUntil" ))).isSuccess ()) {
134153 return Collections .emptyList ();
@@ -195,7 +214,10 @@ private boolean checkPerms(CommandIssuer issuer, RegisteredCommand<?> command) {
195214 }
196215
197216 private Collection <String > suggestDestinations (BukkitCommandCompletionContext context ) {
198- return Try .of (() -> context .getContextValue (Player [].class ))
217+ return Try .of (() -> context .getContextValue (PlayerArrayValue .class ))
218+ .map (PlayerArrayValue ::value )
219+ .recover (IllegalStateException .class , e -> context .getContextValue (Player [].class ))
220+ .recover (IllegalStateException .class , e -> new Player []{context .getContextValue (Player .class )})
199221 .map (players -> {
200222 if (players .length == 0 ) {
201223 // Most likely console did not specify a player
@@ -213,9 +235,7 @@ private Collection<String> suggestDestinationsWithPerms(CommandSender teleporter
213235 return destinationsProvider .suggestDestinations (teleporter , deststring ).stream ()
214236 .filter (packet -> corePermissionsChecker
215237 .checkDestinationPacketPermission (teleporter , Arrays .asList (players ), packet ))
216- .map (packet -> packet .destination () instanceof WorldDestination
217- ? packet .destinationString ()
218- : packet .destination ().getIdentifier () + ":" + packet .destinationString ())
238+ .map (DestinationSuggestionPacket ::parsableString )
219239 .toList ();
220240 }
221241
@@ -248,7 +268,7 @@ private Collection<String> suggestGeneratorPlugins(BukkitCommandCompletionContex
248268 private Collection <String > suggestMVConfigValues (BukkitCommandCompletionContext context ) {
249269 return Try .of (() -> context .getContextValue (String .class ))
250270 .map (propertyName -> config .getStringPropertyHandle ()
251- .getSuggestedPropertyValue (propertyName , context .getInput (), PropertyModifyAction .SET ))
271+ .getSuggestedPropertyValue (propertyName , context .getInput (), PropertyModifyAction .SET , context . getSender () ))
252272 .getOrElse (Collections .emptyList ());
253273 }
254274
@@ -283,18 +303,18 @@ private Collection<String> suggestMVWorlds(BukkitCommandCompletionContext contex
283303
284304 private Collection <String > suggestMVWorldPropsName (BukkitCommandCompletionContext context ) {
285305 return Try .of (() -> {
286- MultiverseWorld world = context .getContextValue (MultiverseWorld .class );
306+ MultiverseWorld world = context .getContextValue (MultiverseWorldValue .class ). value ( );
287307 PropertyModifyAction action = context .getContextValue (PropertyModifyAction .class );
288308 return world .getStringPropertyHandle ().getModifiablePropertyNames (action );
289309 }).getOrElse (Collections .emptyList ());
290310 }
291311
292312 private Collection <String > suggestMVWorldPropsValue (BukkitCommandCompletionContext context ) {
293313 return Try .of (() -> {
294- MultiverseWorld world = context .getContextValue (MultiverseWorld .class );
314+ MultiverseWorld world = context .getContextValue (MultiverseWorldValue .class ). value ( );
295315 PropertyModifyAction action = context .getContextValue (PropertyModifyAction .class );
296316 String propertyName = context .getContextValue (String .class );
297- return world .getStringPropertyHandle ().getSuggestedPropertyValue (propertyName , context .getInput (), action );
317+ return world .getStringPropertyHandle ().getSuggestedPropertyValue (propertyName , context .getInput (), action , context . getSender () );
298318 }).getOrElse (Collections .emptyList ());
299319 }
300320
@@ -335,7 +355,7 @@ private Collection<String> suggestSpawnCategoryPropsValue(BukkitCommandCompletio
335355 return world .getEntitySpawnConfig ()
336356 .getSpawnCategoryConfig (spawnCategory )
337357 .getStringPropertyHandle ()
338- .getSuggestedPropertyValue (propertyName , context .getInput (), action );
358+ .getSuggestedPropertyValue (propertyName , context .getInput (), action , context . getSender () );
339359 }).getOrElse (Collections .emptyList ());
340360 }
341361}
0 commit comments