reset abilities when changing gamemode

This commit is contained in:
Bixilon 2023-09-22 02:08:05 +02:00
parent b094d140f4
commit fa2a73e29d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.abilities
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.entities.entities.player.local.Abilities
enum class Gamemodes(
val canBuild: Boolean,
@ -21,6 +22,7 @@ enum class Gamemodes(
val useTools: Boolean,
val canInteract: InteractionAbilities,
val survival: Boolean,
val abilities: Abilities,
) {
SURVIVAL(
canBuild = true,
@ -28,6 +30,7 @@ enum class Gamemodes(
useTools = true,
canInteract = InteractionAbilities.EVERYTHING,
survival = true,
Abilities(),
),
CREATIVE(
canBuild = true,
@ -35,6 +38,7 @@ enum class Gamemodes(
useTools = true,
canInteract = InteractionAbilities.EVERYTHING,
survival = false,
Abilities(true, true, true),
),
ADVENTURE(
canBuild = false,
@ -42,6 +46,7 @@ enum class Gamemodes(
useTools = false,
canInteract = InteractionAbilities.ONLY_ENTITIES,
survival = true,
Abilities(),
),
SPECTATOR(
canBuild = false,
@ -49,6 +54,7 @@ enum class Gamemodes(
useTools = false,
canInteract = InteractionAbilities.ONLY_ENTITIES,
survival = false,
Abilities(true, true, true),
),
;

View File

@ -29,5 +29,6 @@ object GamemodeChangeHandler : GameEventHandler {
return
}
connection.player.additional.gamemode = next
connection.player.abilities = next.abilities
}
}

View File

@ -169,6 +169,7 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
if (previousGamemode != gamemode) {
playerEntity.additional.gamemode = gamemode
playerEntity.abilities = gamemode.abilities
}
connection.world.hardcore = isHardcore

View File

@ -107,6 +107,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
override fun handle(connection: PlayConnection) {
connection.util.prepareSpawn()
connection.player.additional.gamemode = gamemode
connection.player.abilities = gamemode.abilities
val dimensionChange = this.dimension != connection.world.dimension || this.world != connection.world.name
if (dimensionChange) {
connection.util.resetWorld()