Why doesn't this work?!

Discussion in 'Plugin Development' started by football70500, Aug 18, 2012.

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

    football70500

    So i made a plugin that starves you... It doesn't work, it seems like every time I do the onCommand method, it doesn't work... EVERY TIME. I think bukkit hates me

    Code:JAVA
    1. package me.football70500.SimpleHunger;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7.  
    8. public class Command extends Main {
    9.  
    10. public boolean onCommand(CommandSender sender, Command command, String c, String[] args){
    11. Player send = (Player) sender;
    12. Player target = null;
    13. if(command.getName().equalsIgnoreCase("hunger")){
    14. if(send.hasPermission("sh.hunger")){
    15. if (sender instanceof Player){
    16. if(args.length == 1) {
    17. target = Bukkit.getServer().getPlayer(args [0]);
    18. if (target != null) {
    19. target.setFoodLevel(0);
    20. target.sendMessage(ChatColor.YELLOW + "You are now hungry!");
    21. return true;
    22. } else if (target == null) {
    23. sender.sendMessage(ChatColor.RED + "Player is offline or doesn't exist!");
    24. return true;
    25. }
    26. } else if (args.length == 0) {
    27. send.setFoodLevel(0);
    28. return true;
    29. } else if(args.length > 1){
    30. sender.sendMessage(ChatColor.RED + "Too many args!");
    31. return true;
    32. }
    33. }
    34. }
    35. }
    36. return false;
    37. }
    38. }
    39.  
     
  2. Offline

    ZeusAllMighty11

    I am probably wrong, but why aren't you doing 'Player target = Bukkit.getServer().getPlayer(args[0])' ?
    What if target was an entity, and you tried to get it as a player? 0__0 idk im confused
     
  3. Offline

    football70500

    It works on my other plugin...
     
  4. Offline

    Tog

    Have you registered the command in the plugin.yml?
    Try putting @Override before the onCommand method.
     
  5. Offline

    JDigital1337

    you dont need the @Override, sounds like you didn't put your commands in the plugin.yml
     
  6. Offline

    football70500

    I did


    Code:JAVA
    1. name: SimpleHunger
    2. version: 1
    3. main: me.football70500.SimpleHunger.Main
    4. commands:
    5. hunger:
    6. description: Starves a player.


    Code:JAVA
    1. name: SimpleHunger
    2. version: 1
    3. main: me.football70500.SimpleHunger.Main
    4. commands:
    5. hunger:
    6. description: Starves a player.


    SOMEONE HELP

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page