11package dev .pgm .community .party .feature ;
22
3+ import static dev .pgm .community .party .MapPartyMessages .formatTime ;
34import static dev .pgm .community .utils .PGMUtils .parseMapText ;
45import static net .kyori .adventure .text .Component .text ;
56import static tc .oc .pgm .util .bukkit .BukkitUtils .colorize ;
@@ -137,7 +138,7 @@ public void create(CommandAudience viewer, Player sender, MapPartyPreset preset)
137138 }
138139
139140 if (preset .getDuration () != null ) {
140- setTimelimit (viewer , preset .getDuration ());
141+ setTimelimit (viewer , preset .getDuration (), false );
141142 }
142143
143144 if (type == MapPartyType .REGULAR ) {
@@ -188,10 +189,8 @@ public boolean start(Player sender, boolean delayed) {
188189 }
189190
190191 this .isStartQueued = true ;
191- viewer .sendWarning (
192- text (
193- "Your map party is queued to start after the next match ends!" ,
194- NamedTextColor .GRAY ));
192+ viewer .sendWarning (text (
193+ "Your map party is queued to start after the next match ends!" , NamedTextColor .GRAY ));
195194 return true ;
196195 }
197196
@@ -277,14 +276,46 @@ public void setDescription(CommandAudience viewer, String description) {
277276 .hoverEvent (HoverEvent .showText (text (description , NamedTextColor .GRAY ))));
278277 }
279278
280- public void setTimelimit (CommandAudience viewer , Duration timeLimit ) {
279+ public void setTimelimit (CommandAudience viewer , Duration timeLimit , boolean force ) {
281280 if (isPartyMissing (viewer )) return ;
282281
282+ if (!force
283+ && party .getStartTime () != null
284+ && timeLimit
285+ .minus (Duration .between (party .getStartTime (), Instant .now ()))
286+ .isNegative ()) {
287+ viewer .sendWarning (text ()
288+ .append (text ("Setting the time limit to " ))
289+ .append (duration (timeLimit ).color (NamedTextColor .YELLOW ))
290+ .append (text (" would end the event immediately. Use the force flag to proceed anyways" ))
291+ .color (NamedTextColor .GRAY )
292+ .build ());
293+ return ;
294+ }
295+
283296 party .setLength (timeLimit );
284297 MapPartyMessages .broadcastHostAction (
285298 viewer .getStyledName (),
286299 text ("set the event timelimit to" ),
287300 duration (party .getLength (), NamedTextColor .GREEN ));
301+ if (party .isRunning ()) {
302+ MapPartyMessages .broadcastHostAction (
303+ viewer .getStyledName (),
304+ text ()
305+ .append (text ("The event will now end in " ))
306+ .append (
307+ duration (timeLimit .minus (Duration .between (party .getStartTime (), Instant .now ())))
308+ .color (NamedTextColor .GREEN ))
309+ .color (NamedTextColor .GRAY )
310+ .build ());
311+ ;
312+ }
313+ }
314+
315+ public void extendTimeLimit (CommandAudience viewer , Duration timeToAdd ) {
316+ Duration oldLength = party .getLength ();
317+ Duration newLength = oldLength == null ? timeToAdd : oldLength .plus (timeToAdd );
318+ setTimelimit (viewer , newLength , false );
288319 }
289320
290321 public void toggleMode (CommandAudience viewer ) {
@@ -308,11 +339,10 @@ public void addMap(CommandAudience viewer, MapInfo map) {
308339 if (isRegularParty (viewer )) return ;
309340
310341 if (party .isMapAdded (map )) {
311- viewer .sendWarning (
312- text ()
313- .append (map .getStyledName (MapNameStyle .COLOR ))
314- .append (text (" has already been added!" ))
315- .build ());
342+ viewer .sendWarning (text ()
343+ .append (map .getStyledName (MapNameStyle .COLOR ))
344+ .append (text (" has already been added!" ))
345+ .build ());
316346 return ;
317347 }
318348
@@ -334,11 +364,10 @@ public void removeMap(CommandAudience viewer, MapInfo map) {
334364 if (isRegularParty (viewer )) return ;
335365
336366 if (!(party .isMapAdded (map ))) {
337- viewer .sendWarning (
338- text ()
339- .append (map .getStyledName (MapNameStyle .COLOR ))
340- .append (text (" has not been selected for this map party!" ))
341- .build ());
367+ viewer .sendWarning (text ()
368+ .append (map .getStyledName (MapNameStyle .COLOR ))
369+ .append (text (" has not been selected for this map party!" ))
370+ .build ());
342371 return ;
343372 }
344373
@@ -402,17 +431,15 @@ public void sendPartyWelcome(Player player) {
402431
403432 public String formatLine (String line , MapParty party ) {
404433 return colorize (
405- line .replace ("$name$" , colorize (party .getName ()))
406- .replace ("$time$" , MapPartyMessages .formatTime (party )));
434+ line .replace ("$name$" , colorize (party .getName ())).replace ("$time$" , formatTime (party )));
407435 }
408436
409437 public void setAutoScale (CommandAudience sender , boolean autoscaling ) {
410438 party .setAutoScaling (autoscaling );
411439
412- Component status =
413- text (
414- party .shouldAutoScale () ? "enabled" : "disabled" ,
415- party .shouldAutoScale () ? NamedTextColor .GREEN : NamedTextColor .RED );
440+ Component status = text (
441+ party .shouldAutoScale () ? "enabled" : "disabled" ,
442+ party .shouldAutoScale () ? NamedTextColor .GREEN : NamedTextColor .RED );
416443
417444 MapPartyMessages .broadcastHostAction (
418445 sender .getStyledName (),
@@ -430,17 +457,15 @@ public void toggleMultiplier(CommandAudience sender) {
430457
431458 // Activate asap if party is running, otherwise will be run when event starts
432459 if (getParty ().isRunning ()) {
433- String command =
434- raindropsEnabled
435- ? getEventConfig ().getRaindropActivateCommand ()
436- : getEventConfig ().getRaindropDeactivateCommand ();
460+ String command = raindropsEnabled
461+ ? getEventConfig ().getRaindropActivateCommand ()
462+ : getEventConfig ().getRaindropDeactivateCommand ();
437463 Bukkit .dispatchCommand (Bukkit .getConsoleSender (), command );
438464 }
439465
440- Component status =
441- text (
442- raindropsEnabled ? "enabled" : "disabled" ,
443- raindropsEnabled ? NamedTextColor .GREEN : NamedTextColor .RED );
466+ Component status = text (
467+ raindropsEnabled ? "enabled" : "disabled" ,
468+ raindropsEnabled ? NamedTextColor .GREEN : NamedTextColor .RED );
444469
445470 MapPartyMessages .broadcastHostAction (
446471 sender .getStyledName (),
0 commit comments