Plugin cannot be null

Discussion in 'Plugin Help/Development/Requests' started by bobthefish, Dec 26, 2014.

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

    bobthefish

    Hi, so for the past day or so ive been trying to set up a timer for a pluing im making, however i keep getting this error:

    Code:
    [17:54:55 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'scp'
    in plugin KotH vpre Alpha 1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[ser
    ver.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) ~[server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) ~[server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1043) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :880) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[server.
    jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.validate(Craf
    tScheduler.java:397) ~[server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.runTaskTimer(
    CraftScheduler.java:123) ~[server.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.scheduleSyncR
    epeatingTask(CraftScheduler.java:119) ~[server.jar:git-Spigot-1.7.9-R0.2-204-g53
    4549b]
            at me.BobTheFish.KOTH.StartTimer.init(StartTimer.java:21) ~[?:?]
            at me.BobTheFish.KOTH.ArenaManager.join(ArenaManager.java:78) ~[?:?]
            at me.BobTheFish.KOTH.CommandSetCP.onCommand(CommandSetCP.java:22) ~[?:?
    ]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[ser
    ver.jar:git-Spigot-1.7.9-R0.2-204-g534549b]
            ... 13 more
    >
    i looked all over the forums for an answer but as near as I can tell, this isnt the problem. all the other posts said to make sure that you have

    this.plugin = this;

    in your onEnable method, but I have that and the error still occurs. here is my main class and the class that is causing the problem


    main:
    Code:
    package me.BobTheFish.KOTH;
    
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MainKOTH extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public MainKOTH plugin;
        public ArenaManager am = new ArenaManager();
        public BlockManager bm = new BlockManager();
        public Game gm = new Game();
       
        @Override
        public void onEnable(){
            this.plugin = this;
            logger.info("");
            logger.info("[KotH] King of the Hill has been enabled!! :D");   
            logger.info("");
    
            getCommand("na").setExecutor(new CommandAddArena(this));
            getCommand("aas").setExecutor(new CommandAddArenaSpawn(this));
            getCommand("scp").setExecutor(new CommandSetCP(this));
        }

    StartTimer:
    Code:
    package me.FrostMew.OMS.Timers;
    
    import me.FrostMew.OMS.OMS;
    import me.FrostMew.OMS.Arena.ArenaManager;
    import me.FrostMew.OMS.Arena.Status;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    
    public class StartingTimer implements Runnable{
       
        OMS plugin;
        ArenaManager am;
        public int t;
        int timer;
    
        public StartingTimer(OMS plugin, ArenaManager am) {
            this.plugin = plugin;
            this.am = am;
        }
    
        public void init() {
            this.timer = this.am.getArena().getStartCounter();
            this.t = this.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, this, 20L, 20L);
        }
    
        public void run() {
            if ((this.timer != 0) && (this.am.getArena().getPlayers().size() >= this.am.getArena().getMinPlayers())) {
                this.timer -= 1;
                for(Player p : this.am.getArena().getPlayers()){
                    this.am.getArena().setXpTimer(p, this.timer);
                    p.playSound(p.getLocation(), Sound.CLICK, 10.0F, 10.0F);
                }
            } 
    let me know if you need other classes as well
     
  2. @bobthefish
    1) You're using Spigot
    2) What is OMS plugin? You should be using your main (KOTH) plugin instance since that is main.
     
    bobthefish likes this.
  3. Offline

    bobthefish

    1. sorry about spigot but bukkit forums are more populated then the spigot ones,
    and two i posted the wrong thing

    this is the correct class, i posted a different class that my friend was comparing mine to

    Code:
    package me.BobTheFish.KOTH;
    
    import org.bukkit.Bukkit;
    
    public class StartTimer implements Runnable{
    
        ArenaManager am;
        MainKOTH plugin;
        int timer;
        public int t;
    
        public StartTimer(MainKOTH plugin, ArenaManager am){
            this.plugin = plugin;
            this.am = am;
        }
        public void init(){
            this.timer = 30;
            this.t = Bukkit
                    .getServer()
                    .getScheduler()
                    .scheduleSyncRepeatingTask(
                            am.plugin
                            , this
                            , 20L
                            , 20L);
        }
    
        @Override
        public void run() {
            if (timer > 0) {
                Bukkit.broadcastMessage("" + timer);
                timer -= 1;
            }
            if (this.timer == 0) {
                this.plugin.getServer().getScheduler().cancelTask(this.t);
                plugin.gm.start(am.getCurrentArena());
                Bukkit.broadcastMessage("START");
            }
        }
    }
     
    Last edited by a moderator: Dec 26, 2014
  4. Offline

    DemKazoo

    This looks copied from DevRos's KOTH :confused:
     
  5. Offline

    bobthefish

    Trust me, its all mine, but if it is similar, is there a way for me to look at the source code to see how he fixed this issue?
     
  6. Offline

    DemKazoo

    Remove the line of code on line 9. Should be fixed then :)
     
  7. Offline

    XgXXSnipz

  8. Offline

    bobthefish

    Im sorry, which class are you talking about?

    what? this is not going to turn into a discussion about where I got the idea from, for the record the server that I work on had a poll and players requested a new gamemode, specifically KotH.
     
  9. Offline

    XgXXSnipz

  10. Offline

    bobthefish

    any helpful people taht can shed some light on my problem?
     
  11. Offline

    Skionz

    @bobthefish Post every relevant class in its entirety.
     
  12. Offline

    bobthefish

    Main:
    Code:
    package me.BobTheFish.KOTH;
    
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MainKOTH extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public MainKOTH plugin;
        public ArenaManager am = new ArenaManager();
        public BlockManager bm = new BlockManager();
        public Game gm = new Game();
       
        @Override
        public void onEnable(){
            this.plugin = this;
            logger.info("");
            logger.info("[KotH] King of the Hill has been enabled!! :D");   
            logger.info("");
    
            getCommand("na").setExecutor(new CommandAddArena(this));
            getCommand("aas").setExecutor(new CommandAddArenaSpawn(this));
            getCommand("scp").setExecutor(new CommandSetCP(this));
        }
        @Override
        public void onDisable(){
           
        }
        public void loadArenas(){
           
        }
    }
    StartTimer:
    Code:
    package me.BobTheFish.KOTH;
    
    import org.bukkit.Bukkit;
    
    public class StartTimer implements Runnable{
    
        ArenaManager am;
        MainKOTH plugin;
        int timer;
        public int t;
    
        public StartTimer(MainKOTH plugin, ArenaManager am){
            this.plugin = plugin;
            this.am = am;
        }
        public void init(){
            this.timer = 30;
            this.t = Bukkit
                    .getServer()
                    .getScheduler()
                    .scheduleSyncRepeatingTask(
                            am.plugin
                            , this
                            , 20L
                            , 20L);
        }
    
        @Override
        public void run() {
            if (timer > 0) {
                Bukkit.broadcastMessage("" + timer);
                timer -= 1;
            }
            if (this.timer == 0) {
                this.plugin.getServer().getScheduler().cancelTask(this.t);
                plugin.gm.start(am.getCurrentArena());
                Bukkit.broadcastMessage("START");
            }
        }
    }
    ArenaManager:
    Code:
    package me.BobTheFish.KOTH;
    
    import java.util.ArrayList;
    
    import net.md_5.bungee.api.ChatColor;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    
    public class ArenaManager {
    
        private ArrayList<Arena> arenas = new ArrayList<Arena>();
        MainKOTH plugin;
        private Arena currentArena;
    
        public void addArena(Arena arena) {
            arenas.add(arena);
            Bukkit.broadcastMessage(arenas.toString());
        }
    
        public void removeArena(Arena arena) {
            arenas.remove(arena);
        }
       
        public Arena getArenaByPlayer(Player p){
            for(Arena a : arenas){
                if(a.getPlayers().contains(p)){
                    return a;
                }
                else{
                    return null;
                }
            }
            return null;       
        }
        public Arena getArenaByName(String name){
            for(Arena a : arenas){
                if(a.getName().equalsIgnoreCase(name)){
                    return a;
                }
                else{
                    return null;
                }
            }
            return null;       
        }
        public boolean ArenaExists(String name){
            if(arenas.contains(name)){
                return true;
            }
            else{
                return false;
            }
        }
        public ArrayList<Arena> getArenas(){
            return arenas;
           
        }
        public void join(Player p, Arena a){
            if(a.getPlayers().size() <16){
                a.addPlayer(p);
    //            Location arenaSpawn = new Location(Bukkit.getWorld(plugin.getConfig().getString("Arenas.world")),
    //                    plugin.getConfig().getDouble("Arenas.x"),
    //                    plugin.getConfig().getDouble("Arenas.y"),
    //                    plugin.getConfig().getDouble("Arenas.z"),
    //                    (float) plugin.getConfig().getDouble("Arenas.yaw"),
    //                    (float) plugin.getConfig().getDouble("Arenas.pitch"));
    //            p.teleport(arenaSpawn);
                p.sendMessage(ChatColor.BLUE + "You joined the arena!");
                Bukkit.broadcastMessage(a.getPlayers().size() + "");
            }
            else{
                p.sendMessage(ChatColor.RED + "That arena is full!");
            }
            if(a.getPlayers().size() == 1){
                StartTimer stt = new StartTimer(this.plugin, this);
                stt.init();
                Bukkit.broadcastMessage("Starting arena " + getCurrentArena().getName());
            }
        }
        public Arena getCurrentArena() {
            return currentArena;
        }
        public void setCurrentArena(Arena ca) {
            this.currentArena = ca;
        }
    }
    
    command class: (this is only for testing the timer, not the final version of this command)

    Code:
    package me.BobTheFish.KOTH;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    
    public class CommandSetCP implements CommandExecutor{
    
        MainKOTH plugin;
        public CommandSetCP(MainKOTH instance)
        {
            this.plugin = instance;
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
                String[] args) {
            if(cmd.getName().equalsIgnoreCase("scp")){
                plugin.am.join((Player) sender, plugin.am.getArenaByName(args[0]));
                if(sender instanceof Player){
                    Player p = (Player) sender;
                    if(p.hasPermission("koth.setcapturepoint")){
                        if(args.length == 0){
                            p.sendMessage(ChatColor.RED + "Not enough arguments! use " + ChatColor.GOLD + "/scp <Arena Name>");
                        }
                        else{
                            if(!plugin.am.getArenaByName(args[0]).hasCP()){
                                plugin.am.getArenaByName(args[0]).setCP(new ControlPoint(args[0]));
                                plugin.bm.createCP(p.getLocation());
                                plugin.getConfig().set("CPs." + args[0] + ".x", p.getLocation().getBlockX());
                                plugin.getConfig().set("CPs." + args[0] + ".y", p.getLocation().getBlockY()-1);
                                plugin.getConfig().set("CPs." + args[0] + ".z", p.getLocation().getBlockZ());
                               
                            }
                            else{
                                p.sendMessage(ChatColor.RED + "This arena already has a control point!");
                            }
                        }
                    }
                    else{
                        p.sendMessage(ChatColor.RED + "You do not have permission to add an arena!");
                    }
                }
                else{
                    sender.sendMessage(ChatColor.RED + "You must be a player to add an arena!");
                }
            }
            return false;
        }
    }
    
    Nevermind i figured it out, my arenamanager was missing a value for plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  13. Offline

    mythbusterma

    @bobthefish

    It's quite simple, you need to learn Java naming conventions and learn what an accessor method is, then my eyes may stop bleeding.
     
  14. Offline

    DemKazoo

    Okay, lets start:

    1. Why are you using the Bungee ChatColor API? You'll need to have the exact tsame thing you are using as that API, installed as a plugin..

    2. You are duplicating variables

    3. Plsss remove this.plugin = this;
    And use (Plugin).code

    Coder pls
     
  15. Moved to Bukkit Alternates.
     
Thread Status:
Not open for further replies.

Share This Page