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 * 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. * 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.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.entities.entities.player.local.Abilities
enum class Gamemodes( enum class Gamemodes(
val canBuild: Boolean, val canBuild: Boolean,
@ -21,6 +22,7 @@ enum class Gamemodes(
val useTools: Boolean, val useTools: Boolean,
val canInteract: InteractionAbilities, val canInteract: InteractionAbilities,
val survival: Boolean, val survival: Boolean,
val abilities: Abilities,
) { ) {
SURVIVAL( SURVIVAL(
canBuild = true, canBuild = true,
@ -28,6 +30,7 @@ enum class Gamemodes(
useTools = true, useTools = true,
canInteract = InteractionAbilities.EVERYTHING, canInteract = InteractionAbilities.EVERYTHING,
survival = true, survival = true,
Abilities(),
), ),
CREATIVE( CREATIVE(
canBuild = true, canBuild = true,
@ -35,6 +38,7 @@ enum class Gamemodes(
useTools = true, useTools = true,
canInteract = InteractionAbilities.EVERYTHING, canInteract = InteractionAbilities.EVERYTHING,
survival = false, survival = false,
Abilities(true, true, true),
), ),
ADVENTURE( ADVENTURE(
canBuild = false, canBuild = false,
@ -42,6 +46,7 @@ enum class Gamemodes(
useTools = false, useTools = false,
canInteract = InteractionAbilities.ONLY_ENTITIES, canInteract = InteractionAbilities.ONLY_ENTITIES,
survival = true, survival = true,
Abilities(),
), ),
SPECTATOR( SPECTATOR(
canBuild = false, canBuild = false,
@ -49,6 +54,7 @@ enum class Gamemodes(
useTools = false, useTools = false,
canInteract = InteractionAbilities.ONLY_ENTITIES, canInteract = InteractionAbilities.ONLY_ENTITIES,
survival = false, survival = false,
Abilities(true, true, true),
), ),
; ;

View File

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

View File

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

View File

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