Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add team scale command & add admin chat feedback for other commands #1247

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/src/main/java/tc/oc/pgm/command/CancelCommand.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package tc.oc.pgm.command;

import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.player.PlayerComponent.player;

import cloud.commandframework.annotations.CommandDescription;
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;

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,7 @@ 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", 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 @@ -2,16 +2,20 @@

import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.player.PlayerComponent.player;

import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
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.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,
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
@@ -1,19 +1,25 @@
package tc.oc.pgm.command;

import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.player.PlayerComponent.player;
import static tc.oc.pgm.util.text.TemporalComponent.duration;
import static tc.oc.pgm.util.text.TextException.exception;

import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
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;

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",
player(sender, NameStyle.FANCY),
duration(duration, NamedTextColor.AQUA)),
match);
}
}
96 changes: 74 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 @@ -2,6 +2,7 @@

import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.player.PlayerComponent.player;
import static tc.oc.pgm.util.text.TextException.exception;

import cloud.commandframework.annotations.Argument;
Expand All @@ -17,16 +18,17 @@
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.text.TextParser;

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",
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,16 @@ public void shuffle(
teams.forceJoin(player, null);
}

match.sendMessage(translatable("match.shuffle.ok", NamedTextColor.GREEN));
ChatDispatcher.broadcastAdminChatMessage(
translatable("match.shuffle.announce.ok", 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 +106,41 @@ 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", 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",
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 +151,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",
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",
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",
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",
player(sender, NameStyle.FANCY),
team.getName(),
text(team.getMaxPlayers(), NamedTextColor.AQUA)),
match);
}
}
}
Loading