Skip to content

Commit

Permalink
fix multi arg tab complete suggestion (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Oct 5, 2021
1 parent bf19d52 commit 81f8288
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
12 changes: 3 additions & 9 deletions pkg/edition/java/proxy/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,9 @@ func (p *connectedPlayer) connectedServer() *serverConnection {
return p.connectedServer_
}

func (p *connectedPlayer) Username() string {
return p.profile.Name
}
func (p *connectedPlayer) Username() string { return p.profile.Name }

func (p *connectedPlayer) ID() uuid.UUID {
return p.profile.ID
}
func (p *connectedPlayer) ID() uuid.UUID { return p.profile.ID }

func (p *connectedPlayer) Disconnect(reason component.Component) {
if !p.Active() {
Expand All @@ -426,9 +422,7 @@ func (p *connectedPlayer) Disconnect(reason component.Component) {
}
}

func (p *connectedPlayer) String() string {
return p.profile.Name
}
func (p *connectedPlayer) String() string { return p.profile.Name }

func (p *connectedPlayer) sendLegacyForgeHandshakeResetPacket() {
p.phase().resetConnectionPhase(p)
Expand Down
27 changes: 17 additions & 10 deletions pkg/edition/java/proxy/session_client_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ func (c *clientPlaySessionHandler) handleTabCompleteRequest(p *packet.TabComplet
}

func (c *clientPlaySessionHandler) handleCommandTabComplete(p *packet.TabCompleteRequest) {
startPos := strings.LastIndex(p.Command, " ") + 1
if !(startPos > 0) {
return
}

// In 1.13+, we need to do additional work for the richer suggestions available.
cmd := p.Command[1:]
cmd := strings.TrimPrefix(p.Command, "/")
cmdEndPosition := strings.Index(cmd, " ")
if cmdEndPosition == -1 {
cmdEndPosition = len(cmd)
Expand All @@ -532,22 +537,24 @@ func (c *clientPlaySessionHandler) handleCommandTabComplete(p *packet.TabComplet
if len(suggestions) == 0 {
return
}
if c.log1.Enabled() {
c.log1.Info("Response to TabCompleteRequest", "cmd", cmd, "suggestions", suggestions)
}

offers := make([]packet.TabCompleteOffer, 0, len(suggestions))
for _, suggestion := range suggestions {
offers = append(offers, packet.TabCompleteOffer{
Text: suggestion,
})
}
startPos := strings.Index(p.Command, " ") + 1
if startPos > 0 {
_ = c.player.WritePacket(&packet.TabCompleteResponse{
TransactionID: p.TransactionID,
Start: startPos,
Length: len(p.Command) - startPos,
Offers: offers,
})
}

// Send suggestions
_ = c.player.WritePacket(&packet.TabCompleteResponse{
TransactionID: p.TransactionID,
Start: startPos,
Length: len(p.Command) - startPos,
Offers: offers,
})
}

func (c *clientPlaySessionHandler) handleRegularTabComplete(p *packet.TabCompleteRequest) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/edition/java/proxy/session_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (l *loginSessionHandler) initPlayer(profile *profile.GameProfile, onlineMod
return
}

l.log.Info("Player has connected, completing login", "player", player)
l.log.Info("Player has connected, completing login", "player", player, "id", player.ID())

// Setup permissions
permSetup := &PermissionsSetupEvent{
Expand Down
5 changes: 4 additions & 1 deletion pkg/internal/suggest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ type suggestion struct {
}

func Build(builder *brigodier.SuggestionsBuilder, input string, candidates []string) *brigodier.Suggestions {
given := input[strings.Index(input, " ")+1:]
if input == "" {
return builder.Build()
}
given := input[strings.LastIndex(input, " ")+1:]
var result []suggestion
for _, text := range candidates {
score := Score(given, text)
Expand Down

0 comments on commit 81f8288

Please sign in to comment.