这个错误代表什么以及如何修复它?

时间:2013-11-18 13:47:06

标签: java python exception jython

我是jython / python bukkit插件编码器,我得到了奇怪的错误..我正在尝试重新编写已经在Python中完成的东西(在Java中)...这是代码的java部分:

    HashMap<Player, String> channelList = new HashMap<Player, String>();
    public void useChannel(Player p, String format, String channel){
    if(channel == "main"){
        Bukkit.broadcastMessage(format);
    } else {
          Player[] online = Bukkit.getOnlinePlayers();
          for(int a = 0; a <= online.length - 1; a++){
              if(channelList.get(online[a]) == channel){
                  online[a].sendMessage("*" + format);
              }
          }
    }
}

@EventHandler
public void onChat(AsyncPlayerChatEvent event){
    event.setCancelled(true);
    String channel = event.getMessage().substring(0, 1);
    String userChannel = "";
    switch(channel){
    case "!": userChannel = "spanish";
    case "?": userChannel = "french";
    case "@": userChannel = "dutch";
    case "$": userChannel = "spanish";
    default: userChannel = "main";     
    }
    useChannel(event.getPlayer(), event.getFormat(), userChannel);
}

}

这是我在python / jython中所做的(请记住,这可能不相同,这是导致错误的原因):

    channelList = HashMap()

    def useChannel(self):
    format = event.player.AsyncPlayerChatEvent.getFormat()    
    if(channel == "main"):
      Bukkit.broadcastMessage(format)
    else:
        online = Bukkit.getOnlinePlayers()
        b = online.lenght - 1
        a = 0
        for a in a <= b:
            if channelList.get(online[a]) == channel:
               online[a].sendMessage("* %s"%format)

def balkanChannel(self):
    userChannel = "balkan"
    return userChannel

def germanChannel(self):
    userChannel = "german"
    return userChannel

@hook.event("player.AsyncPlayerChatEvent", "HIGHEST")
def onAsyncPlayerChatEvent(event):
    event.setCancelled(1)
    channel = event.getMessage().substring(0, 1)
    userChannel = ""  
    try:
       options = {
               '!': pyplugin.balkanChannel,
               '$': pyplugin.germanChannel}
       if value in switch:
          switch[value]() 
       else:
           pass
    except KeyError:
          userChannel = "main"
    pyplugin.useChannel(event.getPlayer(), event.getFormat(), userChannel)

这是与聊天相关的插件,应该在AsyncChatPlayerEvent上检查是否有!消息中的$或前缀...这些前缀在Java中作为“case”完成,但据我所知,在Python中没有类似的东西,所以我这样做了(这可能不是正确的方式) )?

这是我在与这些前缀($和!)聊天时遇到的错误:

14:38:59 [SEVERE] java.util.logging.ErrorManager: 5
>
Exception: org.python.core.PyException thrown from the UncaughtExceptionHandler
in thread "Connection #1 read thread"

总结一下,我试图将java代码上面的“重新编码”改为python,但是我得到了一些奇怪的错误......

感谢您的回答! :)

P.S。服务器在发生spitts错误后冻结......如果你需要更多的信息,只需评论...

1 个答案:

答案 0 :(得分:0)

这是我的错,抱歉。我使用了错误的事件......

我使用的是AsyncPlayerChatEvent而不是常规的PlayerChatEvent ...