업로드
대표칭호 없음
Upload18 4e03df7f25d64f6db683ff448ef5875f
이해도 | 플러그인 |
---|
제가 인벤토리 관련 코드를 작성했는데
제가 선택한 아이템일 경우 특정 동작을 취하고,
그 외 아이템일 경우 반환하는 식으로 코드를 짰습니다.
package shopgui.comsangbabo; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; 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 java.util.Objects; public class IronClick implements Listener { @EventHandler public void onClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); int min = 1; int max = 7; int randomAbl = (int) (Math.random() * (max - min)) + 1; if (Objects.requireNonNull(event.getCurrentItem()).getItemMeta().getDisplayName() == null) { return; } else if (Objects.requireNonNull(event.getCurrentItem()).getItemMeta().getDisplayName().equals(" ")) { event.setCancelled(true); return; } else if (Objects.requireNonNull(event.getCurrentItem()).getItemMeta().getDisplayName().equals(ChatColor.GRAY + "ㅎㅇ")) { event.setCancelled(true); return; } else if (Objects.requireNonNull(event.getCurrentItem()).getType() == null) { return; } else if (event.getCurrentItem() == null) { return; } else if (player.getInventory() == null) { return; } if (Objects.requireNonNull(event.getCurrentItem()).getItemMeta().getDisplayName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "추첨")) { if (player.getInventory().containsAtLeast(new ItemStack(Material.EMERALD_BLOCK), 1)) { if (randomAbl== 1) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.GOLD + "" + "L랭크 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "납치"); event.setCancelled(true); } else if (randomAbl == 2) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.LIGHT_PURPLE + "" + "S랭크 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "내성"); event.setCancelled(true); } else if (randomAbl == 3) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.GREEN + "" + "A랭크 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "도살자"); event.setCancelled(true); } else if (randomAbl == 4) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.BLUE + "" + "B랭크 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "동기화"); event.setCancelled(true); } else if (randomAbl == 5) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.GRAY + "" + "C랭크 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "구미호"); event.setCancelled(true); } else if (randomAbl == 6) { player.getInventory().removeItem(new ItemStack(Material.EMERALD_BLOCK, 1)); player.sendMessage(ChatColor.AQUA + "-----------"); player.sendMessage(ChatColor.DARK_RED + "" + "특수 능력이 뽑혔습니당 ㅎ" + ChatColor.WHITE + "!"); player.sendMessage(ChatColor.AQUA + "-----------"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "aw util abi" + " " + player.getName() + " " + "공기"); event.setCancelled(true); } else { player.sendMessage("111"); event.setCancelled(true); } } else { player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "* 에메랄드 블록을 소지하고있지 않습니다!"); event.setCancelled(true); } } } }
위와 같은 코드를 작성한 결과,
서바이벌 모드 상태에서 인벤토리 내의 빈공간(Air)나 밖을 클릭할 시
Could not pass event InventoryClickEvent 라는 콘솔에러가 출력됩니다.
혹시 문제점을 알려주실분이 있나요?
윈초
2022.07.24오류 전체 메시지를 보여주셔야 알 수 있어요!
qsef1256
2022.07.25Objects.requireNonNull(event.getCurrentItem())
에서 걸렸을 가능성이 큽니다. event.getCurrentItem이 null 을 던졌다면 가능합니다 (버킷은 상당히 개판입니다)
다만 저희는 버그 해결을 위해 환경 세팅하고 플러그인 빌드해서 돌리고 싶진 않으니, 오류 전문을 올려주시기 바랍니다
0reo
2022.07.25인텔리제이 사용중이신가요? Objects.requireNonNull 넣으라고 협박하긴하던데 안쓰시는게 나으니 지운담에 해보시는게
업로드
2022.07.26java.lang.NullPointerException: null
at java.util.Objects.requireNonNull(Objects.java:208) ~[?:?]
at com.sangbabo.shopgui.IronClick.onClick(IronClick.java:23) ~[shopGUI.jar:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor1.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:75) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:?]
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:git-Paper-66]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:669) ~[paper-api-1.19-R0.1-SNAPSHOT.jar:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClick(ServerGamePacketListenerImpl.java:3047) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundContainerClickPacket.handle(ServerboundContainerClickPacket.java:58) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundContainerClickPacket.handle(ServerboundContainerClickPacket.java:23) ~[?:?]
at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1358) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:183) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1335) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1328) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1306) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1191) ~[paper-1.19.jar:git-Paper-66]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:302) ~[paper-1.19.jar:git-Paper-66]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
에러 전문입니다!
0reo
2022.07.2623번째 줄에서 오류가 난다고 하네요 getCurrentItem() 메소드를 쓰려면 item이 null인지부터 체크하셔야 할거에요 if문에서 event.getCurrentItem() == null을 제일 첫번째로 실행시키도록 if문 순서를 바꿔보심이?