Skip to content

Commit bf0c7d0

Browse files
committed
Map Party timelimit command improvements
Signed-off-by: Christopher White <[email protected]>
1 parent 2f1401a commit bf0c7d0

File tree

2 files changed

+88
-57
lines changed

2 files changed

+88
-57
lines changed

core/src/main/java/dev/pgm/community/party/MapPartyCommands.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import net.kyori.adventure.text.format.NamedTextColor;
1919
import org.bukkit.entity.Player;
2020
import tc.oc.pgm.api.map.MapInfo;
21+
import tc.oc.pgm.lib.org.incendo.cloud.annotation.specifier.FlagYielding;
2122
import tc.oc.pgm.lib.org.incendo.cloud.annotation.specifier.Greedy;
2223
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Argument;
2324
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Command;
2425
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Default;
26+
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Flag;
2527
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Permission;
2628
import tc.oc.pgm.util.named.NameStyle;
2729

@@ -118,8 +120,17 @@ public void setPartyDesc(CommandAudience viewer, @Argument("desc") @Greedy Strin
118120

119121
@Command("timelimit <duration>")
120122
@Permission(CommunityPermissions.PARTY_HOST)
121-
public void setTimeLimit(CommandAudience viewer, @Argument("duration") Duration timeLimit) {
122-
party.setTimelimit(viewer, timeLimit);
123+
public void setTimeLimit(
124+
CommandAudience viewer,
125+
@Argument("duration") @FlagYielding Duration timeLimit,
126+
@Flag(value = "force", aliases = "f") boolean force) {
127+
party.setTimelimit(viewer, timeLimit, force);
128+
}
129+
130+
@Command("extend <duration>")
131+
@Permission(CommunityPermissions.PARTY_HOST)
132+
public void extendTimeLimit(CommandAudience viewer, @Argument("duration") Duration timeLimit) {
133+
party.extendTimeLimit(viewer, timeLimit);
123134
}
124135

125136
@Command("mode")
@@ -160,21 +171,18 @@ public void addHost(CommandAudience viewer, @Argument("targets") String targets)
160171
if (isPartyMissing(viewer)) return;
161172
MapPartyHosts hosts = party.getParty().getHosts();
162173
PlayerSelection selection = getPlayers(viewer, targets);
163-
selection
164-
.getPlayers()
165-
.forEach(
166-
player -> {
167-
if (!party.canHost(player)) {
168-
viewer.sendWarning(MapPartyMessages.getAddHostError(player));
169-
return;
170-
}
171-
172-
if (hosts.isHost(player.getUniqueId())) {
173-
viewer.sendWarning(MapPartyMessages.getExistingHostError(player));
174-
return;
175-
}
176-
hosts.addSubHost(player);
177-
});
174+
selection.getPlayers().forEach(player -> {
175+
if (!party.canHost(player)) {
176+
viewer.sendWarning(MapPartyMessages.getAddHostError(player));
177+
return;
178+
}
179+
180+
if (hosts.isHost(player.getUniqueId())) {
181+
viewer.sendWarning(MapPartyMessages.getExistingHostError(player));
182+
return;
183+
}
184+
hosts.addSubHost(player);
185+
});
178186
}
179187

180188
@Command("hosts remove <target>")
@@ -183,11 +191,10 @@ public void removeHost(CommandAudience viewer, @Argument("target") TargetPlayer
183191
if (isPartyMissing(viewer)) return;
184192
MapPartyHosts hosts = party.getParty().getHosts();
185193
if (!hosts.removeSubHost(target.getIdentifier())) {
186-
viewer.sendWarning(
187-
text()
188-
.append(text(target.getIdentifier(), NamedTextColor.DARK_AQUA))
189-
.append(text(" is not a party host"))
190-
.build());
194+
viewer.sendWarning(text()
195+
.append(text(target.getIdentifier(), NamedTextColor.DARK_AQUA))
196+
.append(text(" is not a party host"))
197+
.build());
191198
}
192199
}
193200

@@ -204,11 +211,10 @@ public void transferHost(CommandAudience viewer, @Argument("target") Player targ
204211
}
205212

206213
if (hosts.isMainHost(target.getUniqueId())) {
207-
viewer.sendWarning(
208-
text()
209-
.append(player(target, NameStyle.FANCY))
210-
.append(text(" is already the main party host"))
211-
.build());
214+
viewer.sendWarning(text()
215+
.append(player(target, NameStyle.FANCY))
216+
.append(text(" is already the main party host"))
217+
.build());
212218
return;
213219
}
214220

core/src/main/java/dev/pgm/community/party/feature/MapPartyFeature.java

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.pgm.community.party.feature;
22

3+
import static dev.pgm.community.party.MapPartyMessages.formatTime;
34
import static dev.pgm.community.utils.PGMUtils.parseMapText;
45
import static net.kyori.adventure.text.Component.text;
56
import 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

Comments
 (0)