Warning: Complete Noob who fails at reading sometimes.

Discussion in 'Plugin Development' started by Sayshal, Mar 19, 2012.

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

    Sayshal

    Quick question, I'm trying to edit a plugin, I've managed to decompile it properly and have it loaded in NetBeans. Now, I'm trying to send a line to the console (server.log) when the command is ran. I have no idea how to. (I have 2 months java experience, 0 minutes bukkit programming experience.)
     
  2. Offline

    Sabersamus

    Code:java
    1. Logger log = Logger.getLogger("Minecraft");
    2. this.log.info("Look at me :3 im sending stuff to the console");
    3.  
     
  3. Offline

    Sayshal

    Alright that actually makes some sense.
    Now, if I want to send to the console:

    "PLAYER ran the command: COMMAND"

    How would I go about that?
     
  4. Offline

    SgtStud

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (sender instanceof Player == false) {
    return false;
    }
    Player player = (Player) sender;
     
    log.info(player.getDisplayName() + " ran the command " + cmd.getName());
    return true;
    }
     
  5. Offline

    Sabersamus

    Code:java
    1.  
    2. public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args){
    3.  
    4. if(cmd.getName().equalsIgnoreCase("somecommand")){
    5.  
    6. if(cs instanceof Player){
    7.  
    8. Player player = (Player)cs;
    9.  
    10. //do stuff
    11.  
    12. this.log.info(player.getName() + " has used the command " + cmd.getName());
    13.  
    14. return true;
    15.  
    16. }
    17.  
    18. }
    19.  
    20. return false;
    21.  
    22. }
     
  6. Offline

    Sayshal

    Should that be in the main class? (this isn't my plugin im just editing it for personal use)
     
  7. Offline

    SgtStud

    Yes, it should be in the main class in your onEnable() method
     
  8. Offline

    Sabersamus

    this should be where ever you made the command, (better to use a CommandExecutor class)

    (a class that implements CommandExecutor, and then register the command in the main class)
     
  9. Offline

    Sayshal

    That works except for
    Code:
    this.log.info(player.getName() + " has used the command " + cmd.getName());
    It's giving me an error on "this.log" saying: cannot find symbol
     
  10. Offline

    Sabersamus

    symbol what?

    EDIT: sorry just do log.info
     
  11. Offline

    Sayshal

    Code:
    /*    */ package spoof;
    /*    */
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    /*    */
    /*    */ public class Spoof extends JavaPlugin
    /*    */ {
    /*    */@Override
      public void onDisable()
    /*    */  {
    /*    */  }
    /*    */
    /*    */@Override
      public void onEnable()
    /*    */  {
            public boolean onCommand1(CommandSender cs, Command cmd, String label, String[] args){
       
        if(cmd.getName().equalsIgnoreCase("somecommand")){
       
        if(cs instanceof Player){
       
        Player player = (Player)cs;
       
        //do stuff
       
        this.log.info(player.getName() + " has used the command " + cmd.getName());
       
        return true;
       
        }
       
        }
       
        return false;
       
        }
    /*    */  }
    /*    */
    /*    */@Override
      public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    /*    */  {
    /* 19 */    if (label.equalsIgnoreCase("spoof")) return Commands.Spoof(sender, args, Boolean.valueOf(false)).booleanValue();
    /* 20 */    if (label.equalsIgnoreCase("sudo")) return Commands.Spoof(sender, args, Boolean.valueOf(true)).booleanValue();
    /*    */
    /* 22 */    return false;
    /*    */  }
       
     
    /*    */ }
     
    /* Location:          C:\Users\Sayshal\Downloads\Spoof-SNAPSHOT.jar
    * Qualified Name:    org.blockface.spoof.Spoof
    * JD-Core Version:    0.6.0
    */
    That's the main class... Sorry for the noobyness but it's throwing errors everywhere. :S

    This is my new main class (@SgtStud)
    Code:
    /*    */ package spoof;
    /*    */
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    /*    */
    /*    */ public class Spoof extends JavaPlugin
    /*    */ {
    /*    */@Override
      public void onDisable()
    /*    */  {
    /*    */  }
    /*    */
    /*    */@Override
      public void onEnable()
    /*    */  {
    /*    */  }
    /*    */
    /*    */@Override
      public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    /*    */  {
    /* 19 */    if (label.equalsIgnoreCase("spoof")) return Commands.Spoof(sender, args, Boolean.valueOf(false)).booleanValue();
    /* 20 */    if (label.equalsIgnoreCase("sudo")) return Commands.Spoof(sender, args, Boolean.valueOf(true)).booleanValue();
    /*    */
    /* 22 */    return false;
    /*    */  }
       
        public boolean onCommand1(CommandSender cs, Command cmd, String label, String[] args){
       
        if(cmd.getName().equalsIgnoreCase("somecommand")){
       
        if(cs instanceof Player){
       
        Player player = (Player)cs;
       
        //do stuff
       
        log.info(player.getName() + " has used the command " + cmd.getName());
       
        return true;
       
        }
       
        }
       
        return false;
       
        }
    /*    */ }
     
    /* Location:          C:\Users\Sayshal\Downloads\Spoof-SNAPSHOT.jar
    * Qualified Name:    org.blockface.spoof.Spoof
    * JD-Core Version:    0.6.0
    */
    Error is happening here:
    log.info(player.getName() + " has used the command " + cmd.getName());

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  12. Offline

    Sabersamus

    you havent made a variable log anywhere,

    above log.info();
    put Logger log = Logger.getLogger("Minecraft");
     
  13. Offline

    Sayshal

    So I've never actually compiled a jar... Could someone help me :S here are the four files, they are in a project but for whatever reason it never seems to work.

    Spoof.java (main class):
    http://pastie.org/3632087
    Commands.java:
    http://pastie.org/3632089
    Chatty.java:
    http://pastie.org/3632091
    plugin.yml:
    http://pastie.org/3632093

    I added what line I think is mucked up in plugin.yml.

    Error:
    Code:
    2012-03-19 20:08:04 [SEVERE] Could not load 'plugins\Spoof.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:193)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:132)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:56)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)
    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml
        ... 8 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  14. Offline

    rylinaux

    The main in your plugin.yml should look like this ---> main: org.sayshal.spoof.Spoof

    The "org.sayshal.spoof" is your package name, and the "Spoof" on the end is the name of your plugin, which happens to be the name of your main class too.
     
  15. Offline

    Sayshal

    Thankyou. Now, for the actual thing I wanted added, I'm getting this:
    2012-03-19 20:20:37 [INFO] [Sayshal] this is a test
    2012-03-19 20:20:37 [INFO] [Server] this is a test
    When I type ingame /sudo Sayshal /say this is a test

    I want it to show:
    [Spoof] Sayshal sent /sudo Sayshal /say this is a test

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
Thread Status:
Not open for further replies.

Share This Page