Removed useless spawnPosition from config. Send spawn position and look snapshot depending on client version

This commit is contained in:
Nan1t 2022-12-11 13:07:06 +03:00
parent 3c9bb88e19
commit 0af7a4c63d
11 changed files with 35 additions and 175 deletions

View File

@ -23,7 +23,6 @@ import org.spongepowered.configurate.serialize.TypeSerializerCollection;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import ru.nanit.limbo.server.data.*;
import ru.nanit.limbo.util.Colors;
import ru.nanit.limbo.world.Location;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
@ -43,7 +42,6 @@ public final class LimboConfig {
private PingData pingData;
private String dimensionType;
private Location spawnPosition;
private int gameMode;
private boolean useBrandName;
@ -86,14 +84,13 @@ public final class LimboConfig {
address = conf.node("bind").get(SocketAddress.class);
maxPlayers = conf.node("maxPlayers").getInt();
pingData = conf.node("ping").get(PingData.class);
dimensionType = conf.node("dimension").getString();
dimensionType = conf.node("dimension").getString("the_end");
if (dimensionType.equalsIgnoreCase("nether")) {
dimensionType = "the_nether";
}
if (dimensionType.equalsIgnoreCase("end")) {
dimensionType = "the_end";
}
spawnPosition = conf.node("spawnPosition").get(Location.class);
gameMode = conf.node("gameMode").getInt();
useBrandName = conf.node("brandName", "enable").getBoolean();
useJoinMessage = conf.node("joinMessage", "enable").getBoolean();
@ -152,7 +149,6 @@ public final class LimboConfig {
.register(PingData.class, new PingData.Serializer())
.register(BossBar.class, new BossBar.Serializer())
.register(Title.class, new Title.Serializer())
.register(Location.class, new Location.Serializer())
.build();
}
@ -172,10 +168,6 @@ public final class LimboConfig {
return dimensionType;
}
public Location getSpawnPosition() {
return spawnPosition;
}
public int getGameMode() {
return gameMode;
}

View File

@ -131,7 +131,12 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
Runnable sendPlayPackets = () -> {
writePacket(PacketSnapshots.PACKET_JOIN_GAME);
writePacket(PacketSnapshots.PACKET_PLAYER_ABILITIES);
writePacket(PacketSnapshots.PACKET_PLAYER_POS);
if (clientVersion.less(Version.V1_9)) {
writePacket(PacketSnapshots.PACKET_PLAYER_POS_AND_LOOK_LEGACY);
} else {
writePacket(PacketSnapshots.PACKET_PLAYER_POS_AND_LOOK);
}
if (clientVersion.moreOrEqual(Version.V1_19_3))
writePacket(PacketSnapshots.PACKET_SPAWN_POSITION);

View File

@ -38,11 +38,14 @@ public final class PacketSnapshots {
public static PacketSnapshot PACKET_PLAYER_ABILITIES;
public static PacketSnapshot PACKET_PLAYER_INFO;
public static PacketSnapshot PACKET_DECLARE_COMMANDS;
public static PacketSnapshot PACKET_PLAYER_POS;
public static PacketSnapshot PACKET_JOIN_MESSAGE;
public static PacketSnapshot PACKET_BOSS_BAR;
public static PacketSnapshot PACKET_HEADER_AND_FOOTER;
public static PacketSnapshot PACKET_PLAYER_POS_AND_LOOK_LEGACY;
// For 1.19 we need to spawn player outside world to avoid stuck in terrain loading
public static PacketSnapshot PACKET_PLAYER_POS_AND_LOOK;
public static PacketSnapshot PACKET_TITLE_TITLE;
public static PacketSnapshot PACKET_TITLE_SUBTITLE;
public static PacketSnapshot PACKET_TITLE_TIMES;
@ -63,6 +66,7 @@ public final class PacketSnapshots {
loginSuccess.setUuid(uuid);
PacketJoinGame joinGame = new PacketJoinGame();
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setEntityId(0);
joinGame.setEnableRespawnScreen(true);
joinGame.setFlat(false);
@ -73,7 +77,6 @@ public final class PacketSnapshots {
joinGame.setReducedDebugInfo(true);
joinGame.setDebug(false);
joinGame.setViewDistance(0);
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
joinGame.setWorldName(worldName);
joinGame.setWorldNames(worldName);
joinGame.setHashedSeed(0);
@ -84,13 +87,15 @@ public final class PacketSnapshots {
playerAbilities.setFlags(0x02);
playerAbilities.setFieldOfView(0.1F);
PacketPlayerPositionAndLook positionAndLook = new PacketPlayerPositionAndLook();
positionAndLook.setX(server.getConfig().getSpawnPosition().getX());
positionAndLook.setY(server.getConfig().getSpawnPosition().getY());
positionAndLook.setZ(server.getConfig().getSpawnPosition().getZ());
positionAndLook.setYaw(server.getConfig().getSpawnPosition().getYaw());
positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch());
positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt());
int teleportId = ThreadLocalRandom.current().nextInt();
PacketPlayerPositionAndLook positionAndLookLegacy
= new PacketPlayerPositionAndLook(0, 64, 0, 0, 0, teleportId);
PacketPlayerPositionAndLook positionAndLook
= new PacketPlayerPositionAndLook(0, 400, 0, 0, 0, teleportId);
PacketSpawnPosition packetSpawnPosition = new PacketSpawnPosition(0, 400, 0);
PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.emptyList());
@ -100,16 +105,12 @@ public final class PacketSnapshots {
info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid);
PacketSpawnPosition packetSpawnPosition = new PacketSpawnPosition();
packetSpawnPosition.setX((long) server.getConfig().getSpawnPosition().getX());
packetSpawnPosition.setY((long) server.getConfig().getSpawnPosition().getY());
packetSpawnPosition.setZ((long) server.getConfig().getSpawnPosition().getZ());
PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess);
PACKET_JOIN_GAME = PacketSnapshot.of(joinGame);
PACKET_PLAYER_POS_AND_LOOK_LEGACY = PacketSnapshot.of(positionAndLookLegacy);
PACKET_PLAYER_POS_AND_LOOK = PacketSnapshot.of(positionAndLook);
PACKET_SPAWN_POSITION = PacketSnapshot.of(packetSpawnPosition);
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook);
PACKET_PLAYER_INFO = PacketSnapshot.of(info);
PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands);

View File

@ -20,7 +20,7 @@ package ru.nanit.limbo.protocol.packets.play;
import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketOut;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.world.dimension.DimensionRegistry;
import ru.nanit.limbo.world.DimensionRegistry;
public class PacketJoinGame implements PacketOut {

View File

@ -28,34 +28,16 @@ public class PacketPlayerPositionAndLook implements PacketOut {
private double z;
private float yaw;
private float pitch;
private byte flags = 0x08;
private int teleportId;
public void setX(double x) {
public PacketPlayerPositionAndLook() {}
public PacketPlayerPositionAndLook(double x, double y, double z, float yaw, float pitch, int teleportId) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public void setZ(double z) {
this.z = z;
}
public void setYaw(float yaw) {
this.yaw = yaw;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public void setFlags(byte flags) {
this.flags = flags;
}
public void setTeleportId(int teleportId) {
this.teleportId = teleportId;
}
@ -68,7 +50,7 @@ public class PacketPlayerPositionAndLook implements PacketOut {
msg.writeFloat(pitch);
if (version.moreOrEqual(Version.V1_8)) {
msg.writeByte(flags);
msg.writeByte(0x08);
} else {
msg.writeBoolean(true);
}

View File

@ -6,19 +6,13 @@ import ru.nanit.limbo.protocol.registry.Version;
public class PacketSpawnPosition implements PacketOut {
private long x;
private long y;
private long z;
private final long x;
private final long y;
private final long z;
public void setX(long x) {
public PacketSpawnPosition(long x, long y, long z) {
this.x = x;
}
public void setY(long y) {
this.y = y;
}
public void setZ(long z) {
this.z = z;
}

View File

@ -32,7 +32,7 @@ import ru.nanit.limbo.connection.ClientChannelInitializer;
import ru.nanit.limbo.connection.ClientConnection;
import ru.nanit.limbo.connection.PacketHandler;
import ru.nanit.limbo.connection.PacketSnapshots;
import ru.nanit.limbo.world.dimension.DimensionRegistry;
import ru.nanit.limbo.world.DimensionRegistry;
import java.nio.file.Paths;
import java.util.concurrent.ScheduledFuture;

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.dimension;
package ru.nanit.limbo.world;
import net.kyori.adventure.nbt.CompoundBinaryTag;

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.dimension;
package ru.nanit.limbo.world;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag;

View File

@ -1,106 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
public class Location {
private final double x;
private final double y;
private final double z;
private final float yaw;
private final float pitch;
Location(double x, double y, double z, float yaw, float pitch) {
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
Location(double x, double y, double z) {
this(x, y, z, 0.0F, 0.0F);
}
public double getX() {
return x;
}
public int getBlockX() {
return (int) x;
}
public double getY() {
return y;
}
public int getBlockY() {
return (int) y;
}
public double getZ() {
return z;
}
public int getBlockZ() {
return (int) z;
}
public float getYaw() {
return yaw;
}
public float getPitch() {
return pitch;
}
public static Location of(double x, double y, double z) {
return new Location(x, y, z);
}
public static Location of(double x, double y, double z, float yaw, float pitch) {
return new Location(x, y, z, yaw, pitch);
}
public static Location pos(int x, int y, int z) {
return new Location(x, y, z);
}
public static class Serializer implements TypeSerializer<Location> {
@Override
public Location deserialize(Type type, ConfigurationNode node) {
double x = node.node("x").getDouble(0);
double y = node.node("y").getDouble(0);
double z = node.node("z").getDouble(0);
float yaw = node.node("yaw").getFloat(0.0F);
float pitch = node.node("pitch").getFloat(0.0F);
return new Location(x, y, z, yaw, pitch);
}
@Override
public void serialize(Type type, @Nullable Location obj, ConfigurationNode node) { }
}
}

View File

@ -32,14 +32,6 @@ headerAndFooter:
header: '{"text": "&eWelcome!"}'
footer: '{"text": "&9NanoLimbo"}'
# Spawn position in the world
spawnPosition:
'x': 0.0
'y': 400.0
'z': 0.0
'yaw': 0.0
'pitch': 0.0
# Setup player's game mode
# 0 - Survival
# 1 - Creative (hide HP and food bar)