Need some quick help..

Discussion in 'Plugin Development' started by ColaCraft, Jun 2, 2013.

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

    ColaCraft

    Looking over my code, I see no reason why this shouldn't work.

    I am just running a quick test before I write the full plugin.

    Here is my code:
    PHP:
    package me.PorterK.RAF;
     
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    RAF extends JavaPlugin{
     
        public 
    void onEnable(){
         
        }
        public 
    void onDisable(){
         
        }
        public 
    boolean onCommandPlayer senderCommand cmdString labelString[] args ){
     
        if(
    cmd.getName().equalsIgnoreCase("flag")){
            
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "msg porterk derp");
        }
        return 
    false;
    }
    }
    Please tell me what is wrong so I can continue. I am probably going to facepalm quite hard after this, but oh well.


    EDIT: Completely forgot the problem..

    I type /flag & nothing happens. At all.
     
  2. Offline

    Wolfy9247

    Code:java
    1.  
    2. package me.PorterK.RAF;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. import java.util.logging.Logger;
    14.  
    15. public class RAF extends JavaPlugin {
    16.  
    17. private final Logger log = Logger.getLogger("Minecraft");
    18. private final String logTag = "[RAF] " + ChatColor.RESET;
    19.  
    20. private final FileConfiguration config;
    21. private final PluginDescriptionFile pdfFile;
    22.  
    23. @Override
    24. public void onEnable(){
    25. this.pdfFile = this.getDescription();
    26. this.config = this.getConfiguration();
    27. log.info(pLogTag + pdfFile.getName() + " v" + pdfFile.getVersion() + " enabled!");
    28. }
    29.  
    30. @Override
    31. public void onDisable(){
    32. log.info(pLogTag + pdfFile.getName() + " v" + pdfFile.getVersion() + " disabled!");
    33. }
    34. public boolean onCommand(Player sender, Command cmd, String label, String[] args ) {
    35. if(cmd.getName().equalsIgnoreCase("flag")) {
    36. Bukkit.getPlayer("porterk").sendMessage(logTag + "Derp!");
    37. sender.sendMessage(logTag + "Derp!"); // This is what you were trying to do, I assume.
    38. return true;
    39. }
    40. return false;
    41. }
    42. }
    43.  

    Also make sure you have properly included the plugin.yml file in your plugin in order for it to run properly. If you have not registered the command "flag" in the plugin.yml, it will not do anything.
     
  3. Offline

    ColaCraft



    I was accessing the console to run a command (they will be worldguard commands later) & I just happened to choose the "msg porterk derp" command. >,<
     
  4. Offline

    Wolfy9247

    Ah alright, that's understandable. You can change that part to be the same, but I still recommend having the logging and configuration variables setup as well as registering your command in your plugin.yml properly if you haven't done so.
     
  5. Offline

    ColaCraft


    I am going to go ahead & try that, I'll poke you if he result is the same.


    Okay, the updated code is still not working.

    PHP:
    package me.PorterK.RAF;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import java.util.logging.Logger;
     
    public class 
    RAF extends JavaPlugin {
     
    private final 
    Logger log Logger.getLogger("Minecraft");
    private final 
    String logTag "[RAF] " ChatColor.RESET;
     
    private 
    FileConfiguration config;
    private 
    PluginDescriptionFile pdfFile;
     
    @
    Override
    public void onEnable(){
    this.pdfFile this.getDescription();
    this.config this.getConfig();
    log.infologTag pdfFile.getName() + " v" pdfFile.getVersion() + " enabled!");
    }
     
    @
    Override
    public void onDisable(){
    log.infologTag pdfFile.getName() + " v" pdfFile.getVersion() + " disabled!");
    }
    public 
    boolean onCommand(Player senderCommand cmdString labelString[] args ) {
    if(
    cmd.getName().equalsIgnoreCase("flag")) {
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "msg porterk derp");
    sender.sendMessage(logTag "Derp!");
    return 
    true;
    }
    return 
    false;
    }
    }
    It doesn't do anything when I type /flag

    Here is the plugin.yml...

    HTML:
    name: RAF
    main: me.PorterK.RAF.RAF
    version: 1.0
    commands:
        flag:
            description: Adds all the flags to a region
            usage: /flag <region>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page