Solved Error in my onEnable()

Discussion in 'Plugin Development' started by GeppiOMG, Nov 1, 2015.

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

    GeppiOMG

    Hello, everyone who is reading this. I am having a error with my onEnable according to the console.

    Console: http://prntscr.com/8xp7xx

    I am not quite sure why I am getting a error, maybe its because I have multiple classes. I dunno. However, I do know that I have got this to work, on my old Prison Project. its just this one is giving me errors. I have looked on what I did on the Main class. and it looks exactly the same, and my old Prison Project worked 100% fine.

    My onEnable():


    Code:
     public void onEnable() {
            plugin = this;
            getCommand("suicide").setExecutor(new CommandSuicide());
            getCommand("ranks").setExecutor(new CommandRanks());
            //PRIVATE MESSAGE
            getCommand("msg").setExecutor(new CommandPrivateMSG());
            getCommand("pm").setExecutor(new CommandPrivateMSG());
            getCommand("tell").setExecutor(new CommandPrivateMSG());
            //
        }
    Please help as soon as possible.
    Thanks ~Geppi
     
  2. Offline

    Halmerson

  3. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @GeppiOMG Why 3 instances of the same class? Why not use an alias on the command instead? Or make 1 instance and set it for all 3 commands?
     
  4. Offline

    MasterDoctor

    Could you edit your post or reply and include or indicate line 26?
     
  5. Offline

    GeppiOMG

    My main class:


    Code:
    package com.geppiomg.alcatraz;
    
    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.geppiomg.playercmd.CommandPrivateMSG;
    import com.geppiomg.playercmd.CommandRanks;
    import com.geppiomg.playercmd.CommandSuicide;
    
    
    
    public class Main extends JavaPlugin{
      
       
        private static Plugin plugin;
      
        public void onEnable() {
            plugin = this;
            getCommand("suicide").setExecutor(new CommandSuicide());
            getCommand("ranks").setExecutor(new CommandRanks());
            //PRIVATE MESSAGE
            getCommand("msg").setExecutor(new CommandPrivateMSG());
            getCommand("pm").setExecutor(new CommandPrivateMSG());
            getCommand("tell").setExecutor(new CommandPrivateMSG());
            //
        }
      
        public void onDisable() {
            plugin = null;
    }   
           
       
    
      
      
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners) {
                Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
        }
      
        public static Plugin getPlugin() {
            return plugin;
        }
     
      
      
      
    }
    I dont use a Alias because I want it if you do "/pm" it would say "pm <user>" and for "/msg" it would say "/msg <User>
     
  6. Offline

    Halmerson

    @GeppiOMG
    Can we see your PrivateMSG class please as well?
     
  7. @GeppiOMG
    From what I can see - the server is attempting to reload when it's registering the /tell command. As @Halmerson said, can we see your PrivateMSG class?
     
  8. Offline

    GeppiOMG

    @_zircon_ @Halmerson


    Code:
    package com.geppiomg.playercmd;
    
    import org.bukkit.Bukkit;
    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 CommandPrivateMSG implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(cmd.getName().equalsIgnoreCase("msg")) {
         Player player = (Player) sender;
         if(args.length < 2) {
                player.sendMessage("/msg <player> <message>");
                return true;
         }
         @SuppressWarnings("deprecation")
        Player target = Bukkit.getServer().getPlayer(args[0]);
         String message = "";
         for (int i = 1; i < args.length; i++) message += (i > 1 ? " " : "") + args[i];
        
         player.sendMessage(ChatColor.GRAY + "[Me -> " + target.getName() + "] " + message);
    
         target.sendMessage(ChatColor.GRAY + "[" + player.getName() + " - > Me] " + message);
        
        
         return true;
    }
    if(cmd.getName().equalsIgnoreCase("pm")) {
         Player player = (Player) sender;
         if(args.length < 2) {
                player.sendMessage("/pm <player> <message>");
                return true;
         }
         @SuppressWarnings("deprecation")
        Player target = Bukkit.getServer().getPlayer(args[0]);
         String message = "";
         for (int i = 1; i < args.length; i++) message += (i > 1 ? " " : "") + args[i];
        
         player.sendMessage(ChatColor.GRAY + "[Me -> " + target.getName() + "] " + message);
    
         target.sendMessage(ChatColor.GRAY + "[" + player.getName() + " - > Me] " + message);
        
        
         return true;
    }
    if(cmd.getName().equalsIgnoreCase("tell")) {
         Player player = (Player) sender;
         if(args.length < 2) {
                player.sendMessage("/tell <player> <message>");
                return true;
         }
         @SuppressWarnings("deprecation")
        Player target = Bukkit.getServer().getPlayer(args[0]);
         String message = "";
         for (int i = 1; i < args.length; i++) message += (i > 1 ? " " : "") + args[i];
        
         player.sendMessage(ChatColor.GRAY + "[Me -> " + target.getName() + "] " + message);
    
         target.sendMessage(ChatColor.GRAY + "[" + player.getName() + " - > Me] " + message);
        
        
         return true;
    }
    return true;
        
        }
        }
    
    
           
           
           
           
           
           
           
           
           
        
     
  9. Offline

    Zombie_Striker

    Learn to read your own error report: Line 26 of class "main"(god, why do people love to use "main" as a class name)
    This is the problem. It has to do with the tell command (most likely because there already is a command WITH THE EXACT SAME NAME)

    All you have to do is change the name to something el;se to fix it. But let me jump in so you don't have to make another thread about a different problem that could have been avoided.

    Blind casting is NEVER good. Check before you cast.
    You never check if the target is null. What if arg[0] is not the name of a player? Then target would be null and tehre would be errors everywhere.
    "JUST RETURN TRUE! WHAT DO YOU MEAN I CAN RETURN FALSE?" - You, probably.
     
  10. Offline

    Scimiguy

    @Zombie_Striker
    Pfff.. only noobs return false when their code fails or isn't true.

    Oh wait...
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page