Я делаю плагин для друга, он хочет плагин для выращивания сорняков. Я хочу, чтобы, если я щелкну правой кнопкой мыши по цветочному горшку с семенами, в цветочном горшке появится саженец дуба, но я получаю ошибку. Я пробовал столько вещей, чтобы исправить эту ошибку, но я не знаю, как это сделать.
@EventHandler
public void onPlace(PlayerInteractEvent e) {
Player p = e.getPlayer();
//----------------------------------------------------//
ItemStack amnesiaHaze = new ItemStack (Material.BEETROOT_SEEDS, 1);
ItemMeta amnesiaMeta = amnesiaHaze.getItemMeta();
amnesiaMeta.setDisplayName("§2Amnesia-Haze Seeds");
amnesiaHaze.setItemMeta(amnesiaMeta);
//----------------------------------------------------//
Block block = e.getClickedBlock();
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(block.getType() == Material.FLOWER_POT) {
if(p.getInventory().getItemInMainHand().equals(amnesiaHaze)) {
((FlowerPot) block.getState().getData()).setContents(new MaterialData(Material.OAK_SAPLING));
block.getState().update();
p.getInventory().getItemInHand().setAmount(p.getItemInHand().getAmount()-1);
}
}
}
}
Ошибка:
[14:25:20] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to DeniPlugin v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:529) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:514) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:442) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.PlayerInteractManager.a(PlayerInteractManager.java:441) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1250) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:27) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:918) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:911) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:895) [spigot.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:828) [spigot.jar:git-Spigot-800b93f-8160e29]
at java.lang.Thread.run(Unknown Source) [?:?]
**Caused by: java.lang.ClassCastException: org.bukkit.material.MaterialData cannot be cast to org.bukkit.material.FlowerPot**
at de.deni.survival.weedplugin.classes.L_CreatePlant.onPlace(L_CreatePlant.java:33) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[spigot.jar:git-Spigot-800b93f-8160e29]
... 19 more