Simple Plugin Help Please

Discussion in 'Plugin Development' started by SwiftyMove, May 3, 2014.

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

    SwiftyMove

    Hi I am posting for help about a simple kit plugin I am trying to make (I'm kinda new to this) when I enter /kits it tells me the kits but it also gives me the 2 kits I have made so far. All I want it to do is name the kits so then i could do /kit starter and it would give me kit starter alone please help! Heres the code!

    http://pastebin.com/SGScHCtm
     
  2. Offline

    tommycake50

    Well you just do
    commandlabel.equalsIgnoreCase("kit")
    then check the number of args and if it is bigger than 0 then check what it is and give them the items.
    The commandLabel is the command without the args.
     
  3. Offline

    SwiftyMove

    Thank you but can you give me an example has i have not yet worked with many arguments and am still trying to learning! Thanks in advance!
     
  4. Offline

    ZodiacTheories

    SwiftyMove

    EDIT: WELCOME TO BUKKIT!

    Code:java
    1. //instead of if(commandlabel
    2. if(cmd.getName().equalsIgnoreCase("kit")) {
    3. if(args.length == 1) { //Check the length of arguments - /kit is argument 0 and starter is argument 1
    4. if(args[0].equalsIgnoreCase("starter")) {
    5. // Do code
    6.  
    7. //Im checking for the args[0] instead of args[1] because that is how Java works, the Bukkit API makes it easier for us because we can do if(args.length == 1) although in java, the 1 would be replaced with 0
     
  5. Offline

    SwiftyMove

    I knew something would happen so i made a test project and implemented what you said to do but i probably arranged it wrong sorry to trouble you so much but can you please help again its saying i have an internal error and neither of the commands are working? Thanks in advance! and also if you could how would i extend this for multiple commands like kit god or something?

    http://pastebin.com/iqxaCWFC
     
  6. Offline

    ZodiacTheories

    SwiftyMove

    Code:java
    1. package me.swiftymove.fun;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Fun extends JavaPlugin{
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. public static Fun plugin;
    16.  
    17. @Override
    18. public void onEnable(){
    19. this.logger.info("Enabled");
    20.  
    21. }
    22.  
    23. @Override
    24. public void onDisable(){
    25. this.logger.info("Disabled");
    26.  
    27. }
    28.  
    29. public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args){
    30. Player player = (Player) sender;
    31. if(cmd.getName().equalsIgnoreCase("kit"));{
    32. player.sendMessage("works");
    33. if(args.length == 1) {
    34. if(args[0].equalsIgnoreCase("starter")){
    35. ItemStack sp = new ItemStack(Material.STONE_PICKAXE, 1);
    36. player.getInventory().addItem(sp);
    37. return true;
    38. }
    39. return true;
    40. }
    41. }
    42. }


    Might be missing a brace. Using my phone so can't tell - this should work. Also you said if(args.length == 1);
    Do not make it a statement. Think of it as real English, would you ask someone, if I buy this. It doesn't make sense.
     
  7. Offline

    SwiftyMove

    Thank you so much i will now have to try and extend this to several commands but also when i type /starter it also comes up with the message sent when i type /kit this might be because it has return set to true but i will look into it thanks again!
     
Thread Status:
Not open for further replies.

Share This Page