diff --git a/api/src/main/java/de/oliver/fancysitula/api/utils/ServerVersion.java b/api/src/main/java/de/oliver/fancysitula/api/utils/ServerVersion.java index 7b3643b..eb6f225 100644 --- a/api/src/main/java/de/oliver/fancysitula/api/utils/ServerVersion.java +++ b/api/src/main/java/de/oliver/fancysitula/api/utils/ServerVersion.java @@ -7,6 +7,7 @@ public enum ServerVersion { + v1_21_3("1.21.3", 768), v1_21_1("1.21.1", 767), v1_21("1.21", 767), v1_20_6("1.20.6", 766), diff --git a/build.gradle.kts b/build.gradle.kts index 7b2cdc2..2b25f8c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "de.oliver" - version = "0.0.10.1" + version = "0.0.10.2" description = "Simple, lightweight and fast library for minecraft internals" repositories { @@ -23,6 +23,7 @@ dependencies { implementation(project(":api")) implementation(project(":factories")) + implementation(project(":implementations:1_21_3")) implementation(project(":implementations:1_20_6")) implementation("de.oliver.FancyAnalytics:logger:${findProperty("fancyLoggerVersion")}") } diff --git a/factories/build.gradle.kts b/factories/build.gradle.kts index e303422..dae80e5 100644 --- a/factories/build.gradle.kts +++ b/factories/build.gradle.kts @@ -6,6 +6,7 @@ dependencies { compileOnly("io.papermc.paper:paper-api:${findProperty("minecraftVersion")}-R0.1-SNAPSHOT") compileOnly(project(":api")) compileOnly(project(":implementations:1_20_6")) + compileOnly(project(":implementations:1_21_3")) } tasks { diff --git a/factories/src/main/java/de/oliver/fancysitula/factories/PacketFactory.java b/factories/src/main/java/de/oliver/fancysitula/factories/PacketFactory.java index 067fa3f..4af50c7 100644 --- a/factories/src/main/java/de/oliver/fancysitula/factories/PacketFactory.java +++ b/factories/src/main/java/de/oliver/fancysitula/factories/PacketFactory.java @@ -26,6 +26,9 @@ public FS_ClientboundPlayerInfoUpdatePacket createPlayerInfoUpdatePacket( ServerVersion serverVersion, EnumSet actions, List entries) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundPlayerInfoUpdatePacketImpl(actions, entries); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoUpdatePacketImpl(actions, entries); } @@ -68,6 +71,9 @@ public FS_ClientboundAddEntityPacket createAddEntityPacket( int velocityZ, int data) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundAddEntityPacketImpl(entityId, entityUUID, entityType, x, y, z, yaw, pitch, headYaw, velocityX, velocityY, velocityZ, data); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundAddEntityPacketImpl(entityId, entityUUID, entityType, x, y, z, yaw, pitch, headYaw, velocityX, velocityY, velocityZ, data); } @@ -106,6 +112,9 @@ public FS_ClientboundAddEntityPacket createAddEntityPacket( */ public FS_ClientboundPlayerInfoRemovePacket createPlayerInfoRemovePacket(ServerVersion serverVersion, List uuids) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundPlayerInfoRemovePacketImpl(uuids); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundPlayerInfoRemovePacketImpl(uuids); } @@ -147,6 +156,9 @@ public FS_ClientboundPlayerInfoRemovePacket createPlayerInfoRemovePacket(UUID uu */ public FS_ClientboundRemoveEntitiesPacket createRemoveEntitiesPacket(ServerVersion serverVersion, List entityIds) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundRemoveEntitiesPacketImpl(entityIds); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRemoveEntitiesPacketImpl(entityIds); } @@ -185,6 +197,9 @@ public FS_ClientboundTeleportEntityPacket createTeleportEntityPacket( boolean onGround ) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundTeleportEntityPacketImpl(entityId, x, y, z, yaw, pitch, onGround); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundTeleportEntityPacketImpl(entityId, x, y, z, yaw, pitch, onGround); } @@ -223,6 +238,9 @@ public FS_ClientboundTeleportEntityPacket createTeleportEntityPacket( */ public FS_ClientboundRotateHeadPacket createRotateHeadPacket(ServerVersion serverVersion, int entityId, float headYaw) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundRotateHeadPacketImpl(entityId, headYaw); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundRotateHeadPacketImpl(entityId, headYaw); } @@ -249,6 +267,9 @@ public FS_ClientboundRotateHeadPacket createRotateHeadPacket(int entityId, float public FS_ClientboundSetEntityDataPacket createSetEntityDataPacket( ServerVersion serverVersion, int entityId, List entityData) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetEntityDataPacketImpl(entityId, entityData); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEntityDataPacketImpl(entityId, entityData); } @@ -274,6 +295,9 @@ public FS_ClientboundSetEntityDataPacket createSetEntityDataPacket(int entityId, */ public FS_ClientboundSetEquipmentPacket createSetEquipmentPacket(ServerVersion serverVersion, int entityId, Map equipment) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetEquipmentPacketImpl(entityId, equipment); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEquipmentPacketImpl(entityId, equipment); } @@ -300,6 +324,9 @@ public FS_ClientboundSetEquipmentPacket createSetEquipmentPacket(int entityId, M public FS_ClientboundSetPassengersPacket createSetPassengersPacket( ServerVersion serverVersion, int entityId, List passengers) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetPassengersPacketImpl(entityId, passengers); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetPassengersPacketImpl(entityId, passengers); } @@ -329,6 +356,9 @@ public FS_ClientboundSetPassengersPacket createSetPassengersPacket(int entityId, */ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.CreateTeam createTeam) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, createTeam); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, createTeam); } @@ -358,6 +388,9 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str */ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.RemoveTeam removeTeam) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeTeam); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeTeam); } @@ -387,6 +420,9 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str */ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.UpdateTeam updateTeam) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, updateTeam); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, updateTeam); } @@ -416,6 +452,9 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str */ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.AddEntity addEntity) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, addEntity); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, addEntity); } @@ -445,6 +484,9 @@ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(Str */ public FS_ClientboundCreateOrUpdateTeamPacket createCreateOrUpdateTeamPacket(ServerVersion serverVersion, String teamName, FS_ClientboundCreateOrUpdateTeamPacket.RemoveEntity removeEntity) { switch (serverVersion) { + case v1_21_3 -> { + return new de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeEntity); + } case v1_20_5, v1_20_6, v1_21, v1_21_1 -> { return new de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundCreateOrUpdateTeamPacketImpl(teamName, removeEntity); } diff --git a/gradle.properties b/gradle.properties index ee84cbe..9491850 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -minecraftVersion=1.21 +minecraftVersion=1.21.3 fancyLoggerVersion=0.0.4 \ No newline at end of file diff --git a/implementations/1_20_6/build.gradle.kts b/implementations/1_20_6/build.gradle.kts index 9b35c77..f3ba052 100644 --- a/implementations/1_20_6/build.gradle.kts +++ b/implementations/1_20_6/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java-library") - id("io.papermc.paperweight.userdev") version "1.7.1" + id("io.papermc.paperweight.userdev") version "1.7.3" } val minecraftVersion = "1.20.6" diff --git a/implementations/1_21/build.gradle.kts b/implementations/1_21/build.gradle.kts index aced500..83aff2c 100644 --- a/implementations/1_21/build.gradle.kts +++ b/implementations/1_21/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java-library") - id("io.papermc.paperweight.userdev") version "1.7.1" + id("io.papermc.paperweight.userdev") version "1.7.3" } val minecraftVersion = "1.21" diff --git a/implementations/1_21_1/build.gradle.kts b/implementations/1_21_1/build.gradle.kts index 8dc0423..3293cc5 100644 --- a/implementations/1_21_1/build.gradle.kts +++ b/implementations/1_21_1/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java-library") - id("io.papermc.paperweight.userdev") version "1.7.1" + id("io.papermc.paperweight.userdev") version "1.7.3" } val minecraftVersion = "1.21.1" diff --git a/implementations/1_21_3/build.gradle.kts b/implementations/1_21_3/build.gradle.kts new file mode 100644 index 0000000..c94313b --- /dev/null +++ b/implementations/1_21_3/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("java-library") + id("io.papermc.paperweight.userdev") version "1.7.3" +} + +val minecraftVersion = "1.21.3" + +paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION + +dependencies { + paperweight.paperDevBundle("$minecraftVersion-R0.1-SNAPSHOT") + compileOnly(project(":api")) + + testImplementation(project(":api")) + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2") +} + +tasks { + test { + useJUnitPlatform() + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImpl.java new file mode 100644 index 0000000..44572a0 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImpl.java @@ -0,0 +1,48 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundAddEntityPacket; +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.EntityType; + +import java.util.UUID; + +public class ClientboundAddEntityPacketImpl extends FS_ClientboundAddEntityPacket { + + public ClientboundAddEntityPacketImpl(int entityId, UUID entityUUID, EntityType entityType, double x, double y, double z, float yaw, float pitch, float headYaw, int velocityX, int velocityY, int velocityZ, int data) { + super(entityId, entityUUID, entityType, x, y, z, yaw, pitch, headYaw, velocityX, velocityY, velocityZ, data); + } + + @Override + public Object createPacket() { + net.minecraft.world.entity.EntityType vanillaType = BuiltInRegistries.ENTITY_TYPE.getValue(CraftNamespacedKey.toMinecraft(entityType.getKey())); + + return new ClientboundAddEntityPacket( + entityId, + entityUUID, + x, + y, + z, + AngelConverter.degreesToVanillaByte(pitch), + AngelConverter.degreesToVanillaByte(yaw), + vanillaType, + data, + new Vec3(velocityX, velocityY, velocityZ), + AngelConverter.degreesToVanillaByte(headYaw) + ); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundAddEntityPacket packet = (ClientboundAddEntityPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundCreateOrUpdateTeamPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundCreateOrUpdateTeamPacketImpl.java new file mode 100644 index 0000000..39201c6 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundCreateOrUpdateTeamPacketImpl.java @@ -0,0 +1,128 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundCreateOrUpdateTeamPacket; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import io.papermc.paper.adventure.PaperAdventure; +import net.minecraft.ChatFormatting; +import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.scores.PlayerTeam; +import net.minecraft.world.scores.Scoreboard; +import net.minecraft.world.scores.Team; + +public class ClientboundCreateOrUpdateTeamPacketImpl extends FS_ClientboundCreateOrUpdateTeamPacket { + + private static final Scoreboard SCOREBOARD = new Scoreboard(); + + public ClientboundCreateOrUpdateTeamPacketImpl(String teamName, CreateTeam createTeam) { + super(teamName, createTeam); + } + + public ClientboundCreateOrUpdateTeamPacketImpl(String teamName, RemoveTeam removeTeam) { + super(teamName, removeTeam); + } + + public ClientboundCreateOrUpdateTeamPacketImpl(String teamName, UpdateTeam updateTeam) { + super(teamName, updateTeam); + } + + public ClientboundCreateOrUpdateTeamPacketImpl(String teamName, AddEntity addEntity) { + super(teamName, addEntity); + } + + public ClientboundCreateOrUpdateTeamPacketImpl(String teamName, RemoveEntity removeEntity) { + super(teamName, removeEntity); + } + + @Override + public Object createPacket() { + return switch (method) { + case CREATE_TEAM -> createCreateTeamPacket(); + case REMOVE_TEAM -> createRemoveTeamPacket(); + case UPDATE_TEAM -> createUpdateTeamPacket(); + case ADD_ENTITY -> createAddEntityPacket(); + case REMOVE_ENTITY -> createRemoveEntityPacket(); + }; + } + + private Object createCreateTeamPacket() { + if (createTeam == null) { + return null; + } + + PlayerTeam playerTeam = new PlayerTeam(SCOREBOARD, teamName); + playerTeam.setDisplayName(PaperAdventure.asVanilla(createTeam.getDisplayName())); + playerTeam.setAllowFriendlyFire(createTeam.isAllowFriendlyFire()); + playerTeam.setSeeFriendlyInvisibles(createTeam.isCanSeeFriendlyInvisibles()); + playerTeam.setNameTagVisibility(Team.Visibility.byName(createTeam.getNameTagVisibility().getName())); + playerTeam.setCollisionRule(PlayerTeam.CollisionRule.byName(createTeam.getCollisionRule().getName())); + playerTeam.setColor(ChatFormatting.getById(createTeam.getColor().getId())); + playerTeam.setPlayerPrefix(PaperAdventure.asVanilla(createTeam.getPrefix())); + playerTeam.setPlayerSuffix(PaperAdventure.asVanilla(createTeam.getSuffix())); + for (String entity : createTeam.getEntities()) { + playerTeam.getPlayers().add(entity); + } + + return ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, true); + } + + private Object createRemoveTeamPacket() { + if (removeTeam == null) { + return null; + } + + PlayerTeam playerTeam = new PlayerTeam(SCOREBOARD, teamName); + return ClientboundSetPlayerTeamPacket.createRemovePacket(playerTeam); + } + + private Object createUpdateTeamPacket() { + if (updateTeam == null) { + return null; + } + + PlayerTeam playerTeam = new PlayerTeam(SCOREBOARD, teamName); + playerTeam.setDisplayName(PaperAdventure.asVanilla(updateTeam.getDisplayName())); + playerTeam.setAllowFriendlyFire(updateTeam.isAllowFriendlyFire()); + playerTeam.setSeeFriendlyInvisibles(updateTeam.isCanSeeFriendlyInvisibles()); + playerTeam.setNameTagVisibility(Team.Visibility.byName(updateTeam.getNameTagVisibility().getName())); + playerTeam.setCollisionRule(PlayerTeam.CollisionRule.byName(updateTeam.getCollisionRule().getName())); + playerTeam.setColor(ChatFormatting.getById(updateTeam.getColor().getId())); + playerTeam.setPlayerPrefix(PaperAdventure.asVanilla(updateTeam.getPrefix())); + playerTeam.setPlayerSuffix(PaperAdventure.asVanilla(updateTeam.getSuffix())); + + return ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(playerTeam, true); + } + + private Object createAddEntityPacket() { + if (addEntity == null) { + return null; + } + + PlayerTeam playerTeam = new PlayerTeam(SCOREBOARD, teamName); + for (String entity : addEntity.getEntities()) { + playerTeam.getPlayers().add(entity); + } + return ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(playerTeam, addEntity.getEntities(), ClientboundSetPlayerTeamPacket.Action.ADD); + } + + private Object createRemoveEntityPacket() { + if (removeEntity == null) { + return null; + } + + PlayerTeam playerTeam = new PlayerTeam(SCOREBOARD, teamName); + for (String entity : removeEntity.getEntities()) { + playerTeam.getPlayers().add(entity); + } + return ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(playerTeam, removeEntity.getEntities(), ClientboundSetPlayerTeamPacket.Action.REMOVE); + } + + @Override + protected void sendPacketTo(FS_RealPlayer player) { + ClientboundSetPlayerTeamPacket packet = (ClientboundSetPlayerTeamPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImpl.java new file mode 100644 index 0000000..b8fe806 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImpl.java @@ -0,0 +1,30 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoRemovePacket; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; +import java.util.UUID; + +public class ClientboundPlayerInfoRemovePacketImpl extends FS_ClientboundPlayerInfoRemovePacket { + + public ClientboundPlayerInfoRemovePacketImpl(List uuids) { + super(uuids); + } + + @Override + public Object createPacket() { + return new ClientboundPlayerInfoRemovePacket(uuids); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundPlayerInfoRemovePacket packet = (ClientboundPlayerInfoRemovePacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImpl.java new file mode 100644 index 0000000..fe4d6c1 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImpl.java @@ -0,0 +1,53 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoUpdatePacket; +import de.oliver.fancysitula.versions.v1_21_3.utils.GameProfileImpl; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import io.papermc.paper.adventure.PaperAdventure; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.GameType; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +public class ClientboundPlayerInfoUpdatePacketImpl extends FS_ClientboundPlayerInfoUpdatePacket { + + public ClientboundPlayerInfoUpdatePacketImpl(EnumSet actions, List entries) { + super(actions, entries); + } + + @Override + public Object createPacket() { + EnumSet vanillaActions = EnumSet.noneOf(ClientboundPlayerInfoUpdatePacket.Action.class); + for (FS_ClientboundPlayerInfoUpdatePacket.Action action : actions) { + vanillaActions.add(ClientboundPlayerInfoUpdatePacket.Action.valueOf(action.name())); + } + + List entries = new ArrayList<>(); + for (Entry entry : this.entries) { + entries.add(new ClientboundPlayerInfoUpdatePacket.Entry( + entry.uuid(), + GameProfileImpl.asVanilla(entry.profile()), + entry.listed(), + entry.latency(), + GameType.byId(entry.gameMode().getId()), + PaperAdventure.asVanilla(entry.displayName()), + -1, + null // TODO: Add ChatSession support + )); + } + + return new ClientboundPlayerInfoUpdatePacket(vanillaActions, entries); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundPlayerInfoUpdatePacket packet = (ClientboundPlayerInfoUpdatePacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImpl.java new file mode 100644 index 0000000..90671fd --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImpl.java @@ -0,0 +1,37 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundRemoveEntitiesPacket; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; + +public class ClientboundRemoveEntitiesPacketImpl extends FS_ClientboundRemoveEntitiesPacket { + + /** + * @param entityIds IDs of the entities to remove + */ + public ClientboundRemoveEntitiesPacketImpl(List entityIds) { + super(entityIds); + } + + @Override + public Object createPacket() { + int[] ids = new int[this.entityIds.size()]; + for (int i = 0; i < this.entityIds.size(); i++) { + ids[i] = this.entityIds.get(i); + } + + return new ClientboundRemoveEntitiesPacket(ids); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundRemoveEntitiesPacket packet = (ClientboundRemoveEntitiesPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImpl.java new file mode 100644 index 0000000..0ccd04e --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImpl.java @@ -0,0 +1,38 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundRotateHeadPacket; +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import net.minecraft.server.level.ServerPlayer; + +public class ClientboundRotateHeadPacketImpl extends FS_ClientboundRotateHeadPacket { + + public ClientboundRotateHeadPacketImpl(int entityId, float headYaw) { + super(entityId, headYaw); + } + + @Override + public Object createPacket() { + ClientboundRotateHeadPacket packet = null; + + try { + packet = ReflectionUtils.createUnsafeInstance(ClientboundRotateHeadPacket.class); + ReflectionUtils.setFinalField(packet, "entityId", entityId); + ReflectionUtils.setFinalField(packet, "yHeadRot", AngelConverter.degreesToVanillaByte(headYaw)); + } catch (Exception e) { + e.printStackTrace(); + } + return packet; + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundRotateHeadPacket packet = (ClientboundRotateHeadPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImpl.java new file mode 100644 index 0000000..09667e6 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImpl.java @@ -0,0 +1,67 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundSetEntityDataPacket; +import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import io.papermc.paper.adventure.PaperAdventure; +import net.kyori.adventure.text.Component; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class ClientboundSetEntityDataPacketImpl extends FS_ClientboundSetEntityDataPacket { + + public ClientboundSetEntityDataPacketImpl(int entityId, List entityData) { + super(entityId, entityData); + } + + @Override + public Object createPacket() { + List> dataValues = new ArrayList<>(); + for (EntityData data : entityData) { + try { + Class entityClass = Class.forName(data.getAccessor().entityClassName()); + net.minecraft.network.syncher.EntityDataAccessor accessor = ReflectionUtils.getStaticField(entityClass, data.getAccessor().accessorFieldName()); + + Object vanillaValue = data.getValue(); + + if (data.getValue() == null) { + continue; + } + + if (data.getValue() instanceof Component c) { + vanillaValue = PaperAdventure.asVanilla(c); + } + + if (data.getValue() instanceof ItemStack i) { + vanillaValue = net.minecraft.world.item.ItemStack.fromBukkitCopy(i); + } + + if (data.getValue() instanceof BlockState b) { + vanillaValue = ((CraftBlockState) b).getHandle(); + } + + dataValues.add(SynchedEntityData.DataValue.create(accessor, vanillaValue)); + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + return new ClientboundSetEntityDataPacket(entityId, dataValues); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImpl.java new file mode 100644 index 0000000..cee9a61 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImpl.java @@ -0,0 +1,45 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import com.mojang.datafixers.util.Pair; +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundSetEquipmentPacket; +import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.EquipmentSlot; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ClientboundSetEquipmentPacketImpl extends FS_ClientboundSetEquipmentPacket { + + public ClientboundSetEquipmentPacketImpl(int entityId, Map equipment) { + super(entityId, equipment); + } + + @Override + public Object createPacket() { + List> slots = new ArrayList<>(); + + for (Map.Entry entry : equipment.entrySet()) { + EquipmentSlot equipmentSlot = net.minecraft.world.entity.EquipmentSlot.byName(entry.getKey().name().toLowerCase()); + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(entry.getValue()); + + slots.add(Pair.of(equipmentSlot, itemStack)); + } + + return new ClientboundSetEquipmentPacket(entityId, slots); + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundSetEquipmentPacket packet = (ClientboundSetEquipmentPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImpl.java new file mode 100644 index 0000000..20b8420 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImpl.java @@ -0,0 +1,45 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundSetPassengersPacket; +import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; + +public class ClientboundSetPassengersPacketImpl extends FS_ClientboundSetPassengersPacket { + + public ClientboundSetPassengersPacketImpl(int entityId, List passengers) { + super(entityId, passengers); + } + + + @Override + public Object createPacket() { + int[] passengers = new int[this.passengers.size()]; + for (int i = 0; i < this.passengers.size(); i++) { + passengers[i] = this.passengers.get(i); + } + + try { + ClientboundSetPassengersPacket packet = ReflectionUtils.createUnsafeInstance(ClientboundSetPassengersPacket.class); + ReflectionUtils.setFinalField(packet, "vehicle", entityId); + ReflectionUtils.setFinalField(packet, "passengers", passengers); + return packet; + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundSetPassengersPacket packet = (ClientboundSetPassengersPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImpl.java new file mode 100644 index 0000000..390fe39 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImpl.java @@ -0,0 +1,43 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.entities.FS_RealPlayer; +import de.oliver.fancysitula.api.packets.FS_ClientboundTeleportEntityPacket; +import de.oliver.fancysitula.versions.v1_21_3.utils.VanillaPlayerAdapter; +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.PositionMoveRotation; +import net.minecraft.world.phys.Vec3; + +import java.util.Set; + +public class ClientboundTeleportEntityPacketImpl extends FS_ClientboundTeleportEntityPacket { + + public ClientboundTeleportEntityPacketImpl(int entityId, double x, double y, double z, float yaw, float pitch, boolean onGround) { + super(entityId, x, y, z, yaw, pitch, onGround); + } + + @Override + public Object createPacket() { + ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket( + entityId, + new PositionMoveRotation( + new Vec3(x, y, z), + Vec3.ZERO, + yaw, + pitch + ), + Set.of(), + onGround + ); + + return packet; + } + + @Override + public void sendPacketTo(FS_RealPlayer player) { + ClientboundTeleportEntityPacket packet = (ClientboundTeleportEntityPacket) createPacket(); + + ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); + vanillaPlayer.connection.send(packet); + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/GameProfileImpl.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/GameProfileImpl.java new file mode 100644 index 0000000..0cc5fb3 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/GameProfileImpl.java @@ -0,0 +1,33 @@ +package de.oliver.fancysitula.versions.v1_21_3.utils; + +import com.mojang.authlib.GameProfile; +import de.oliver.fancysitula.api.utils.FS_GameProfile; + +import java.util.Map; + +public class GameProfileImpl { + + public static GameProfile asVanilla(FS_GameProfile gameProfile) { + GameProfile gf = new GameProfile(gameProfile.getUUID(), gameProfile.getName()); + + for (Map.Entry entry : gameProfile.getProperties().entrySet()) { + FS_GameProfile.Property property = entry.getValue(); + + gf.getProperties().put(entry.getKey(), new com.mojang.authlib.properties.Property(property.name(), property.value(), property.signature())); + } + + return gf; + } + + public static FS_GameProfile fromVanilla(GameProfile gameProfile) { + FS_GameProfile fsGameProfile = new FS_GameProfile(gameProfile.getId(), gameProfile.getName()); + + for (Map.Entry entry : gameProfile.getProperties().entries()) { + com.mojang.authlib.properties.Property property = entry.getValue(); + + fsGameProfile.getProperties().put(entry.getKey(), new FS_GameProfile.Property(property.name(), property.value(), property.signature())); + } + + return fsGameProfile; + } +} diff --git a/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/VanillaPlayerAdapter.java b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/VanillaPlayerAdapter.java new file mode 100644 index 0000000..9d6f000 --- /dev/null +++ b/implementations/1_21_3/src/main/java/de/oliver/fancysitula/versions/v1_21_3/utils/VanillaPlayerAdapter.java @@ -0,0 +1,12 @@ +package de.oliver.fancysitula.versions.v1_21_3.utils; + +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class VanillaPlayerAdapter { + + public static ServerPlayer asVanilla(Player p) { + return ((CraftPlayer) p).getHandle(); + } +} diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImplTest.java new file mode 100644 index 0000000..1cb95bb --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundAddEntityPacketImplTest.java @@ -0,0 +1,65 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundAddEntityPacketImpl; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; +import org.bukkit.entity.EntityType; + +import java.util.UUID; + +class ClientboundAddEntityPacketImplTest { + + //TODO: Fix this test (registry problems) + // @Test + void createPacket() { + int entityId = 10000; + UUID entityUUID = UUID.randomUUID(); + EntityType entityType = EntityType.PIG; + + double x = 5; + double y = 57; + double z = 203; + + float yaw = 142; + float pitch = 247; + float headYaw = 90; + + int velocityX = 0; + int velocityY = 0; + int velocityZ = 0; + + int data = 0; + + ClientboundAddEntityPacketImpl packet = new ClientboundAddEntityPacketImpl( + entityId, + entityUUID, + entityType, + x, + y, + z, + yaw, + pitch, + headYaw, + velocityX, + velocityY, + velocityZ, + data + ); + + ClientboundAddEntityPacket createdPacket = (ClientboundAddEntityPacket) packet.createPacket(); + + assert createdPacket.getId() == entityId; + assert createdPacket.getUUID().equals(entityUUID); + assert createdPacket.getType().getDescriptionId().equals(entityType.getKey().getKey()); + assert createdPacket.getX() == x; + assert createdPacket.getY() == y; + assert createdPacket.getZ() == z; + assert createdPacket.getYRot() == AngelConverter.degreesToVanillaByte(yaw); + assert createdPacket.getXRot() == AngelConverter.degreesToVanillaByte(pitch); + assert createdPacket.getYHeadRot() == AngelConverter.degreesToVanillaByte(headYaw); + assert createdPacket.getXa() == velocityX; + assert createdPacket.getYa() == velocityY; + assert createdPacket.getZa() == velocityZ; + assert createdPacket.getData() == data; + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImplTest.java new file mode 100644 index 0000000..cc94a4d --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoRemovePacketImplTest.java @@ -0,0 +1,23 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundPlayerInfoRemovePacketImpl; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.UUID; + +class ClientboundPlayerInfoRemovePacketImplTest { + + @Test + void createPacket() { + List uuids = List.of(UUID.randomUUID(), UUID.randomUUID()); + + ClientboundPlayerInfoRemovePacketImpl packet = new ClientboundPlayerInfoRemovePacketImpl(uuids); + ClientboundPlayerInfoRemovePacket vanillaPacket = (ClientboundPlayerInfoRemovePacket) packet.createPacket(); + + for (UUID uuid : uuids) { + assert vanillaPacket.profileIds().contains(uuid); + } + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImplTest.java new file mode 100644 index 0000000..a6ad9e3 --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundPlayerInfoUpdatePacketImplTest.java @@ -0,0 +1,62 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoUpdatePacket; +import de.oliver.fancysitula.api.utils.FS_GameProfile; +import de.oliver.fancysitula.api.utils.FS_GameType; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundPlayerInfoUpdatePacketImpl; +import net.kyori.adventure.text.Component; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.UUID; + +class ClientboundPlayerInfoUpdatePacketImplTest { + + @Test + void createPacket() { + // Setup packet + EnumSet actions = EnumSet.noneOf(FS_ClientboundPlayerInfoUpdatePacket.Action.class); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + actions.add(FS_ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED); + + FS_GameProfile gameProfile = new FS_GameProfile(UUID.randomUUID(), "Test name"); + boolean listed = true; + int latency = 42; + FS_GameType gameMode = FS_GameType.SURVIVAL; + Component displayName = Component.text("Test displayname"); + + List entries = new ArrayList<>(); + entries.add(new FS_ClientboundPlayerInfoUpdatePacket.Entry( + gameProfile.getUUID(), + gameProfile, + listed, + latency, + gameMode, + displayName + )); + + ClientboundPlayerInfoUpdatePacketImpl packet = new ClientboundPlayerInfoUpdatePacketImpl(actions, entries); + + ClientboundPlayerInfoUpdatePacket createdPacket = (ClientboundPlayerInfoUpdatePacket) packet.createPacket(); + + assert createdPacket.entries().size() == 1; + assert createdPacket.actions().size() == 3; + + // check entry + ClientboundPlayerInfoUpdatePacket.Entry entry = createdPacket.entries().getFirst(); + assert entry.profile().getId().equals(gameProfile.getUUID()); + assert entry.profile().getName().equals(gameProfile.getName()); + assert entry.listed() == listed; + assert entry.latency() == latency; + assert entry.gameMode().getId() == gameMode.getId(); + + // check actions + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER); + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME); + assert createdPacket.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED); + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImplTest.java new file mode 100644 index 0000000..bb71e5c --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRemoveEntitiesPacketImplTest.java @@ -0,0 +1,21 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundRemoveEntitiesPacketImpl; +import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class ClientboundRemoveEntitiesPacketImplTest { + + @Test + void createPacket() { + List entityIds = List.of(95, 120, 154, 187); + + ClientboundRemoveEntitiesPacketImpl packet = new ClientboundRemoveEntitiesPacketImpl(entityIds); + ClientboundRemoveEntitiesPacket createdPacket = (ClientboundRemoveEntitiesPacket) packet.createPacket(); + + assert createdPacket.getEntityIds().size() == entityIds.size(); + assert createdPacket.getEntityIds().containsAll(entityIds); + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImplTest.java new file mode 100644 index 0000000..cf0106d --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundRotateHeadPacketImplTest.java @@ -0,0 +1,22 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundRotateHeadPacketImpl; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import org.junit.jupiter.api.Test; + +class ClientboundRotateHeadPacketImplTest { + + @Test + void createPacket() throws Exception { + int entityId = 184; + float headYaw = 45; + + ClientboundRotateHeadPacketImpl packet = new ClientboundRotateHeadPacketImpl(entityId, (byte) headYaw); + ClientboundRotateHeadPacket createdPacket = (ClientboundRotateHeadPacket) packet.createPacket(); + + assert ReflectionUtils.getField(createdPacket, "entityId").equals(entityId); + assert createdPacket.getYHeadRot() == AngelConverter.degreesToVanillaByte(headYaw); + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImplTest.java new file mode 100644 index 0000000..97bdaaa --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEntityDataPacketImplTest.java @@ -0,0 +1,29 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.packets.FS_ClientboundSetEntityDataPacket; +import de.oliver.fancysitula.api.utils.entityData.FS_TextDisplayData; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetEntityDataPacketImpl; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; + +import java.util.List; + +class ClientboundSetEntityDataPacketImplTest { + + //TODO: Fix this test (using registry) +// @Test + void createPacket() { + int entityId = 712; + List entityData = List.of( + new FS_ClientboundSetEntityDataPacket.EntityData( + FS_TextDisplayData.TEXT, + "Hello, World!" + ) + ); + + ClientboundSetEntityDataPacketImpl packet = new ClientboundSetEntityDataPacketImpl(entityId, entityData); + ClientboundSetEntityDataPacket createdPacket = (ClientboundSetEntityDataPacket) packet.createPacket(); + + assert createdPacket.id() == entityId; + assert createdPacket.packedItems().size() == 1; + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImplTest.java new file mode 100644 index 0000000..943c9cc --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetEquipmentPacketImplTest.java @@ -0,0 +1,29 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetEquipmentPacketImpl; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.Map; + +class ClientboundSetEquipmentPacketImplTest { + + //TODO: Fix this test (registry problems) + // @Test + void createPacket() { + // Setup packet + Map equipment = Map.of( + FS_EquipmentSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD), + FS_EquipmentSlot.OFFHAND, new ItemStack(Material.SHIELD), + FS_EquipmentSlot.HEAD, new ItemStack(Material.DIAMOND_HELMET) + ); + + ClientboundSetEquipmentPacketImpl packet = new ClientboundSetEquipmentPacketImpl(42, equipment); + ClientboundSetEquipmentPacket createdPacket = (ClientboundSetEquipmentPacket) packet.createPacket(); + + assert createdPacket.getEntity() == 42; + assert createdPacket.getSlots().size() == 3; + } +} \ No newline at end of file diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImplTest.java new file mode 100644 index 0000000..34bc26e --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundSetPassengersPacketImplTest.java @@ -0,0 +1,29 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundSetPassengersPacketImpl; +import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class ClientboundSetPassengersPacketImplTest { + + @Test + void createPacket() { + // Setup packet + int vehicleID = 712; + List passengers = new ArrayList<>(); + passengers.add(571); + passengers.add(572); + + ClientboundSetPassengersPacketImpl packet = new ClientboundSetPassengersPacketImpl(vehicleID, passengers); + ClientboundSetPassengersPacket createdPacket = (ClientboundSetPassengersPacket) packet.createPacket(); + + // Check packet + assert createdPacket.getVehicle() == vehicleID; + assert createdPacket.getPassengers().length == 2; + assert createdPacket.getPassengers()[0] == 571; + assert createdPacket.getPassengers()[1] == 572; + } +} diff --git a/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImplTest.java b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImplTest.java new file mode 100644 index 0000000..758e55c --- /dev/null +++ b/implementations/1_21_3/src/test/java/de/oliver/fancysitula/versions/v1_21_3/packets/ClientboundTeleportEntityPacketImplTest.java @@ -0,0 +1,32 @@ +package de.oliver.fancysitula.versions.v1_21_3.packets; + +import de.oliver.fancysitula.api.utils.AngelConverter; +import de.oliver.fancysitula.versions.v1_21_3.packets.ClientboundTeleportEntityPacketImpl; +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import org.junit.jupiter.api.Test; + +class ClientboundTeleportEntityPacketImplTest { + + @Test + void createPacket() { + int entityId = 4313; + double x = 15.0; + double y = 57.0; + double z = -27.0; + float yaw = 90.0f; + float pitch = 45.0f; + boolean onGround = true; + + ClientboundTeleportEntityPacketImpl packet = new ClientboundTeleportEntityPacketImpl(entityId, x, y, z, yaw, pitch, onGround); + ClientboundTeleportEntityPacket createdPacket = (ClientboundTeleportEntityPacket) packet.createPacket(); + + assert createdPacket != null; + assert createdPacket.getId() == entityId; + assert createdPacket.getX() == x; + assert createdPacket.getY() == y; + assert createdPacket.getZ() == z; + assert createdPacket.getyRot() == AngelConverter.degreesToVanillaByte(yaw); + assert createdPacket.getxRot() == AngelConverter.degreesToVanillaByte(pitch); + assert createdPacket.isOnGround() == onGround; + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 8113dff..58680aa 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,5 +6,6 @@ include(":implementations") include(":implementations:1_20_6") include(":implementations:1_21") include(":implementations:1_21_1") +include(":implementations:1_21_3") include(":test_plugin") \ No newline at end of file diff --git a/test_plugin/build.gradle.kts b/test_plugin/build.gradle.kts index bcb8cbb..978a51a 100644 --- a/test_plugin/build.gradle.kts +++ b/test_plugin/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { implementation(project(":api")) implementation(project(":factories")) implementation(project(":implementations:1_20_6")) + implementation(project(":implementations:1_21_3")) implementation("de.oliver.FancyAnalytics:logger:${findProperty("fancyLoggerVersion")}") }