Plugin bug or wtf ?

Discussion in 'Plugin Development' started by Ardhakian, May 30, 2014.

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

    Ardhakian

    Hello guys , my english is bad but Google traduction is my friends :)

    Here is the problem with this line of code that should work :
    ---------------------------------------------------------------------

    package fr.Ardhakian.plug1;

    import java.util.logging.Logger;

    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {

    public Logger Log = Logger.getLogger("Minecraft");

    public void onEnable() {
    }

    public void onDisable() {
    }

    public boolean oncommand(CommandSender sender, Command cmd, String label,
    String args[]) {
    Player player = (Player) sender;

    if (sender instanceof Player) {

    } else if (label.equalsIgnoreCase("Creep")) {

    Location lp = player.getLocation();
    Location location = new Location(lp.getWorld(), lp.getX() + 5,
    lp.getY(), lp.getZ());

    player.getWorld().createExplosion(location, 4);

    return false;
    }
    return false;
    }
    }
    -------------------------------------------------------------------------
    My plugin.yml :
    ---------------------------------------
    main: fr.Ardhakian.plug1.Main
    name: Plug1
    version: 1.0
    description: Tuto
    commands:
    Creep:
    description: 'boom'
    usage: '/Creep [subcommand etc]'
    ----------------------------------------
    The result of plugin should be use commands ( /Creep ) a create explosion .
    thank you here to help me .
    Ardhakian .
     
  2. Offline

    iTornado1234

    Register the command on the onEnable.
     
  3. Offline

    amhokies

    You shouldn't have to, as far as I know.
     
  4. Offline

    fireblast709

    iTornado1234 default executor is the main class, thus not needed.
    Ardhakian make sure you have all the casing correct. Namely, oncommand != onCommand ;). Also, use the Logger object you can find in JavaPlugin (just call 'getLogger()' in your main class to get it) instead of Logger.getLogger("Minecraft").
    Code:java
    1. public void onEnable()
    2. {
    3. this.log = this.getLogger();
    4. }


    Lastly, don't just assume that the CommandSender is a Player (it could be the console, or a command block.
    Code:java
    1. if(sender instanceof Player)
    2. {
    3. Player player = (Player) sender;
    4. if(label.equalsIgnoreCase("Creep"))
    5. {
    6. // Other code
    7. }
    8. }
     
  5. Offline

    iTornado1234

  6. Offline

    Ardhakian

    Thank you it works! Your support helped me a lot .
     
Thread Status:
Not open for further replies.

Share This Page