No commands working

Discussion in 'Plugin Development' started by CraftCreeper6, Apr 7, 2014.

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

    CraftCreeper6

    Hello, I am currently working on a Prison plugin, but no commands work;
    Upgrade package:
    Register
    Code:java
    1. package me.CraftCreeper6.Upgrade;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class Regiter extends JavaPlugin{
    6.  
    7. public void onEnable(){
    8. System.out.print("Succesfully enabled!");
    9.  
    10.  
    11. getServer().getPluginManager().registerEvents(new me.CraftCreeper6.Prison.Ranks(), this);
    12. }
    13.  
    14. public void onDisable(){
    15. System.out.print("Succesfully disabled!");
    16. }
    17.  
    18. }
    19.  

    Yes I spelled Register wrong.... :p

    Checker:
    Code:java
    1. package me.CraftCreeper6.Upgrade;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.enchantments.Enchantment;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Checker extends JavaPlugin {
    11.  
    12. public boolean onCommand(CommandSender sender, Command cmd,
    13. String commandLabel, String[] args) {
    14. Player p = (Player) sender;
    15. if (commandLabel.equalsIgnoreCase("AUT")
    16. && args[0].equalsIgnoreCase("sword")
    17. && p.getInventory().getItemInHand().equals(Material.DIAMOND_SWORD)
    18. && p.getInventory().contains(Material.LAPIS_BLOCK, 10)) {
    19. p.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, 2);
    20.  
    21. }else if (commandLabel.equalsIgnoreCase("AUT")
    22. && args[0].equalsIgnoreCase("pickaxe")
    23. && p.getInventory().getItemInHand().equals(Material.DIAMOND_PICKAXE)
    24. && p.getInventory().contains(Material.LAPIS_BLOCK, 10)) {
    25. p.getInventory().getItemInHand().addEnchantment(Enchantment.DIG_SPEED, 2);
    26.  
    27. }else if (commandLabel.equalsIgnoreCase("AUT")
    28. && args[0].equalsIgnoreCase("spade")
    29. && p.getInventory().getItemInHand().equals(Material.DIAMOND_SPADE)
    30. && p.getInventory().contains(Material.LAPIS_BLOCK, 10)) {
    31. p.getInventory().getItemInHand().addEnchantment(Enchantment.DIG_SPEED, 2);
    32.  
    33. }else if (commandLabel.equalsIgnoreCase("AUT")
    34. && args[0].equalsIgnoreCase("hoe")
    35. && p.getInventory().getItemInHand().equals(Material.DIAMOND_HOE)
    36. && p.getInventory().contains(Material.LAPIS_BLOCK, 10)) {
    37. p.getInventory().getItemInHand().addEnchantment(Enchantment.LUCK, 2);
    38.  
    39. }else if (commandLabel.equalsIgnoreCase("AUT")
    40. && args[0].equalsIgnoreCase("axe")
    41. && p.getInventory().getItemInHand().equals(Material.DIAMOND_AXE)
    42. && p.getInventory().contains(Material.LAPIS_BLOCK, 10)) {
    43. p.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, 2);
    44.  
    45. }
    46. return true;
    47. }
    48. }

    Enchanting^^

    Rankup
    Code:java
    1. package me.CraftCreeper6.Upgrade;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    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.event.Listener;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class BalanceCheck extends JavaPlugin implements Listener {
    14.  
    15. public static ArrayList<String> hasConfig = new ArrayList<String>();
    16.  
    17. private String pn = "┬žLAUT> " + ChatColor.BLUE;
    18.  
    19. public boolean onCommand(CommandSender sender, Command cmd,
    20. String commandLabel, String[] args) {
    21. Player p = (Player) sender;
    22. if (commandLabel.equalsIgnoreCase("AUT")
    23. && args[0].equalsIgnoreCase("conv")
    24. && p.getInventory().contains(Material.DIAMOND, 64)) {
    25.  
    26. if (hasConfig.contains(p.getName())) {
    27.  
    28. p.sendMessage(pn + "Succesfully transfered!");
    29. getConfig().set("Money", p.getName() + 3);
    30.  
    31. } else {
    32.  
    33. getConfig().set("Money" + p.getName(), 3);
    34.  
    35. }
    36. } else if (args[0].equalsIgnoreCase("bal")
    37. && hasConfig.contains(p.getName())) {
    38.  
    39. p.sendMessage(pn + "Your current balance is: " + getConfig().getInt("Money"));
    40.  
    41. }
    42. return true;
    43. }
    44. }

    Transfer Diamond to Money :)

    Rank handler
    Code:java
    1. package me.CraftCreeper6.Prison;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    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.event.Listener;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Ranks extends JavaPlugin implements Listener {
    15.  
    16. private String pn = "┬žLAUT> " + ChatColor.BLUE;
    17.  
    18. public static ArrayList<String> A = new ArrayList<String>();
    19. public static ArrayList<String> B = new ArrayList<String>();
    20. public static ArrayList<String> C = new ArrayList<String>();
    21. public static ArrayList<String> D = new ArrayList<String>();
    22. public static ArrayList<String> E = new ArrayList<String>();
    23.  
    24. public void Join(PlayerJoinEvent e) {
    25. Player p = e.getPlayer();
    26.  
    27. A.add(p.getName());
    28. p.sendMessage(pn
    29. + " You are rank A, type /AUT rankup to check the amount of items needed to rank up!");
    30.  
    31. }
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd,
    34. String commandLabel, String[] args) {
    35. Player p = (Player) sender;
    36. if (commandLabel.equalsIgnoreCase("AUT")
    37. && args[0].equalsIgnoreCase("rankup")) {
    38.  
    39. if (p.getInventory().contains(Material.DIAMOND, 20)
    40. && A.contains(p.getName())) {
    41. B.add(p.getName());
    42. A.remove(p.getName());
    43. p.sendMessage(pn
    44. + " Congratulations! You have reached rank B collect 50 Diamonds to rank up!");
    45. } else if (p.getInventory().contains(Material.DIAMOND, 50)
    46. && B.contains(p.getName())) {
    47. C.add(p.getName());
    48. B.remove(p.getName());
    49. p.sendMessage(pn
    50. + " Congratulations! You have reached rank B collect 150 Diamonds to rank up!");
    51. } else if (p.getInventory().contains(Material.DIAMOND, 120)
    52. && C.contains(p.getName())) {
    53. D.add(p.getName());
    54. C.remove(p.getName());
    55. p.sendMessage(pn
    56. + " Congratulations! You have reached rank D collect 200 Diamonds to rank up!");
    57. } else if (p.getInventory().contains(Material.DIAMOND, 200)
    58. && D.contains(p.getName())) {
    59. E.add(p.getName());
    60. D.remove(p.getName());
    61. p.sendMessage(pn
    62. + " Congratulations! You have reached the highest rank! Get 1000 Diamonds and you will be released!");
    63. }
    64. }
    65. return true;
    66.  
    67. }
    68. }


    Plugin.yml

    Code:
    name: AUT
    author: CraftCreeper6
    main: me.CraftCreeper6.Upgrade.Regiter
    description: dfdf
    version: 1.0
     
    commands:
        AUT:
           sword :
                description: Enchant sword
           axe :
                description: Enchant axe
           pickaxe :
                description: Enchant pickaxe
           hoe :
                description: Enchant hoe
           spade :
                description: Enchant spade
           conv :
                description: convert diamond to money
           bal :
                description: Check your balance
           rankup :
                description: Rank up
    
    Sorry if I spammed to much, if anyone could tell me how to make spoilers :p
    Any help aprecciated
     
  2. Offline

    DrTURTLE2

    Oh jeez, first off, in the classes you want that you have commands, you want to implement CommandExecutor, not JavaPlugin.

    Once you do that, you have to register your commands in your onEnable.

    Code:java
    1. getCommand("COMMANDHERE").setExecutor(new PACKAGE.CLASSNAMEHERE(this));


    Also in your rankup class, you don't have to implement listener.

    CraftCreeper6
     
  3. Offline

    Fred12i12i

    Just a quick tips
    you dont have to put If(commandLabel.equalsIgnoreCase("AUT") for every command. you just have to put it one time like this:
    Code:java
    1. if (commandLabel.equalsIgnoreCase("AUT")){
    2. if(args[0].equalsIgnoreCase("sword")){
    3. //code
    4. } else if (args[0].equalsIgnoreCase("pickaxe")){
    5. //code
    6. }
    7. }
    8. and so on

    saves you alot of time when you make bigger plugins :)
     
    DrTURTLE2 likes this.
  4. Offline

    CraftCreeper6

    Fred12i12i Have not coded in forever :p Forgot everything I knew
    DrTURTLE2 Its not that bad... Is it? And for all my other plugins I never had a command executer and they worked fine... Hmmm
     
  5. Offline

    DrTURTLE2


    That's because you are extending javaplugin in them which is bad practice.
     
Thread Status:
Not open for further replies.

Share This Page