1.17.1 How to make client think they're in a different game mode?

Discussion in 'Spigot Plugin Development' started by HAHALOSAH, Nov 25, 2021.

  1. I was able to change the game mode of a client using packets. I changed the game mode from spectator to creative. However, on the client, I am able to fly through blocks and I cannot change the selected item in the toolbar. How do I enable this? Also, don't ask me why I'm trying to do this, I just am
  2. So you changed the game mode of the client from spectator to creative, yet the server thinks the player is in spectator, or you changed the game mode of the client from creative to spectator and the server knows the player is in creative? I'm assuming the latter, however, bad news for you is that as far as I know there's no way to enable the hotbar in spectator. So I'm gonna ask what you don't want to be asked: why are you intending to do this? Perhaps we can find a workaround.
  3. What's weird is that even though the CLIENT thinks its in creative, it can still fly through blocks. When I disconnect myself from the server by pulling my ethernet cord, I can STILL fly through blocks. This means there is another packet I still have to send to fully update the game mode, which I don't know...
  4. What packets are you sending? And is your server hosted on localhost?
  5. Code (Java):
    ((CraftPlayer) player).getHandle().b.sendPacket(
                    new PacketPlayOutGameStateChange(new PacketPlayOutGameStateChange.a(3), <gamemode>));
    And no, this is a server I bought that is not hosted on localhost.
    When the client thinks its in creative while its actually in spectator on the server, remember how I said changing hotbar slot won't work? Spectator commands are still working! Even though I can't see what is going on, the spectator commands still work. For ex. If I press "1" twice I still teleport
    Also, I tried changing the client from creative to spectator, so the client thinks its in spectator. Now I can't fly through blocks! I just need to know what other packet I should send...
    #6 HAHALOSAH, Nov 25, 2021
    Last edited: Nov 25, 2021
  6. PacketPlayOutPlayerInfo I think, since PacketPlayOutEntityMetadata doesn't have anything about player gamemode and this is the only other packet that deals with player's gamemode (except respawn and join which are of no interest to you).
  7. upload_2021-11-25_11-12-8.png
    I guess I'll try anyways
    • Like Like x 1