PszemoPL | 2019-03-02 21:12:12 UTC | #1
Mój plugin na efekty powoduje że jak wyrzucę itemki z eq to wyskakuje taki error. Pomoże ktoś?
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1776) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:23) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:9) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [mc.jar:git-Spigot-db6de12-18fbb24]
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_8_R3.SystemUtils.a(SourceFile:44) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [mc.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
Caused by: java.lang.NullPointerException
at pl.pszemopl.efekty.events.InventoryClickListener.onClickMain(InventoryClickListener.java:20) ~[?:?]
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) ~[?:?]
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:306) ~[mc.jar:git-Spigot-db6de12-18fbb24]
... 15 more
[22:01:14 ERROR]: Could not pass event InventoryCreativeEvent to pPLextraefekty v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [mc.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1776) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:23) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInSetCreativeSlot.a(SourceFile:9) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [mc.jar:git-Spigot-db6de12-18fbb24]
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_8_R3.SystemUtils.a(SourceFile:44) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [mc.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [mc.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
Caused by: java.lang.NullPointerException
at pl.pszemopl.pplextraefekty.events.InventoryClickListener.onClickMain(InventoryClickListener.java:20) ~[?:?]
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[?:?]
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:306) ~[mc.jar:git-Spigot-db6de12-18fbb24]
... 15 more
Nieznajomy11 | 2019-03-02 21:11:41 UTC | #2
Potrzebne jest źródło, żeby powiedzieć coś więcej odnośnie do błędu. Gdzieś w onClickMain jakiś getter (strzelam, że pewnie getInventory lub podobny) zwraca nulla.
Kamilkime | 2019-03-02 21:16:11 UTC | #3
https://www.spigotmc.org/threads/tutorial-how-to-read-stacktraces-solve-most-of-your-plugin-problems-by-yourself.48121/
Polecam przeczytanie sobie poradnika o odczytywaniu błędu, dobrze jest to umieć =)
PszemoPL | 2019-03-02 21:17:10 UTC | #4
Tak wyglądaa kod w funkcji “onClickMain”
public class InventoryClickListener implements Listener {
@SuppressWarnings("deprecation")
@EventHandler
public void onClickMain(InventoryClickEvent event) {
Player p = (Player) event.getWhoClicked();
if (ChatUtil.fixColor(Config.NAME).equalsIgnoreCase(event.getClickedInventory().getName())) {
event.setCancelled(true);
if (event.getSlot() == Config.SPEED_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY)), Config.SPEED_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY), Config.SPEED_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Config.SPEED_DURATION, 1, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.SPEED_DURATION, 1, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Config.SPEED_DURATION, 0, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.SPEED_DURATION1, 0, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Config.SPEED_DURATION1, 0, true));
ChatUtil.sendMessage(p, Config.SPEED_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.SPEED_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.SPEED_BUYTITLE), ChatUtil.fixColor(Config.SPEED_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.SPEED_LACK);
}
}
if (event.getSlot() == Config.STRENGTH_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY)), Config.STRENGTH_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY), Config.STRENGTH_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.STRENGTH_DURATION, 0, true));
ChatUtil.sendMessage(p, Config.STRENGTH_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.STRENGTH_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.STRENGTH_BUYTITLE), ChatUtil.fixColor(Config.STRENGTH_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.STRENGTH_LACK);
}
}
if (event.getSlot() == Config.HASTE_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY)), Config.HASTE_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY), Config.HASTE_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.HASTE_DURATION, 0, true));
ChatUtil.sendMessage(p, Config.HASTE_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.HASTE_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.HASTE_BUYTITLE), ChatUtil.fixColor(Config.HASTE_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.HASTE_LACK);
}
}
}
}
}
Nieznajomy11 | 2019-03-02 21:20:33 UTC | #5
Musisz podać całą klasę InventoryClickListener, bez żadnych zmian.
PszemoPL | 2019-03-02 21:21:43 UTC | #6
no to jest
Nieznajomy11 | 2019-03-02 21:25:27 UTC | #7
Zgodnie z kodem, który wkleiłeś 20 linia to:
ChatUtil.sendMessage(p, Config.SPEED_LACK);
Nie widzę, żeby coś tutaj mogło wyrzucić NPE.
Kamilkime | 2019-03-02 21:29:14 UTC | #9
To może policz linijki u siebie w kodzie?
PszemoPL | 2019-03-02 21:43:16 UTC | #10
20 linijka to
if (ChatUtil.fixColor(Config.NAME).equalsIgnoreCase(event.getClickedInventory().getName())) {
PszemoPL | 2019-03-02 21:50:23 UTC | #11
Proszę InventoryClickListener razem z importami
package pl.pszemopl.pplextraefekty.events;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import pl.pszemopl.pplextraefekty.configurations.Config;
import pl.pszemopl.pplextraefekty.utils.ChatUtil;
public class InventoryClickListener implements Listener {
@SuppressWarnings("deprecation")
@EventHandler
public void onClickMain(InventoryClickEvent event) {
Player p = (Player) event.getWhoClicked();
if (ChatUtil.fixColor(Config.NAME).equalsIgnoreCase(event.getClickedInventory().getName())) {
event.setCancelled(true);
if (event.getSlot() == Config.SPEED_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY)), Config.SPEED_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.SPEED_CURRENCY), Config.SPEED_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Config.SPEED_DURATION, 1, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.SPEED_DURATION, 1, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Config.SPEED_DURATION, 0, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.SPEED_DURATION1, 0, true));
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Config.SPEED_DURATION1, 0, true));
ChatUtil.sendMessage(p, Config.SPEED_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.SPEED_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.SPEED_BUYTITLE), ChatUtil.fixColor(Config.SPEED_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.SPEED_LACK);
}
}
if (event.getSlot() == Config.STRENGTH_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY)), Config.STRENGTH_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.STRENGTH_CURRENCY), Config.STRENGTH_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Config.STRENGTH_DURATION, 0, true));
ChatUtil.sendMessage(p, Config.STRENGTH_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.STRENGTH_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.STRENGTH_BUYTITLE), ChatUtil.fixColor(Config.STRENGTH_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.STRENGTH_LACK);
}
}
if (event.getSlot() == Config.HASTE_SLOT) {
if (p.getInventory().containsAtLeast(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY)), Config.HASTE_AMOUNT)) {
p.getInventory().removeItem(new ItemStack(Material.getMaterial(Config.HASTE_CURRENCY), Config.HASTE_AMOUNT));
p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Config.HASTE_DURATION, 0, true));
ChatUtil.sendMessage(p, Config.HASTE_BUYMESS);
Bukkit.getOnlinePlayers().forEach(all -> ChatUtil.sendMessage(all, Config.HASTE_BUYBC.replace("{PLAYER}", p.getName())));
p.sendTitle(ChatUtil.fixColor(Config.HASTE_BUYTITLE), ChatUtil.fixColor(Config.HASTE_BUYSUBTITLE));
} else {
ChatUtil.sendMessage(p, Config.HASTE_LACK);
}
}
}
}
}
Kamilkime | 2019-03-02 21:50:31 UTC | #12
Jeśli gracz kliknie poza inventory - getClickedInventory() zwróci null
I najlepiej wrzucaj kod np. na pastebin.com
PszemoPL | 2019-03-02 21:50:40 UTC | #13
okej
PszemoPL | 2019-03-02 22:13:29 UTC | #14
nie działa
Kamilkime | 2019-03-02 22:14:02 UTC | #15
No… Napisanie nie działa
zupełnie nic mi nie mówi - jakieś błędy, kod, itd.
PszemoPL | 2019-03-02 22:15:14 UTC | #16
Tak wygląda kod
https://pastebin.com/Ptx6qMDG
A to jest błąd
https://pastebin.com/HhK96dJS
Kamilkime | 2019-03-02 22:16:53 UTC | #17
To teraz przeczytaj raz jeszcze co ci napisałem, co może być null’em :/
PszemoPL | 2019-03-02 22:18:56 UTC | #18
No getClickedInventory()
Kamilkime | 2019-03-02 22:19:30 UTC | #19
No, to teraz się zastanów co sprawdzasz tym warunkiem
system | 2019-04-03 22:19:30 UTC | #20
Ten temat został automatycznie zamknięty 32 dni po ostatnim wpisie. Tworzenie nowych odpowiedzi nie jest już możliwe.