forked from GeyserMC/Geyser
Fix spectator mode
This commit is contained in:
parent
56d84c24d3
commit
0215220ac1
1 changed files with 12 additions and 7 deletions
|
@ -42,6 +42,7 @@ import org.geysermc.connector.network.translators.inventory.PlayerInventoryTrans
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Translator(packet = ServerNotifyClientPacket.class)
|
@Translator(packet = ServerNotifyClientPacket.class)
|
||||||
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
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.MAY_FLY);
|
||||||
playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP);
|
playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP);
|
||||||
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||||
|
gameMode = GameMode.CREATIVE; // spectator doesnt exist on bedrock
|
||||||
}
|
}
|
||||||
|
|
||||||
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
||||||
|
@ -89,14 +91,18 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
||||||
session.sendUpstreamPacket(playerGameTypePacket);
|
session.sendUpstreamPacket(playerGameTypePacket);
|
||||||
session.setGameMode(gameMode);
|
session.setGameMode(gameMode);
|
||||||
|
|
||||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
// We need to delay this because otherwise it's overridden by the adventure settings from the abilities packet
|
||||||
adventureSettingsPacket.setPlayerPermission(PlayerPermission.MEMBER);
|
session.getConnector().getGeneralThreadPool().schedule(() -> {
|
||||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
adventureSettingsPacket.setPlayerPermission(PlayerPermission.MEMBER);
|
||||||
session.sendUpstreamPacket(adventureSettingsPacket);
|
adventureSettingsPacket.setCommandPermission(CommandPermission.NORMAL);
|
||||||
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
|
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||||
|
session.sendUpstreamPacket(adventureSettingsPacket);
|
||||||
|
}, 50, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
EntityDataMap metadata = entity.getMetadata();
|
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();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
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
|
// Update the crafting grid to add/remove barriers for creative inventory
|
||||||
PlayerInventoryTranslator.updateCraftingGrid(session, session.getInventory());
|
PlayerInventoryTranslator.updateCraftingGrid(session, session.getInventory());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ENTER_CREDITS:
|
case ENTER_CREDITS:
|
||||||
switch ((EnterCreditsValue) packet.getValue()) {
|
switch ((EnterCreditsValue) packet.getValue()) {
|
||||||
|
|
Loading…
Reference in a new issue