jython/python中的奇怪类型错误?

2024-06-28 20:05:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我是bukkit jython/python插件程序员。最近几天,我一直在努力解决这个问题。我必须给用户添加药剂效果,如果我在代码中手动输入效果名称、持续时间和放大器,这不是问题,但是当我想从配置中获取它们时,我得到以下错误:

    13:38:20 [SEVERE] Could not pass event PlayerInteractEvent to ItemEffect v1.0
    Traceback (most recent call last):
    File "<iostream>", line 126, in onPlayerInteractEvent
    TypeError: addPotionEffect(): 1st arg can't be coerced to org.bukkit.potion.Poti
    onEffect

下面是代码的一部分:

^{pr2}$

当我打印getpotioneffect时,我得到:

    13:38:20 [INFO] PotionEffect(PotionEffectType.SPEED, 600, 1)

没关系,应该行得通。我测试了它,没有从配置信息,它工作完美。。。综上所述,上述代码无效,但下面的代码有效:

    getpotioneffect = PotionEffect(PotionEffectType.SPEED, 600, 1)
    if iteminhand == currentKey:
       event.getPlayer().addPotionEffect(getpotioneffect)

链接到这个事件的javadocs!在

http://jd.bukkit.org/rb/apidocs/org/bukkit/entity/LivingEntity.html#addPotionEffect(org.bukkit.potion.PotionEffect)

谢谢!在


Tags: to代码org插件eventjython程序员speed
1条回答
网友
1楼 · 发布于 2024-06-28 20:05:47

在第一个代码段中,^{{cd1>}是一个字符串。您可以在某处检查它添加^{{cd2>}。

您想要的是替换:

geteffectname = "PotionEffectType.%s"%effectname
getpotioneffect = "PotionEffect(%s, %i, 1)"%(geteffectname, durationinticks)

使用此选项:

^{pr2}$

相关问题 更多 >