Solved Please tell me how to Hide Plugin!!

Discussion in 'Plugin Development' started by Ishityu, Jan 22, 2018.

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

    Ishityu

    Code:
    package cream.sun;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class HideAndShow extends JavaPlugin {
        public void onEnable(){
            getCommand("hide").setExecutor(this);
            getCommand("show").setExecutor(this);
                   
                   
                 
                }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("hide"))
            {
              if (!(sender instanceof Player))
              {
                sender.sendMessage("Run this command in the game.");
                return true;
              }
              Player player = (Player)sender;
              Location loc = player.getLocation();
              if (args.length == 0)
              {
              player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
              player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("HideMessage")));
              for (Player allplayer : getServer().getOnlinePlayers()) {
                if (!allplayer.isOp()) {
                  player.hidePlayer(allplayer);
                }
              }
              return true;
              }
              if (args.length == 1)
              {
                Player target = getServer().getPlayer(args[0]);
                String str = args[0];
                if (target == null)
                {
                   
                  player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString(ChatColor.YELLOW + str + "PlayerIsnt")));
                }
                else
                {
                 Player name = target.getPlayer();
                 String name1 = name.getName();
                  player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString(ChatColor.YELLOW + name1 + "OnlyHide")));
                  player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
                  player.hidePlayer(target);
                }
              }
              return true;
            }
            
    
            if (cmd.getName().equalsIgnoreCase("show"))
            {
              if (!(sender instanceof Player))
              {
                sender.sendMessage("Run this command in the game.");
                return true;
              }
              Player player = (Player)sender;
              Location loc = player.getLocation();
              if (args.length == 0)
              {
              player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
              player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ShowMessage")));
              for (Player allplayer : getServer().getOnlinePlayers()) {
                if (!allplayer.isOp()) {
                  player.showPlayer(allplayer);
                }
              }
              return true;
              }
              if (args.length == 1)
              {
                Player target = getServer().getPlayer(args[0]);
             
                if (target == null)
                {
                      String str = args[0];
                  player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString(ChatColor.YELLOW + str + "PlayerIsnt")));
                }
                else
                {
                    Player name = target.getPlayer();
                     String name1 = name.getName();
                  player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString(ChatColor.YELLOW + name1 + "OnlyShow")));
                  player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
                  player.showPlayer(target);
                }
              }
              return true;
            }
            return false;
          }
    }
     
  2. Online

    timtower Administrator Administrator Moderator

    @Ishityu And what do you need help with?
     
  3. Offline

    Ishityu

    this is a plugin.yml


    Code:
    name: HideAndShow
    version: 1.0
    main: cream.sun.HideAndShow
    author: Cream_sun
    default-permissions: NOT_OP
    
    commands:
      HideAndShow:
        usage: /hide [show]
        default: true
    this is a config.yml

    Code:
    HideMessage: '&6&lPlayer is hiding.'
    ShowMessage: '&a&lPlayer is showing.'
    PlayerIsnt: '&6&l isn't.'
    OnlyHide: '&6&l is hiding.'
    OnlyShow: '&6&l is showing.'
    I wrote a this plugin, but don't run thier command. (/hide & /show)
    Where am I wrong? Please tell me.

    I wrote a this plugin, but don't run thier command. (/hide & /show)
    Where am I wrong? Please tell me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 22, 2018
  4. Online

    timtower Administrator Administrator Moderator

    @Ishityu Because your command is /HideAndShow according to your plugin.yml
    You should also get NullPointerExceptions when starting the server.
     
  5. Offline

    Ishityu

    Could you tell me more?
    Sorry, I'm a biginner.
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    Ishityu

    Is this correct?
    Code:
    commands:
      hide:
        default: true
     
  8. Online

    timtower Administrator Administrator Moderator

  9. Offline

    Ishityu

    Thank you very much!!
    But, it becomes error when I run their commands.
     
  10. Online

    timtower Administrator Administrator Moderator

    What errors do you get then?
     
  11. Offline

    Ishityu

    Oh, sorry. I forgot to put a photo.
    [​IMG]
    like thier.
     
    Last edited: Jan 23, 2018
  12. Online

    timtower Administrator Administrator Moderator

    @Ishityu Print all string values from the config to the console please.
     
  13. Offline

    Ishityu

    Sorry, i don't understand that you say.
     
  14. Online

    timtower Administrator Administrator Moderator

    It looks like it is using an empty config, print the values that are in the config to the console.
     
  15. Offline

    Ishityu

    Should I show config.yml?

    Code:
    HideMessage: '&6&lPlayer is hiding.'
    
    ShowMessage: '&a&lPlayer is showing.'
    PlayerIsnt: '&6&l isn't.'
    OnlyHide: '&6&l is hiding.'
    OnlyShow: '&6&l is showing.'
    my config.yml
     
  16. Online

    timtower Administrator Administrator Moderator

    @Ishityu Print the value of the strings before you put them into ChatColor.translateAlternateColorCode
     
  17. Offline

    Ishityu

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
          {
            if (cmd.getName().equalsIgnoreCase("hide"))
            {
              if (!(sender instanceof Player))
              {
                sender.sendMessage("Run this command in the game.");
                return true;
              }
              Player player = (Player)sender;
              Location loc = player.getLocation();
              if (args.length == 0)
              {
              player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
              player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("HideMessage")));
              for (Player allplayer : getServer().getOnlinePlayers()) {
                if (!allplayer.isOp()) {
                  player.hidePlayer(allplayer);
                }
              }
              return true;
    here?
     
  18. Online

    timtower Administrator Administrator Moderator

    @Ishityu Before this line:
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("HideMessage")));
     
  19. Offline

    Ishityu

    I do not know what I should fill in in front of this line.
    Could you write an example what value I should put?
     
  20. Online

    timtower Administrator Administrator Moderator

    You only need to print the value that is in the config (last part of the line) to the console.
    Part of debugging.
     
  21. Offline

    Ishityu

    In other words print the value of the strings when I run </hide>. Right?
     
  22. Online

    timtower Administrator Administrator Moderator

  23. Offline

    Ishityu

    Well, why will an error be given?
    Error contents: An error is given when I run </hide> or </show>.
    But,
    Code:
    player.playSound(loc, Sound.ENDERMAN_TELEPORT, 1, 1);
    This code is run.
     
  24. Online

    timtower Administrator Administrator Moderator

    @Ishityu That is what I am trying to find out, but I don't see debug messages or the code for the debug messages so I can't say anything about it.
    Please post your full server log using http://pastebin.com
     
  25. Offline

    Ishityu

  26. Online

    timtower Administrator Administrator Moderator

    @Ishityu Print the value of getConfig().getString("HideMessage") to the console.
    And that is the error, not the full log.
     
  27. Offline

    Ishityu

    Sorry, Should I post getConfig().getString("HideMessage") to the console?
     
  28. Online

    timtower Administrator Administrator Moderator

    Yes
     
  29. Offline

    Colinus999

    I think I found the error:
    Should be:
    Code:
    player.sendMessage(String.format(ChatColor.translateAlternateColorCodes('&', getConfig().getString("PlayerIsnt")),str));
    And in your config:
    Code:
    PlayerIsnt: '&6&l%s is not hidden.'
    You were trying to get the String "§ePlayerName PlayerIsnt" which is null.
    You did this not only at this line of code.
     
    Last edited: Jan 23, 2018
  30. Offline

    Ishityu

    Thank you everyone.
    But, there is a new trouble!
    A file isnt made when I reloaded it.
     
Thread Status:
Not open for further replies.

Share This Page