I am a 14-year old intermediate programmer. I ask humbly that you explain your answer in terms that I would understand, and not criticize me for asking a seemingly obvious question. With that, here is the problem I am encountering:
HERE'S WHAT IM BUILDING: I am building a Minecraft Java Edition plugin which, when provided with a command /dui create <name> will create a YAML file with the corresponding UI. The UI's that I am speaking of are basically chest-like interfaces with items in each row that have special properties (edited in the YAML file). These items will lead to different interfaces with each having some cool commands and functions.
Information that might be useful:
I am using using spigot-api-1.8.8 as my dependency. I am using the latest version of paper under 1.8.8, when visiting their website.
Spigot API Version: 1.8 (.8) Server: Paper (localhost) IDE: IntelliJ Community Edition Java Version: 1.8 (JDK 8) (the recommended Java version)
Directory:
DecentUI
- src
- com.kanske.decentui
- commands
- DecentUICommands.java
DecentUI.java
- plugin.yml
(I'm sorry if you don't need the contents of each file) Contents of each file:
// commands/DecentUICommands.java
package com.kanske.decentui.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
public class DecentUICommands implements CommandExecutor {
private File customConfigFile;
private FileConfiguration customConfig;
Plugin plugin;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
if (command.getName().equalsIgnoreCase("dui")) {
if (args[0].equalsIgnoreCase("create")) {
if (args.length == 2) {
createCustomConfig(args[1]);
plugin.getConfig().set("title", "this_is_working");
plugin.saveConfig();
plugin.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + plugin.getConfig().getString("title"));
}
}
}
return true;
}
public FileConfiguration getCustomConfig() {
return this.customConfig;
}
private void createCustomConfig(String name) {
customConfigFile = new File(plugin.getDataFolder(), name+".yml");
customConfig = new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
}
// DecentUI.java
package com.kanske.decentui;
import com.kanske.decentui.commands.DecentUICommands;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class DecentUI extends JavaPlugin {
@Override
public void onEnable() {
getCommand("dui").setExecutor(new DecentUICommands());
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "SERVER ENABLED");
}
@Override
public void onDisable() {
getServer().getConsoleSender().sendMessage(ChatColor.RED + "SERVER DISABLED");
}
}
# plugin.yml
name: DecentUI
version: 0.1
author: kanske
main: com.kanske.decentui.DecentUI
api-version: 1.8
commands:
create:
description: create a GUI menu that is saved in config_files.
usage: /<command> create
Each time, I am building the artifacts, then running the server with a run.bat file in the Server folder, with inner-contents of:
java -Xmx2048M -jar server.jar (server.jar is paper)
Hopefully this is enough information for you. Thank you for your time :)
Here is the Java debugging error (although I know it probably doesn't mean much (which it certainly didn't for me)):
java.lang.NullPointerException
I compiled the code without DecentUICommands.java and it worked fine, as in the server started without any errors.
The error seems to be on
DecentUI.class, in theonEnablemethod.The line that create the error is
getCommand("dui").setExecutor(new DecentUICommands());. Why ?plugin.ymlyou declaredcreatecommand, that should be used as/create. But you are never using it./guicommand, which is never declared in the plugin yaml file.The
plugin.ymlshould be like that:In the
onEnable()method, it would like like that: