8000 Reintroduce map phase XML tag by applenick · Pull Request #891 · PGMDev/PGM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Reintroduce map phase XML tag #891

New issue

Have a question about this project? Sign up for 8000 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

Merged
merged 3 commits into from
Jun 20, 2021
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
7 changes: 7 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/map/MapInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ default String getStyledNameLegacy(MapNameStyle style, @Nullable CommandSender s
*/
WorldInfo getWorld();

/**
* Get the {@link Phase} for the map.
*
* @return The {@link Phase}.
*/
Phase getPhase();

/**
* Create an immutable copy of this info.
*
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/map/Phase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tc.oc.pgm.api.map;

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

import java.util.Locale;
import net.kyori.adventure.text.Component;

public enum Phase {
PRODUCTION,
DEVELOPMENT;

public Component toComponent() {
return translatable("map.phase." + this.name().toLowerCase());
}

public static Phase of(String query) {
query = query.toLowerCase(Locale.ROOT);
for (Phase phase : Phase.values()) {
if (phase.toString().toLowerCase(Locale.ROOT).startsWith(query)) {
return phase;
}
}
return null;
}
}
22 changes: 21 additions & 1 deletion core/src/main/java/tc/oc/pgm/command/MapCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static net.kyori.adventure.text.Component.translatable;
import static net.kyori.adventure.text.event.ClickEvent.runCommand;
import static net.kyori.adventure.text.event.HoverEvent.showText;
import static tc.oc.pgm.util.text.TextException.invalidFormat;

import app.ashcon.intake.Command;
import app.ashcon.intake.CommandException;
Expand Down Expand Up @@ -34,6 +35,7 @@
import tc.oc.pgm.api.map.MapInfo;
import tc.oc.pgm.api.map.MapLibrary;
import tc.oc.pgm.api.map.MapTag;
import tc.oc.pgm.api.map.Phase;
import tc.oc.pgm.rotation.MapPool;
import tc.oc.pgm.rotation.MapPoolManager;
import tc.oc.pgm.util.Audience;
Expand All @@ -56,7 +58,8 @@ public void maps(
@Default("1") Integer page,
@Fallback(Type.NULL) @Switch('t') String tags,
@Fallback(Type.NULL) @Switch('a') String author,
@Fallback(Type.NULL) @Switch('n') String name)
@Fallback(Type.NULL) @Switch('n') String name,
@Fallback(Type.NULL) @Switch('p') String phaseType)
throws CommandException {
Stream<MapInfo> search = Sets.newHashSet(library.getMaps()).stream();
if (tags != null) {
Expand All @@ -81,6 +84,11 @@ public void maps(
search = search.filter(map -> matchesName(map, name));
}

Phase phase = phaseType == null ? Phase.PRODUCTION : Phase.of(phaseType);
if (phase == null) throw invalidFormat(phaseType, Phase.class, null);

search = search.filter(map -> map.getPhase() == phase);

Set<MapInfo> maps = search.collect(Collectors.toCollection(TreeSet::new));
int resultsPerPage = 8;
int pages = (maps.size() + resultsPerPage - 1) / resultsPerPage;
Expand Down Expand Up @@ -147,6 +155,12 @@ private static boolean matchesName(MapInfo map, String query) {
return map.getName().toLowerCase().contains(query);
}

private static boolean matchesPhase(MapInfo map, String query) {
checkNotNull(map);
query = checkNotNull(query).toLowerCase();
return map.getPhase().equals(Phase.of(query));
}

@Command(
aliases = {"map", "mapinfo"},
desc = "Show info about a map",
Expand Down Expand Up @@ -226,6 +240,12 @@ public void map(Audience audience, CommandSender sender, @Text MapInfo map) {
.append(mapInfoLabel("map.info.proto"))
.append(text(map.getProto().toString(), NamedTextColor.GOLD))
.build());

audience.sendMessage(
text()
.append(mapInfoLabel("map.info.phase"))
.append(map.getPhase().toComponent().color(NamedTextColor.GOLD))
.build());
}

audience.sendMessage(createTagsComponent(map.getTags()));
Expand Down
8000
18 changes: 15 additions & 3 deletions core/src/main/java/tc/oc/pgm/map/MapInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tc.oc.pgm.api.map.Contributor;
import tc.oc.pgm.api.map.MapInfo;
import tc.oc.pgm.api.map.MapTag;
import tc.oc.pgm.api.map.Phase;
import tc.oc.pgm.api.map.WorldInfo;
import tc.oc.pgm.map.contrib.PlayerContributor;
import tc.oc.pgm.map.contrib.PseudonymContributor;
Expand All @@ -33,6 +34,7 @@ public class MapInfoImpl implements MapInfo {
private final String id;
private final Version proto;
private final Version version;
private final Phase phase;
private final String name;
private final String description;
private final LocalDate created;
Expand Down Expand Up @@ -60,7 +62,8 @@ public MapInfoImpl(
@Nullable Collection<MapTag> tags,
@Nullable Collection<Integer> players,
@Nullable WorldInfo world,
@Nullable Component gamemode) {
@Nullable Component gamemode,
Phase phase) {
this.name = checkNotNull(name);
this.id = checkNotNull(MapInfo.normalizeName(id == null ? name : id));
this.proto = checkNotNull(proto);
Expand All @@ -75,6 +78,7 @@ public MapInfoImpl(
this.players = players == null ? new LinkedList<>() : players;
this.world = world == null ? new WorldInfoImpl() : world;
this.gamemode = gamemode;
this.phase = phase;
}

public MapInfoImpl(MapInfo info) {
Expand All @@ -92,7 +96,8 @@ public MapInfoImpl(MapInfo info) {
info.getTags(),
info.getMaxPlayers(),
info.getWorld(),
info.getGamemode());
info.getGamemode(),
info.getPhase());
}

public MapInfoImpl(Element root) throws InvalidXMLException {
Expand All @@ -115,7 +120,9 @@ public MapInfoImpl(Element root) throws InvalidXMLException {
null,
null,
parseWorld(root),
XMLUtils.parseFormattedText(root, "game"));
XMLUtils.parseFormattedText(root, "game"),
XMLUtils.parseEnum(
Node.fromLastChildOrAttr(root, "phase"), Phase.class, "phase", Phase.PRODUCTION));
}

@Override
Expand Down Expand Up @@ -188,6 +195,11 @@ public WorldInfo getWorld() {
return world;
}

@Override
public Phase getPhase() {
return phase;
}

@Override
public int hashCode() {
return getId().hashCode();
Expand Down
6 changes: 6 additions & 0 deletions util/src/main/i18n/templates/map.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ map.info.pools = Pools

map.info.objective = Objective

map.info.phase = Phase

# {0} = name of a maptag (e.g "#tnt" or "#controlpoint")
map.info.mapTag.hover = Click to list all {0} maps

Expand Down Expand Up @@ -74,6 +76,10 @@ map.cycled = Cycled

map.protectPortal = You may not obstruct this area

map.phase.production = Production

map.phase.development = Development

# {0} = map pool name (e.g. "Mega")
pool.change = Map pool has been set to {0} in order to better adjust to the current player count.

Expand Down
2 changes: 2 additions & 0 deletions util/src/main/i18n/templates/misc.properties
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,7 @@ type.uuid = uuid

type.localdate = (yyyy-mm-dd) date

type.phase = phase

# {0} = a URL (e.g. "https://oc.tc")
chat.clickLink = More info at {0}
0