Need Help!

Discussion in 'Plugin Development' started by bartboy8, May 7, 2012.

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

    bartboy8

    This plugin I am making has 1 arg. I am not sure how to do this though. I want the first cmd to be whatever I choose. ATM it is stick. And the second command to be them item of the persons choosing here is what I have come up with so far. Please Help!
    Code:
    package da.head.change;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class DifferentArmor extends JavaPlugin{
        public Logger logger = Logger.getLogger("Minecraft");
        public static DifferentArmor 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("stick")){
            if(args.length == 0){
                player.sendMessage(ChatColor.DARK_RED + "TOO LITTLE ARGUMENTS!");
            }else if(args[1].equalsIgnoreCase("bedrock")) {
                ItemStack stick = new ItemStack(Material.STICK, 1);
                ItemStack bedrock = new ItemStack(Material.BEDROCK, 1);
                PlayerInventory pi = player.getInventory();
                pi.addItem(stick);
                pi.setHelmet(bedrock);
            }
    }
        return false;
    }
    }
    Anyone?

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

    colony88

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. Player player = (Player)sender;
    3. if(commandLabel.equalsIgnoreCase("stick")){
    4. if(args.length < 1) return false;
    5. if(args.length > 2) return false;
    6. if(args[0].equalsIgnoreCase("bedrock")){
    7. player.getInventory().addItem(new ItemStack(Material.STICK, 1));
    8. player.getInventory().addItem(new ItemStack(Material.BEDROCK, 1));
    9. }
    10. }
    11. return true;
    12. }
     
    bartboy8 likes this.
  3. Offline

    bartboy8

    Thank you sooo much!
     
  4. Offline

    colony88

    Another way to do it would be:
    Code:java
    1. if(commandLabel.equalsIgnoreCase("stick")){
    2. if(args.length == 1){
    3. if(args[0].equalsIgnoreCase("bedrock")){
    4.  
    5. }
    6. }
    7. else{
    8. return false;
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page