Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 00:23:03 +01:00
Start on converting to the new NukkitX protocol library updates
Dieser Commit ist enthalten in:
Ursprung
989312835f
Commit
4f461bf374
@ -67,7 +67,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.nukkitx.protocol</groupId>
|
<groupId>com.nukkitx.protocol</groupId>
|
||||||
<artifactId>bedrock-v389</artifactId>
|
<artifactId>bedrock-v389</artifactId>
|
||||||
<version>2.4.4</version>
|
<version>2.4.6-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -30,7 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
|||||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlags;
|
import com.nukkitx.protocol.bedrock.data.EntityFlags;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
@ -73,7 +73,7 @@ public class Entity {
|
|||||||
|
|
||||||
protected LongSet passengers = new LongOpenHashSet();
|
protected LongSet passengers = new LongOpenHashSet();
|
||||||
protected Map<AttributeType, Attribute> attributes = new HashMap<>();
|
protected Map<AttributeType, Attribute> attributes = new HashMap<>();
|
||||||
protected EntityDataDictionary metadata = new EntityDataDictionary();
|
protected EntityDataMap metadata = new EntityDataMap();
|
||||||
|
|
||||||
public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
|
@ -27,6 +27,8 @@ package org.geysermc.connector.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.CommandPermission;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -74,11 +76,8 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
addPlayerPacket.setRotation(getBedrockRotation());
|
addPlayerPacket.setRotation(getBedrockRotation());
|
||||||
addPlayerPacket.setMotion(motion);
|
addPlayerPacket.setMotion(motion);
|
||||||
addPlayerPacket.setHand(hand);
|
addPlayerPacket.setHand(hand);
|
||||||
addPlayerPacket.setPlayerFlags(0);
|
addPlayerPacket.getAdventureSettings().setCommandPermission(CommandPermission.NORMAL);
|
||||||
addPlayerPacket.setCommandPermission(0);
|
addPlayerPacket.getAdventureSettings().setPlayerPermission(PlayerPermission.VISITOR);
|
||||||
addPlayerPacket.setWorldFlags(0);
|
|
||||||
addPlayerPacket.setPlayerPermission(0);
|
|
||||||
addPlayerPacket.setCustomFlags(0);
|
|
||||||
addPlayerPacket.setDeviceId("");
|
addPlayerPacket.setDeviceId("");
|
||||||
addPlayerPacket.setPlatformChatId("");
|
addPlayerPacket.setPlatformChatId("");
|
||||||
addPlayerPacket.getMetadata().putAll(getMetadata());
|
addPlayerPacket.getMetadata().putAll(getMetadata());
|
||||||
@ -91,7 +90,7 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
if (getLastSkinUpdate() == -1) {
|
if (getLastSkinUpdate() == -1) {
|
||||||
if (playerList) {
|
if (playerList) {
|
||||||
PlayerListPacket playerList = new PlayerListPacket();
|
PlayerListPacket playerList = new PlayerListPacket();
|
||||||
playerList.setType(PlayerListPacket.Type.ADD);
|
playerList.setAction(PlayerListPacket.Action.ADD);
|
||||||
playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId));
|
playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId));
|
||||||
session.getUpstream().sendPacket(playerList);
|
session.getUpstream().sendPacket(playerList);
|
||||||
}
|
}
|
||||||
@ -107,7 +106,7 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
// remove from playerlist if player isn't on playerlist
|
// remove from playerlist if player isn't on playerlist
|
||||||
Geyser.getGeneralThreadPool().execute(() -> {
|
Geyser.getGeneralThreadPool().execute(() -> {
|
||||||
PlayerListPacket playerList = new PlayerListPacket();
|
PlayerListPacket playerList = new PlayerListPacket();
|
||||||
playerList.setType(PlayerListPacket.Type.REMOVE);
|
playerList.setAction(PlayerListPacket.Action.REMOVE);
|
||||||
playerList.getEntries().add(new PlayerListPacket.Entry(uuid));
|
playerList.getEntries().add(new PlayerListPacket.Entry(uuid));
|
||||||
session.getUpstream().sendPacket(playerList);
|
session.getUpstream().sendPacket(playerList);
|
||||||
});
|
});
|
||||||
|
@ -45,6 +45,7 @@ import com.nukkitx.nbt.tag.CompoundTag;
|
|||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
||||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
import com.nukkitx.protocol.bedrock.data.GameRule;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -304,7 +305,7 @@ public class GeyserSession implements Player {
|
|||||||
startGamePacket.setBonusChestEnabled(false);
|
startGamePacket.setBonusChestEnabled(false);
|
||||||
startGamePacket.setStartingWithMap(false);
|
startGamePacket.setStartingWithMap(false);
|
||||||
startGamePacket.setTrustingPlayers(true);
|
startGamePacket.setTrustingPlayers(true);
|
||||||
startGamePacket.setDefaultPlayerPermission(1);
|
startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
startGamePacket.setServerChunkTickRange(4);
|
startGamePacket.setServerChunkTickRange(4);
|
||||||
startGamePacket.setBehaviorPackLocked(false);
|
startGamePacket.setBehaviorPackLocked(false);
|
||||||
startGamePacket.setResourcePackLocked(false);
|
startGamePacket.setResourcePackLocked(false);
|
||||||
|
@ -129,8 +129,7 @@ public class TranslatorsInit {
|
|||||||
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
||||||
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
||||||
|
|
||||||
// FIXME: This translator messes with allowing flight in creative mode. Will need to be addressed later
|
Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
||||||
// Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
|
||||||
|
|
||||||
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
||||||
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
||||||
|
@ -44,12 +44,12 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case 1:
|
case NONE:
|
||||||
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
InteractAction.INTERACT, Hand.MAIN_HAND);
|
InteractAction.INTERACT, Hand.MAIN_HAND);
|
||||||
session.getDownstream().getSession().send(interactPacket);
|
session.getDownstream().getSession().send(interactPacket);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case UNKNOWN_1:
|
||||||
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
InteractAction.ATTACK, Hand.MAIN_HAND);
|
InteractAction.ATTACK, Hand.MAIN_HAND);
|
||||||
session.getDownstream().getSession().send(attackPacket);
|
session.getDownstream().getSession().send(attackPacket);
|
||||||
|
@ -46,7 +46,7 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||||||
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
||||||
addBossEntity(session, entityId);
|
addBossEntity(session, entityId);
|
||||||
|
|
||||||
bossEventPacket.setType(BossEventPacket.Type.SHOW);
|
bossEventPacket.setAction(BossEventPacket.Action.SHOW);
|
||||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||||
@ -55,15 +55,15 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||||||
bossEventPacket.setDarkenSky(0);
|
bossEventPacket.setDarkenSky(0);
|
||||||
break;
|
break;
|
||||||
case UPDATE_TITLE:
|
case UPDATE_TITLE:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.TITLE);
|
bossEventPacket.setAction(BossEventPacket.Action.TITLE);
|
||||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||||
break;
|
break;
|
||||||
case UPDATE_HEALTH:
|
case UPDATE_HEALTH:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE);
|
bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE);
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.HIDE);
|
bossEventPacket.setAction(BossEventPacket.Action.HIDE);
|
||||||
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
||||||
break;
|
break;
|
||||||
case UPDATE_STYLE:
|
case UPDATE_STYLE:
|
||||||
|
@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.java;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||||
|
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
@ -42,7 +43,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||||||
|
|
||||||
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
||||||
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
bedrockPacket.setPlayerPermission(1);
|
bedrockPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
session.getUpstream().sendPacket(bedrockPacket);
|
session.getUpstream().sendPacket(bedrockPacket);
|
||||||
|
|
||||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||||
|
@ -26,14 +26,18 @@
|
|||||||
package org.geysermc.connector.network.translators.java.entity.player;
|
package org.geysermc.connector.network.translators.java.entity.player;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayerAbilitiesPacket> {
|
public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayerAbilitiesPacket> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,7 +46,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntityDataDictionary metadata = entity.getMetadata();
|
EntityDataMap metadata = entity.getMetadata();
|
||||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
@ -50,24 +54,18 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||||||
entityDataPacket.getMetadata().putAll(metadata);
|
entityDataPacket.getMetadata().putAll(metadata);
|
||||||
session.getUpstream().sendPacket(entityDataPacket);
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
|
|
||||||
int playerFlags = 0;
|
Set<AdventureSettingsPacket.Flag> playerFlags = new HashSet<>();
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
||||||
|
if (packet.isCanFly())
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
|
||||||
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
if (packet.isFlying())
|
||||||
playerFlags = setPlayerFlag(0x40, packet.isCanFly(), playerFlags); // can fly
|
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||||
playerFlags = setPlayerFlag(0x200, packet.isFlying(), playerFlags); // is flying
|
|
||||||
|
|
||||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
adventureSettingsPacket.setPlayerPermission(1);
|
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||||
session.getUpstream().sendPacket(adventureSettingsPacket);
|
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int setPlayerFlag(int flag, boolean value, int playerFlags) {
|
|
||||||
if (value) {
|
|
||||||
return playerFlags | flag;
|
|
||||||
} else {
|
|
||||||
return playerFlags & ~flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayer
|
|||||||
if (packet.getAction() != PlayerListEntryAction.ADD_PLAYER && packet.getAction() != PlayerListEntryAction.REMOVE_PLAYER) return;
|
if (packet.getAction() != PlayerListEntryAction.ADD_PLAYER && packet.getAction() != PlayerListEntryAction.REMOVE_PLAYER) return;
|
||||||
|
|
||||||
PlayerListPacket translate = new PlayerListPacket();
|
PlayerListPacket translate = new PlayerListPacket();
|
||||||
translate.setType(packet.getAction() == PlayerListEntryAction.ADD_PLAYER ? PlayerListPacket.Type.ADD : PlayerListPacket.Type.REMOVE);
|
translate.setAction(packet.getAction() == PlayerListEntryAction.ADD_PLAYER ? PlayerListPacket.Action.ADD : PlayerListPacket.Action.REMOVE);
|
||||||
|
|
||||||
for (PlayerListEntry entry : packet.getEntries()) {
|
for (PlayerListEntry entry : packet.getEntries()) {
|
||||||
if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
|
if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
|
||||||
|
@ -31,13 +31,16 @@ import com.github.steveice10.mc.protocol.data.game.world.notify.EnterCreditsValu
|
|||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
||||||
@ -64,14 +67,21 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
session.getUpstream().sendPacket(stopRainPacket);
|
session.getUpstream().sendPacket(stopRainPacket);
|
||||||
break;
|
break;
|
||||||
case CHANGE_GAMEMODE:
|
case CHANGE_GAMEMODE:
|
||||||
int playerFlags = 0;
|
Set<AdventureSettingsPacket.Flag> playerFlags = new HashSet<>();
|
||||||
|
|
||||||
GameMode gameMode = (GameMode) packet.getValue();
|
GameMode gameMode = (GameMode) packet.getValue();
|
||||||
playerFlags = setPlayerFlag(0x01, gameMode == GameMode.ADVENTURE, playerFlags); // world immutable
|
if (gameMode == GameMode.ADVENTURE)
|
||||||
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD);
|
||||||
playerFlags = setPlayerFlag(0x40, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR, playerFlags); // can fly
|
|
||||||
playerFlags = setPlayerFlag(0x80, gameMode == GameMode.SPECTATOR, playerFlags); // no clip
|
if (gameMode == GameMode.CREATIVE)
|
||||||
playerFlags = setPlayerFlag(0x200, gameMode == GameMode.SPECTATOR, playerFlags); // is flying
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
|
||||||
|
if (gameMode == GameMode.SPECTATOR) {
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP);
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||||
|
}
|
||||||
|
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
||||||
|
|
||||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||||
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
||||||
@ -79,12 +89,12 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
session.setGameMode(gameMode);
|
session.setGameMode(gameMode);
|
||||||
|
|
||||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
adventureSettingsPacket.setPlayerPermission(1);
|
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||||
session.getUpstream().sendPacket(adventureSettingsPacket);
|
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||||
|
|
||||||
EntityDataDictionary 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 || gameMode == GameMode.SPECTATOR);
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
@ -110,12 +120,4 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int setPlayerFlag(int flag, boolean value, int playerFlags) {
|
|
||||||
if (value) {
|
|
||||||
return playerFlags | flag;
|
|
||||||
} else {
|
|
||||||
return playerFlags & ~flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -165,12 +165,12 @@ public class SkinUtils {
|
|||||||
);
|
);
|
||||||
|
|
||||||
PlayerListPacket playerRemovePacket = new PlayerListPacket();
|
PlayerListPacket playerRemovePacket = new PlayerListPacket();
|
||||||
playerRemovePacket.setType(PlayerListPacket.Type.REMOVE);
|
playerRemovePacket.setAction(PlayerListPacket.Action.REMOVE);
|
||||||
playerRemovePacket.getEntries().add(updatedEntry);
|
playerRemovePacket.getEntries().add(updatedEntry);
|
||||||
session.getUpstream().sendPacket(playerRemovePacket);
|
session.getUpstream().sendPacket(playerRemovePacket);
|
||||||
|
|
||||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||||
playerAddPacket.setType(PlayerListPacket.Type.ADD);
|
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||||
playerAddPacket.getEntries().add(updatedEntry);
|
playerAddPacket.getEntries().add(updatedEntry);
|
||||||
session.getUpstream().sendPacket(playerAddPacket);
|
session.getUpstream().sendPacket(playerAddPacket);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren