ChatColor error

Discussion in 'Spigot Plugin Development' started by Roimeiqui7, May 25, 2018.

  1. Anyone knows why this error:

    Code (Text):
    Could not load 'plugins\Scylla.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ExceptionInInitializerError
            at ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin( ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins( [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins( [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init( [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at java.base/ [?:?]
    Caused by: java.lang.ExceptionInInitializerError
            at java.base/java.lang.Class.forName0(Native Method) ~[?:?]
            at java.base/java.lang.Class.forName( ~[?:?]
            at<init>( ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            ... 6 more
    Caused by: java.lang.NullPointerException
            at org.bukkit.ChatColor.translateAlternateColorCodes( ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at me.roimeiqui.scylla.Scylla.color( ~[?:?]
            at me.roimeiqui.scylla.Scylla.<clinit>( ~[?:?]
            at java.base/java.lang.Class.forName0(Native Method) ~[?:?]
            at java.base/java.lang.Class.forName( ~[?:?]
            at<init>( ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            ... 6 more
    I have imported org.bukkit.ChatColor

    Thanks for your help
  2. Could you please send your code?
    • Agree Agree x 1
  3. From a quick look I'd assume you're getting a value from config that does not exist, and are passing it to a method similar to this:
    Code (Java):
    public static String color(String string) { // where you give 'null' as the input
        return ChatColor.translateAlternateColorCodes('&', string);
    .. in main class called Scylla, so either the value you're trying to get is not set or you're accessing it before config has been set up.

    Let's see how close I was :oops:
    • Agree Agree x 1
  4. Its imposible couse my plugin doesn't load, it crash when I start the server
  5. It's throwing a NPE meaning something isn't set properly. We need to see code.
  6. My plugin has 14 clases, do I must to send all of them?
  7. Let's start with the main class
  8. Main class:

    Code (Text):

    package me.roimeiqui.scylla;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import me.roimeiqui.commands.GameModeCommand;
    import me.roimeiqui.commands.InvSeeCommand;
    import me.roimeiqui.commands.KillCommand;
    import me.roimeiqui.commands.RemovePermissionsCommand;
    import me.roimeiqui.commands.VanishCommand;
    import me.roimeiqui.commands.playervault.InventoryEvent;
    import me.roimeiqui.commands.tpcommand.TPDirectCommand;
    import me.roimeiqui.commands.tpcommand.TPHereDirectCommand;
    import me.roimeiqui.multicommands.MultiCommand;
    import me.roimeiqui.multicommands.MultiCommandEvent;
    import me.roimeiqui.scylla.files.CommandsFile;
    import me.roimeiqui.scylla.files.Data;
    import me.roimeiqui.scylla.files.MessageFile;
    import me.roimeiqui.scylla.listner.JoinEvent;
    import me.roimeiqui.scylla.utils.TPCooldown;

    public class Scylla extends JavaPlugin{
     public static String color(String s) {return ChatColor.translateAlternateColorCodes('&', s);}
     public static Scylla pl;
     private MessageFile mf;
     public static String prefix = color(MessageFile.message.getString("General.Prefix"));
     public void onEnable(){
      Bukkit.getPluginManager().registerEvents(new JoinEvent(), this);
      Bukkit.getPluginManager().registerEvents(new MultiCommandEvent(), this);
      Bukkit.getPluginManager().registerEvents(new InventoryEvent(), this);
     public void onDisable(){
     public void checkCommands() {
      getCommand("gamemode").setExecutor(new GameModeCommand());
      getCommand("gm").setExecutor(new GameModeCommand());
      getCommand("gmc").setExecutor(new GameModeCommand());
      getCommand("gms").setExecutor(new GameModeCommand());
      getCommand("gma").setExecutor(new GameModeCommand());
      getCommand("vanish").setExecutor(new VanishCommand());
      getCommand("v").setExecutor(new VanishCommand());
      getCommand("tp").setExecutor(new TPDirectCommand());
      getCommand("s").setExecutor(new TPHereDirectCommand());
      getCommand("tphere").setExecutor(new TPHereDirectCommand());
      getCommand("invsee").setExecutor(new InvSeeCommand());
      getCommand("kill").setExecutor(new KillCommand());
      getCommand("command").setExecutor(new MultiCommand());
      getCommand("rp").setExecutor(new RemovePermissionsCommand());
     public void checkFiles() { MessageFile();
     public void loadConfig() {

  9. NathanWolf


    So much static spaghetti ... this is likely your problem:

    Code (Text):
    public static String prefix = color(MessageFile.message.getString("General.Prefix"));
    Note sure if the problem is that General.Prefix doesn't exist in your config, or if the config just isn't going to be valid from a static scope like this. You should probably initialize that stuff in onEnable instead.

    And try to cool it down on all the statics if possible :)
  10. My plugin doesn't load, so Config.yml doesn't exists @NathanWolf
  11. NathanWolf


    You are trying to load something from your config before your plugin is even enabled. That's what static scope does, the instant your class is loaded by a classloader that code will execute.
    • Agree Agree x 2
  12. That's easy:
    Code (Text):
        public static String string;
            new BukkitRunnable(){

                public void run() {
                   string = fc.getString("Path");
    What it does? It just defines the String string with a delay of 5 seconds (20L == 1 sec). So there's time to create the file(Actually in takes less than a second to create a file)
  13. He's talking about
    Code (Text):
    public static String prefix = color(MessageFile.message.getString("General.Prefix"));
    • Agree Agree x 1
  14. Did you even understand what the problem is? He's getting a value from a config that doesn't exists in the moment when he do it
  15. NathanWolf


    Trying to start a bukkit task in static scope is not the right solution, it's going in the completely wrong direction and will probably throw an exception that a plugin tried to register a task while disabled.

    EDIT: Like, seriously overcomplicating the problem- just read the config in onEnable.
  16. He should put that in his onEnable :sleep:
    • Agree Agree x 1
  17. NathanWolf


    If he puts it in onEnable he doesn't need to schedule anything. Just load the config there and read it like 99% of other plugins do...
  18. I actually thought it was obvious
  19. So i must to remove "static" in all my clases @NathanWolf
  20. Also that's true!