Skip to content

Commit

Permalink
Add static helper to display game config source name
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jun 8, 2024
1 parent 26cdb86 commit 6989504
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public Identifier source() {
return this.source;
}

/**
* @return the source location that this config was loaded from, if loaded from a file.
*/
public static String sourceName(GameConfig<?> config) {
return Optional.ofNullable(config.source).map(Identifier::toString).orElse("[unknown source]");
}

/**
* @return the name for this game config, defaulted to the game type name if none is specified
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private ManagedGameSpace addGameSpace(GameConfig<?> config, GameConfig<?> source
this.idToGameSpace.put(id, gameSpace);
this.userIdToGameSpace.put(userId, gameSpace);

Plasmid.LOGGER.info("Game space {} (source: {}) opened", id, config.source());
Plasmid.LOGGER.info("Game space {} (source: {}) opened", id, GameConfig.sourceName(config));
GameEvents.OPENED.invoker().onGameSpaceOpened(config, gameSpace);

procedure.apply(gameSpace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xyz.nucleoid.plasmid.Plasmid;
import xyz.nucleoid.plasmid.event.GameEvents;
import xyz.nucleoid.plasmid.game.*;
import xyz.nucleoid.plasmid.game.config.GameConfig;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void close(GameCloseReason reason) {

var players = Lists.newArrayList(this.players);

Plasmid.LOGGER.info("Game space {} (source: {}) closing for reason {}", this.metadata.id(), this.metadata.sourceConfig().source(), reason);
Plasmid.LOGGER.info("Game space {} (source: {}) closing for reason {}", this.metadata.id(), GameConfig.sourceName(this.metadata.sourceConfig()), reason);
GameEvents.CLOSING.invoker().onGameSpaceClosing(this, reason);
this.lifecycle.onClosing(this, reason);

Expand Down

0 comments on commit 6989504

Please sign in to comment.