Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justADeni committed Oct 28, 2023
1 parent 1a61bea commit deacef0
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 70 deletions.
16 changes: 1 addition & 15 deletions src/main/java/com/github/justadeni/standapi/StandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import com.github.shynixn.mccoroutine.bukkit.ticks
import kotlinx.coroutines.*
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.World
import org.bukkit.entity.Player
import java.util.Collections
Expand Down Expand Up @@ -161,20 +160,11 @@ object StandManager {
if (!ticking.containsKey(-1))
continue

//val taskQueue = mutableListOf<() -> Unit>()

val listIt = ticking[-1]!!.iterator()
while (listIt.hasNext()) {
val stand = listIt.next()
/*
if (stand.getAttached() == null){
taskQueue.add {
remove(stand)
addWithId(stand, -2)
}
continue
}
*/

stand.getAttached() ?: continue
val entity = withContext(StandAPI.plugin().minecraftDispatcher) { Bukkit.getEntity(stand.getAttached()!!.first) } ?: continue

Expand All @@ -183,10 +173,6 @@ object StandManager {
addWithId(stand, entity.entityId)
stand.setLocation(entity.location.applyOffset(stand.getAttached()?.second))
}
/*
for (task in taskQueue)
task.invoke()
*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.github.justadeni.standapi.StandAPI
* @suppress
*/
class EntityMoveListener {

init {
StandAPI.manager().addPacketListener(object : PacketAdapter(StandAPI.plugin(), ListenerPriority.LOW, PacketType.Play.Server.REL_ENTITY_MOVE) {
override fun onPacketSending(event: PacketEvent) {
Expand All @@ -26,8 +27,10 @@ class EntityMoveListener {
val attachedToPlayer = Util.getPlayerById(entityId, player.world)

for (stand in list) {
val cloned = packet.shallowClone()

stand.setLocationNoUpdate(player.location.applyOffset(stand.getAttached()?.second))

val cloned = packet.shallowClone()
cloned.integers.write(0, stand.id)
cloned.sendTo(player)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,8 @@ class EntityPitchListener {

val list = StandManager.attachedTo(entityId) ?: return

//val attachedToPlayer = Misc.getPlayerById(entityId, player.world)

for (stand in list) {
/*
val cloned = packet.shallowClone()
if (stand.isAttachedPitch())
stand.rotations[0] = (Rotation(cloned.bytes.read(1) * 360.0F / 256.0F, stand.getHeadPose().yaw, stand.getHeadPose().roll))
else
cloned.bytes.write(1, (stand.getHeadPose().pitch * 256.0F / 360.0F).toInt().toByte())
cloned.bytes.write(0, (stand.getBodyPose().yaw * 256.0F / 360.0F).toInt().toByte())
cloned.integers.write(0, stand.id)
cloned.sendTo(player)

if (attachedToPlayer != null)
cloned.sendTo(attachedToPlayer)
*/
if (stand.isAttachedPitch())
stand.setHeadPose(Rotation(packet.bytes.read(1) * 360.0F / 256.0F, stand.getHeadPose().yaw, stand.getHeadPose().roll))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.github.justadeni.standapi.datatype.Rotation
* @suppress
*/
class EntityPitchMoveListener {

init {
StandAPI.manager().addPacketListener(object : PacketAdapter(StandAPI.plugin(), ListenerPriority.LOW, PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) {
override fun onPacketSending(event: PacketEvent) {
Expand All @@ -28,16 +29,9 @@ class EntityPitchMoveListener {

for (stand in list) {

val cloned = packet.shallowClone()

stand.setLocationNoUpdate(player.location.applyOffset(stand.getAttached()?.second))
/*
if (stand.isAttachedPitch())
stand.rotations[0] = (Rotation(cloned.bytes.read(1) * 360.0F / 256.0F, stand.getHeadPose().yaw ,stand.getHeadPose().roll))
else
cloned.bytes.write(1, (stand.getHeadPose().pitch * 256.0F / 360.0F).toInt().toByte())

*/
val cloned = packet.shallowClone()
cloned.bytes.write(0, (stand.getBodyPose().yaw * 256.0F / 360.0F).toInt().toByte())
cloned.integers.write(0, stand.id)
cloned.sendTo(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,12 @@ class EntityYawListener {
init {
StandAPI.manager().addPacketListener(object : PacketAdapter(StandAPI.plugin(), ListenerPriority.LOW, PacketType.Play.Server.ENTITY_HEAD_ROTATION) {
override fun onPacketSending(event: PacketEvent) {
//val player = event.player
val packet = event.packet
val entityId = packet.integers.read(0)

val list = StandManager.attachedTo(entityId) ?: return

//val attachedToPlayer = Misc.getPlayerById(entityId, player.world)

for (stand in list) {
/*
val cloned = packet.shallowClone()
cloned.integers.write(0, stand.id)
if (stand.isAttachedYaw())
stand.rotations[0] = Rotation(stand.getHeadPose().pitch, cloned.bytes.read(0) * 360.0F / 256.0F, stand.getHeadPose().roll)
else
continue
cloned.sendTo(player)
if (attachedToPlayer != null)
cloned.sendTo(attachedToPlayer)
*/

if (stand.isAttachedYaw())
stand.setHeadPose(Rotation(stand.getHeadPose().pitch, packet.bytes.read(0) * 360.0F / 256.0F, stand.getHeadPose().roll))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ class TeleportListener {

val loc = Location(player.world, packet.doubles.read(0), packet.doubles.read(1), packet.doubles.read(2))
for (stand in list){
/*
if (stand.getAttached()!!.second == Offset.ZERO) {
packet.shallowClone().also { it.integers.write(0, stand.id) }.sendTo(listOf(player))
continue
}
val altPacket = packet.shallowClone()
altPacket.integers.write(0, stand.id)
altPacket.doubles.write(0,altPacket.doubles.read(0) + stand.getAttached()!!.second.x)
altPacket.doubles.write(1,altPacket.doubles.read(1) + stand.getAttached()!!.second.y)
altPacket.doubles.write(2,altPacket.doubles.read(2) + stand.getAttached()!!.second.z)
altPacket.sendTo(player)
*/

stand.setLocation(loc.applyOffset(stand.getAttached()?.second))
}
}
Expand Down
Binary file modified target/StandAPI-1.8.jar
Binary file not shown.

0 comments on commit deacef0

Please sign in to comment.