Solved Command not working!

Discussion in 'Plugin Development' started by FletchTech90, Apr 26, 2014.

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

    FletchTech90

    Hi. I have a problem with my code, I'm trying to make a plugin that can refresh a person's oxygen. It also has a cooldown using HashMap. All that happens when I type /oxygen is it heads straight for the "return false;" area and skips everything. Please help!

    Here's my code:
    Code:java
    1. package me.FletchTech90.CraftingCrafter.plugin;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin {
    13.  
    14. public void onEnable() {
    15.  
    16. }
    17.  
    18. public void onDisable() {
    19.  
    20. }
    21.  
    22. ArrayList<Player> cooldown = new ArrayList<Player>();
    23.  
    24. public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args) {
    25. if(cmd.getName().equalsIgnoreCase("oxygen")){
    26. if(sender instanceof Player){
    27. final Player p = (Player) sender;
    28. if(p.hasPermission("cc.oxygen")){
    29. if(cooldown.contains(p)){
    30. p.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "Oxygen" + ChatColor.DARK_RED + "] " + ChatColor.YELLOW + "You haven't waited the full cooldown time.");
    31. }
    32. else{
    33. p.setRemainingAir(10);
    34. p.sendMessage(ChatColor.DARK_AQUA + "[" + ChatColor.AQUA + "Oxygen" + ChatColor.DARK_AQUA + "] " + ChatColor.GREEN + "Your oxygen has been refilled. Please wait 2 minutes before using the command again.");
    35. cooldown.add(p);
    36. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    37. public void run() {
    38. cooldown.remove(p);
    39. }
    40. }, 2400);
    41. return true;
    42. }
    43. }
    44. else{
    45. sender.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "Oxygen" + ChatColor.DARK_RED + "] " + ChatColor.YELLOW + "You don't have permission to use this command.");
    46. return true;
    47. }
    48. }
    49. else{
    50. sender.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "Oxygen" + ChatColor.DARK_RED + "] " + ChatColor.YELLOW + "You must be a player!");
    51. return true;
    52. }
    53. return true;
    54. }
    55. return true;
    56. }
    57.  
    58. }
    59.  


    Plugin.yml file:
    Code:
    name: Oxygen
    version: 0.0.2
    main: me.FletchTech90.CraftingCrafter.plugin.Main
     
    commands:
        oxygen:
            description: Give yourself full air underwater.
            permission: cc.oxygen
            usage: /<command>
    permissions:
        cc.oxygen:
            description: Allows you to use /oxygen
            default: op
     
  2. Offline

    MCForger

  3. Offline

    FletchTech90

  4. Offline

    MCForger

    FletchTech90
    Change this
    Code:java
    1. public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args)

    To this by swapping Command and CommandSender
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
     
  5. Offline

    FletchTech90

    Will do, I'll tell ya how it goes.
     
  6. Offline

    MCForger

    FletchTech90
    Also I recommend storing by UUID rather than the actual player object.
    *Remember to null the list on disable after your done with it to
     
  7. Offline

    FletchTech90

    Thanks so much! It worked!
     
  8. Offline

    MCForger

Thread Status:
Not open for further replies.

Share This Page