Error on Stratup : is it up to date?

Discussion in 'Spigot Plugin Development' started by StarFan33, Jul 5, 2018.

  1. Hello Guys,
    I am working on a new Plugin and it will support I18N

    But everytime I am starting the server i am getting this error:
    Code (Text):
    [20:47:22 ERROR]: Error occurred while enabling Bukkify v1.0-SNAPSHOT (Is it up to date?)
    java.lang.NullPointerException: null
            at com.blackypaw.mc.i18n.I18NSpigotAdapter.getI18N(I18NSpigotAdapter.java:63) ~[?:?]
            at com.bukkify.bukkify.Commands.HelpCommand.<init>(HelpCommand.java:22) ~[?:?]
            at com.bukkify.bukkify.Bukkify.onEnable(Bukkify.java:13) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
            at java.lang.Thread.run(Unknown Source) [?:?]
    [20:47:22 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:47:22 INFO]: Done (2,697s)! For help, type "help" or "?"
    >
     
    My Main class (Its named Bukkify because the project is called bukkify)

    Code (Java):
    package com.bukkify.bukkify;

    import com.bukkify.bukkify.Commands.HelpCommand;
    import org.bukkit.plugin.java.JavaPlugin;

    public final class Bukkify extends JavaPlugin {

      public static Bukkify plugin;

      @Override
      public void onEnable() {
        getLogger().info("Bukkify | Minecraft Server Management Solution");
        this.getCommand("bukkify").setExecutor( new HelpCommand());
        plugin = this;
      }

      @Override
      public void onDisable() {
        getLogger().info("See you soon!");
      }
    }
     
    And the HelpCommand class
    Code (Java):
    package com.bukkify.bukkify.Commands;

    import com.blackypaw.mc.i18n.I18NSpigotAdapter;
    import com.blackypaw.mc.i18n.InjectionAwareI18N;
    import com.blackypaw.mc.i18n.Localizer;
    import com.blackypaw.mc.i18n.PropertyTranslationStorage;
    import com.bukkify.bukkify.Bukkify;
    import org.bukkit.Bukkit;
    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 java.io.File;
    import java.io.IOException;
    import java.util.Locale;
    import java.util.UUID;

    public class HelpCommand implements CommandExecutor {

      public InjectionAwareI18N<UUID> i18n = i18n = I18NSpigotAdapter.getI18N();
      public PropertyTranslationStorage storage = new PropertyTranslationStorage( i18n, new File( Bukkify.plugin.getDataFolder(), "translations" ) );
      public Localizer localizer = i18n.createLocalizer( storage );

      public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        try {
         storage.loadLanguage( Locale.ENGLISH);
        } catch (IOException e) {
          e.printStackTrace();
        }
        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("bukkify")) {
          if (player.hasPermission("bukkify.info")) {
            player.sendMessage( localizer.translateDirect( i18n.getLocale( player.getUniqueId() ), "bukkify-help-command-heading = Bukkify Commands:", player.getName() ));
          } else {
            sender.sendMessage(ChatColor.RED + "You are not allowed to use this Command");
          }
          return false;
        }
        return false;
      }
    }
     
    Please help me to fix the code. If possible please explain how to ship isues like that in future
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

  3. Nice that you told me what i allready know. I am here because the stuff i was finding was not working by default. so can you please provide a solution and explain how it works and what was wrong. thanks in advance
    For beginners that shit is may not easy as Hello World
     
  4. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    No.
    "Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime."

    We're not here to fix your code, we're here to teach you how to fix your code. So, let's walk through the stacktrace with what you should already know.
    What line is the error occurring on?
     
    • Agree Agree x 1
  5. the error is this
    Code (Text):
    public InjectionAwareI18N<UUID> i18n = i18n = I18NSpigotAdapter.getI18N();
    if you still have the same code as the above for helpcommand class
     
  6. the error apears at java.lang.NullPointerException: null and thats mean that theres a value with null initzialized
     
  7. Error is on line 22 in HelpCommand class
    Error is in Main class on line 13
     
  8. and here: at com.blackypaw.mc.i18n.I18NSpigotAdapter.getI18N(I18NSpigotAdapter.java:63) ~[?:?] but this is a external source
     
  9. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Good...
    Right
    And that's the source. You're right, it is an external source that's causing the issue. You'll need to take this up with the other plugin author, or see if it's an existing issue on GitHub (if it's open source). You can also check the source to find the cause and a possible fix.
     
  10. It is OpenSource .. so that means i have basicly to clean up the shit of an other guy? Great....
     
  11. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Welcome to programming!

    The issue could still be with your plugin, perhaps it's loading after yours and isn't initialized yet? Add a depend entry to your plugin.yml.
     
    • Agree Agree x 1
  12. How to use the depend? just the url or plugin name?
     
  13. Was just about to say. It's quite obvious actually. Judging from the source, the variable being accessed which turns out to be null is set during the enable stage of that i18n plugin (nice to see people using frameworks like that). This means OP is accessing (or rather, using) the plugin as API even before it's enabled. Adding a dependency on the plugin through the plugin yml should fix it.

    I'm gonna be real honest here. I'm suprised to see people using frameworks such as i18n in Minecraft plugins, and definitely kudos to you for using such framework, but it literally takes 3 seconds to Google your question; https://www.spigotmc.org/wiki/plugin-yml/
     
  14. Optic_Fusion1

    Resource Staff

    May i ask why it surprises you?
     
  15. Because the average Minecraft developer simply doesn't use any external libraries that don't directly have anything to do with Minecraft. It's a great framework to use; we use it at where I work (in node.js). For example I often see people asking how to properly make servers (in bungee) communicate with each other. People start suggesting the plugin messaging channel (which isn't even designed for those kind of things), or bare bone sockets, but I never see anyone suggesting things like message brokers (such as RabbitMQ or Apache Kafka) while they are often the perfect candidate for those kind of jobs.

    If you want to discuss these kind of things with me, you're probably better off adding me on Discord as we're often going off topic with these kind of things. You can find me on Discord through my website :p
     
  16. Every time I see a thread about a nullpointerexception I am just eager to spam links to java courses.

    The NullPointerException is one of the most commen bugs here and it's also the easiest to fix. Everyone that has done a bit of the fundamental stuff of Java (what is a String, references parsing stuff etc) knows what is and how to fix it. Not blaming you for missing that part, but simply sharing your code and saying 'Help' won't get you much further.
    Being able to properly debug your OWN code is a huge step in helping you to code better and I fully agree with @ScarabCoder.

    Googling your error almost always gets you an useful stackoverflow thread. More often then not, will it show you what's wrong. Now the only thing you need is the line that the error is thrown at. Luckly, stacktraces provide you these and I would recommend you to read on what output they give, it's so useful once you understand it. The TL:TR is basically, the first line shows you were the error happens and the class and line is shown between the ().
     
  17. hah, got a way to ship null pointer exceptions, using kotlin as main programming language :p
    But now I am getting this error at build:
    Code (Text):
    [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.51:kapt (kapt) on project Bukkify: Compilation failure
    [ERROR] java.lang.IllegalStateException: failed to analyze: java.lang.reflect.InvocationTargetException
     
    • Optimistic Optimistic x 1
  18. Fixed that to. Muhahaha it works :cool: