1313import io .github .md5sha256 .realty .command .util .DurationParser ;
1414import io .github .md5sha256 .realty .command .util .SubregionLandlordUpdater ;
1515import io .github .md5sha256 .realty .command .util .WorldGuardRegion ;
16- import io .github .md5sha256 .realty .command .util .WorldGuardRegionParser ;
1716import io .github .md5sha256 .realty .command .util .WorldGuardRegionResolver ;
1817import io .github .md5sha256 .realty .database .RealtyLogicImpl ;
1918import io .github .md5sha256 .realty .database .RealtyLogicImpl .CreateAuctionResult ;
@@ -83,7 +82,7 @@ public record AuctionCommandGroup(
8382 .required ("paymentDuration" , DurationParser .duration ())
8483 .required ("minBid" , DoubleParser .doubleParser (0 ))
8584 .required ("minBidStep" , DoubleParser .doubleParser (0 ))
86- .required ("region" , WorldGuardRegionParser . worldGuardRegion ())
85+ .optional ("region" , WorldGuardRegionResolver . worldGuardRegionResolver ())
8786 .handler (this ::executeCreate )
8887 .build (),
8988 base .literal ("cancel" )
@@ -94,13 +93,13 @@ public record AuctionCommandGroup(
9493 base .literal ("bid" )
9594 .permission ("realty.command.auction.bid" )
9695 .required ("bid" , DoubleParser .doubleParser (0 ))
97- .required ("region" , WorldGuardRegionParser . worldGuardRegion ())
96+ .optional ("region" , WorldGuardRegionResolver . worldGuardRegionResolver ())
9897 .handler (this ::executeBid )
9998 .build (),
10099 base .literal ("paybid" )
101100 .permission ("realty.command.auction.paybid" )
102101 .required ("amount" , DoubleParser .doubleParser (0 , Double .MAX_VALUE ))
103- .required ("region" , WorldGuardRegionParser . worldGuardRegion ())
102+ .optional ("region" , WorldGuardRegionResolver . worldGuardRegionResolver ())
104103 .handler (this ::executePayBid )
105104 .build ()
106105 );
@@ -110,11 +109,9 @@ public record AuctionCommandGroup(
110109
111110 private void executeInfo (@ NotNull CommandContext <CommandSourceStack > ctx ) {
112111 CommandSender sender = ctx .sender ().getSender ();
113- if (!(sender instanceof Player player )) {
114- return ;
115- }
116112 WorldGuardRegion region = ctx .<WorldGuardRegion >optional ("region" )
117- .orElseGet (() -> WorldGuardRegionResolver .resolveAtLocation (player .getLocation ()));
113+ .orElseGet (() -> sender instanceof Player player
114+ ? WorldGuardRegionResolver .resolveAtLocation (player .getLocation ()) : null );
118115 if (region == null ) {
119116 sender .sendMessage (messages .messageFor (MessageKeys .ERROR_NO_REGION ));
120117 return ;
@@ -171,13 +168,19 @@ private void executeInfo(@NotNull CommandContext<CommandSourceStack> ctx) {
171168 private void executeCreate (@ NotNull CommandContext <CommandSourceStack > ctx ) {
172169 CommandSender sender = ctx .sender ().getSender ();
173170 if (!(sender instanceof Player player )) {
171+ sender .sendMessage (messages .messageFor (MessageKeys .COMMON_PLAYERS_ONLY ));
174172 return ;
175173 }
176174 Duration bidDuration = ctx .get ("bidDuration" );
177175 Duration paymentDuration = ctx .get ("paymentDuration" );
178176 double minBid = ctx .get ("minBid" );
179177 double minBidStep = ctx .get ("minBidStep" );
180- WorldGuardRegion region = ctx .get ("region" );
178+ WorldGuardRegion region = ctx .<WorldGuardRegion >optional ("region" )
179+ .orElseGet (() -> WorldGuardRegionResolver .resolveAtLocation (player .getLocation ()));
180+ if (region == null ) {
181+ sender .sendMessage (messages .messageFor (MessageKeys .ERROR_NO_REGION ));
182+ return ;
183+ }
181184 String regionId = region .region ().getId ();
182185 CompletableFuture .runAsync (() -> {
183186 try {
@@ -211,11 +214,10 @@ private void executeCreate(@NotNull CommandContext<CommandSourceStack> ctx) {
211214 // ── /realty auction cancel [region] ──
212215
213216 private void executeCancel (@ NotNull CommandContext <CommandSourceStack > ctx ) {
214- if (!(ctx .sender ().getSender () instanceof Player sender )) {
215- return ;
216- }
217+ CommandSender sender = ctx .sender ().getSender ();
217218 WorldGuardRegion region = ctx .<WorldGuardRegion >optional ("region" )
218- .orElseGet (() -> WorldGuardRegionResolver .resolveAtLocation (sender .getLocation ()));
219+ .orElseGet (() -> sender instanceof Player player
220+ ? WorldGuardRegionResolver .resolveAtLocation (player .getLocation ()) : null );
219221 if (region == null ) {
220222 sender .sendMessage (messages .messageFor (MessageKeys .ERROR_NO_REGION ));
221223 return ;
@@ -246,10 +248,16 @@ private void executeCancel(@NotNull CommandContext<CommandSourceStack> ctx) {
246248
247249 private void executeBid (@ NotNull CommandContext <CommandSourceStack > ctx ) {
248250 if (!(ctx .sender ().getSender () instanceof Player sender )) {
251+ ctx .sender ().getSender ().sendMessage (messages .messageFor (MessageKeys .COMMON_PLAYERS_ONLY ));
249252 return ;
250253 }
251254 double bidAmount = ctx .<Double >get ("bid" );
252- WorldGuardRegion region = ctx .get ("region" );
255+ WorldGuardRegion region = ctx .<WorldGuardRegion >optional ("region" )
256+ .orElseGet (() -> WorldGuardRegionResolver .resolveAtLocation (sender .getLocation ()));
257+ if (region == null ) {
258+ sender .sendMessage (messages .messageFor (MessageKeys .ERROR_NO_REGION ));
259+ return ;
260+ }
253261 String regionId = region .region ().getId ();
254262 CompletableFuture .runAsync (() -> {
255263 try {
@@ -296,7 +304,12 @@ private void executePayBid(@NotNull CommandContext<CommandSourceStack> ctx) {
296304 return ;
297305 }
298306 double amount = ctx .get ("amount" );
299- WorldGuardRegion region = ctx .get ("region" );
307+ WorldGuardRegion region = ctx .<WorldGuardRegion >optional ("region" )
308+ .orElseGet (() -> WorldGuardRegionResolver .resolveAtLocation (sender .getLocation ()));
309+ if (region == null ) {
310+ sender .sendMessage (messages .messageFor (MessageKeys .ERROR_NO_REGION ));
311+ return ;
312+ }
300313 String regionId = region .region ().getId ();
301314 // Balance check on main thread
302315 double balance = economy .getBalance (sender );
0 commit comments