Plugin works only after reload

Discussion in 'Programming' started by GhostSHAURMA, Dec 30, 2019.

  1. Hi,

    I have a plugin that doesnt woks when i start a server but after /reload it starts to work as it should

    It doesnt throw any errors but still doesnt work at all

    There is some code:

    Code (Java):
    public class GroundControl extends JavaPlugin
    {
        public static Plugin plug;
     
        public static boolean InProgress = false;
     
        public static Inventory teamc;
     
        public static Scoreboard s = Bukkit.getScoreboardManager().getNewScoreboard();
     
        public static Team teamr = s.registerNewTeam("Red");
        public static Team teamb = s.registerNewTeam("Blue");
        public static Team teamy = s.registerNewTeam("Yellow");
        public static Team teamg = s.registerNewTeam("Green");
        public static Team team = s.registerNewTeam("Spectators");
     
        public static int sec = 0;
     
        public void onEnable()
        {
            plug = this;
         
            ItemMeta meta = Handler.teamch.getItemMeta();
            meta.setDisplayName("Выбор команды");
            List<String> lore = new ArrayList<String>();
            lore.add("ПКМ для выбора");
            meta.setLore(lore);
            Handler.teamch.setItemMeta(meta);
            for (Player P : Bukkit.getOnlinePlayers())
            {
                P.getInventory().clear();
                Location l = P.getLocation();
                l.setX(0);
                l.setY(41);
                l.setZ(0);
                P.teleport(l);
                P.getInventory().clear();
                P.getInventory().addItem(Handler.teamch);
                P.setAllowFlight(false);
                team.addEntry(P.getName());
                P.setScoreboard(GroundControl.s);
                Handler.CanFirePrime.put((Entity) P, true);
                Handler.CanFireSec.put((Entity) P, true);
            }
         
            getCommand("start").setExecutor(new Start());
         
            teamc = Bukkit.createInventory(null,5,"Выбор команды");
            ItemStack teamred = new ItemStack(Material.RED_STAINED_GLASS_PANE);
            meta = teamred.getItemMeta();
            meta.setDisplayName("Команда красных");
            teamred.setItemMeta(meta);
            ItemStack teamblue = new ItemStack(Material.BLUE_STAINED_GLASS_PANE);
            meta = teamblue.getItemMeta();
            meta.setDisplayName("Команда синих");
            teamblue.setItemMeta(meta);
            ItemStack teamryeilow = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE);
            meta = teamryeilow.getItemMeta();
            meta.setDisplayName("Команда жёлтых");
            teamryeilow.setItemMeta(meta);
            ItemStack teamgreen = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
            meta = teamgreen.getItemMeta();
            meta.setDisplayName("Команда зелёных");
            teamgreen.setItemMeta(meta);
            ItemStack teamsp = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE);
            meta = teamsp.getItemMeta();
            meta.setDisplayName("Набдюдатели");
            teamsp.setItemMeta(meta);
            teamc.setItem(0, teamred);
            teamc.setItem(1, teamblue);
            teamc.setItem(2, teamryeilow);
            teamc.setItem(3, teamgreen);
            teamc.setItem(4, teamsp);
         
            team.setColor(ChatColor.GRAY);
            team.setDisplayName("Наблюдатели");
            team.setPrefix("<Наблюдатели> ");
            team.setAllowFriendlyFire(false);
            team.setCanSeeFriendlyInvisibles(true);
            teamr.setColor(ChatColor.RED);
            teamr.setDisplayName("Красные");
            teamr.setPrefix("<Красные> ");
            teamr.setAllowFriendlyFire(false);
            teamr.setCanSeeFriendlyInvisibles(true);
            teamb.setColor(ChatColor.BLUE);
            teamb.setDisplayName("Синие");
            teamb.setPrefix("<Синие> ");
            teamb.setAllowFriendlyFire(false);
            teamb.setCanSeeFriendlyInvisibles(true);
            teamy.setColor(ChatColor.YELLOW);
            teamy.setDisplayName("Жёлтые");
            teamy.setPrefix("<Жёлтые> ");
            teamy.setAllowFriendlyFire(false);
            teamy.setCanSeeFriendlyInvisibles(true);
            teamg.setColor(ChatColor.GREEN);
            teamg.setDisplayName("Зелёные");
            teamg.setPrefix("<Зелёные> ");
            teamg.setAllowFriendlyFire(false);
            teamg.setCanSeeFriendlyInvisibles(true);
         
            Bukkit.getPluginManager().registerEvents(new Handler(), this);
        }
    }
    Can someone help?
     
  2. What do you mean by "not working"?
     
  3. I mean not working at all. It is not even creating the teams.
     
  4. Oh, I just realized its not even loading so here's yml:
    Code (YAML):
    name: GroundControl
    main
    : GC.main.GroundControl
    version
    : 1.0
    commands
    :
     start
    :
      description
    : Start the game
      usage
    : /start
     
  5. Send your startup log, if the plugin doesn't load it might provide some insight.
     
  6. Ok, i havent seen this before but it throws this:
    Code (Text):
    [21:38:02] [Server thread/ERROR]: Could not load 'plugins\GroundControl.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ExceptionInInitializerError
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:334) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:253) [spigot.jar:git-Spigot-9de398a-9c887d4]
        at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins(CraftServer.java:350) [spigot.jar:git-Spigot-9de398a-9c887d4]
        at net.minecraft.server.v1_14_R1.DedicatedServer.init(DedicatedServer.java:194) [spigot.jar:git-Spigot-9de398a-9c887d4]
        at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:776) [spigot.jar:git-Spigot-9de398a-9c887d4]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
    Caused by: java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_181]
        at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_181]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:59) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        ... 6 more
    Caused by: java.lang.NullPointerException
        at GC.main.GroundControl.<clinit>(GroundControl.java:28) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_181]
        at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_181]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:59) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
        ... 6 more
    here:
    Code (Java):
    public static Scoreboard s = Bukkit.getScoreboardManager().getNewScoreboard();
     
  7. Initialize all of your variables in your onEnable.
     
  8. Thanks! Its working now
     
  9. Strahan

    Benefactor

    ...and stop puking static all over everything. There isn't any need for most of that to be static.
     
    • Agree Agree x 1