Skip to content

Commit

Permalink
Add team scale command & add admin chat feedback for other commands
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 committed Sep 23, 2023
1 parent f9da16d commit a9f0d6d
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 60 deletions.
11 changes: 9 additions & 2 deletions core/src/main/java/tc/oc/pgm/command/CancelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.listeners.ChatDispatcher;
import tc.oc.pgm.restart.CancelRestartEvent;
import tc.oc.pgm.restart.RestartManager;
import tc.oc.pgm.start.StartMatchModule;
import tc.oc.pgm.timelimit.TimeLimitCountdown;
import tc.oc.pgm.timelimit.TimeLimitMatchModule;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.player.PlayerComponent;

public final class CancelCommand {

@CommandMethod("cancel|cancelrestart|cr")
@CommandDescription("Cancels all countdowns")
@CommandPermission(Permissions.STOP)
public void cancel(Audience audience, Match match) {
public void cancel(CommandSender sender, Audience audience, Match match) {
if (RestartManager.isQueued()) {
match.callEvent(new CancelRestartEvent());
audience.sendMessage(translatable("admin.cancelRestart.restartUnqueued", NamedTextColor.RED));
Expand All @@ -35,6 +39,9 @@ public void cancel(Audience audience, Match match) {

match.getCountdown().cancelAll();
match.needModule(StartMatchModule.class).setAutoStart(false);
audience.sendMessage(translatable("admin.cancelCountdowns", NamedTextColor.GREEN));
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"admin.cancelCountdowns.announce", PlayerComponent.player(sender, NameStyle.FANCY)),
match);
}
}
51 changes: 38 additions & 13 deletions core/src/main/java/tc/oc/pgm/command/FreeForAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import cloud.commandframework.annotations.CommandPermission;
import com.google.common.collect.Range;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.ffa.FreeForAllMatchModule;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.listeners.ChatDispatcher;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.player.PlayerComponent;
import tc.oc.pgm.util.text.TextParser;

@CommandMethod("ffa|players")
Expand All @@ -21,26 +25,45 @@ public final class FreeForAllCommand {
@CommandDescription("Set the min players")
@CommandPermission(Permissions.RESIZE)
public void min(
Audience audience, FreeForAllMatchModule ffa, @Argument("min-players") int minPlayers) {
Match match,
CommandSender sender,
FreeForAllMatchModule ffa,
@Argument("min-players") int minPlayers) {
TextParser.assertInRange(minPlayers, Range.atLeast(0));

ffa.setMinPlayers(minPlayers);
sendResizedMessage(audience, "min", ffa.getMinPlayers());
sendResizedMessage(match, sender, "min", ffa.getMinPlayers());
}

@CommandMethod("min reset")
@CommandDescription("Reset the min players")
@CommandPermission(Permissions.RESIZE)
public void min(Audience audience, FreeForAllMatchModule ffa) {
public void min(Match match, CommandSender sender, FreeForAllMatchModule ffa) {
ffa.setMinPlayers(null);
sendResizedMessage(audience, "min", ffa.getMinPlayers());
sendResizedMessage(match, sender, "min", ffa.getMinPlayers());
}

@CommandMethod("scale <factor>")
@CommandDescription("Scale the max players by a given factor")
@CommandPermission(Permissions.RESIZE)
public void max(
Match match,
CommandSender sender,
FreeForAllMatchModule ffa,
@Argument("factor") double scale) {
int maxOverfill = (int) (ffa.getMaxOverfill() * scale);
int maxSize = (int) (ffa.getMaxPlayers() * scale);
ffa.setMaxPlayers(maxSize, maxOverfill);

sendResizedMessage(match, sender, "max", ffa.getMaxPlayers());
}

@CommandMethod("max <max-players> [max-overfill]")
@CommandDescription("Set the max players")
@CommandPermission(Permissions.RESIZE)
public void max(
Audience audience,
Match match,
CommandSender sender,
FreeForAllMatchModule ffa,
@Argument("max-players") int maxPlayers,
@Argument("max-overfill") Integer maxOverfill) {
Expand All @@ -51,22 +74,24 @@ public void max(

ffa.setMaxPlayers(maxPlayers, maxOverfill);

sendResizedMessage(audience, "max", ffa.getMaxPlayers());
sendResizedMessage(match, sender, "max", ffa.getMaxPlayers());
}

@CommandMethod("max reset")
@CommandDescription("Reset the max players")
@CommandPermission(Permissions.RESIZE)
public void max(Audience audience, FreeForAllMatchModule ffa) {
public void max(Match match, CommandSender sender, FreeForAllMatchModule ffa) {
ffa.setMaxPlayers(null, null);
sendResizedMessage(audience, "max", ffa.getMaxPlayers());
sendResizedMessage(match, sender, "max", ffa.getMaxPlayers());
}

private void sendResizedMessage(Audience audience, String type, int value) {
audience.sendMessage(
private void sendResizedMessage(Match match, CommandSender sender, String type, int value) {
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize." + type,
"match.resize.announce." + type,
PlayerComponent.player(sender, NameStyle.FANCY),
translatable("match.info.players", NamedTextColor.YELLOW),
text(value, NamedTextColor.AQUA)));
text(value, NamedTextColor.AQUA)),
match);
}
}
13 changes: 13 additions & 0 deletions core/src/main/java/tc/oc/pgm/command/StartCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import java.time.Duration;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.listeners.ChatDispatcher;
import tc.oc.pgm.start.StartCountdown;
import tc.oc.pgm.start.StartMatchModule;
import tc.oc.pgm.start.UnreadyReason;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.player.PlayerComponent;
import tc.oc.pgm.util.text.TemporalComponent;

public final class StartCommand {

Expand All @@ -22,6 +28,7 @@ public final class StartCommand {
@CommandPermission(Permissions.START)
public void start(
Audience audience,
CommandSender sender,
Match match,
StartMatchModule start,
@Argument("duration") Duration duration) {
Expand All @@ -41,5 +48,11 @@ public void start(

match.getCountdown().cancelAll(StartCountdown.class);
start.forceStartCountdown(duration, null);
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"admin.start.announce",
PlayerComponent.player(sender, NameStyle.FANCY),
TemporalComponent.duration(duration, NamedTextColor.AQUA)),
match);
}
}
100 changes: 78 additions & 22 deletions core/src/main/java/tc/oc/pgm/command/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.party.Competitor;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.join.JoinMatchModule;
import tc.oc.pgm.join.JoinRequest;
import tc.oc.pgm.listeners.ChatDispatcher;
import tc.oc.pgm.teams.Team;
import tc.oc.pgm.teams.TeamMatchModule;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.player.PlayerComponent;
import tc.oc.pgm.util.text.TextParser;

@CommandMethod("team")
Expand All @@ -37,7 +39,7 @@ public final class TeamCommand {
@CommandDescription("Force a player onto a team")
@CommandPermission(Permissions.JOIN_FORCE)
public void force(
MatchPlayer sender,
CommandSender sender,
JoinMatchModule join,
@Argument("player") MatchPlayer joiner,
@Argument("team") Party team) {
Expand All @@ -49,21 +51,25 @@ public void force(
} else {
join.forceJoin(joiner, (Competitor) team);
}

sender.sendMessage(
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"join.ok.force",
NamedTextColor.GRAY,
"join.ok.force.announce",
PlayerComponent.player(sender, NameStyle.FANCY),
joiner.getName(NameStyle.FANCY),
joiner.getParty().getName(),
oldParty.getName()));
oldParty.getName()),
joiner.getMatch());
}

@CommandMethod("shuffle")
@CommandDescription("Shuffle players among the teams")
@CommandPermission(Permissions.JOIN_FORCE)
public void shuffle(
Match match, TeamMatchModule teams, @Flag("a") boolean all, @Flag("f") boolean force) {
Match match,
CommandSender sender,
TeamMatchModule teams,
@Flag("a") boolean all,
@Flag("f") boolean force) {
if (match.isRunning() && !force) {
throw exception("match.shuffle.err");
}
Expand All @@ -74,14 +80,17 @@ public void shuffle(
teams.forceJoin(player, null);
}

match.sendMessage(translatable("match.shuffle.ok", NamedTextColor.GREEN));
ChatDispatcher.broadcastAdminChatMessage(
translatable("match.shuffle.announce.ok", PlayerComponent.player(sender, NameStyle.FANCY)),
match);
}

@CommandMethod("alias <team> <name>")
@CommandDescription("Rename a team")
@CommandPermission(Permissions.GAMEPLAY)
public void alias(
Match match,
CommandSender sender,
TeamMatchModule teams,
@Argument("team") Team team,
@Argument("name") @Greedy String name) {
Expand All @@ -98,14 +107,44 @@ public void alias(
final Component oldName = team.getName().color(NamedTextColor.GRAY);
team.setName(name);

match.sendMessage(translatable("match.alias.ok", oldName, team.getName()));
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.alias.announce.ok",
PlayerComponent.player(sender, NameStyle.FANCY),
oldName,
team.getName()),
match);
}

@CommandMethod("scale <teams> <factor>")
@CommandDescription("Resizes all teams by a given factor")
@CommandPermission(Permissions.RESIZE)
public void scale(
CommandSender sender,
Match match,
@Argument("teams") Collection<Team> teams,
@Argument("factor") double scale) {
for (Team team : teams) {
int maxOverfill = (int) (team.getMaxOverfill() * scale);
int maxSize = (int) (team.getMaxPlayers() * scale);
team.setMaxSize(maxSize, maxOverfill);

ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize.announce.max",
PlayerComponent.player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}

@CommandMethod("size <teams> <max-players> [max-overfill]")
@CommandDescription("Set the max players on a team")
@CommandPermission(Permissions.RESIZE)
public void max(
Audience audience,
CommandSender sender,
Match match,
@Argument("teams") Collection<Team> teams,
@Argument("max-players") int maxPlayers,
@Argument("max-overfill") Integer maxOverfill) {
Expand All @@ -116,49 +155,66 @@ public void max(
else TextParser.assertInRange(maxOverfill, Range.atLeast(maxPlayers));

team.setMaxSize(maxPlayers, maxOverfill);
audience.sendMessage(
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize.max", team.getName(), text(team.getMaxPlayers(), NamedTextColor.AQUA)));
"match.resize.announce.max",
PlayerComponent.player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}

@CommandMethod("size <teams> reset")
@CommandDescription("Reset the max players on a team")
@CommandPermission(Permissions.RESIZE)
public void max(Audience audience, @Argument("teams") Collection<Team> teams) {
public void max(CommandSender sender, Match match, @Argument("teams") Collection<Team> teams) {
for (Team team : teams) {
team.resetMaxSize();
audience.sendMessage(
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize.max", team.getName(), text(team.getMaxPlayers(), NamedTextColor.AQUA)));
"match.resize.announce.max",
PlayerComponent.player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}

@CommandMethod("min <teams> <min-players>")
@CommandDescription("Set the min players on a team")
@CommandPermission(Permissions.RESIZE)
public void min(
Audience audience,
CommandSender sender,
Match match,
@Argument("teams") Collection<Team> teams,
@Argument("min-players") int minPlayers) {
TextParser.assertInRange(minPlayers, Range.atLeast(0));
for (Team team : teams) {
team.setMinSize(minPlayers);
audience.sendMessage(
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize.min", team.getName(), text(team.getMinPlayers(), NamedTextColor.AQUA)));
"match.resize.announce.min",
PlayerComponent.player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}

@CommandMethod("min <teams> reset")
@CommandDescription("Reset the min players on a team")
@CommandPermission(Permissions.RESIZE)
public void min(Audience audience, @Argument("teams") Collection<Team> teams) {
public void min(CommandSender sender, Match match, @Argument("teams") Collection<Team> teams) {
for (Team team : teams) {
team.resetMinSize();
audience.sendMessage(
ChatDispatcher.broadcastAdminChatMessage(
translatable(
"match.resize.min", team.getName(), text(team.getMinPlayers(), NamedTextColor.AQUA)));
"match.resize.announce.min",
PlayerComponent.player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}
}
Loading

0 comments on commit a9f0d6d

Please sign in to comment.