因此,我插件中的所有内容均正常运行,并且可以正常生成马并将它们删除,但是没有问题,但是,每当我右键单击air或block时,这都会在控制台日志中发生。
[18:07:20 ERROR]: Could not pass event PlayerInteractEvent to FiorePlugin v1.2
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:235) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:458) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:951) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_191]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_191]
at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
Caused by: java.lang.NullPointerException
at io.github.bxnie.events.HorseSpawn.onPlayerInteract(HorseSpawn.java:37) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-eb3d921-2b93d83]
... 17 more
这是我的HorseSpawn类,错误所引用:
package io.github.bxnie.events;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
public class HorseSpawn implements Listener {
private HashMap<UUID, Long> cooldowndonkey = new HashMap<UUID, Long>();
private HashMap<UUID, Long> cooldownbrown = new HashMap<UUID, Long>();
private HashMap<UUID, Long> cooldownblack = new HashMap<UUID, Long>();
private HashMap<UUID, Long> cooldownwhite = new HashMap<UUID, Long>();
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
Player p = e.getPlayer();
ItemStack item = e.getItem();
if(item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Donkey")) {
if(cooldowndonkey.containsKey(p.getUniqueId()) && cooldowndonkey.get(p.getUniqueId()) > System.currentTimeMillis()) {
e.setCancelled(true);
long remainingTime = cooldowndonkey.get(p.getUniqueId()) - System.currentTimeMillis();
p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Horses" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You cannot spawn your horse for another " + ChatColor.RED + ChatColor.ITALIC + remainingTime/1000 + ChatColor.GRAY + ChatColor.ITALIC + " seconds");
} else {
cooldowndonkey.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
Donkey donkey = (Donkey) p.getWorld().spawn(p.getLocation(), Donkey.class);
donkey.setAdult();
donkey.setTamed(true);
donkey.setOwner(p);
donkey.getInventory().setSaddle(new ItemStack(Material.SADDLE));
donkey.setCustomName(ChatColor.GRAY + "Donkey");
donkey.setPassenger(p);
donkey.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.3);
donkey.setInvulnerable(true);
}
}
if(item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Brown Horse")) {
if(cooldownbrown.containsKey(p.getUniqueId()) && cooldownbrown.get(p.getUniqueId()) > System.currentTimeMillis()) {
e.setCancelled(true);
long remainingTime = cooldownbrown.get(p.getUniqueId()) - System.currentTimeMillis();
p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Horses" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You cannot spawn your horse for another " + ChatColor.RED + ChatColor.ITALIC + remainingTime/1000 + ChatColor.GRAY + ChatColor.ITALIC + " seconds");
} else {
cooldownbrown.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
Horse horsebrown = (Horse) p.getWorld().spawn(p.getLocation(), Horse.class);
horsebrown.setAdult();
horsebrown.setTamed(true);
horsebrown.setOwner(p);
horsebrown.getInventory().setSaddle(new ItemStack(Material.SADDLE));
horsebrown.setCustomName(ChatColor.RED + "Horse");
horsebrown.setPassenger(p);
horsebrown.setJumpStrength(0.4);
horsebrown.setInvulnerable(true);
horsebrown.setColor(Color.BROWN);
horsebrown.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.45);
}
}
if(item.getItemMeta().getDisplayName().equals(ChatColor.DARK_GRAY + "Black Horse")) {
if(cooldownblack.containsKey(p.getUniqueId()) && cooldownblack.get(p.getUniqueId()) > System.currentTimeMillis()) {
e.setCancelled(true);
long remainingTime = cooldownblack.get(p.getUniqueId()) - System.currentTimeMillis();
p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Horses" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You cannot spawn your horse for another " + ChatColor.RED + ChatColor.ITALIC + remainingTime/1000 + ChatColor.GRAY + ChatColor.ITALIC + " seconds");
} else {
cooldownblack.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
Horse horseblack = (Horse) p.getWorld().spawn(p.getLocation(), Horse.class);
horseblack.setAdult();
horseblack.setTamed(true);
horseblack.setOwner(p);
horseblack.getInventory().setSaddle(new ItemStack(Material.SADDLE));
horseblack.setCustomName(ChatColor.DARK_GRAY + "Horse");
horseblack.setPassenger(p);
horseblack.setJumpStrength(0.6);
horseblack.setColor(Color.BLACK);
horseblack.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.6);
horseblack.setInvulnerable(true);
}
}
if(item.getItemMeta().getDisplayName().equals(ChatColor.WHITE + "White Horse")) {
if(cooldownwhite.containsKey(p.getUniqueId()) && cooldownwhite.get(p.getUniqueId()) > System.currentTimeMillis()) {
e.setCancelled(true);
long remainingTime = cooldownwhite.get(p.getUniqueId()) - System.currentTimeMillis();
p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Horses" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You cannot spawn your horse for another " + ChatColor.RED + ChatColor.ITALIC + remainingTime/1000 + ChatColor.GRAY + ChatColor.ITALIC + " seconds");
} else {
cooldownwhite.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
Horse horsewhite = (Horse) p.getWorld().spawn(p.getLocation(), Horse.class);
horsewhite.setAdult();
horsewhite.setTamed(true);
horsewhite.setOwner(p);
horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
horsewhite.setCustomName(ChatColor.WHITE + "Horse");
horsewhite.setPassenger(p);
horsewhite.setJumpStrength(1.2);
horsewhite.setColor(Color.WHITE);
horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.8);
horsewhite.setInvulnerable(true);
}
}
return;
}
return;
}
@EventHandler
public void onPLayerDismount(VehicleExitEvent e) {
if(e.getExited() instanceof Player) {
if(e.getVehicle() instanceof Donkey) {
Donkey donkey = (Donkey) e.getVehicle();
if(donkey.getCustomName() != null) {
if(donkey.getCustomName().equals(ChatColor.GRAY + "Donkey")) {
donkey.remove();
}
}
}
if(e.getVehicle() instanceof Horse) {
Horse horse = (Horse) e.getVehicle();
if(horse.getCustomName() != null) {
if(horse.getCustomName().equals(ChatColor.RED + "Horse")) {
horse.remove();
}
if(horse.getCustomName().equals(ChatColor.DARK_GRAY + "Horse")) {
horse.remove();
}
if(horse.getCustomName().equals(ChatColor.WHITE + "Horse")) {
horse.remove();
}
}
}
}
}
}
老实说,我不知道我在做什么错,这个错误才会出现。请帮助