I have added a config and now the command was not working

Discussion in 'Spigot Plugin Development' started by optischTV, Mar 30, 2019.

  1. my command /day was ever working but no i have coded a config.yml and have the message make editable. But now it come ingame: An internal error ...

    Here my codes and errors:

    Error:
    Code (Text):
    ByGoalZ issued server command: /day
    [18:23:44 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'day' in plugin EssentialsRelPlus v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_201]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_201]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.NullPointerException
            at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.java:324) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at de.bygoalz.commands.cmd_day.onCommand(cmd_day.java:21) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            ... 15 more
    Code Main:
    Code (Java):
    package de.bygoalz.main;



    import java.io.File;

    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import de.bygoalz.commands.TphereCommand;
    import de.bygoalz.commands.TptoggleCommand;
    import de.bygoalz.commands.cmd_chatclear;
    import de.bygoalz.commands.cmd_clear;
    import de.bygoalz.commands.cmd_craft;
    import de.bygoalz.commands.cmd_day;
    import de.bygoalz.commands.cmd_enderchest;
    import de.bygoalz.commands.cmd_feed;
    import de.bygoalz.commands.cmd_fly;
    import de.bygoalz.commands.cmd_gamemode;
    import de.bygoalz.commands.cmd_heal;
    import de.bygoalz.commands.cmd_invsee;
    import de.bygoalz.commands.cmd_item;
    import de.bygoalz.commands.cmd_night;
    import de.bygoalz.commands.cmd_ping;
    import de.bygoalz.commands.cmd_repair;
    import de.bygoalz.commands.cmd_tp;
    import de.bygoalz.commands.cmd_tpall;
    import de.bygoalz.listeners.JoinListener;
    import de.bygoalz.listeners.QuitListener;
    public class Main extends JavaPlugin {
     
        public static File file;
        public static FileConfiguration cfg;
     
     
         
     
        public static String prefix = "§7[§6System§7]";
     
        public void onEnable() {
            saveDefaultConfig();
            Main.file = new File("plugins/EssentialsRelnana", "config.yml");
            Main.cfg  = YamlConfiguration.loadConfiguration(Main.file);
         
         
         

            Bukkit.getConsoleSender().sendMessage("§7----------------------------------------------------------------------------------");
            Bukkit.getConsoleSender().sendMessage("§7Das §6Essentials§7- §6System §7wurde erfolgreich §aaktiviert§7!");
            Bukkit.getConsoleSender().sendMessage("§cAutor: ByGoalZ");
            Bukkit.getConsoleSender().sendMessage("§5YouTube: optischTV");
            Bukkit.getConsoleSender().sendMessage("§7-----------------------------------------------------------------------------------");
     
     
        getCommand("heal").setExecutor(new cmd_heal());
        getCommand("feed").setExecutor(new cmd_feed());
        getCommand("fly").setExecutor(new cmd_fly());
        getCommand("gamemode").setExecutor(new cmd_gamemode());
        getCommand("gm").setExecutor(new cmd_gamemode());
        getCommand("item").setExecutor(new cmd_item());
        getCommand("day").setExecutor(new cmd_day());
        getCommand("night").setExecutor(new cmd_night());
        getCommand("ping").setExecutor(new cmd_ping());
        getCommand("clear").setExecutor(new cmd_clear());
        getCommand("clearchat").setExecutor(new cmd_chatclear());
        getCommand("invsee").setExecutor(new cmd_invsee());
        getCommand("tp").setExecutor(new cmd_tp());
        getCommand("tptoggle").setExecutor(new TptoggleCommand());
        getCommand("tphere").setExecutor(new TphereCommand());
        getCommand("craft").setExecutor(new cmd_craft());
        getCommand("tpall").setExecutor(new cmd_tpall());
        getCommand("repair").setExecutor(new cmd_repair());
        getCommand("enderchest").setExecutor(new cmd_enderchest());
        PluginManager pm = Bukkit.getPluginManager();
        pm.registerEvents(new JoinListener(), this);
        pm.registerEvents(new QuitListener(), this);
     
         
        }
     
     
     
     
     
     
     

                   public void onDisable(){
                           Bukkit.getConsoleSender().sendMessage("§7----------------------------------------------------------------------------------");
                          Bukkit.getConsoleSender().sendMessage("§7Das §6Essentials§7- §6System §7wurde erfolgreich §cdeaktiviert§7!");
                          Bukkit.getConsoleSender().sendMessage("§cAutor: ByGoalZ");
                          Bukkit.getConsoleSender().sendMessage("§5YouTube: optischTV");
                          Bukkit.getConsoleSender().sendMessage("§7-----------------------------------------------------------------------------------");
    }
                 
                   public void loadConfig(){
                       getConfig().options().copyDefaults(true);
                       saveConfig();
                   
                   }
                         
                       }


    Code command class (day):
    Code (Java):
    package de.bygoalz.commands;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import de.bygoalz.main.Main;

    public class cmd_day implements CommandExecutor {

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            Player p = (Player) sender;
         
            if (cmd.getName().equalsIgnoreCase("day")) {
                if (p.hasPermission("system.day")) {
                    p.getWorld().setTime(0);
                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.cfg.getString("day")));
                    return true;
                } else {
                    p.sendMessage(Main.prefix + "§cDu hast keine Rechte für diesen Befehl!");
                    return true;
                }
            }
            return false;
        }

    }
     
    #1 optischTV, Mar 30, 2019
    Last edited by a moderator: Mar 30, 2019
  2. and here is my config.yml:


    # EssentialsRel+ - Config
    # YouTube: optischTV
    # Bei Fragen kommt gerne auf den Teamspeak3: Mineami.de!

    # Hier kannst du die Narichten der Befehle einstellen:

    day: "hallo"
     
  3. This is not a resource, remove the resource tag.

    Secondly, use code tags.
     
  4. SteelPhoenix

    Moderator

    Please use code brackets and remove the resource prefix..

    - You should not abuse static
    - You should name your main class something unique and descriptive
    - You should use the ChatColor enum
    - You should not assume the command sender is a player
    - You should follow Java convention
     
  5. SeelPhoenix what i must be change in my sources and where?
     
  6. Create an instance of main and make that static ONLY
    Code (Text):

    public static Main instance;
    // Make sure to add instance = this inside onEnable()
    public static Main getInstance() {
    return instance;
    }
    That you can access the configuration with
    Code (Text):
    Main.getInstance().getConfig().getString(“path”));
     
  7. But the man in the tutorial had its so how I and its work on him.
     
  8. SteelPhoenix

    Moderator

    You shouldn't copy paste something and expect it to work...
     
  9. You obviously don't understand how the code works. Instead of just copying what someone else writes, pause whatever video you're watching and read through the code and understand it. Or else you're just going to be coming back to this forum every time you have an error saying that it works for the guy making the tutorial but not for you.

    And also, this isn't a resource.
     
  10. i dont copy paste it but i would look that this plugin work and after that I read the code.
     
  11. Grammar? Or at least English....

    Do you know basic Java or was this all copy & paste?
     
  12. Well, it looks like you base your development in copy paste videos, you can watch them if you want, but understand the videos, not copy paste the code, also learn Java first to be more easy to you to code.