diff --git a/.gitignore b/.gitignore index e6a241f..a8e7777 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ whitelist.json *.bin log /cpu.out -/ram.out \ No newline at end of file +/ram.out +/permissions \ No newline at end of file diff --git a/server/broadcast.go b/server/broadcast.go index 645b6a2..2cb0a70 100644 --- a/server/broadcast.go +++ b/server/broadcast.go @@ -160,6 +160,10 @@ func (p *PlayerController) BroadcastMovement(id int32, x1, y1, z1 float64, yaw, p.player.SetPosition(x1, y1, z1, yaw, pitch, ong) inArea, notInArea := p.PlayersInArea(x1, y1, z1) + if distance > 8 { + id = 0 + } + for _, pl := range notInArea { if pl.IsSpawned(p.player.EntityId()) { pl.DespawnPlayer(p) diff --git a/server/network/handlers/PlayerMovement.go b/server/network/handlers/PlayerMovement.go index a5affd9..a3b42be 100644 --- a/server/network/handlers/PlayerMovement.go +++ b/server/network/handlers/PlayerMovement.go @@ -10,6 +10,9 @@ func PlayerMovement( state *player.Player, p packet.Packet, ) { + if state.IsDead() { + return + } x, y, z := state.Position() yaw, pitch := state.Rotation() switch pk := p.(type) { diff --git a/server/player/player.go b/server/player/player.go index d72a780..582d93e 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -12,6 +12,7 @@ type Player struct { isHardCore bool gameMode byte + dead bool health float32 food int32 foodSaturation float32 @@ -64,6 +65,18 @@ func (p *Player) Dimension() *world.Dimension { return p.dimension } +func (p *Player) IsDead() bool { + p.mu.RLock() + defer p.mu.RUnlock() + return p.dead +} + +func (p *Player) SetDead(a bool) { + p.mu.Lock() + defer p.mu.Unlock() + p.dead = a +} + func (p *Player) SetDimension(d *world.Dimension) { p.mu.Lock() defer p.mu.Unlock() diff --git a/server/player_controller.go b/server/player_controller.go index 1dbbc91..e10c098 100644 --- a/server/player_controller.go +++ b/server/player_controller.go @@ -31,6 +31,7 @@ func (p *PlayerController) Name() string { } func (p *PlayerController) Respawn(d *world.Dimension) { + p.player.SetDead(false) p.session.SendPacket(&packet.Respawn{ GameMode: p.player.GameMode(), PreviousGameMode: -1, @@ -150,6 +151,7 @@ func (p *PlayerController) SetHealth(health float32) { } func (p *PlayerController) Kill(message string) { + p.player.SetDead(true) p.BroadcastHealth() if f, _ := world.GameRule(p.Server.World.Gamerules()["doImmediateRespawn"]).Bool(); !f { p.session.SendPacket(&packet.GameEvent{ @@ -161,6 +163,7 @@ func (p *PlayerController) Kill(message string) { EntityID: p.player.EntityId(), SourceTypeID: 0, }) + p.Despawn() p.session.SendPacket(&packet.CombatDeath{ Message: message, PlayerID: p.player.EntityId(), diff --git a/server/server_config.go b/server/server_config.go index 7da853a..11e80ad 100644 --- a/server/server_config.go +++ b/server/server_config.go @@ -95,6 +95,7 @@ var DefaultConfig = Config{ ReloadComplete: "§aReload complete.", ServerClosed: "Server closed.", OnlineMode: "The server is in online mode.", + Slain: "%player% was slain by %killer%", }, Web: Web{ ServerIP: "0.0.0.0", @@ -135,6 +136,7 @@ type Messages struct { ReloadComplete string `toml:"reload_complete"` ServerClosed string `toml:"server_closed"` OnlineMode string `toml:"online_mode"` + Slain string `toml:"slain"` } type Chat struct {