Bukkit Coding My Plugin Wont Work

Discussion in 'Plugin Development' started by Darkdestroyerjn, Mar 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Darkdestroyerjn

    Heres My Error (Btw Insert Code Isnt Working On My Pc)
    Loading libraries, please wait...
    [09:22:34 INFO]: Starting minecraft server version 1.7.2
    [09:22:34 INFO]: Loading properties
    [09:22:34 INFO]: Default game type: SURVIVAL
    [09:22:34 INFO]: Generating keypair
    [09:22:35 INFO]: Starting Minecraft server on *:25568
    [09:22:36 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.
    3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
    [09:22:36 ERROR]: Could not load 'plugins\DarkBukkit.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:137) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:313) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:236) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:31
    2) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
    at me.darkdestroyerj.DarkBukkit.Main.<init>(Main.java:19) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[?:1.7.0_25]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    ~[?:1.7.0_25]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce) ~[?:1.7.0_25]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_2
    5]
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:133) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    ... 9 more
    [09:22:36 INFO]: [GroupManager] Loading GroupManager v2.0 (2.11.1) (Phoenix)
    [09:22:36 INFO]: [Multiverse-Core] Loading Multiverse-Core v2.4-b527
    [09:22:36 INFO]: Preparing level "world"
    [09:22:36 INFO]: Preparing start region for level 0 (Seed: -1820964542409378046)

    [09:22:37 INFO]: Preparing spawn area: 27%
    [09:22:38 INFO]: Preparing start region for level 1 (Seed: -1820964542409378046)

    [09:22:39 INFO]: Preparing start region for level 2 (Seed: -1820964542409378046)

    [09:22:39 INFO]: [GroupManager] Enabling GroupManager v2.0 (2.11.1) (Phoenix)
    [09:22:39 INFO]: GroupManager - INFO - World Found: world
    [09:22:39 INFO]: GroupManager - INFO - Superperms support enabled.
    [09:22:39 INFO]: GroupManager - INFO - Scheduled Data Saving is set for every 10
    minutes!
    [09:22:39 INFO]: GroupManager - INFO - Backups will be retained for 24 hours!
    [09:22:39 INFO]: GroupManager version 2.0 (2.11.1) (Phoenix) is enabled!
    [09:22:39 INFO]: [Multiverse-Core] Enabling Multiverse-Core v2.4-b527
    [09:22:39 INFO]: [Multiverse-Core] - Version 2.4-b527 (API v14) Enabled - By Rig
    by, fernferret, lithium3141 and main--
    [09:22:40 INFO]: [AllPay] - Version 10.0 - using only an item based economy for
    Multiverse-Core v2.4-b527
    [09:22:40 INFO]: [Multiverse-Core] Loading World & Settings - 'world' - Env: NOR
    MAL - Type: NORMAL & seed: -1820964542409378046
    [09:22:40 INFO]: [Multiverse-Core] Loading World & Settings - 'world_nether' - E
    nv: NETHER - Type: NORMAL & seed: -1820964542409378046
    [09:22:40 INFO]: [Multiverse-Core] Loading World & Settings - 'world_the_end' -
    Env: THE_END - Type: NORMAL & seed: -1820964542409378046
    [09:22:40 INFO]: [Multiverse-Core] Loading World & Settings - 'PvP' - Env: NORMA
    L - Type: FLAT & seed: -9178144438266403602
    [09:22:40 INFO]: Preparing start region for level 3 (Seed: -9178144438266403602)

    [09:22:41 INFO]: [Multiverse-Core] 4 - World(s) loaded.
    [09:22:41 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [09:22:41 INFO]: Done (4.579s)! For help, type "help" or "?"
    [09:22:41 INFO]: GroupManager - INFO - Bukkit Permissions Updated!
    [09:27:43 WARN]: Can't keep up! Did the system time change, or is the server ove
    rloaded? Running 2347ms behind, skipping 46 tick(s)
    >


    heres my Main Code Class:
    package me.darkdestroyerj.DarkBukkit;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin{
    MyConfigManager manager;
    MyConfig HomesConfig;
    public void onEnable() {
    Bukkit.getServer().getLogger().info("DarKBukkitCore Enabled");
    }

    {


    manager = new MyConfigManager(this);
    HomesConfig = manager .getNewConfig("HomesConfig.yml", new String[] { "DarkBukkitConfig", "Homes Config"});
    getCommand("gmc").setExecutor(new Commands(this));
    getCommand("gms").setExecutor(new Commands(this));
    getCommand("gma").setExecutor(new Commands(this));
    getCommand("hub").setExecutor(new Commands(this));
    }

    {
    }
    public void onDisable() {
    Bukkit.getServer().getLogger().info("DarkBukkitCore Disabled");

    }
    }

    Heres My Commands Class:

    package me.darkdestroyerj.DarkBukkit;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    public class Commands implements Listener, CommandExecutor {
    MyConfigManager manager;
    MyConfig HomesConfig;
    public static final Main passedPlugin = null;
    public Main plugin;

    {
    {
    this.plugin = passedPlugin;
    }
    }


    public Commands(Main main) {
    }






    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    {
    if (sender instanceof Player) {
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("gmc")){
    if (player.hasPermission("darkbukkit.gamemode.creative")) {
    } else {
    player.sendMessage(ChatColor.RED + "You Dont Have Permitted To Do this!");
    return true;
    }
    player.setGameMode(GameMode.CREATIVE);
    player.sendMessage(ChatColor.BLUE + " [DarkBukkit]Gamemode Changed To Creative");
    }
    }




    if (sender instanceof Player) {
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("hub")){
    String hub = "spawn " + player.getName();
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hub);
    player.sendMessage(ChatColor.AQUA + "[DarkBukkit] Teleported To Hub");

    }
    }




    if (sender instanceof Player) {
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("gms")){
    if (!player.hasPermission("darkbukkit.gamemode.survival")) {

    player.sendMessage(ChatColor.RED + "You Dont Have Permitted To Do this!");
    } else {
    player.setGameMode(GameMode.SURVIVAL);
    player.sendMessage(ChatColor.BLUE + " [DarkBukkit]Gamemode Changed To Survival");
    }
    }
    }

    if (sender instanceof Player) {
    if(cmd.getName().equalsIgnoreCase("gma")){
    Player player = (Player) sender;
    if (!player.hasPermission("darkbukkit.gamemode.adventure")) {

    player.sendMessage(ChatColor.RED + "You Dont Have Permitted To Do this!");
    } else {
    player.setGameMode(GameMode.ADVENTURE);
    player.sendMessage(ChatColor.BLUE + " [DarkBukkit]Gamemode Changed To Adventure");
    }
    }
    }
    return true;
    }
    {
    }
    {

    {

    } {
    }
    }

    {
    }

    }


    heres my plugin.yml:
    name: DarkBukkitCore
    version: 2.0
    main: me.darkdestroyerj.DarkBukkit.Main
    author: Darkdestroyerj
    description: DarkBukkit Core

    commands:
    gmc:
    aliases:
    description: Gamemode Creative!
    hub:
    aliases:
    description: Hub Command!
    gms:
    aliases:
    description: Gamemode Survival!
    gma:
    aliases:
    description: Gamemode Adventure!
    permissions:
    darkbukkit.gamemode.creative:
    description: Gamemode Creative Permission!
    darkbukkit.gamemode.survival:
    description: Gamemode Survival Permission!
    darkbukkit.gamemode.adventure:
    description: Gamemode Adventure Permission!


    heres myconfigmanager:
    package me.darkdestroyerj.DarkBukkit;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.i:confused:utputStream;
    import java.nio.charset.Charset;

    import org.bukkit.plugin.java.JavaPlugin;

    public class MyConfigManager
    {
    private JavaPlugin plugin;

    public MyConfigManager(JavaPlugin plugin)
    {
    this.plugin = plugin;
    }

    public MyConfig getNewConfig(String fileName, String[] header)
    {
    File file = this.getConfigFile(fileName);

    if(!file.exists())
    {
    this.prepareFile(fileName);
    if(header != null && header.length != 0)
    this.setHeader(file, header);
    }

    MyConfig config = new MyConfig(this.getConfigContent(fileName), file, this.getCommentsNum(file), plugin);
    return config;
    }

    public MyConfig getNewConfig(String fileName)
    {
    return this.getNewConfig(fileName, null);
    }

    private File getConfigFile(String file)
    {
    if(file.isEmpty() || file == null)
    return null;

    File configFile;

    if(file.contains("/"))
    {
    if(file.startsWith("/"))
    configFile = new File(plugin.getDataFolder() + file.replace("/", File.separator));
    else configFile = new File(plugin.getDataFolder() + File.separator + file.replace("/", File.separator));
    }
    else configFile = new File(plugin.getDataFolder(), file);

    return configFile;
    }

    public void prepareFile(String filePath, String resource)
    {
    File file = this.getConfigFile(filePath);

    if(file.exists())
    return;

    try
    {
    file.getParentFile().mkdirs();
    file.createNewFile();

    if(resource != null)
    if(!resource.isEmpty())
    this.copyResource(plugin.getResource(resource), file);

    }
    catch (IOException e){e.printStackTrace();}
    }

    public void prepareFile(String filePath)
    {
    this.prepareFile(filePath, null);
    }

    public void setHeader(File file, String[] header)
    {
    if(!file.exists())
    return;

    try
    {
    String currentLine;
    StringBuilder config = new StringBuilder("");
    BufferedReader reader = new BufferedReader(new FileReader(file));

    while((currentLine = reader.readLine()) != null)
    config.append(currentLine + "\n");

    reader.close();
    config.append("# +----------------------------------------------------+ #\n");

    for(String line : header)
    {
    if(line.length() > 50)
    continue;

    int lenght = (50 - line.length()) / 2;
    StringBuilder finalLine = new StringBuilder(line);

    for(int i = 0; i < lenght; i++)
    {
    finalLine.append(" ");
    finalLine.reverse();
    finalLine.append(" ");
    finalLine.reverse();
    }

    if(line.length() % 2 != 0)
    finalLine.append(" ");

    config.append("# < " + finalLine.toString() + " > #\n");
    }
    config.append("# +----------------------------------------------------+ #");

    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(this.prepareConfigString(config.toString()));
    writer.flush();
    writer.close();
    }
    catch (IOException e){e.printStackTrace();}
    }

    public InputStream getConfigContent(File file)
    {
    if(!file.exists())
    return null;
    try
    {
    int commentNum = 0;

    String addLine;
    String currentLine;
    String pluginName = this.getPluginName();

    StringBuilder whole = new StringBuilder("");
    BufferedReader reader = new BufferedReader(new FileReader(file));

    while((currentLine = reader.readLine()) != null)
    {
    if(currentLine.startsWith("#"))
    {
    addLine = currentLine.replaceFirst("#", pluginName + "_COMMENT_" + commentNum + ":");
    whole.append(addLine + "\n");
    commentNum++;
    }
    else whole.append(currentLine + "\n");
    }

    String config = whole.toString();
    InputStream configStream = new ByteArrayInputStream(config.getBytes(Charset.forName("UTF-8")));

    reader.close();
    return configStream;
    }
    catch (IOException e){e.printStackTrace();return null;}
    }

    private int getCommentsNum(File file)
    {
    if(!file.exists())
    return 0;
    try
    {
    int comments = 0;
    String currentLine;

    BufferedReader reader = new BufferedReader(new FileReader(file));

    while((currentLine = reader.readLine()) != null)
    if(currentLine.startsWith("#"))
    comments++;

    reader.close();
    return comments;
    }
    catch (IOException e){e.printStackTrace();return 0;}
    }

    public InputStream getConfigContent(String filePath)
    {
    return this.getConfigContent(this.getConfigFile(filePath));
    }

    private String prepareConfigString(String configString)
    {
    int lastLine = 0;
    int headerLine = 0;

    String[] lines = configString.split("\n");
    StringBuilder config = new StringBuilder("");

    for(String line : lines)
    {
    if(line.startsWith(this.getPluginName() + "_COMMENT"))
    {
    String comment = "#" + line.trim().substring(line.indexOf(":") + 1);

    if(comment.startsWith("# +-"))
    {
    if(headerLine == 0)
    {
    config.append(comment + "\n");
    lastLine = 0;
    headerLine = 1;
    }
    else if(headerLine == 1)
    {
    config.append(comment + "\n\n");
    lastLine = 0;
    headerLine = 0;
    }
    }
    else
    {
    String normalComment;
    if(comment.startsWith("# ' "))
    normalComment = comment.substring(0, comment.length() - 1).replaceFirst("# ' ", "# ");
    else normalComment = comment;

    if(lastLine == 0)
    config.append(normalComment + "\n");
    else if(lastLine == 1)
    config.append("\n" + normalComment + "\n");

    lastLine = 0;
    }
    }
    else
    {
    config.append(line + "\n");
    lastLine = 1;
    }
    }
    return config.toString();
    }

    public void saveConfig(String configString, File file)
    {
    String configuration = this.prepareConfigString(configString);

    try
    {
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(configuration);
    writer.flush();
    writer.close();

    }
    catch (IOException e){e.printStackTrace();}
    }

    public String getPluginName()
    {
    return plugin.getDescription().getName();
    }

    private void copyResource(InputStream resource, File file)
    {
    try
    {
    OutputStream out = new FileOutputStream(file);

    int length;
    byte[] buf = new byte[1024];

    while((length = resource.read(buf)) > 0)
    out.write(buf, 0, length);

    out.close();
    resource.close();
    }
    catch (Exception e) {e.printStackTrace();}
    }
    }
    heres My MyConfig Class:
    package me.darkdestroyerj.DarkBukkit;

    import java.io.File;
    import java.io.InputStream;
    import java.util.List;
    import java.util.Set;

    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MyConfig
    {
    private int comments;
    private MyConfigManager manager;

    private File file;
    private FileConfiguration config;

    public MyConfig(InputStream configStream, File configFile, int comments, JavaPlugin plugin)
    {
    this.comments = comments;
    this.manager = new MyConfigManager(plugin);
    this.file = configFile;
    this.config = YamlConfiguration.loadConfiguration(configStream);
    }

    public Object get(String path) {return this.config.get(path);}

    public Object get(String path, Object def) {return this.config.get(path, def);}

    public String getString(String path) {return this.config.getString(path);}

    public String getString(String path, String def) {return this.config.getString(path, def);}

    public int getInt(String path) {return this.config.getInt(path);}

    public int getInt(String path, int def) {return this.config.getInt(path, def);}

    public boolean getBoolean(String path) {return this.config.getBoolean(path);}

    public boolean getBoolean(String path, boolean def) {return this.config.getBoolean(path, def);}

    public void createSection(String path) {this.config.createSection(path);}

    public ConfigurationSection getConfigurationSection(String path) {return this.config.getConfigurationSection(path);}

    public double getDouble(String path) {return this.config.getDouble(path);}

    public double getDouble(String path, double def) {return this.config.getDouble(path, def);}

    public List<?> getList(String path) {return this.config.getList(path);}

    public List<?> getList(String path, List<?> def) {return this.config.getList(path, def);}

    public boolean contains(String path) {return this.config.contains(path);}

    public void removeKey(String path) {this.config.set(path, null);}

    public void set(String path, Object value) {this.config.set(path, value);}

    public void set(String path, Object value, String comment)
    {
    if(!this.config.contains(path))
    {
    this.config.set(manager.getPluginName() + "_COMMENT_" + comments, " " + comment);
    comments++;
    }
    this.config.set(path, value);
    }

    public void set(String path, Object value, String[] comment)
    {
    for(String comm : comment)
    {
    if(!this.config.contains(path))
    {
    this.config.set(manager.getPluginName() + "_COMMENT_" + comments, " " + comm);
    comments++;
    }
    }
    this.config.set(path, value);
    }

    public void setHeader(String[] header)
    {
    manager.setHeader(this.file, header);
    this.comments = header.length + 2;
    this.reloadConfig();
    }

    public void reloadConfig() {this.config = YamlConfiguration.loadConfiguration(manager.getConfigContent(file));}

    public void saveConfig()
    {
    String config = this.config.saveToString();
    manager.saveConfig(config, this.file);
    }

    public Set<String> getKeys() {return this.config.getKeys(false);}
    }

    plz Message Me What i need to fix am not getting any error on eclipse
     
  2. Offline

    Jnorr44

    whoa, this should be in the plugin development section, and you should put your code on pastie or pastebin and just post a link.
     
  3. Offline

    jthort

  4. Offline

    Lolmewn

    (Assuming this is going to be moved soon) - What's your plugin.yml?
     
  5. Offline

    TnT

    Moved to the correct forum.
     
Thread Status:
Not open for further replies.

Share This Page