我正在创建一个PvP插件,但是我无法继续,因为我有一个烦人的演员问题,无法解决。我正在尝试获取最后的损坏原因,即伤害者,检查伤害者是否使用了箭,将“箭头”转换为射手。但是它经常在控制台中给我错误。
所以这是我的代码
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行是什么。