Вопрос Проблема Could not pass event InventoryClickEvent

Lauma

Пользователь
Сообщения
5
Разрешается выкладывание кода, файлов конфигураций, логов и т.д. только под BB-код CODE
Java:
[21:56:35 ERROR]: Could not pass event InventoryClickEvent to deepWanderingTrader v1.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:72) ~[patched_1.12.2.jar:git-Paper-1620]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:513) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:2002) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:33) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[patched_1.12.2.jar:git-Paper-1620]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_321]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_321]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:850) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:774) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:666) ~[patched_1.12.2.jar:git-Paper-1620]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_321]
Caused by: java.lang.IllegalArgumentException: CommandLine cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:660) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:607) ~[patched_1.12.2.jar:git-Paper-1620]
        at ru.lauma.trader.TraderListener.onClickInventory(TraderListener.java:68) ~[?:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor554.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:70) ~[patched_1.12.2.jar:git-Paper-1620]
помогите разобраться в чем ошибка, есть житель, при пкм по жителю открывается меню в есть вещи, мне нужно что бы при нажатие на вещь выполнялась команда в консоли которая прописана в конфиге плагина
Java:
Код фулл класса
package ru.lauma.trader;

import net.citizensnpcs.api.event.NPCRightClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import ru.lauma.trader.TraderItems;
import ru.lauma.trader.TraderManager;
import ru.lauma.trader.TraderPlugin;
import ru.lauma.trader.tools.Economy;
import ru.lauma.trader.tools.Utils;

import java.util.List;


import static ru.lauma.trader.tools.Utils.getConfig;

public class TraderListener
implements Listener {

    private static TraderPlugin plugin;
    public String cmds;

    @EventHandler
    public void onClickNpcRight(NPCRightClickEvent e) {
        Player player = e.getClicker();
        try {
            if (e.getNPC().getId() == TraderPlugin.getTraderManager().getTrader()) {
                player.openInventory(TraderPlugin.getTraderManager().getInventory());
            }
        } catch (Exception exception) {
            // empty catch block
        }
    }

    @EventHandler
    public void onClickInventory(InventoryClickEvent e) {
        Player player = (Player) e.getWhoClicked();
        TraderManager manager = TraderPlugin.getTraderManager();
        if (e.getInventory() != null && e.getInventory().getTitle().equals(Utils.color(Utils.getString("settings.title")))) {
            e.setCancelled(true);
            for (TraderItems item : manager.getItems()) {
                if (e.getCurrentItem().getType() == Material.AIR || e.getSlot() != item.getSlot()) continue;
                if (Economy.getBalance(player) < (double) item.getPrice()) {
                    Utils.sendMessage((CommandSender) player, Utils.getMessage("no-money"));
                    return;
                }
                if (e.getCurrentItem().getAmount() <= 0) continue;
                Economy.withDraw(player, item.getPrice());
                String cmds = getConfig().getString(".commands");
68             Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmds);
                Utils.sendMessage((CommandSender)player, Utils.getMessage("successfully"));
                e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
                }
            }
        }
    }
 
Последнее редактирование:
Так нельзя получать данные из конфига. Что-то должно быть до точки или точки не должно быть.
Если у тебя там лист (список) из команд, то надо проходить через forEach, а не получать одну строку.
 
Так нельзя получать данные из конфига. Что-то должно быть до точки или точки не должно быть.
Если у тебя там лист (список) из команд, то надо проходить через forEach, а не получать одну строку.
Сделал как ты написал теперь вот эта ошибка, поможешь решить ?

Java:
@EventHandler
public void onClickInventory(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    TraderManager manager = TraderPlugin.getTraderManager();
    if (e.getInventory() != null && e.getInventory().getTitle().equals(color(getString("settings.title")))) {
        e.setCancelled(true);
        for (TraderItems item : manager.getItems()) {
            if (e.getCurrentItem().getType() == Material.AIR || e.getSlot() != item.getSlot()) continue;
            if (Economy.getBalance(p) < (double) item.getPrice()) {
                sendMessage((CommandSender) p, getMessage("no-money"));
                return;
            }
            if (e.getCurrentItem().getAmount() <= 0) continue;
            Economy.withDraw(p, item.getPrice());
66            for(String command : plugin.getConfig().getStringList("commands")) {
                Bukkit.dispatchCommand(console, command);
            }
            sendMessage((CommandSender) p, getMessage("successfully"));
            e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
            }
        }
    }
}
[SPOILER="Logs"
Java:
Could not pass event InventoryClickEvent to deepWanderingTrader v1.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:72) ~[patched_1.12.2.jar:git-Paper-1620]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.12.2.jar:git-Paper-1620]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:513) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:2002) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:33) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14) ~[patched_1.12.2.jar:git-Paper-1620]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_321]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_321]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:850) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:774) ~[patched_1.12.2.jar:git-Paper-1620]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:666) ~[patched_1.12.2.jar:git-Paper-1620]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_321]
Caused by: java.lang.NullPointerException
        at ru.lauma.trader.TraderListener.onClickInventory(TraderListener.java:66) ~[?:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor445.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:70) ~[patched_1.12.2.jar:git-Paper-1620]
[/SPOILER]
 
Назад
Сверху Снизу