Need help with error

Discussion in 'Plugin Development' started by HerobrineLivesHere, Sep 7, 2013.

Thread Status:
Not open for further replies.
  1. I made my first plugin but I get this error when I get it to the server. It doesn't respond to any commands either but is enabled. Any help?

    Error log:
    Code:
    [PaintBall] Enabling PaintBall v1.0
    2013-09-07 22:52:30 [SEVERE] Error occurred while enabling PaintBall v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.swecraft.paintball.SettingsManager.get(SettingsManager.java:40)
        at me.swecraft.paintball.ArenaManager.setup(ArenaManager.java:23)
        at me.swecraft.paintball.Paintball.onEnable(Paintball.java:16)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:286)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:268)
        at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:319)
        at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:296)
        at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:256)
        at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:164)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:397)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
     
  2. Offline

    tommycake50

    java.lang.NullPointerException at me.swecraft.paintball.SettingsManager.get(SettingsManager.java:40) at me.swecraft.paintball.ArenaManager.setup(ArenaManager.java:23) at me.swecraft.paintball.Paintball.onEnable(Paintball.java:16)
    Look at those lines and work it out for yourself.
    or just show us the code.
     
  3. Offline

    Lolmewn Retired Staff

    What is on line 40 in your SettingsManager class?
     
  4. Code:
    return (T)  arenas.get(path);
     
  5. Offline

    Lolmewn Retired Staff

  6. Can't get it to work. Do you want the code instead?
     
  7. Offline

    Lolmewn Retired Staff

    HerobrineLivesHere Yes please.

    HerobrineLivesHere Please just paste it using [ code] blocks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Settings manager:
    Code:
    package me.swecraft.paintball;
     
    import java.io.File;
     
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;
     
    public class SettingsManager {
       
        private SettingsManager() { }
       
        private static SettingsManager instance = new SettingsManager();
       
        public static SettingsManager getInstance() {
            return instance;
        }
       
        private Plugin p;
        private FileConfiguration arenas;
        private File afile;
       
        public void setup(Plugin p) {
            this.p = p;
           
            if (!p.getDataFolder().exists()) p.getDataFolder().mkdir();
           
            afile = new File(p.getDataFolder(), "arenas.yml");
            if(!afile.exists()) {
                try { afile.createNewFile(); }
                catch (Exception e) { e.printStackTrace(); }
            }
           
            arenas = YamlConfiguration.loadConfiguration(afile);
        }
       
        @SuppressWarnings("unchecked")
        public<T> T get(String path) {
            return (T)  arenas.get(path);
        }
       
        public void set(String path, Object value) {
            arenas.set(path, value);
            try {
                arenas.save(afile);
                save();
            }
            catch (Exception e) { e.printStackTrace(); }
        }
       
        public ConfigurationSection createConfigurationSection(String path) {
            ConfigurationSection s = arenas.createSection(path);
            save();
            return s;
        }
       
        private void save() {
            try { afile.createNewFile(); }
            catch (Exception e) { e.printStackTrace(); }
        }
       
        public Plugin getPlugin() {
            return p;
        }
    }
    Arena manager:
    Code:
    package me.swecraft.paintball;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.entity.Player;
     
    public class ArenaManager {
     
        public enum Team { RED, BLUE; }
       
        private ArenaManager() { }
       
        private static ArenaManager instance = new ArenaManager();
       
        public static ArenaManager getInstance() {
            return instance;
        }
       
        private ArrayList<Arena> arenas = new ArrayList<Arena>();
       
        public void setup() {
            for (int i : SettingsManager.getInstance().<List<Integer>>get("ids")) {
                arenas.add(new Arena(i));
            }
        }
       
        public ArrayList<Arena> getArenas() {
            return arenas;
        }
       
        public Arena getArena(int id) {
            for (Arena a : arenas) {
                if (a.getID() == id) return a;
            }
            return null;
        }
       
        public Arena getArena(Player p) {
            for (Arena a : arenas) {
                if (a.containsPlayer(p)) return a;
            }
            return null;
        }
    }
    Paintball:
    Code:
    package me.swecraft.paintball;
     
    import me.swecraft.paintball.listeners.ArmorRemove;
    import me.swecraft.paintball.listeners.BlockBreak;
    import me.swecraft.paintball.listeners.PlayerAttack;
    import me.swecraft.paintball.listeners.PlayerDeath;
    import me.swecraft.paintball.listeners.PlayerLeave;
    import me.swecraft.paintball.listeners.SnowballListeners;
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Paintball extends JavaPlugin{
       
        public void onEnable() {
            ArenaManager.getInstance().setup();
           
            CommandManager cm = new CommandManager();
            cm.setup();
            getCommand("pb").setExecutor(cm);
           
            Bukkit.getServer().getPluginManager().registerEvents(new ArmorRemove(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new BlockBreak(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerAttack(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerDeath(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerLeave(), this);
            Bukkit.getServer().getPluginManager().registerEvents(new SnowballListeners(), this);
        }
     
    }
    
     
  9. Offline

    Lolmewn Retired Staff

    HerobrineLivesHere You're setting up the second instance of the SettingsManager, not the first. You should pass your main class to the constructor, not have anything static in your Settings Manger class, and then call setup();
     
Thread Status:
Not open for further replies.

Share This Page