Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strage behavor when setting Gamemode in AsyncPlayerConfigurationEvent #2040

Open
nicolube opened this issue Mar 22, 2024 · 1 comment
Open

Comments

@nicolube
Copy link

I got some strage behavor when setting a player into Spactator in the config event. Hotbat invisible like spectator but player appears on clientsite as Creative or something, ,with block colisions and stuff.

Should there not be an error or something if it is not allowed?

Here is the my code: It's Kotlin

package de.primecodes

import net.minestom.server.MinecraftServer
import net.minestom.server.entity.GameMode
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent
import net.minestom.server.event.player.PlayerBlockBreakEvent
import net.minestom.server.event.player.PlayerBlockPlaceEvent
import net.minestom.server.event.player.PlayerMoveEvent
import net.minestom.server.event.player.PlayerSpawnEvent
import net.minestom.server.instance.AnvilLoader
import java.net.InetSocketAddress

fun main() {
    val server = MinecraftServer.init();

    val instanceManager = MinecraftServer.getInstanceManager()

    val loader  = AnvilLoader("world")
    val container = instanceManager.createInstanceContainer(loader)

    val eventHandler = MinecraftServer.getGlobalEventHandler()


    eventHandler.addListener(AsyncPlayerConfigurationEvent::class.java) { event ->
        event.spawningInstance = container
        event.player.gameMode = GameMode.SPECTATOR // Hotbar is not visible, blocks solid, and you can fly 
        // event.player.gameMode = GameMode.CREATIVE // Works as expected
    }

    server.start(InetSocketAddress("0.0.0.0", 25565));
}
@mworzala
Copy link
Member

You should set the game mode in the spawn event. Editing play-state values (like game mode) is not supported (though this should likely become an error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants