gpt4 book ai didi

java - Bukkit/Spigot - EntityDamageByEntityEvent : cast the shooter

转载 作者:行者123 更新时间:2023-12-02 02:55:13 25 4
gpt4 key购买 nike

我正在创建一个 PvP 插件,但我无法继续,因为我有一个无法解决的恼人的 Actor 问题。我正在尝试获取最后一个伤害原因,即伤害者,检查伤害者是否使用了箭头,将“箭头”转换为<射手。但它不断地在我的控制台中给出错误。

这是我的代码

Player player = (Player)event.getPlayer(); // this variable is in my public void onPlayerMovement event
if(((EntityDamageByEntityEvent) player.getLastDamageCause()).getDamager() instanceof Arrow)
{
Arrow arrow = (Arrow) ((EntityDamageByEntityEvent) player.getLastDamageCause()).getDamager();
ProjectileSource shooter = ((ProjectileSource) ((EntityDamageByEntityEvent) player.getLastDamageCause()).getDamager());

if(shooter instanceof Player) // checking if the shooter is a player.
{
shooter.sendMessage("You hitted someone with a bow right?");
player.sendMessage("You got hit by a bow..");
}
}

我想将箭头转换为射手的原因是因为我想向射手显示一条消息,以及其他一些东西。

这是错误

[22:39:10 ERROR]: Could not pass event PlayerMoveEvent to FendykPVP v1.8
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:270) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PacketPlayInFlying.a(SourceFile:126) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:57) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_121]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.entity.CraftArrow cannot be cast to org.bukkit.entity.Player
at GameCore.playerKill.onPlayerMovement(playerKill.java:102) ~[?:?]
at sun.reflect.GeneratedMethodAccessor1391.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
... 15 more

我希望有人能帮我解决这个问题

最佳答案

这可能有效,也可能无效,我自己还没有测试过。但在转换之前你需要检查它是否是箭头。另外,为了获取射手,射弹类中还有箭头可以使用的方法 arrow.getShooter()

if(((EntityDamageByEntityEvent) player.getLastDamageCause()).getDamager() instanceof Arrow) {
Arrow arrow = (Arrow) ((EntityDamageByEntityEvent) player.getLastDamageCause()).getDamager();
ProjectileSource shooter = arrow.getShooter();

if(shooter instanceof Player) // checking if the shooter is a player.
{
Player shooterPlayer = (Player) shooter;
shooterPlayer.sendMessage("You hitted someone with a bow right?");
player.sendMessage("You got hit by a bow..");
}
}

如果没有帮助,请告诉我第 102 行是什么。

关于java - Bukkit/Spigot - EntityDamageByEntityEvent : cast the shooter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43194090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com