Вопрос Не получается сделать /reload команду

Версия Minecraft
1.19.X

KainMPGSS

Пользователь
Сообщения
35
Решения
2
Делаю релоад команду для плагина и нифига не работает!
Помогите пожалуйста!

Ошибка:
Код:
[11:35:12 WARN]: Unexpected exception while parsing console command "fastlogger reload"
org.bukkit.command.CommandException: Unhandled exception executing command 'fastlogger' in plugin FastLogger v0.1-TEST
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.4.jar:git-Paper-550]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchServerCommand(CraftServer.java:892) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:501) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:448) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1174) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-550]
        at java.lang.Thread.run(Thread.java:842) ~[?:?]
Caused by: java.lang.ClassCastException: class com.destroystokyo.paper.console.TerminalConsoleCommandSender cannot be cast to class org.bukkit.entity.Player (com.destroystokyo.paper.console.TerminalConsoleCommandSender and org.bukkit.entity.Player are in unnamed module of loader java.net.URLClassLoader @1b9e1916)
        at ru.quarkus.flCommand.onCommand(flCommand.java:21) ~[QSLogger.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        ... 9 more

Код команды:
Java:
package ru.quarkus;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class flCommand implements CommandExecutor, TabCompleter {

    private Plugin plugin;

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
        Player p = (Player) sender;
        if (sender.hasPermission("fastlogger.reload")) {
            if (args.length == 0) {
                p.sendMessage(Color.get("&d&lFastLogger Commands:"));
                p.sendMessage(Color.get("  &d/fl reload &7(Alias: /fastlogger reload)"));
            } else if (args.length == 1 && args[0].equals("reload")) {
                this.plugin.getConfig();
            }
        } else {
            p.sendMessage(Color.get("&d&lFastLogger &7» &cNo permission!"));
        }
        return true;
    }

    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
        if (commandSender instanceof Player) {
            List<String> completions = new ArrayList<>();
            if (strings.length == 1 && "reload".startsWith(strings[0])) {
                completions.add("reload");
            }
            return completions;
        }
        return null;
    }


}
 
Код:
[11:43:48 WARN]: Unexpected exception while parsing console command "fl reload"
org.bukkit.command.CommandException: Unhandled exception executing command 'fl' in plugin FastLogger v0.1-TEST
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.4.jar:git-Paper-550]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchServerCommand(CraftServer.java:892) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:501) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:448) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1174) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-550]
        at java.lang.Thread.run(Thread.java:842) ~[?:?]
Caused by: java.lang.ClassCastException: class com.destroystokyo.paper.console.TerminalConsoleCommandSender cannot be cast to class org.bukkit.entity.Player (com.destroystokyo.paper.console.TerminalConsoleCommandSender and org.bukkit.entity.Player are in unnamed module of loader java.net.URLClassLoader @1b9e1916)
        at ru.quarkus.flCommand.onCommand(flCommand.java:21) ~[QSLogger.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        ... 9 more
 
Код:
[11:43:48 WARN]: Unexpected exception while parsing console command "fl reload"
org.bukkit.command.CommandException: Unhandled exception executing command 'fl' in plugin FastLogger v0.1-TEST
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.4.jar:git-Paper-550]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchServerCommand(CraftServer.java:892) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:501) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:448) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1174) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-550]
        at java.lang.Thread.run(Thread.java:842) ~[?:?]
Caused by: java.lang.ClassCastException: class com.destroystokyo.paper.console.TerminalConsoleCommandSender cannot be cast to class org.bukkit.entity.Player (com.destroystokyo.paper.console.TerminalConsoleCommandSender and org.bukkit.entity.Player are in unnamed module of loader java.net.URLClassLoader @1b9e1916)
        at ru.quarkus.flCommand.onCommand(flCommand.java:21) ~[QSLogger.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        ... 9 more
Надо писать команду /fl reload от имени игрока, а не от имени консоли
 
Java:
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
    if (sender.hasPermission("fastlogger.reload")) {
        if (args.length == 0) {
            sender.sendMessage(Color.get("&d&lFastLogger Commands:"));
            sender.sendMessage(Color.get("  &d/fl reload &7(Alias: /fastlogger reload)"));
        } else if (args.length == 1 && args[0].equals("reload")) {
            this.plugin.reloadConfig();
            sender.sendMessage(Color.get("&d&lFastLogger &7» Config reloaded!"));
        }
    } else {
        sender.sendMessage(Color.get("&d&lFastLogger &7» &cNo permission!"));
    }
    return true;
}
А как сделать чтобы и так и так можно было?
 
@Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { if (sender.hasPermission("fastlogger.reload")) { if (args.length == 0) { sender.sendMessage(Color.get("&d&lFastLogger Commands:")); sender.sendMessage(Color.get(" &d/fl reload &7(Alias: /fastlogger reload)")); } else if (args.length == 1 && args[0].equals("reload")) { this.plugin.reloadConfig(); sender.sendMessage(Color.get("&d&lFastLogger &7» Config reloaded!")); } } else { sender.sendMessage(Color.get("&d&lFastLogger &7» &cNo permission!")); } return true;

сама команда работает, а с аргументом reload нет


Код:
[11:50:59 WARN]: Unexpected exception while parsing console command "fl reload"
org.bukkit.command.CommandException: Unhandled exception executing command 'fl' in plugin FastLogger v0.1-TEST
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchCommand(CraftServer.java:929) ~[paper-1.19.4.jar:git-Paper-550]
        at org.bukkit.craftbukkit.v1_19_R3.CraftServer.dispatchServerCommand(CraftServer.java:892) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:501) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:448) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1397) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1174) ~[paper-1.19.4.jar:git-Paper-550]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320) ~[paper-1.19.4.jar:git-Paper-550]
        at java.lang.Thread.run(Thread.java:842) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.plugin.Plugin.reloadConfig()" because "this.plugin" is null
        at ru.quarkus.flCommand.onCommand(flCommand.java:26) ~[QSLogger.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.4-R0.1-SNAPSHOT.jar:?]
        ... 9 more
 
Напиши это в главный класс:
Java:
public static Plugin get;
И это в onEnable:
Java:
get = this;
После чего в flCommand напиши
Java:
НазваниеГлавногоКласса.get.reloadConfig();
Всё работает без ошибок, я в конфите отключил сообщение о выходе игрока. Сделал reload но всё равно пишет

Конфиг:
YAML:
join_event: true
leave_event: false  # Это я выключил
block_place_event: true
block_break_event: true
reload_msg: '&d&lFastLogger &7» &aConfig reloaded!'
no_perm: '&d&lFastLogger &7» &cNo permission!'

Консоль:
Код:
> fl
[11:58:42 INFO]: FastLogger Commands:
[11:58:42 INFO]:   /fl reload (Alias: /fastlogger reload)
[11:58:46 INFO]: KainMPG_YT lost connection: Disconnected
[11:58:46 INFO]: [FLog] [STDOUT] KainMPG_YT left from you server :(
[11:58:46 INFO]: KainMPG_YT left the game
[11:58:48 INFO]: UUID of player KainMPG_YT is a666f213-6c50-3075-925e-a998aed793af
[11:58:48 INFO]: [FLog] [STDOUT] KainMPG_YT joined to you server!
[11:58:48 INFO]: KainMPG_YT joined the game
[11:58:48 INFO]: KainMPG_YT[/127.0.0.1:50509] logged in with entity id 201 at ([world]-95.70992894156349, 72.0, -23.30861434835716)
> fl reload
[11:59:05 INFO]: FastLogger » Config reloaded!
[11:59:07 INFO]: KainMPG_YT lost connection: Disconnected
[11:59:07 INFO]: [FLog] [STDOUT] KainMPG_YT left from you server :(    <----- Вот показывается
[11:59:07 INFO]: KainMPG_YT left the game

Код:
Java:
    @org.bukkit.event.EventHandler
    public void onLeave(PlayerQuitEvent e) {
        String nickname = e.getPlayer().getName();
        if (FastLogger.getCfg().getBoolean("leave_event")) {
            System.out.println(nickname + " left from you server :(");
        }
    }
 
Напиши это в главный класс:
Java:
public static Plugin get;
И это в onEnable:
Java:
get = this;
Большое нет, статикам бой.
Java:
public class FastLoggerCommand implements CommandExecutor, TabCompleter {

    private final FastLoggerPlugin plugin;

    public FastLoggerCommand(FastLoggerPlugin plugin) {
      this.plugin = plugin;
    }

    //...

}
Java:
public class FastLoggerPlugin extends JavaPlugin {

    @Override
     public void onEnable() {
         final FastLoggerCommand command = new FastLoggerCommand(this);
         getCommand("fastlogger").setExecutor(command);
         getCommand("fastlogger").setTabCompleter(command);
     }

}
 
Ну, вообще это замена этому статическому полю "get". Так что теперь в классе команды вместо
Java:
FastLogger.get.reloadConfig();
нужно использовать
Java:
plugin.reloadConfig();
 
Назад
Сверху Снизу