Wy is my plugin not working??

Discussion in 'Plugin Development' started by Kaimido, Apr 10, 2016.

Thread Status:
Not open for further replies.
  1. I was trying to work in multiple classes, but my plugin didn't work and i dont know wy. Here is the CONSOLE error:
    Code:
    10.04 16:54:12 [Server] INFO ... 6 more
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_66]
    10.04 16:54:12 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_66]
    10.04 16:54:12 [Server] INFO at org.geamteam.Minetopia.Main.<clinit>(Main.java:13) ~[?:?]
    10.04 16:54:12 [Server] INFO Caused by: java.lang.NullPointerException
    10.04 16:54:12 [Server] INFO ... 6 more
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_66]
    10.04 16:54:12 [Server] INFO at java.lang.Class.forName0(Native Method) ~[?:1.8.0_66]
    10.04 16:54:12 [Server] INFO Caused by: java.lang.ExceptionInInitializerError
    10.04 16:54:12 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_66]
    10.04 16:54:12 [Server] INFO at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:527) [spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at net.minecraft.server.v1_9_R1.DedicatedServer.init(DedicatedServer.java:201) [spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugins(CraftServer.java:296) [spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-os7.jar:git-Spigot-944aa20-8d16fc0]
    10.04 16:54:12 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.ExceptionInInitializerError
    10.04 16:54:12 [Server] ERROR Could not load 'plugins/Minetopia.jar' in folder 'plugins'
    And here is my Main class:

    Code:
    package org.geamteam.Minetopia;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.nio.file.CopyOption;
    import java.nio.file.Files;
    
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.geamteam.Minetopia.commands.OpenBankCommand;
    import org.geamteam.Minetopia.events.InventoryClick;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class Main extends JavaPlugin {
       
        public static Main instance;
        public static File configf, messagesf, dataf;
        public static FileConfiguration config, messages, data;
        public static PluginDescriptionFile pdf;
        public static String version = pdf.getVersion();
        public static Plugin mt;
       
        public static FileConfiguration getConfigFile() {
            return config;
        }
        public static FileConfiguration getMessages() {
            return messages;
        }
        public static FileConfiguration getData() {
            return data;
        }
        public static String getVersion() {
            return version;
        }
        public static void reloadFiles() {
            try {
                config.load(configf);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
            try {
                messages.load(messagesf);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
            try {
                config.load(configf);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }
       
        public void onEnable() {
            setupConfig();
           
            getServer().getPluginManager().registerEvents(new InventoryClick(), this);
           
            getCommand("openbank").setExecutor(new OpenBankCommand());
        }
       
        public void onDisable() {
        }
       
        public void setupConfig() {
            if(!getDataFolder().exists()) {
                getDataFolder().mkdirs();
            }
           
            configf = new File(getDataFolder(), "config.yml");
            messagesf = new File(getDataFolder(), "messages.yml");
            dataf = new File(getDataFolder(), "bank-accounts.yml");
           
            if(!configf.exists()) {
                try {
                    Files.copy(getResource("config.yml"), configf.toPath(), new CopyOption[0]);
                } catch (IOException e) {
                    getLogger().info("Het is niet gelukt om de config files te create. Error report: " + e.getMessage());
                }
            }
            if(!messagesf.exists()) {
                try {
                    Files.copy(getResource("messages.yml"), configf.toPath(), new CopyOption[0]);
                } catch (IOException e) {
                    getLogger().info("Het is niet gelukt om de messages files te create. Error report: " + e.getMessage());
                }
            }
            if(!dataf.exists()) {
                try {
                    Files.copy(getResource("bank-accounts.yml"), configf.toPath(), new CopyOption[0]);
                } catch (IOException e) {
                    getLogger().info("Het is niet gelukt om de bank-accounts files te create. Error report: " + e.getMessage());
                }
            }
            try {
                config.load(configf);
            } catch (FileNotFoundException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'config.yml' niet vinden.");
            } catch (IOException e) {
                getLogger().info(ChatColor.DARK_RED+"Er is een onbekende fout opgetreden bij het laden van de 'config.yml'."
                        +"Report deze error alstublieft bij de developer van de plugin: " + e.getMessage());
            } catch (InvalidConfigurationException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'config.yml' niet laden door een fout in de file: " + e.getMessage());
            }
            try {
                messages.load(messagesf);
            } catch (FileNotFoundException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'messages.yml' niet vinden.");
            } catch (IOException e) {
                getLogger().info(ChatColor.DARK_RED+"Er is een onbekende fout opgetreden bij het laden van de 'messages.yml'."
                        +"Report deze error alstublieft bij de developer van de plugin: " + e.getMessage());
            } catch (InvalidConfigurationException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'messages.yml' niet laden door een fout in de file: " + e.getMessage());
            }
            try {
                config.load(configf);
            } catch (FileNotFoundException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'bank-accounts.yml' niet vinden.");
            } catch (IOException e) {
                getLogger().info(ChatColor.DARK_RED+"Er is een onbekende fout opgetreden bij het laden van de 'config.yml'."
                        +"Report deze error alstublieft bij de developer van de plugin: " + e.getMessage());
            } catch (InvalidConfigurationException e) {
                getLogger().info(ChatColor.RED + "Kon de file 'bank-accounts.yml' niet laden door een fout in de file: " + e.getMessage());
            }
        }
    
    }
    
    And this is my plugin.yml:

    Code:
    name: Minetopia
    main: org.geamteam.Minetopia.Main
    version: 1.0
    author: Kantanic
    website: www.geamteam.org
    commands:
      openbank:
        description: Opent een specefike bank.
    Can anyone help me with this problem? BTW: Sorry for my bad english
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Kaimido Get rid of all the static. You don't need it.
    And you have a nullpointer, you are calling pdf.getVersion without pdf being initialized.
     
  3. Thanks, my pluign is finaly enabled. I removed this:
    Code:
    public static PluginDescriptionFile pdf;
    public static String version = pdf.getVersion();
    But i have 2 more questions:
    1: How do i initializ the pdf?
    2: I tryed to use the command that i have made in another class, and he didn't works. This is my commands class:
    Code:
    package org.geamteam.Minetopia.commands;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.geamteam.Minetopia.Main;
    import org.geamteam.Minetopia.OpenBankClass;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class OpenBankCommand implements CommandExecutor {
    
        private String noPermission;
        private String openBankText;
        private String notExist;
    
        public OpenBankCommand() {
            noPermission = ChatColor.translateAlternateColorCodes('&', Main.getData().getString("no-permission-text"));
            openBankText = ChatColor.translateAlternateColorCodes('&', Main.getData().getString("openbank-other"));
            notExist = ChatColor.translateAlternateColorCodes('&', Main.getData().getString("bank-not-exist"));
        }
    
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
            if(label.equalsIgnoreCase("openbank")) {
                if(s.hasPermission("minetopia.openbank")) {
                    if(args.length >=1) {
                        if(Main.getData().contains(args[0])) {
                            OpenBankClass.openBank(args[0], ((Player) s));
                            s.sendMessage(openBankText);
                        }  else s.sendMessage(notExist);
                    } else s.sendMessage(ChatColor.RED + "Usage: /openbank <bank>");
                } else s.sendMessage(noPermission);
            } return false;
        }
    }
    
    The main class and the plugin.yml are the same.
     
    Last edited: Apr 10, 2016
  4. Offline

    timtower Administrator Administrator Moderator

    @Kaimido You dont need the pdf stuff.
     
  5. Alright, and what about the command?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Kaimido How is it not working? What is broken? What is happening? What should happen?
     
  7. Offline

    Lolmewn

    Also, what is this import? :confused: That doesn't look like bukkit at all!

    import net.md_5.bungee.api.ChatColor;
     
  8. Offline

    mine-care

  9. There should open a GUI with stuff in it and send the player a message.
    But nothing hapend. Just a empty chat. Not even a "Unknown command" message.
     
  10. Offline

    Zombie_Striker

    @Kaimido
    Unknown command comes from the command not being registered in a plugin.yml/ having your onCommand always return false. Make sure you have the correct command put in the plugin.yml and you are returning true if the command sent is your command.
     
    cococow123 likes this.
  11. I said NOT even a Unknown command message
     
  12. Offline

    mcdorli

    Errors? Do the plugin get registered? Can we see the latest code?
     
  13. Offline

    Lordloss

    @Lolmewn this is what happens if you dont pay attention while importing bukkit.chatcolor.

    @Kaimido your "plugin is not working" because it dont have an employment contract. Its hard to get one these days. ;)
     
    cococow123 and Zombie_Striker like this.
  14. Offline

    mcdorli

    No, this happens if you start pressing every pissible button eclipse privides you with to solve problems.
     
  15. Offline

    Scorpionvssub

    Off topic question...I see many "md_5 chatcolor" imports are bad for use, but why? what is its purpose of being in there if its "bad"
     
  16. Offline

    mcdorli

    It's not bad, it simply won't work if you use an official bukkit version (1.7.x),
     
  17. Offline

    Scorpionvssub

    so it doesnt matter for usee in 1.8-1.9?
     
  18. Offline

    Lordloss

    @mcdorli basically the same what i said.

    @Scorpionvssub its just not the ChatColor of bukkit, its the import of the Bungee Cord API.
     
  19. Offline

    Zombie_Striker

    @Scorpionvssub
    Basically, that Chatcolor is meant for the BungeeCordAPI, while the org.bukkit Chatcolor is meant for all other servers that do not have Bungee. This was a bigger deal back when Bukkit was still being updated.
     
Thread Status:
Not open for further replies.

Share This Page