11package player
22
33import (
4+ "github.com/zeppelinmc/zeppelin/properties"
45 "github.com/zeppelinmc/zeppelin/protocol/net"
56 "github.com/zeppelinmc/zeppelin/protocol/net/io/encoding"
67 "github.com/zeppelinmc/zeppelin/protocol/net/packet"
78 "github.com/zeppelinmc/zeppelin/protocol/net/packet/configuration"
89 "github.com/zeppelinmc/zeppelin/protocol/net/packet/play"
910 "github.com/zeppelinmc/zeppelin/protocol/net/tags"
11+ "github.com/zeppelinmc/zeppelin/protocol/text"
12+ "github.com/zeppelinmc/zeppelin/server/command"
1013 "github.com/zeppelinmc/zeppelin/server/entity"
1114 "github.com/zeppelinmc/zeppelin/server/player/state"
1215 "github.com/zeppelinmc/zeppelin/server/world/dimension"
@@ -18,18 +21,22 @@ import (
1821
1922type Player struct {
2023 * net.Conn
24+ * state.PlayerEntity
2125
2226 playerList * PlayerList
23- // the player entity
24- state * state.PlayerEntity
2527 // the entity id for this player
2628 entityId int32
2729
30+ Unlisted bool
31+
2832 ClientInformation atomic.Pointer [configuration.ClientInformation ]
2933
3034 dimensionManager * dimension.DimensionManager
3135 worldLevel * level.Level
3236
37+ serverProperties * properties.ServerProperties
38+ commandManager * command.Manager
39+
3340 // the time in milliseconds that the keep alive packet was sent to the server from the client
3441 sbLastKeepalive atomic.Int64
3542 // the time in milliseconds that the keep alive packet was sent to the client from the server
@@ -47,14 +54,17 @@ func int32toAtomic(i int32) atomic.Int32 {
4754 return * (* atomic .Int32 )(unsafe .Pointer (& i ))
4855}
4956
50- func (list * PlayerList ) New (conn * net.Conn , en * state.PlayerEntity , dimensionManager * dimension.DimensionManager , worldLevel * level.Level ) * Player {
57+ func (list * PlayerList ) New (conn * net.Conn , en * state.PlayerEntity , dimensionManager * dimension.DimensionManager , worldLevel * level.Level , serverProperties * properties. ServerProperties , commandManager * command. Manager ) * Player {
5158 p := & Player {
52- entityId : entity .NewEntityId (),
53- state : en ,
59+ entityId : entity .NewEntityId (),
60+ PlayerEntity : en ,
5461
5562 dimensionManager : dimensionManager ,
5663 worldLevel : worldLevel ,
5764
65+ serverProperties : serverProperties ,
66+ commandManager : commandManager ,
67+
5868 registryIndexes : make (map [string ][]string ),
5969
6070 packetAwaited : int32toAtomic (- 1 ),
@@ -122,11 +132,19 @@ func (p *Player) finishConfiguration() error {
122132
123133// startGame finishes the initialization for the player and logs it into the world
124134func (p * Player ) startGame () error {
135+ if err := p .sendCommandGraph (); err != nil {
136+ return err
137+ }
138+
125139 if err := p .WritePacket (& play.Login {
126- EntityID : p .entityId ,
127- DimensionName : p .state .Dimension (),
128- GameMode : 1 ,
129- DimensionType : int32 (slices .Index (p .registryIndexes ["minecraft:dimension_type" ], p .state .Dimension ())),
140+ EntityID : p .entityId ,
141+ DimensionName : p .DimensionName (),
142+ GameMode : byte (p .GameMode ()),
143+ DimensionType : int32 (slices .Index (p .registryIndexes ["minecraft:dimension_type" ], p .DimensionName ())),
144+ ViewDistance : p .serverProperties .ViewDistance ,
145+ SimulationDistance : p .serverProperties .SimulationDistance ,
146+ HashedSeed : p .worldLevel .Data .WorldGenSettings .Seed .Hash (),
147+ EnforcesSecureChat : p .serverProperties .EnforceSecureProfile ,
130148 }); err != nil {
131149 return err
132150 }
@@ -141,8 +159,8 @@ func (p *Player) startGame() error {
141159 return err
142160 }
143161
144- x , y , z := p .state . Position ()
145- yaw , pitch := p .state . Rotation ()
162+ x , y , z := p .Position ()
163+ yaw , pitch := p .Rotation ()
146164
147165 if err := p .SynchronizePosition (x , y , z , yaw , pitch ); err != nil {
148166 return err
@@ -166,8 +184,8 @@ func (p *Player) startGame() error {
166184
167185// SynchronizePosition teleports the player to the specified coordinates
168186func (p * Player ) SynchronizePosition (x , y , z float64 , yaw , pitch float32 ) error {
169- p .state . SetPosition (x , y , z )
170- p .state . SetRotation (yaw , pitch )
187+ p .SetPosition (x , y , z )
188+ p .SetRotation (yaw , pitch )
171189
172190 if err := p .WritePacket (& play.SynchronizePlayerPosition {X : x , Y : y , Z : z , Yaw : yaw , Pitch : pitch }); err != nil {
173191 return err
@@ -184,3 +202,13 @@ func (p *Player) Login() error {
184202 }
185203 return p .startGame ()
186204}
205+
206+ // SystemMessage sends a system message (unsigned) to the player
207+ func (p * Player ) SystemMessage (msg text.TextComponent ) error {
208+ return p .WritePacket (& play.SystemChatMessage {Content : msg })
209+ }
210+
211+ // sendCommandGraph sends the command graph to the player
212+ func (p * Player ) sendCommandGraph () error {
213+ return p .WritePacket (p .commandManager .Encode ())
214+ }
0 commit comments