Skip to content

Commit

Permalink
Minor cleanup of id use
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 committed Aug 7, 2024
1 parent cc94739 commit 68176d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
15 changes: 12 additions & 3 deletions core/src/main/java/tc/oc/pgm/api/map/MapLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
public interface MapLibrary {

/**
* Get the {@link MapInfo} given its id or name.
* Get the {@link MapInfo} given its name, or id.
*
* @param idOrName The id or an approximate name of a map.
* @param nameOrId The id or an approximate name of a map.
* @return The best matching {@link MapInfo} or {@code null} if not found.
*/
@Nullable
MapInfo getMap(String idOrName);
MapInfo getMap(String nameOrId);

/**
* Get the {@link MapInfo} given its id.
*
* @param id The id of the map
* @return The {@link MapInfo} with that id, or null.
*/
@Nullable
MapInfo getMapById(String id);

/**
* Get all {@link MapInfo}s matching the query.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/command/MapCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private ComponentLike formatMapSource(CommandSender sender, MapInfo map) {
.append(text(" ["))
.append(translatable("map.info.xml.edit"))
.append(text("]"))
.clickEvent(runCommand("/showxml " + map.getId()))
.clickEvent(runCommand("/showxml " + map.getName()))
.hoverEvent(showText(translatable("map.info.xml.edit.tip", NamedTextColor.AQUA))));
}
return xmlText;
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/tc/oc/pgm/map/MapLibraryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MapLibraryImpl(
@Override
public MapInfo getMap(String idOrName) {
// Exact match
MapInfo bySlug = maps.get(StringUtils.slugify(idOrName));
MapInfo bySlug = getMapById(StringUtils.slugify(idOrName));
if (bySlug != null && !bySlug.hasCustomId()) return bySlug;

// Fuzzy match
Expand All @@ -63,6 +63,11 @@ public MapInfo getMap(String idOrName) {
return byName != null ? byName : bySlug;
}

@Override
public @Nullable MapInfo getMapById(String id) {
return maps.get(id);
}

@Override
public Stream<MapInfo> getMaps(@Nullable String query) {
Stream<MapInfo> maps = this.maps.values().stream();
Expand Down Expand Up @@ -169,7 +174,7 @@ public CompletableFuture<?> loadNewMaps(boolean reset) {
@Override
public CompletableFuture<MapContext> loadExistingMap(String id) {
return CompletableFuture.supplyAsync(() -> {
final MapInfo info = maps.get(id);
final MapInfo info = getMapById(id);
if (info == null) {
throw new RuntimeException(
new MapMissingException(id, "Unable to find map from id (was it deleted?)"));
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/tc/oc/pgm/rotation/pools/MapPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static MapInfo getVariant(MapLibrary maps, MapInfo map, List<String> var
for (String varId : variantIds) {
VariantInfo variant = variants.get(varId);
if (variant == null) continue;
MapInfo variantMap = maps.getMap(variant.getId());
MapInfo variantMap = maps.getMapById(variant.getId());
if (variantMap != null) {
return variantMap;
} else {
Expand Down Expand Up @@ -154,7 +154,6 @@ public void setNextMap(MapInfo map) {}
* @param match The match that is currently ending
*/
public void unloadPool(Match match) {}
;

@Override
public int compareTo(MapPool o) {
Expand Down

0 comments on commit 68176d5

Please sign in to comment.