Programming hide command

Discussion in 'Plugin Development' started by Bostrot, Apr 20, 2014.

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

    Bostrot

    Hi I want to write a little plugin where players are teleported to other players... Now is my problem that everytime I write the command in-game it returns false. I think it's beacause of the Name -> UUID change but I don't know... My Code:
    Code:java
    1. package com.eric.hide;
    2.  
    3. import java.util.UUID;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class main extends JavaPlugin{
    11. public void onEnable() {
    12. System.out.println("MyPlugin is finished with sarting");
    13. }
    14. public void onDisable() {
    15. System.out.println("MyPlugin has stopped");
    16. }
    17. public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args){
    18.  
    19. //Sender -> Player
    20. Player p = null;
    21. if(sender instanceof Player){
    22. p = (Player)sender;
    23. }
    24.  
    25. //Command hide
    26. if(cmd.getName().equalsIgnoreCase("hide")){
    27. if(args.length > 1){
    28. return false;
    29. }
    30. if(args.length == 0){
    31. Player[] targets = getServer().getOnlinePlayers();
    32. for(Player targetPlayer : targets){
    33. targetPlayer.hidePlayer(p);
    34. }
    35. }
    36.  
    37. if(args.length == 1){
    38. Player target = getServer().getPlayer(UUID.fromString(args[0]));
    39. target.hidePlayer(p);
    40.  
    41. }
    42. return true;
    43. }
    44.  
    45. return false;
    46. }
    47.  
    48. }

    There is no error if the server starts.
    Plugin.yml:
    Code:
    name: MultiPlugin
    version: 1.0
    author: Eric
    main: com.eric.hide.main
    commands:
      hide:
        usage: /hide <player> [player]
        description: Hide you or another player
     
  2. Offline

    Tehmaker

    Try printing out some lines to console or player. I would do one after the:
    Code:
    if(cmd.getName().equalsIgnoreCase("Hide)){
    
    Then do another after every if statement, and check to see where it stops running properly.
     
  3. Offline

    Bostrot

    I did as you said and no message is shown... So the problem is in one of the first lines or?
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("hide")){
    2. p.sendMessage("First is working!");
    3. if(args.length > 1){
    4. p.sendMessage("Second is working!");
    5. return false;
    6. }
    7. if(args.length == 0){
    8. p.sendMessage("Third is working!");
    9. Player[] targets = getServer().getOnlinePlayers();
    10. for(Player targetPlayer : targets){
    11. targetPlayer.hidePlayer(p);
    12. }
    13. }
    14.  
    15. if(args.length == 1){
    16. p.sendMessage("Fourth is working!");
    17. Player target = getServer().getPlayer(UUID.fromString(args[0]));
    18. target.hidePlayer(p);
    19.  
    20. }
    21. return true;
    22. }
     
  4. Offline

    sipsi133

    Bostrot put @Override above onCommand() method.

    Code:
    @Override
    public boolean onCommand(....) {
     
  5. Offline

    mmiillkkaa

    Your main class is com.eric.hide.main, make sure you have it set to that in your plugin.yml.
     
  6. Offline

    Bostrot

    sipsi133 No the error is still there...

    mmiillkkaa I am sure that I have the right main class defined...
     
  7. Offline

    mmiillkkaa

    Bostrot Your plugin.yml says otherwise.

    Edit: Typo with phone keyboard
     
  8. Offline

    Bostrot

    mmiillkkaa oh yes... but this is only on this thread. In eclipse it is right...
     
  9. Offline

    mmiillkkaa

    Bostrot Then could you please post your most up-to-date plugin.yml?

    Nevermind, you already have.
    Are you including the latest plugin.yml in the jar you build?
     
  10. Offline

    Bostrot

    mmiillkkaa Yes I have. And there is no error.
     
  11. Offline

    mmiillkkaa

    Bostrot What is the command you are typing?
     
  12. Offline

    Bostrot

  13. Offline

    mmiillkkaa

    Bostrot What I mean is, what are you exactly typing into chat? For example, "/hide mmiillkkaa," or "/hide mmiillkkaa Bostrot."
     
  14. Offline

    Bostrot

  15. Offline

    mmiillkkaa

    Bostrot I tested this myself and it is working. What problems are you having, if any?
     
  16. Offline

    Bostrot

  17. Offline

    mmiillkkaa

    Bostrot They're the same as yours.
     
Thread Status:
Not open for further replies.

Share This Page