Skip to content

Commit

Permalink
Support doing attribute in who command
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavanki committed Dec 19, 2021
1 parent 3191053 commit a151760
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
20 changes: 20 additions & 0 deletions docs/common_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ Looking tells you at least the name of the place where you are and its descripti

The command `l` is a shortcut for `look`.

### Who

To see which players are around, regardless of location, use the `who` command.

```
$ who
PLAYER DOING CONNECTED
------ ----- ---------
Ahalish Vibing 1h2m34s
Rehtaoh 1h3m57s
```

Wizards can also see the name of each player's actor and their location.

Set the "doing" attribute on your player to fill in the DOING column with your status.

```
$ set_attr me doing=Vibing
```

### Moving

Most locations in the universe should have at least one exit. To traverse an exit and move to another location, use the `go` command. Use the abbreviated name of the exit to indicate where you want your player to go.
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/xyz/deszaras/grounds/command/WhoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ protected String executeImpl() throws CommandException {
boolean isWizard = Role.isWizard(player);
TabularOutput table = new TabularOutput();
if (isWizard) {
table.defineColumn("PLAYER", "%-20.20s")
table.defineColumn("PLAYER", "%-16.16s")
.defineColumn("ACTOR", "%-12.12s")
.defineColumn("LOCATION", "%-20.20s")
.defineColumn("LOCATION", "%-16.16s")
.defineColumn("DOING", "%-20.20s")
.defineColumn("CONNECTED", "%s");
} else {
table.defineColumn("PLAYER", "%-20.20s")
table.defineColumn("PLAYER", "%-16.16s")
.defineColumn("DOING", "%-20.20s")
.defineColumn("CONNECTED", "%s");
}

Expand All @@ -66,9 +68,11 @@ protected String executeImpl() throws CommandException {
shellActor.getUsername(),
shellPlayerLocation.isPresent() ?
shellPlayerLocation.get().getName() : "<none>",
shellPlayer.getDoing().orElse(""),
TimeUtils.toString(connectionDuration));
} else {
table.addRow(shellPlayer.getName(),
shellPlayer.getDoing().orElse(""),
TimeUtils.toString(connectionDuration));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/xyz/deszaras/grounds/model/AttrNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ private AttrNames() {
* The attribute for the mailbox of a thing (usually a player).
*/
public static final String MAILBOX = "mailbox";
/**
* The attribute for what a thing is doing (usually a player). This is not a
* protected attribute.
*/
public static final String DOING = "doing";

/**
* The names of all protected attributes as a set. Only the GOD player may
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/xyz/deszaras/grounds/model/Thing.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,29 @@ public void setMailbox(Thing mailbox) {
}
}

/**
* Gets what this thing is doing.
*
* @return doing
*/
@JsonIgnore
public Optional<String> getDoing() {
return getAttr(AttrNames.DOING).map(a -> a.getValue());
}

/**
* Sets what this thing is doing. Pass a null value to remove it.
*
* @param doing doing
*/
public void setDoing(String doing) {
if (doing != null) {
setAttr(AttrNames.DOING, doing);
} else {
removeAttr(AttrNames.DOING);
}
}

private final Object attrMonitor = new Object();

/**
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/xyz/deszaras/grounds/model/ThingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ public void testMailbox() throws Exception {
assertTrue(thing.getMailbox().isEmpty());
}

@Test
public void testDoing() {
assertTrue(thing.getDoing().isEmpty());

thing.setDoing("Gaming");
assertEquals("Gaming", thing.getDoing().get());

thing.setDoing(null);
assertTrue(thing.getDoing().isEmpty());
}

@Test
public void testAttrStringValue() {
thing.setAttr("a", "b");
Expand Down

0 comments on commit a151760

Please sign in to comment.