Skip to content

Commit

Permalink
Added --show-player-count for java status command
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg committed Sep 25, 2021
1 parent 6e3ceae commit 0c7304a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions java_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type statusCmd struct {

UseProxy bool `usage:"supports contacting Bungeecord when proxy_protocol enabled"`
ProxyVersion byte `usage:"version of PROXY protocol to use" default:"1"`

ShowPlayerCount bool `usage:"show just the online player count"`
}

func (c *statusCmd) Name() string {
Expand All @@ -45,8 +47,8 @@ func (c *statusCmd) SetFlags(flags *flag.FlagSet) {
}
}

func (c *statusCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
options := []mcpinger.McPingerOption{}
func (c *statusCmd) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus {
var options []mcpinger.McPingerOption
if c.Timeout > 0 {
options = append(options, mcpinger.WithTimeout(c.Timeout))
}
Expand Down Expand Up @@ -84,9 +86,13 @@ func (c *statusCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interf
return subcommands.ExitFailure
}

fmt.Printf("%s:%d : version=%s online=%d max=%d motd='%s'",
c.Host, c.Port,
info.Version.Name, info.Players.Online, info.Players.Max, info.Description.Text)
if c.ShowPlayerCount {
fmt.Printf("%d\n", info.Players.Online)
} else {
fmt.Printf("%s:%d : version=%s online=%d max=%d motd='%s'\n",
c.Host, c.Port,
info.Version.Name, info.Players.Online, info.Players.Max, info.Description.Text)
}

return subcommands.ExitSuccess
}
Expand Down

0 comments on commit 0c7304a

Please sign in to comment.