3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Fix spectator mode

Dieser Commit ist enthalten in:
RednedEpic 2020-05-24 14:46:36 -05:00
Ursprung 56d84c24d3
Commit 0215220ac1

Datei anzeigen

@ -42,6 +42,7 @@ import org.geysermc.connector.network.translators.inventory.PlayerInventoryTrans
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
@Translator(packet = ServerNotifyClientPacket.class)
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
@ -80,6 +81,7 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP);
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
gameMode = GameMode.CREATIVE; // spectator doesnt exist on bedrock
}
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
@ -89,14 +91,18 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
session.sendUpstreamPacket(playerGameTypePacket);
session.setGameMode(gameMode);
// We need to delay this because otherwise it's overridden by the adventure settings from the abilities packet
session.getConnector().getGeneralThreadPool().schedule(() -> {
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
adventureSettingsPacket.setPlayerPermission(PlayerPermission.MEMBER);
adventureSettingsPacket.setCommandPermission(CommandPermission.NORMAL);
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
adventureSettingsPacket.getFlags().addAll(playerFlags);
session.sendUpstreamPacket(adventureSettingsPacket);
}, 50, TimeUnit.MILLISECONDS);
EntityDataMap metadata = entity.getMetadata();
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR);
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE);
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
@ -105,7 +111,6 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
// Update the crafting grid to add/remove barriers for creative inventory
PlayerInventoryTranslator.updateCraftingGrid(session, session.getInventory());
break;
case ENTER_CREDITS:
switch ((EnterCreditsValue) packet.getValue()) {