Plugin Help

Discussion in 'Plugin Development' started by PieMan456, Oct 22, 2013.

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

    PieMan456

    Hello,
    I am trying to figure out how to add spaces in between commands for my plugin. I have tried but I just cannot find why.
    Here is my main

    package me.pieman.drinks;


    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Drinks extends JavaPlugin{

    @Override
    public void onEnable(){
    getLogger().info("Drinks has been ENABLED!");
    }

    @Override
    public void onDisable(){
    getLogger().info("Drinks has been DISABLED");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    if(commandLabel.equalsIgnoreCase("coke")){
    Player player = (Player) sender;
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1200, 2));
    player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1200, 2));
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 600, 2));
    }else if(commandLabel.equalsIgnoreCase("sprite")){
    Player player = (Player) sender;
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1200, 2));
    player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 1200, 2));
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1200, 2));
    }else if(commandLabel.equalsIgnoreCase("coorslite")){
    Player player = (Player) sender;
    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 1));
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1200, 2));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 1200, 1));
    }else if(commandLabel.equalsIgnoreCase("yuengling")){
    Player player = (Player) sender;
    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 1));
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
    player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 200, 1));
    }
    return false;
    }
    }
    Here is my plugin.yml
    name: Drinks
    main: me.pieman.drinks.Drinks
    version: 1.0
    Description: A plugin that allows you to drink all of your favorite beverages.
    commands:
    drink coke:
    description: Drink a bottle of coke
    default: true
    permission: drink.coke
    permission-message: You don't have permission!
    drink sprite:
    description: Drink a bottle of sprite
    default: true
    permission: drink.sprite
    permission-message: You don't have permission!
    drink coorslite:
    description: Drink a bottle of coors lite
    default: true
    permission: drink.coorslite
    permission-message: You don't have permission!
    drink yuengling:
    description: Drink a bottle of yuengling
    default: true
    permission: drink.yuengling
    permission-message: You don't have permission!
    If you know what is wrong please help me
     
  2. Offline

    thegarfish

    Are you attempting to do something like.. /drink coke? Right now the command is /coke
     
  3. Offline

    PieMan456

    yes that is what I am trying to do
     
  4. Offline

    thegarfish

    Then you are going to need to use arguments for your command code.
     
  5. Offline

    PieMan456

    How do I do that Could you give me an example?
     
  6. Offline

    thegarfish

    Here is something that I used in one of my other plugins.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label,
    2. String[] args) {
    3. if (sender instanceof Player) {
    4. Player player = (Player) sender;
    5. if (cmd.getName().equalsIgnoreCase("join")) {
    6. if (args.length == 1) {
    7. if (args[0].equalsIgnoreCase("red")) {
    8. redteam.add(player.getName());
    9. blueteam.remove(player.getName());
    10. sender.sendMessage(ChatColor.AQUA + "[Siege] "
    11. + ChatColor.RED
    12. + "You have joined the Red team!");
    13. } else {
    14. if (args[0].equalsIgnoreCase("blue")) {
    15. blueteam.add(player.getName());
    16. redteam.remove(player.getName());
    17. sender.sendMessage(ChatColor.AQUA + "[Siege] "
    18. + ChatColor.RED
    19. + "You have joined the Blue team!");
    20. }
    21. if (args[0].equalsIgnoreCase("game")) {
    22. crossServer(player);
    23. }
    24. }
    25. } else {
    26. sender.sendMessage(ChatColor.AQUA + "[Siege] "
    27. + ChatColor.RED + "Usage: /join red; /join blue");
    28. }
    29. }
    30. }
    31. return false;
    32.  
    33. }
     
  7. Offline

    PieMan456

    so I would put if(args[0].equalsIgnoreCase("coke") ?
     
  8. Offline

    xTrollxDudex

    I'm getting a headache reading that, please put in syntax or code tags next time
     
Thread Status:
Not open for further replies.

Share This Page