TagAPI Help

Discussion in 'Plugin Development' started by ZodiacTheories, Apr 10, 2014.

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

    ZodiacTheories

    Hey guys, so I am coding a private plugin for someone (for free) called BetterTags. What it is meant to do is when you type /tagpro, /tagmember or /tagadmin then your nametags switch to the one that you specified. However, when I type the commands, nothing happens. I think it is to do with the AsyncPlayerReceiveNameTagEvent because what I've done is created an three different ArrayLists, one for pro, member and admin and everytime a player does /tagpro, they get added and in the EventHandler, if it contains the player, then they get the nametag.

    For some reason this doesn't seem to work...

    Here is my code:

    Code:java
    1. package me.thesamster8.bettertags;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
    15.  
    16. public class Main extends JavaPlugin implements Listener, CommandExecutor {
    17.  
    18. @Override
    19. public void onEnable() {
    20. getServer().getPluginManager().registerEvents(this, this);
    21. getServer().getPluginManager().registerEvents(new Member(), this);
    22. getCommand("tagpro").setExecutor(new Main());
    23. getCommand("tagadmin").setExecutor(new Main());
    24. getCommand("tagmember").setExecutor(new Main());
    25. }
    26.  
    27. @Override
    28. public void onDisable() {
    29. }
    30.  
    31. ArrayList<String> pros = new ArrayList<String>();
    32. ArrayList<String> admins = new ArrayList<String>();
    33. public static List<String> members = new ArrayList<String>();
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    36. if(!(sender instanceof Player)) {
    37. sender.sendMessage("You must be a Player");
    38. return true;
    39. }
    40.  
    41. Player p = (Player) sender;
    42.  
    43. if(cmd.getName().equalsIgnoreCase("tagpro")) {
    44. if(p.hasPermission("tagcommand.pro")) {
    45. pros.add(p.getName());
    46. return true;
    47. }
    48.  
    49. if(cmd.getName().equalsIgnoreCase("tagadmin")) {
    50. if(p.hasPermission("tagcommand.admin")) {
    51. admins.add(p.getName());
    52. return true;
    53. }
    54.  
    55. if(cmd.getName().equalsIgnoreCase("tagmember")) {
    56. if(p.hasPermission("tagcommand.member")) {
    57. members.add(p.getName());
    58. return true;
    59. }
    60. }
    61. }
    62. }
    63. return true;
    64. }
    65.  
    66. @EventHandler
    67. public void onTag(AsyncPlayerReceiveNameTagEvent event) {
    68. Player player = event.getNamedPlayer();
    69. if(pros.contains(player.getName())) {
    70. event.setTag(ChatColor.AQUA + player.getName());
    71. }
    72. }
    73.  
    74.  
    75.  
    76. @EventHandler
    77. public void onNameTag(AsyncPlayerReceiveNameTagEvent event) {
    78. Player player = event.getNamedPlayer();
    79. if(admins.contains(player.getName())) {
    80. event.setTag(ChatColor.DARK_AQUA + player.getName());
    81. }
    82. }
    83. }
    84.  
    85.  


    Code:java
    1. package me.thesamster8.bettertags;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
    8.  
    9. public class Member implements Listener {
    10.  
    11. @EventHandler
    12. public void onTagTag(AsyncPlayerReceiveNameTagEvent event) {
    13. Player player = event.getNamedPlayer();
    14. if(Main.members.contains(player.getName())) {
    15. event.setTag(ChatColor.BOLD.toString() + ChatColor.GRAY + player.getDisplayName());
    16. }
    17. }
    18. }
    19.  


    Thanks
     
  2. Offline

    RainoBoy97

    Remove line 22, 23 and 24 in your first code snippet. You cannot instantiate your main class.
     
  3. Offline

    ZodiacTheories

    RainoBoy97

    Oh really? Then how do I register my commands?
     
  4. Offline

    Wruczek

    It is on main class. You do not need to register this. Just remove.
     
  5. Offline

    itzrobotix

    Just no. What dafudge have you done. Ok remove the implements CommandExecutor you don't need that, if you are having the onCommand mehtod in your main class all you need to do is in your plugin.yml add this;
    commands:
    Command1:
    description: Blah
    Command2:
    description: Blah2
    As for the rest of your code I recommend learning the basics of the Bukkit API before trying to hook into another.
     
  6. Offline

    ahuby09

    right do all above , then if you want the tags to update i would advise you would use a event that happens once every so offen (other whys players don't show if constant) and then put the following
    Code:
    for(Player t : Bukkit.getOnlinePlayers()){
      TagAPI.refreshPlayer(t);
      }
    i use the noteblock play event @ZodiacTheories although i suppose you could do it in the command but i wouldn't recommend this
     
  7. Offline

    ZodiacTheories

  8. Offline

    ahuby09

    glad to help did it work for you , if not please feel free to inbox me
     
  9. Offline

    RainoBoy97

    ZodiacTheories
    1. You don't need to register commands in the main class.
    2. You cannot instantiate any main class of any plugin.
     
  10. Offline

    ZodiacTheories

Thread Status:
Not open for further replies.

Share This Page