forked from GeyserMC/Geyser
Start on converting to the new NukkitX protocol library updates
This commit is contained in:
parent
989312835f
commit
4f461bf374
12 changed files with 58 additions and 58 deletions
|
@ -67,7 +67,7 @@
|
|||
<dependency>
|
||||
<groupId>com.nukkitx.protocol</groupId>
|
||||
<artifactId>bedrock-v389</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.6-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</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.nukkitx.math.vector.Vector3f;
|
||||
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.EntityFlags;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
|
@ -73,7 +73,7 @@ public class Entity {
|
|||
|
||||
protected LongSet passengers = new LongOpenHashSet();
|
||||
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) {
|
||||
this.entityId = entityId;
|
||||
|
|
|
@ -27,6 +27,8 @@ package org.geysermc.connector.entity;
|
|||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
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.PlayerListPacket;
|
||||
import lombok.Getter;
|
||||
|
@ -74,11 +76,8 @@ public class PlayerEntity extends LivingEntity {
|
|||
addPlayerPacket.setRotation(getBedrockRotation());
|
||||
addPlayerPacket.setMotion(motion);
|
||||
addPlayerPacket.setHand(hand);
|
||||
addPlayerPacket.setPlayerFlags(0);
|
||||
addPlayerPacket.setCommandPermission(0);
|
||||
addPlayerPacket.setWorldFlags(0);
|
||||
addPlayerPacket.setPlayerPermission(0);
|
||||
addPlayerPacket.setCustomFlags(0);
|
||||
addPlayerPacket.getAdventureSettings().setCommandPermission(CommandPermission.NORMAL);
|
||||
addPlayerPacket.getAdventureSettings().setPlayerPermission(PlayerPermission.VISITOR);
|
||||
addPlayerPacket.setDeviceId("");
|
||||
addPlayerPacket.setPlatformChatId("");
|
||||
addPlayerPacket.getMetadata().putAll(getMetadata());
|
||||
|
@ -91,7 +90,7 @@ public class PlayerEntity extends LivingEntity {
|
|||
if (getLastSkinUpdate() == -1) {
|
||||
if (playerList) {
|
||||
PlayerListPacket playerList = new PlayerListPacket();
|
||||
playerList.setType(PlayerListPacket.Type.ADD);
|
||||
playerList.setAction(PlayerListPacket.Action.ADD);
|
||||
playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId));
|
||||
session.getUpstream().sendPacket(playerList);
|
||||
}
|
||||
|
@ -107,7 +106,7 @@ public class PlayerEntity extends LivingEntity {
|
|||
// remove from playerlist if player isn't on playerlist
|
||||
Geyser.getGeneralThreadPool().execute(() -> {
|
||||
PlayerListPacket playerList = new PlayerListPacket();
|
||||
playerList.setType(PlayerListPacket.Type.REMOVE);
|
||||
playerList.setAction(PlayerListPacket.Action.REMOVE);
|
||||
playerList.getEntries().add(new PlayerListPacket.Entry(uuid));
|
||||
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.data.GamePublishSetting;
|
||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -304,7 +305,7 @@ public class GeyserSession implements Player {
|
|||
startGamePacket.setBonusChestEnabled(false);
|
||||
startGamePacket.setStartingWithMap(false);
|
||||
startGamePacket.setTrustingPlayers(true);
|
||||
startGamePacket.setDefaultPlayerPermission(1);
|
||||
startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR);
|
||||
startGamePacket.setServerChunkTickRange(4);
|
||||
startGamePacket.setBehaviorPackLocked(false);
|
||||
startGamePacket.setResourcePackLocked(false);
|
||||
|
|
|
@ -129,8 +129,7 @@ public class TranslatorsInit {
|
|||
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
||||
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(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
||||
|
|
|
@ -44,12 +44,12 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
|||
return;
|
||||
|
||||
switch (packet.getAction()) {
|
||||
case 1:
|
||||
case NONE:
|
||||
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||
InteractAction.INTERACT, Hand.MAIN_HAND);
|
||||
session.getDownstream().getSession().send(interactPacket);
|
||||
break;
|
||||
case 2:
|
||||
case UNKNOWN_1:
|
||||
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||
InteractAction.ATTACK, Hand.MAIN_HAND);
|
||||
session.getDownstream().getSession().send(attackPacket);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
||||
addBossEntity(session, entityId);
|
||||
|
||||
bossEventPacket.setType(BossEventPacket.Type.SHOW);
|
||||
bossEventPacket.setAction(BossEventPacket.Action.SHOW);
|
||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||
|
@ -55,15 +55,15 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||
bossEventPacket.setDarkenSky(0);
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
bossEventPacket.setType(BossEventPacket.Type.TITLE);
|
||||
bossEventPacket.setAction(BossEventPacket.Action.TITLE);
|
||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||
break;
|
||||
case UPDATE_HEALTH:
|
||||
bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE);
|
||||
bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE);
|
||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||
break;
|
||||
case REMOVE:
|
||||
bossEventPacket.setType(BossEventPacket.Type.HIDE);
|
||||
bossEventPacket.setAction(BossEventPacket.Action.HIDE);
|
||||
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
||||
break;
|
||||
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.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import org.geysermc.connector.entity.PlayerEntity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
@ -42,7 +43,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||
|
||||
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
||||
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||
bedrockPacket.setPlayerPermission(1);
|
||||
bedrockPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||
session.getUpstream().sendPacket(bedrockPacket);
|
||||
|
||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||
|
|
|
@ -26,14 +26,18 @@
|
|||
package org.geysermc.connector.network.translators.java.entity.player;
|
||||
|
||||
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.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayerAbilitiesPacket> {
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +46,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||
if (entity == null)
|
||||
return;
|
||||
|
||||
EntityDataDictionary metadata = entity.getMetadata();
|
||||
EntityDataMap metadata = entity.getMetadata();
|
||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
|
@ -50,24 +54,18 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||
entityDataPacket.getMetadata().putAll(metadata);
|
||||
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
|
||||
playerFlags = setPlayerFlag(0x40, packet.isCanFly(), playerFlags); // can fly
|
||||
playerFlags = setPlayerFlag(0x200, packet.isFlying(), playerFlags); // is flying
|
||||
if (packet.isFlying())
|
||||
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||
|
||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||
adventureSettingsPacket.setPlayerPermission(1);
|
||||
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
||||
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||
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;
|
||||
|
||||
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()) {
|
||||
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.server.world.ServerNotifyClientPacket;
|
||||
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.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
||||
|
@ -64,14 +67,21 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||
session.getUpstream().sendPacket(stopRainPacket);
|
||||
break;
|
||||
case CHANGE_GAMEMODE:
|
||||
int playerFlags = 0;
|
||||
|
||||
Set<AdventureSettingsPacket.Flag> playerFlags = new HashSet<>();
|
||||
GameMode gameMode = (GameMode) packet.getValue();
|
||||
playerFlags = setPlayerFlag(0x01, gameMode == GameMode.ADVENTURE, playerFlags); // world immutable
|
||||
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
||||
playerFlags = setPlayerFlag(0x40, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR, playerFlags); // can fly
|
||||
playerFlags = setPlayerFlag(0x80, gameMode == GameMode.SPECTATOR, playerFlags); // no clip
|
||||
playerFlags = setPlayerFlag(0x200, gameMode == GameMode.SPECTATOR, playerFlags); // is flying
|
||||
if (gameMode == GameMode.ADVENTURE)
|
||||
playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD);
|
||||
|
||||
if (gameMode == GameMode.CREATIVE)
|
||||
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();
|
||||
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
||||
|
@ -79,12 +89,12 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||
session.setGameMode(gameMode);
|
||||
|
||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||
adventureSettingsPacket.setPlayerPermission(1);
|
||||
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
||||
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||
|
||||
EntityDataDictionary metadata = entity.getMetadata();
|
||||
EntityDataMap metadata = entity.getMetadata();
|
||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR);
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
|
@ -110,12 +120,4 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||
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();
|
||||
playerRemovePacket.setType(PlayerListPacket.Type.REMOVE);
|
||||
playerRemovePacket.setAction(PlayerListPacket.Action.REMOVE);
|
||||
playerRemovePacket.getEntries().add(updatedEntry);
|
||||
session.getUpstream().sendPacket(playerRemovePacket);
|
||||
|
||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||
playerAddPacket.setType(PlayerListPacket.Type.ADD);
|
||||
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||
playerAddPacket.getEntries().add(updatedEntry);
|
||||
session.getUpstream().sendPacket(playerAddPacket);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue