Skip to content

Commit

Permalink
Added spigot setRot
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRedMagic committed Jun 15, 2024
1 parent d8e69d0 commit 38cfcaa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

apply(plugin = "maven-publish")
val versionVar = "0.5.28"
val versionVar = "0.5.29"
val groupIdVar = "com.redmagic"
val artifactIdVar = "UndefinedAPI"

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/redmagic/undefinedapi/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Main: JavaPlugin() {

event<PlayerJoinEvent> {

println(player.getTexture())
player.location.block.glow(ChatColor.RED, listOf(player), 10000)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ object SpigotNMSMappings {
const val ClientboundContainerSetSlotPacketSlot = "e"
const val ClientboundContainerSetSlotPacketItemStack = "f"
const val ServerboundSetCarriedItemPacketSlot = "a"


const val EntitySetRotMethod = "a"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.redmagic.undefinedapi.nms.EntityInteract
import com.redmagic.undefinedapi.nms.extensions.getPrivateField
import com.redmagic.undefinedapi.nms.interfaces.NMSEntity
import com.redmagic.undefinedapi.nms.v1_20_4.NMSManager
import com.redmagic.undefinedapi.nms.v1_20_4.SpigotNMSMappings
import com.redmagic.undefinedapi.nms.v1_20_4.entity.entityClasses.UndefinedEntity
import com.redmagic.undefinedapi.nms.v1_20_4.extensions.sendPacket
import net.minecraft.ChatFormatting
Expand Down Expand Up @@ -146,7 +147,11 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
val entity = getUndefinedEntityClass(nmsEntityType, craftWorld.handle)

entity.setPos(newLocation.x, newLocation.y, newLocation.z)
entity.setRot(newLocation.yaw, newLocation.pitch)

val m = Entity::class.java.getDeclaredMethod(SpigotNMSMappings.EntitySetRotMethod, Float::class.java, Float::class.java)
m.isAccessible = true
m.invoke(entity, newLocation.yaw, newLocation.pitch)


scoreboard.addPlayerToTeam(entity.uuid.toString(), team)

Expand All @@ -167,7 +172,9 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
override fun teleport(newLocation: Location) {
entity?.let {
entity!!.setPos(newLocation.x, newLocation.y, newLocation.z)
entity!!.setRot(newLocation.yaw, newLocation.pitch)
val m = Entity::class.java.getDeclaredMethod(SpigotNMSMappings.EntitySetRotMethod, Float::class.java, Float::class.java)
m.isAccessible = true
m.invoke(entity, newLocation.yaw, newLocation.pitch)

val packet = ClientboundTeleportEntityPacket(entity!!)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package com.redmagic.undefinedapi.nms.v1_20_5

/**
* This object contains constant values used for Spigot NMS mapping.
*
* @property ClientboundSetEntityDataPacketEntityID The key used to access the entity ID in the ClientboundSetEntityDataPacket.
* @property ClientboundSetEntityDataPacketSyncedEntityList The key used to access the synchronized entity list in the ClientboundSetEntityDataPacket.
* @property ServerboundInteractPacketEntityID The key used to access the entity ID in the ServerboundInteractPacket.
* @property ServerboundInteractPacketAction The key used to access the action in the ServerboundInteractPacket.
* @property ServerboundInteractPacketActionHand The key used to access the action hand in the ServerboundInteractPacket.
* @property ServerCommonPacketListenerImplConnection The key used to access the connection in the ServerCommonPacketListenerImpl.
*/

object SpigotNMSMappings {

const val ClientboundSetEntityDataPacketEntityID = "c"
Expand All @@ -23,4 +14,6 @@ object SpigotNMSMappings {
const val ClientboundContainerSetSlotPacketSlot = "f"
const val ClientboundContainerSetSlotPacketItemStack = "g"
const val ServerboundSetCarriedItemPacketSlot = "b"

const val EntitySetRotMethod = "a"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.redmagic.undefinedapi.nms.v1_20_5.entity
import com.redmagic.undefinedapi.nms.EntityInteract
import com.redmagic.undefinedapi.nms.interfaces.NMSEntity
import com.redmagic.undefinedapi.nms.v1_20_5.NMSManager
import com.redmagic.undefinedapi.nms.v1_20_5.SpigotNMSMappings
import com.redmagic.undefinedapi.nms.v1_20_5.entity.entityClass.UndefinedEntity
import com.redmagic.undefinedapi.nms.v1_20_5.extensions.sendPacket
import net.minecraft.ChatFormatting
Expand Down Expand Up @@ -141,7 +142,9 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
val entity = getUndefinedEntityClass(nmsEntityType, craftWorld.handle)

entity.setPos(newLocation.x, newLocation.y, newLocation.z)
entity.setRot(newLocation.yaw, newLocation.pitch)
val m = Entity::class.java.getDeclaredMethod(SpigotNMSMappings.EntitySetRotMethod, Float::class.java, Float::class.java)
m.isAccessible = true
m.invoke(entity, newLocation.yaw, newLocation.pitch)

scoreboard.addPlayerToTeam(entity.uuid.toString(), team)

Expand All @@ -162,7 +165,9 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
override fun teleport(newLocation: Location) {
entity?.let {
entity!!.setPos(newLocation.x, newLocation.y, newLocation.z)
entity!!.setRot(newLocation.yaw, newLocation.pitch)
val m = Entity::class.java.getDeclaredMethod(SpigotNMSMappings.EntitySetRotMethod, Float::class.java, Float::class.java)
m.isAccessible = true
m.invoke(entity, newLocation.yaw, newLocation.pitch)

val packet = ClientboundTeleportEntityPacket(entity!!)

Expand Down

0 comments on commit 38cfcaa

Please sign in to comment.