Solved Help with a Mumble Plugin

Discussion in 'Plugin Development' started by Clarkcj, Mar 5, 2015.

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

    Clarkcj

    Hello guys this is one of my first plugins, It is a mumble plugin. Basically there are two commands, when you type /mumble it will give you the location of where to download the mumble from. And another command that will basically be /mumbleinfo that will be The Mumble Server Information. But when I do that command nothing happens ingame not even an error message in console. Here is the class code:

    Code:
    package me.Clarkcj.mumble;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Mumble extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Mumble plugin;
      
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
      
        }
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + "Has Been Enabled!");
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if (commandLabel.equalsIgnoreCase("mumble")){
                player.sendMessage(ChatColor.GOLD + "You can get mumble at http://mumble.sourceforge.net/!");
              
               if (commandLabel.equalsIgnoreCase("mumbleinfo")){
                  player.sendMessage(ChatColor.GOLD + "The mumble's info is test.mumble.com");
               }
            }
            return false;
        }
    }
    Also can someone give me advice how to add a config file, to the plugin so it takes in account what the serverip for mumble is. Thank you.
     
  2. Offline

    CraftCreeper6

    @Clarkcj
    Have you added the commands to the plugin.yml?

    EDIT: Also, you need @Override. Furthermore, check before casting, casting CommandSender to Player will give you a stacktrace. Be careful.
     
  3. Offline

    hopstar

    Did you add it in your plugin.yml?
     
  4. Offline

    Clarkcj

    Yes, I added it to my plugin.yml here is the plugin.yml. @CraftCreeper6 where would I add the @Override to?

    Code:
    name: Mumble
    main: me.Clarkcj.mumble.Mumble
    version: 1.0
    author: Clarkcj
    description: >
                 Mumble Plugin.
    commands:
      mumble:
        description: Sends mumble information
      mumbleinfo:
        description: Sends user mumble info
     
  5. Offline

    MordorKing78

    I'm not sure if this is what you want,

    Code:
    if (commandLabel.equalsIgnoreCase("mumble")){
                player.sendMessage(ChatColor.GOLD + "You can get mumble at http://mumble.sourceforge.net/!");
            
               if (commandLabel.equalsIgnoreCase("mumbleinfo")){
                  player.sendMessage(ChatColor.GOLD + "The mumble's info is test.mumble.com");
               }
            }
    I think you ment this,

    Code:
        if (commandLabel.equalsIgnoreCase("mumble")){ //if the command mumble is executed
            player.sendMessage(ChatColor.GOLD + "You can get mumble at http://mumble.sourceforge.net/!"); //send message
        }else if (commandLabel.equalsIgnoreCase("mumbleinfo")){ //if mumble isn't executed and mumbleinfo is
            player.sendMessage(ChatColor.GOLD + "The mumble's info is test.mumble.com"); //send message
        }
     
  6. @Clarkcj If you haven't already, please at least learn the basics of Java. If you don't know at least the basics, nothing is going to make sense to you when you're coding. The Bukkit API is written in Java, so if you want to learn Bukkit, learn Java first. I guarentee you that if you do, coding, debugging, and Bukkit itself will make so much more sense. :)
     
  7. Offline

    Clarkcj

    @CodePlaysMinecraft@MordorKing78 I have learned some of the basic's of Java, its just I am a little rusty. As well I got it working, and got the configuration working new code is.

    Code:
    package me.Clarkcj.mumble;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Mumble extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Mumble plugin;
    
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    
        }
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + "Has Been Enabled!");
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if (commandLabel.equalsIgnoreCase("mumble")){
                player.sendMessage(ChatColor.GOLD + "You can get mumble at http://mumble.sourceforge.net/!"); //send command
            }else if (commandLabel.equalsIgnoreCase("mumbleinfo")){
                player.sendMessage(ChatColor.GOLD + "The mumble's info is " + getConfig().getString("Server"));
                player.sendMessage(ChatColor.GOLD + "The Port: " + getConfig().getString("Port"));
                }
            return false;
        }
    }
    Feel free to use the code in any of your plugins.
     
  8. Offline

    teej107

  9. Offline

    pie_flavor

    @Clarkcj I feel like I'm fighting a losing battle here, but here goes...
    Never use commandLabel! Use cmd.getName()! commandLabel can be anything really, it's the alias that the user actually types. If someone registers any aliases at all your plugin will break. But cmd.getName() always returns what you're looking for.
    Other things:
    Logger.getLogger("Minecraft") doesn't work. There is a method you can call called getLogger().
    You don't need plugin description files or loggers! bukkit automatically logs both when the plugin is loaded and when it is enabled, as well as when it is disabled.
    Instead of all the config stuff you wrote in onEnable, just do saveDefaultConfig(). It saves the default if there isn't a config and does nothing if one exists.
     
Thread Status:
Not open for further replies.

Share This Page