Code:
[07:37:54 ERROR]: Error occurred while enabling SkyPlugin v1.0-SNAPSHOT (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "org.bukkit.Server.getPluginCommand(String)" is null
at org.harttman.skyPlugin.SkyPlugin.onEnable(SkyPlugin.java:12) ~[skyplugin-1.0-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[paper-1.20.1.jar:git-Paper-196]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:642) ~[paper-1.20.1.jar:git-Paper-196]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:553) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:635) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:434) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:308) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1100) ~[paper-1.20.1.jar:git-Paper-196]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.20.1.jar:git-Paper-196]
at java.lang.Thread.run(Thread.java:1583) ~[?:?]
Code:
paper-plugin.yml:
name: SkyPlugin
version: '1.0-SNAPSHOT'
main: org.harttman.skyPlugin.SkyPlugin
api-version: '1.20'
commands:
heal:
description: Восстановить все хп
usage: /<command>
aliases:
- healme
- he
Code:
plugin.yml:
name: SkyPlugin
version: '1.0-SNAPSHOT'
main: org.harttman.skyPlugin.SkyPlugin
api-version: '1.20'
commands:
heal:
description: Восстановить все хп
usage: /<command>
aliases:
- healme
- he
Main.java:
Code:
package org.harttman.skyPlugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.harttman.skyPlugin.commands.HealCommand;
import org.harttman.skyPlugin.events.BlockEvent;
public class SkyPlugin extends JavaPlugin {
@Override
public void onEnable() {
getLogger().info("Плашин успешно загрузился!");
getServer().getPluginManager().registerEvents(new BlockEvent(), this);
getServer().getPluginCommand("heal").setExecutor(new HealCommand());
}
@Override
public void onDisable() {
getLogger().info("Плагин отключен!");
}
}
commands.HealCommands:
Java:
package org.harttman.skyPlugin.commands;
import org.bukkit.ChatColor;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HealCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player))
sender.sendMessage(ChatColor.RED + "Эта команда должна выполняться непосредсвтенно в игре");
assert sender instanceof Player;
Player player = (Player) sender;
if(command.getName().equalsIgnoreCase("heal")) {
double health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
player.setHealth(health);
player.sendMessage(ChatColor.GREEN + "Здоровья было восстановленно!");
}
return true;
}
}