Skip to content

Commit

Permalink
feat: Support Minecraft_1_21_4
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Dec 10, 2024
1 parent 2f553e8 commit 0fa5ca2
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 27 deletions.
10 changes: 5 additions & 5 deletions .examples/extend/simple-proxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/grpc v1.68.0 // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
5 changes: 5 additions & 0 deletions .examples/extend/simple-proxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -342,6 +343,7 @@ golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -360,6 +362,7 @@ golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand All @@ -376,6 +379,7 @@ golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
Expand Down Expand Up @@ -443,6 +447,7 @@ google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0=
google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
Expand Down
14 changes: 0 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/robinbraemer/event v0.0.1 h1:2499Bm1c13+//IZyAQpjoTg4vQ+dndE8trxo1aUxWdI=
github.com/robinbraemer/event v0.0.1/go.mod h1:fKkjL2UbPajNcxc4oWYyRCcUalss0YtPxwMtZTuNo8o=
github.com/robinbraemer/event v0.1.1 h1:1T7GturBzxsa8UUe/r3EmW9aHLErKBggfn43up5hOUA=
github.com/robinbraemer/event v0.1.1/go.mod h1:fKkjL2UbPajNcxc4oWYyRCcUalss0YtPxwMtZTuNo8o=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
Expand Down Expand Up @@ -200,8 +198,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand Down Expand Up @@ -254,8 +250,6 @@ golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -267,23 +261,17 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -312,8 +300,6 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0=
google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA=
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
Expand Down
19 changes: 17 additions & 2 deletions pkg/edition/java/proto/packet/tablist/playerinfo/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type (
Latency int // in milliseconds
GameMode int
DisplayName *chat.ComponentHolder // nil-able
ShowHat bool
ListOrder int
RemoteChatSession *chat.RemoteChatSession // nil-able
}
Expand Down Expand Up @@ -63,14 +64,15 @@ func ContainsAction(actions []UpsertAction, action UpsertAction) bool {
}

func (u *Upsert) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
bytes := make([]byte, -mathutil.FloorDiv(-len(UpsertActions), 8))
z := len(UpsertActions) + 1
bytes := make([]byte, -mathutil.FloorDiv(-len(UpsertActions), z))
if _, err = io.ReadFull(rd, bytes); err != nil {
return err
}

u.ActionSet = nil
for i, action := range UpsertActions {
if bytes[i/8]&(1<<uint(i%8)) != 0 {
if bytes[i/z]&(1<<uint(i%z)) != 0 {
u.ActionSet = append(u.ActionSet, action)
}
}
Expand Down Expand Up @@ -105,6 +107,7 @@ var (
UpdateLatencyAction UpsertAction = &updateLatencyAction{}
UpdateDisplayNameAction UpsertAction = &updateDisplayNameAction{}
UpdateListOrderAction UpsertAction = &updateListOrderAction{}
UpdateHatAction UpsertAction = &updateHatAction{}

UpsertActions = []UpsertAction{
AddPlayerAction,
Expand All @@ -114,6 +117,7 @@ var (
UpdateLatencyAction,
UpdateDisplayNameAction,
UpdateListOrderAction,
UpdateHatAction,
}
)

Expand Down Expand Up @@ -249,3 +253,14 @@ func (a *updateListOrderAction) Decode(c *proto.PacketContext, rd io.Reader, inf
info.ListOrder, err = util.ReadVarInt(rd)
return err
}

type updateHatAction struct{}

func (a *updateHatAction) Encode(c *proto.PacketContext, wr io.Writer, info *Entry) error {
return util.WriteBool(wr, info.ShowHat)
}

func (a *updateHatAction) Decode(c *proto.PacketContext, rd io.Reader, info *Entry) (err error) {
info.ShowHat, err = util.ReadBool(rd)
return err
}
1 change: 1 addition & 0 deletions pkg/edition/java/proto/state/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func init() {
m(0x28, version.Minecraft_1_20_3),
m(0x2B, version.Minecraft_1_20_5),
m(0x2D, version.Minecraft_1_21_2),
m(0x2F, version.Minecraft_1_21_4),
)
Play.ServerBound.Register(&config.FinishedUpdate{},
m(0x0B, version.Minecraft_1_20_2),
Expand Down
3 changes: 2 additions & 1 deletion pkg/edition/java/proto/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
Minecraft_1_20_5 = v(766, "1.20.5", "1.20.6")
Minecraft_1_21 = v(767, "1.21", "1.21.1")
Minecraft_1_21_2 = v(768, "1.21.2", "1.21.3")
Minecraft_1_21_4 = v(769, "1.21.4")

// Versions ordered from lowest to highest
Versions = []*proto.Version{
Expand All @@ -65,7 +66,7 @@ var (
Minecraft_1_18, Minecraft_1_18_2,
Minecraft_1_19, Minecraft_1_19_1, Minecraft_1_19_3, Minecraft_1_19_4,
Minecraft_1_20, Minecraft_1_20_2, Minecraft_1_20_3, Minecraft_1_20_5,
Minecraft_1_21, Minecraft_1_21_2,
Minecraft_1_21, Minecraft_1_21_2, Minecraft_1_21_4,
}
)

Expand Down
10 changes: 9 additions & 1 deletion pkg/edition/java/proxy/tablist/tablist.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package tablist

import (
"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
"time"

"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"

"go.minekube.com/common/minecraft/component"

"go.minekube.com/gate/pkg/edition/java/profile"
"go.minekube.com/gate/pkg/edition/java/proto/packet"
"go.minekube.com/gate/pkg/edition/java/proxy/crypto"
Expand Down Expand Up @@ -70,6 +72,12 @@ type Entry interface {
// SetListed sets whether the entry is listed.
// Only changeable in 1.19.3 and above!
SetListed(bool) error
// ListOrder returns the order/priority of the entry in the tab list.
// Since Minecraft 1.21.2.
ListOrder() int
// SetListOrder sets the order/priority of the entry in the tab list.
// Since Minecraft 1.21.2.
SetListOrder(int) error
}

// Viewer is a tab list viewer (player).
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Service) UnregisterServer(ctx context.Context, c *connect.Request[pb.Un

found := s.p.Unregister(serverInfo)
if !found {
return nil, connect.NewError(connect.CodeNotFound,
return nil, connect.NewError(connect.CodeNotFound,
fmt.Errorf("server not found with name %q and address %q", serverInfo.Name(), serverInfo.Addr()))
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func (s *Service) DisconnectPlayer(ctx context.Context, c *connect.Request[pb.Di
} else {
player = s.p.PlayerByName(c.Msg.Player)
}

if player == nil {
return nil, connect.NewError(connect.CodeNotFound, errors.New("player not found"))
}
Expand Down
34 changes: 33 additions & 1 deletion pkg/internal/tablist/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package tablist
import (
"errors"
"fmt"
"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
"sync"
"time"

"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
"go.minekube.com/gate/pkg/edition/java/proto/version"

"go.minekube.com/common/minecraft/component"

"go.minekube.com/gate/pkg/edition/java/profile"
"go.minekube.com/gate/pkg/edition/java/proto/packet/tablist/playerinfo"
"go.minekube.com/gate/pkg/edition/java/proxy/player"
Expand All @@ -21,6 +24,7 @@ type EntryAttributes struct {
Latency time.Duration
GameMode int
Listed bool
ListOrder int
ChatSession player.ChatSession
}

Expand All @@ -40,6 +44,7 @@ type internalEntry interface {
SetGameModeInternal(gameMode int)
SetChatSessionInternal(chatSession player.ChatSession)
SetListedInternal(listed bool)
SetListOrderInternal(order int)
}

func doInternalEntity(e tablist.Entry, fn func(internalEntry)) {
Expand Down Expand Up @@ -166,6 +171,33 @@ func (e *Entry) SetListed(listed bool) error {
return e.OwningTabList.EmitActionRaw(playerinfo.UpdateListedAction, upsertEntry)
}

func (e *Entry) ListOrder() int {
e.RLock()
defer e.RUnlock()
return e.EntryAttributes.ListOrder
}
func (e *Entry) SetListOrderInternal(i int) {
e.Lock()
e.EntryAttributes.ListOrder = i
e.Unlock()
}

func (e *Entry) SetListOrder(i int) error {
e.Lock()
e.EntryAttributes.ListOrder = i
profileID := e.EntryAttributes.Profile.ID
e.Unlock()
if e.OwningTabList.GetViewer().Protocol().GreaterEqual(version.Minecraft_1_21_2) {
upsertEntry, err := rawEntry(profileID)
if err != nil {
return fmt.Errorf("error creating upsert entry: %w", err)
}
upsertEntry.ListOrder = i
return e.OwningTabList.EmitActionRaw(playerinfo.UpdateListOrderAction, upsertEntry)
}
return nil
}

func rawEntry(profileID uuid.UUID) (*playerinfo.Entry, error) {
if profileID == uuid.Nil {
return nil, errors.New("profile id must not be zero")
Expand Down
19 changes: 18 additions & 1 deletion pkg/internal/tablist/tablist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package tablist

import (
"fmt"
"go.minekube.com/common/minecraft/component"
"reflect"
"sync"
"time"

"go.minekube.com/common/minecraft/component"

"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
"go.minekube.com/gate/pkg/edition/java/proto/packet/tablist/legacytablist"
"go.minekube.com/gate/pkg/edition/java/proto/packet/tablist/playerinfo"
Expand Down Expand Up @@ -211,6 +212,9 @@ func (t *TabList) add(entry tablist.Entry) (*playerinfo.Upsert, error) {
var actions []playerinfo.UpsertAction
playerInfoEntry := &playerinfo.Entry{
ProfileID: entry.Profile().ID,
GameMode: entry.GameMode(),
Listed: entry.Listed(),
ListOrder: entry.ListOrder(),
}

t.Lock()
Expand Down Expand Up @@ -239,6 +243,10 @@ func (t *TabList) add(entry tablist.Entry) (*playerinfo.Upsert, error) {
actions = append(actions, playerinfo.UpdateListedAction)
playerInfoEntry.Listed = entry.Listed()
}
if previousEntry.ListOrder() != entry.ListOrder() && t.Viewer.Protocol().GreaterEqual(version.Minecraft_1_21_2) {
actions = append(actions, playerinfo.UpdateListOrderAction)
playerInfoEntry.ListOrder = entry.ListOrder()
}
if !reflect.DeepEqual(previousEntry.ChatSession(), entry.ChatSession()) {
if from := entry.ChatSession(); from != nil {
actions = append(actions, playerinfo.InitializeChatAction)
Expand Down Expand Up @@ -272,6 +280,10 @@ func (t *TabList) add(entry tablist.Entry) (*playerinfo.Upsert, error) {
}
playerInfoEntry.Latency = int(entry.Latency().Milliseconds())
playerInfoEntry.Listed = entry.Listed()
if entry.ListOrder() != 0 && t.Viewer.Protocol().GreaterEqual(version.Minecraft_1_21_2) {
actions = append(actions, playerinfo.UpdateListOrderAction)
playerInfoEntry.ListOrder = entry.ListOrder()
}
}

return &playerinfo.Upsert{
Expand Down Expand Up @@ -357,5 +369,10 @@ func (t *TabList) processUpdateForEntry(actions []playerinfo.UpsertAction, info
e.SetListedInternal(info.Listed)
})
}
if playerinfo.ContainsAction(actions, playerinfo.UpdateListOrderAction) {
doInternalEntity(currentEntry, func(e internalEntry) {
e.SetListOrderInternal(info.ListOrder)
})
}
return nil
}

0 comments on commit 0fa5ca2

Please sign in to comment.