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

Reintroduce rot related commands #1094

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 10 additions & 1 deletion core/src/main/java/tc/oc/pgm/api/setting/SettingKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.modules.PlayerTimeMatchModule;
import tc.oc.pgm.util.Aliased;

/**
* A toggleable setting with various possible {@link SettingValue}s.
*
* @see SettingValue
*/
public enum SettingKey {
public enum SettingKey implements Aliased {
CHAT(
"chat",
Material.SIGN,
Expand Down Expand Up @@ -106,6 +109,12 @@ public List<String> getAliases() {
return aliases;
}

@NotNull
@Override
public Iterator<String> iterator() {
return aliases.iterator();
}

/**
* Get a list of the possible {@link SettingValue}s.
*
Expand Down
18 changes: 5 additions & 13 deletions core/src/main/java/tc/oc/pgm/command/ClassCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import static net.kyori.adventure.text.Component.space;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
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.specifier.FlagYielding;
import cloud.commandframework.annotations.specifier.Greedy;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.classes.ClassMatchModule;
import tc.oc.pgm.classes.PlayerClass;
Expand All @@ -23,8 +21,9 @@ public final class ClassCommand {
@CommandMethod("class|selectclass|c|cl [class]")
@CommandDescription("Select your class")
public void classSelect(
Match match, MatchPlayer player, @Argument("class") @FlagYielding PlayerClass newClass) {
final ClassMatchModule classes = getClasses(match);
ClassMatchModule classes,
MatchPlayer player,
@Argument("class") @Greedy PlayerClass newClass) {
final PlayerClass currentClass = classes.getSelectedClass(player.getId());

if (newClass == null) {
Expand All @@ -49,8 +48,7 @@ public void classSelect(

@CommandMethod("classlist|classes|listclasses|cls")
@CommandDescription("List all available classes")
public void classList(Match match, MatchPlayer player) {
final ClassMatchModule classes = getClasses(match);
public void classList(ClassMatchModule classes, MatchPlayer player) {
final PlayerClass currentClass = classes.getSelectedClass(player.getId());

player.sendMessage(
Expand Down Expand Up @@ -83,10 +81,4 @@ public void classList(Match match, MatchPlayer player) {
player.sendMessage(result.build());
}
}

private ClassMatchModule getClasses(Match match) {
final ClassMatchModule classes = match.getModule(ClassMatchModule.class);
if (classes == null) throw exception("match.class.notEnabled");
return classes;
}
}
24 changes: 5 additions & 19 deletions core/src/main/java/tc/oc/pgm/command/FreeForAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
Expand All @@ -11,7 +10,6 @@
import com.google.common.collect.Range;
import net.kyori.adventure.text.format.NamedTextColor;
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.util.text.TextParser;
Expand All @@ -22,8 +20,8 @@ public final class FreeForAllCommand {
@CommandMethod("min <min-players>")
@CommandDescription("Set the min players")
@CommandPermission(Permissions.RESIZE)
public void min(Audience audience, Match match, @Argument("min-players") int minPlayers) {
final FreeForAllMatchModule ffa = getFfa(match);
public void min(
Audience audience, FreeForAllMatchModule ffa, @Argument("min-players") int minPlayers) {
TextParser.assertInRange(minPlayers, Range.atLeast(0));

ffa.setMinPlayers(minPlayers);
Expand All @@ -33,8 +31,7 @@ public void min(Audience audience, Match match, @Argument("min-players") int min
@CommandMethod("min reset")
@CommandDescription("Reset the min players")
@CommandPermission(Permissions.RESIZE)
public void min(Audience audience, Match match) {
final FreeForAllMatchModule ffa = getFfa(match);
public void min(Audience audience, FreeForAllMatchModule ffa) {
ffa.setMinPlayers(null);
sendResizedMessage(audience, "min", ffa.getMinPlayers());
}
Expand All @@ -44,11 +41,9 @@ public void min(Audience audience, Match match) {
@CommandPermission(Permissions.RESIZE)
public void max(
Audience audience,
Match match,
FreeForAllMatchModule ffa,
@Argument("max-players") int maxPlayers,
@Argument("max-overfill") Integer maxOverfill) {
final FreeForAllMatchModule ffa = getFfa(match);

TextParser.assertInRange(maxPlayers, Range.atLeast(ffa.getMinPlayers()));

if (maxOverfill == null) maxOverfill = (int) Math.ceil(1.25 * maxPlayers);
Expand All @@ -62,8 +57,7 @@ public void max(
@CommandMethod("max reset")
@CommandDescription("Reset the max players")
@CommandPermission(Permissions.RESIZE)
public void max(Audience audience, Match match) {
final FreeForAllMatchModule ffa = getFfa(match);
public void max(Audience audience, FreeForAllMatchModule ffa) {
ffa.setMaxPlayers(null, null);
sendResizedMessage(audience, "max", ffa.getMaxPlayers());
}
Expand All @@ -75,12 +69,4 @@ private void sendResizedMessage(Audience audience, String type, int value) {
translatable("match.info.players", NamedTextColor.YELLOW),
text(value, NamedTextColor.AQUA)));
}

private FreeForAllMatchModule getFfa(Match match) {
final FreeForAllMatchModule ffa = match.getModule(FreeForAllMatchModule.class);
if (ffa == null) {
throw exception("command.moduleNotFound", text("free-for-all"));
}
return ffa;
}
}
8 changes: 4 additions & 4 deletions core/src/main/java/tc/oc/pgm/command/InventoryCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.inventory.ViewInventoryMatchModule;

public final class InventoryCommand {
@CommandMethod("inventory|inv|vi <player>")
@CommandDescription("View a player's inventory")
public void inventory(Match match, MatchPlayer viewer, @Argument("player") MatchPlayer holder) {
final ViewInventoryMatchModule inventories = match.needModule(ViewInventoryMatchModule.class);

public void inventory(
ViewInventoryMatchModule inventories,
MatchPlayer viewer,
@Argument("player") MatchPlayer holder) {
if (inventories.canPreviewInventory(viewer, holder)) {
inventories.previewInventory(viewer.getBukkit(), holder.getInventory());
} else {
Expand Down
14 changes: 6 additions & 8 deletions core/src/main/java/tc/oc/pgm/command/JoinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import cloud.commandframework.annotations.Flag;
import cloud.commandframework.annotations.specifier.FlagYielding;
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;
Expand All @@ -19,27 +18,26 @@ public final class JoinCommand {
@CommandDescription("Join the match")
@CommandPermission(Permissions.JOIN)
public void join(
Match match,
JoinMatchModule joiner,
MatchPlayer player,
@Flag(value = "force", aliases = "f") boolean force,
@Argument("team") @FlagYielding Party team) {
if (team != null && !(team instanceof Competitor)) {
leave(player, match);
leave(joiner, player);
return;
}

final JoinMatchModule join = match.needModule(JoinMatchModule.class);
if (force && player.getBukkit().hasPermission(Permissions.JOIN_FORCE)) {
join.forceJoin(player, (Competitor) team);
joiner.forceJoin(player, (Competitor) team);
} else {
join.join(player, (Competitor) team);
joiner.join(player, (Competitor) team);
}
}

@CommandMethod("leave|obs|spectator|spec")
@CommandDescription("Leave the match")
@CommandPermission(Permissions.LEAVE)
public void leave(MatchPlayer player, Match match) {
match.needModule(JoinMatchModule.class).leave(player);
public void leave(JoinMatchModule joiner, MatchPlayer player) {
joiner.leave(player);
}
}
8 changes: 4 additions & 4 deletions core/src/main/java/tc/oc/pgm/command/MapCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ public void map(
if (PGM.get().getMapOrder() instanceof MapPoolManager) {
String mapPools =
((MapPoolManager) PGM.get().getMapOrder())
.getMapPools().stream()
.filter(pool -> pool.getMaps().contains(map))
.map(MapPool::getName)
.collect(Collectors.joining(", "));
.getMapPoolStream()
.filter(pool -> pool.getMaps().contains(map))
.map(MapPool::getName)
.collect(Collectors.joining(", "));
if (!mapPools.isEmpty()) {
audience.sendMessage(
text()
Expand Down
56 changes: 46 additions & 10 deletions core/src/main/java/tc/oc/pgm/command/MapDevCommand.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,65 @@
package tc.oc.pgm.command;

import static net.kyori.adventure.text.Component.text;

import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandDescription;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import org.jetbrains.annotations.NotNull;
import cloud.commandframework.annotations.Flag;
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.player.MatchPlayer;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.util.PrettyPaginatedComponentResults;
import tc.oc.pgm.util.text.TextFormatter;
import tc.oc.pgm.variables.Variable;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static net.kyori.adventure.text.Component.text;
import static tc.oc.pgm.command.util.ParserConstants.CURRENT;

public class MapDevCommand {

@CommandMethod("variables [target]")
@CommandMethod("variables [target] [page]")
@CommandDescription("Inspect variables for a player")
@CommandPermission(Permissions.DEBUG)
public void showVariables(
Match match, @NotNull MatchPlayer sender, @Argument("target") MatchPlayer target) {
MatchPlayer filterable = target == null ? sender : target;
Audience audience,
CommandSender sender,
Match match,
@Argument(value = "target", defaultValue = CURRENT) MatchPlayer target,
@Argument(value = "page", defaultValue = "1") int page,
@Flag(value = "query", aliases = "q") String query,
@Flag(value = "all", aliases = "a") boolean all) {

List<Variable<?>> variables = match.getFeatureContext().getAll()
.stream()
.filter(Variable.class::isInstance)
.map(v -> (Variable<?>) v)
.filter(v -> query == null || v.getId().contains(query))
.sorted(Comparator.comparing(Variable::getId))
.collect(Collectors.toList());


int resultsPerPage = all ? variables.size() : 8;
int pages = all ? 1 : (variables.size() + resultsPerPage - 1) / resultsPerPage;

Component title =
TextFormatter.paginate(
text("Variables for ").append(target.getName()),
page,
pages,
NamedTextColor.DARK_AQUA,
NamedTextColor.AQUA,
true);
Component header = TextFormatter.horizontalLineHeading(sender, title, NamedTextColor.BLUE);

sender.sendMessage(text("Showing variables for " + filterable.getNameLegacy() + ":"));
for (Variable<?> v : match.getFeatureContext().getAll(Variable.class)) {
sender.sendMessage(text(v.getId() + ": " + v.getValue(filterable)));
}
PrettyPaginatedComponentResults.display(audience, variables, page, resultsPerPage, header,
(v, i) -> text().append(text(v.getId() + ": ", NamedTextColor.AQUA), text(v.getValue(target))));
}
}
Loading