Can you guys help me with Tag if im doing wrong

Discussion in 'Spigot Plugin Development' started by Ver_Elite, Jun 23, 2016.

  1. So i want to make /tag (player) (tag) i want to set it to a player i used asyncplayerchatevent
    but when i do it like /tag Ver_Elite Happy

    this what happen:
    Tag.PNG


    Tag1.PNG
    it same tag in all player who has permission for that


    this one is listener
    this one is Tag
    Code (Text):
    package me.cms.commands;

    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import me.cms.Main;
    import net.md_5.bungee.api.ChatColor;

    public class Tag implements CommandExecutor {
    Main plugin;

        public Tag(Main instance){
            plugin = instance;
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("tag")) {

            if (args.length < 2) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lCMS &8» &6Please use /tag (player) (tag)"));
                return true;
            }


            Player target = Bukkit.getServer().getPlayer(args[0]);
            if (target == null) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lCMS &8» &6That player is not online!"));
                return true;
            }

            StringBuilder sb = new StringBuilder();
            for(int i = 1; i < args.length; i++) {
                sb.append(args[i]).append("");
            }

            String tag = sb.toString().trim();
            plugin.getConfig().set("CMS.Chat.Tag", tag);
            plugin.saveConfig();
            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lCMS &8» &6Tag has been set to &8[&7"  + tag + "&8]"));
            target.playSound(target.getLocation(), Sound.LEVEL_UP, 1, 1);
            return true;
            }
            return true;
        }
    }
     
     
    #1 Ver_Elite, Jun 23, 2016
    Last edited: Jun 23, 2016
  2. If Im doing wrong please tell me what should i do
     
  3. Code (Text):
    if(player.hasPermission("tag")) {
                Tag = ChatColor.translateAlternateColorCodes('&', "&8[&7" + plugin.getConfig().getString("CMS.Chat.Tag") + "&8] ");
            } else
    If they have the permission 'tag' they will always have the same tag on.
     
    • Agree Agree x 1
  4. are you sure?
     
  5. He literally read what your if statement meant. Yes he's sure
     
  6. are you sure!!!!
     
    • Funny Funny x 2
  7. i wanted that you can set random tag to a player

    but idk how to do that
     
  8. set("Tag." + name, tag);
    String tag = get("Tag." + name);
     
  9. owh like that but how do i do that?
     
  10. I would keep the Tag on memory once it's loaded, in something like Map<UUID, String> and and on PlayerQuitEvent and onDisabled save it to the config, and when a player joins load it, if the player has a CustomTag (on the Map) use it, if not then use the Rank tag with permissions and stuff.
     
  11. looks hard
     
  12. You must specified a player in the args first and then set that player's nametag.
     
    • Agree Agree x 1
  13. can you edit my code and how it works?
     
  14. Like:
    Code (Text):
    if(cmd.getName().equalIgnoreCase("nametag-set")){
      sender.setNameTag("BlaBla This is a name tag");
    }
    return true;
    Or set a custom nametag:
    Code (Text):
    if(cmd.getName().equalIgnoreCase("nametag-custom")){
    if(sender instanceof Player){
      if(args.length >= 1){
         String tag = "";
         for (int i = 0 ; args.length != i; i++){
            tag = tag + args[i] + " ";
         }
         sender.setNameTag(tag);
        }
      }
    }
    }
    And if I type /nametag-custom ThisIsANameTag
    Your name will set to ThisIsANameTag
    :)
     
    • Like Like x 1
  15. thanks i will test it out
     
  16. You can change the variables if it have problem.
     
  17. sender.setNameTag(tag); this code it give me error at setNameTag
     
  18. -sigh- that method does not exist.
    @KhoaHoangVN at this point you are just stating random non-existent methods.
     
  19. Or you can create a class. Like PlayerNameTag class. You can ask how to make a custom class for plugins.
     
  20. I have a solution!
    You can use NameTagAPI!
    Please download here and put it in the library and you're all set!
    The value is setTag() , not setNameTag(); .
    Hope you can do it! ;)
     
    • Like Like x 1