개인 자료란 (JE)

  서버 커뮤니티

Profile Namul 대표칭호 없음

TheNamul d0be88a9d1fc444cb1ffba68dbbf077a

Profile

질문하기 Java

protocolLib 이용하는데 WrappedDataWatcher 부분에서 막혔습니다.

2024.06.12 조회 수 81 추천 수 0
이해도 초보자 
게임버전 (JE) 1.20, 1.20.1 
게임버전 (BE) 관련없음 

package com.example.motionplugin;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.Vector3F;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class MotionPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        getLogger().info("MotionPlugin has been enabled");
    }

    @Override
    public void onDisable() {
        getLogger().info("MotionPlugin has been disabled");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player && command.getName().equalsIgnoreCase("playmotion")) {
            Player player = (Player) sender;
            startSwingingMotion(player);
            return true;
        }
        return false;
    }

    public void startSwingingMotion(Player player) {
        new BukkitRunnable() {
            double angle = 0;
            boolean direction = true; // true면 오른쪽으로, false면 왼쪽으로

            @Override
            public void run() {
                // 팔을 좌우로 흔드는 모션
                if (direction) {
                    angle += 10;
                    if (angle >= 10) {
                        direction = false;
                    }
                } else {
                    angle -= 10;
                    if (angle <= -10) {
                        direction = true;
                    }
                }

                // 새 팔 각도 설정
                setPlayerArmAngle(player, angle);
            }
        }.runTaskTimer(this, 0L, 10L); // 0L 딜레이 후 10L (0.5초)마다 실행
    }

    private void setPlayerArmAngle(Player player, double angle) {
        ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

        // DataWatcher 설정
        WrappedDataWatcher watcher = new WrappedDataWatcher(player);

        // 팔의 각도 설정 (각도는 라디안으로 변환)
        float radians = (float) Math.toRadians(angle);

        // DataWatcherObject를 사용하여 오른팔 각도 설정
        WrappedDataWatcher.Serializer vectorSerializer = WrappedDataWatcher.Registry.get(Vector3F.getMinecraftClass());
        WrappedDataWatcherObject rightArmPose = new WrappedDataWatcherObject(15, vectorSerializer); 
        watcher.setObject(rightArmPose, new Vector3F(0, radians, 0));

        // 패킷 생성 및 전송
        PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
        packet.getIntegers().write(0, player.getEntityId());
        packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());

        try {
            for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
                protocolManager.sendServerPacket(onlinePlayer, packet);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

이게 코드이고 현재 protocolLib 버전은 5.2.0 ,마크 버전은 1.20.2
들어가서 명령어 사용하면

Internal Exception: io.netty.handler.codec. Encoder Exception: java.lang.ClassCastException: class net.minecraft.network.syncher.Datawatcher$Item cannot be cast to class net.minecraft.network.syncher.Datawatcher$b (net.minecraft.network.syncher.Datawatcher$Item and net.minecraft.network.syncher.Datawatcher$b are in unnamed module of loader java.net.URLClassLoader @504bae78) 

이러한 오류가 뜹니다. 도움 구합니다.




2개의 댓글