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 org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at java.base/java.lang.Thread.run(Thread.java:844) [?:?]
    Caused by: java.lang.ExceptionInInitializerError
            at java.base/java.lang.Class.forName0(Native Method) ~[?:?]
            at java.base/java.lang.Class.forName(Class.java:374) ~[?:?]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[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(ChatColor.java:324) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at me.roimeiqui.scylla.Scylla.color(Scylla.java:26) ~[?:?]
            at me.roimeiqui.scylla.Scylla.<clinit>(Scylla.java:30) ~[?:?]
            at java.base/java.lang.Class.forName0(Native Method) ~[?:?]
            at java.base/java.lang.Class.forName(Class.java:374) ~[?:?]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[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 org.bukkit.plugin.java.JavaPlugin;
    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;
     @SuppressWarnings("unused")
     private MessageFile mf;
     public static String prefix = color(MessageFile.message.getString("General.Prefix"));
     
     public void onEnable(){
      checkCommands();
      checkFiles();
      loadConfig();
      TPCooldown.startRun();
      Data.setupData();
      CommandsFile.setupCommands();
      Bukkit.getPluginManager().registerEvents(new JoinEvent(), this);
      Bukkit.getPluginManager().registerEvents(new MultiCommandEvent(), this);
      Bukkit.getPluginManager().registerEvents(new InventoryEvent(), this);
      MultiCommand.setupHashMaps();
     }
     public void onDisable(){
     }
     
     public void checkCommands() {
      //GAMEMODES
      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());
      //VANISH
      getCommand("vanish").setExecutor(new VanishCommand());
      getCommand("v").setExecutor(new VanishCommand());
      //TELEPORT
      getCommand("tp").setExecutor(new TPDirectCommand());
      getCommand("s").setExecutor(new TPHereDirectCommand());
      getCommand("tphere").setExecutor(new TPHereDirectCommand());
      //INVSEE
      getCommand("invsee").setExecutor(new InvSeeCommand());
      //KILL
      getCommand("kill").setExecutor(new KillCommand());
      //COMMANDS
      getCommand("command").setExecutor(new MultiCommand());
      //RP
      getCommand("rp").setExecutor(new RemovePermissionsCommand());
     }
     
     public void checkFiles() {
      this.mf=new MessageFile();
     }
     
     public void loadConfig() {
      this.getConfig().options().copyDefaults(true);
      this.getConfig().options().copyHeader(true);
      this.saveDefaultConfig();
     }
     
     
     
    }

     
     
  9. NathanWolf

    Supporter

    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

    Supporter

    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(){

                @Override
                public void run() {
                   string = fc.getString("Path");
                }
            }.runTaskLater(this,100L);
    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

    Supporter

    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

    Supporter

    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!