2014-04-06 54 views
0

我正在制作一个Craftbukkit插件,它在播放器计数列表中有一条消息,如HIVE-MC或Omega Realm。我在Ecplise编码并使用ProtocolLib v3.2.0和Craftbukkit 1.7.2 R0.3。我对java很陌生,不太了解它。我知道一切都是进口的。使用ProtocolLibrary PacketAdapter时发生错误()

到目前为止,这里都是进口的方法,代码和错误

方法:

import java.io.File; 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.List; 

import org.bukkit.plugin.java.JavaPlugin; 

import com.comphenix.protocol.PacketType; 
import com.comphenix.protocol.ProtocolLibrary; 
import com.comphenix.protocol.events.ListenerOptions; 
import com.comphenix.protocol.events.ListenerPriority; 
import com.comphenix.protocol.events.PacketAdapter; 
import com.comphenix.protocol.wrappers.WrappedGameProfile; 

代码:

private List<WrappedGameProfile> message = new ArrayList<WrappedGameProfile>(); 

public void onEnable() { 
    if(!new File(getDataFolder(),"RESET.FILE").exists()){ 
     try { 
      getConfig().set("PCMessage", 
        Arrays.asList(new String[]{"First Line", "Second Line"})); 
      new File(getDataFolder(),"RESET.FILE").createNewFile(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

    } 
    saveConfig(); 

    for (String str : getConfig().getStringList("PCMessage")) 
     message.add(new WrappedGameProfile("1", str)); 



    ProtocolLibrary 
    .getProtocolManager() 
    .addPacketListener(
      new PacketAdapter(
        this,ListenerPriority.NORMAL, 
      Arrays.asList(new PacketType[] {PacketType.Status.Server.OUT_SERVER_INFO}), 
      new ListenerOptions[] { ListenerOptions.ASYNC })); { 

    } 
} 

错误:

enter image description here

Cannot instantiate the type PacketAdapter

回答

0

正如你将在Javadocs为PacketAdapeter看到,它被声明为:

public abstract class PacketAdapter implements PacketListener 

abstract意味着该类不是一个完整的类,并且必须作为一个完整的类或anonymous class,它不能被实例化。你需要找到PacketAdapter的一个子类,或者自己创建一个。

欲了解更多信息,请参阅Java教程Abstract Methods and Classes