TagAPI - Change/color the name over people's heads!

Discussion in 'Resources' started by mbaxter, Sep 6, 2012.

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

    adamson_g

    if i do:
    Code:
    [syntax=java]
    public void onNameTag(PlayerReceiveNameTagEvent event){
        Player seenPlayer = event.getNamedPlayer();
        Player player = event.getPlayer();
        if(player.hasPermission(new Permissions().canSeeNameColor)){
        event.setTag(ChatColor.GREEN + seenPlayer.getDisplayName());
            TagAPI.refreshPlayer(seenPlayer, player);
        }
    }[/syntax]
    
    if they have permission canSeeNameColor they will see everyone with a green name?
    cant get java syntax to work
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    You are calling the refresh method from inside the event. That is a problem :p
     
  3. Offline

    adamson_g

    How else would i refresh it?
     
  4. Offline

    linkrock4

    Okay so, i simply want to get some ones nametag and change it to red but its not working ._. can anyone help?!
     
  5. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    read the tutorial
     
    chasechocolate and aviator14 like this.
  6. Offline

    aviator14

    Refresh manually fires the event. putting it in an event it creates will cause an infinite loop. If you've modified the event, you've already changed the name tags.
     
  7. Offline

    cocoson

    i cant seem to get it to work i even tested it with your default
    Code:
        @EventHandler
        public void onNameTag(PlayerReceiveNameTagEvent event) {
        if (event.getNamedPlayer().getName().equals("md_5")) {
        event.setTag(ChatColor.RED + "md_5");
        }
        }
    but i cant seem to get any thing to work this is how i'm trying it now and the way i want it to work but cant seem to get it to can some one please help me.

    Code:
    package me.cocoson.cviewer.listeners;
     
    import me.cocoson.cviewer.CViewer;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.kitteh.tag.PlayerReceiveNameTagEvent;
     
    public class Listener_TagAPI {
        private CViewer plugin;
       
       
        public Listener_TagAPI(CViewer plugin){
            this.plugin = plugin;
        }
     
       
        @EventHandler (priority = EventPriority.HIGHEST)
        public void onNameTag(PlayerReceiveNameTagEvent event) {
            Player player = event.getNamedPlayer();
                if (plugin.hiddenPlayers.contains(player.getName())){
                        event.setTag(ChatColor.AQUA + player.getName());
               
            }
        }
    }
    
     
  8. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    cocoson Are you registering the event? Add debug code to see what's firing.
     
  9. Offline

    cocoson

    mbaxter yes i'm registering the event with this
    Code:
    public void tagapicheck(){
            if (Bukkit.getPluginManager().getPlugin("TagAPI") != null){
                log.info("[CViewer] " + "TagAPI Found!");
                log.info("[CViewer] " + "Hooked into TagAPI");
                Bukkit.getPluginManager().registerEvents(new Listener_TagAPI(this), this);
            } else {
                log.info("[CViewer] " + "TagAPI is not Installed!");
                log.info("[CViewer] " + "Vanished names will not be Colored!");
                HandlerList.unregisterAll(new Listener_TagAPI(this));
                
            }
        }
    
    that way they dont need to use TagAPI if they dont want to.
    if there is a better way to do this please dont hesitate to tell me that i'm a dumb ass.
     
  10. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    Have you added debug code to see what's going on, if it's firing at all.
     
  11. Offline

    cocoson

    lol going to sound like a noob but i dont know how to add debuging to it been a while since i last used java
     
  12. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    sprinkle logging everywhere
     
  13. Offline

    jollyajax

    Hey,

    Sorry if this is a bit of a silly question, but I can't figure out why on earth I'm getting a particular error. I have a scheduled task running that executes a refresh through the static method you provided, but I am continually getting an error stating:

    Caused by: org.kitteh.tag.TagAPIException: A plugin attempted to call a TagAPI m
    ethod from another thread!
    at org.kitteh.tag.TagAPI.check(TagAPI.java:175)
    at org.kitteh.tag.TagAPI.refreshPlayer(TagAPI.java:107)

    Is this an issue directly correlating to it being called through an async task?

    Thanks in advance.
     
  14. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    You should never, ever ever call methods that affect players from an async task. Ever.

    Always use sync tasks unless you know exactly what you're doing.
     
    jollyajax and Comphenix like this.
  15. Offline

    jollyajax

    Thanks for the response. It was a very very specific use case that involved network connections/sockets - but I'll just re-purpose the logic into a more standardized sync task. Queing the changes from the async task into a thread safe main thread method.
     
    mbaxter likes this.
  16. Offline

    RoyalKingdoms

    I am used to config-files. How can I use this?
    I am kind of new to this kind of Plugins.
     
  17. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    This is an API for other plugins to use. Just running this plugin will do nothing. :)
     
  18. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    Oops! For a short period you could not depend on this plugin with maven if looking for latest or pointing direct at version 1.8. LATEST will now work for maven, and if you were manually pointing at 1.8, point to 1.8.1 instead.
     
  19. Offline

    cocoson

    lol got something mixed up for some reason my players got random names of the other players like fugalow becaome cocoson/ cocoson became jack/ jack became fugalow.

    lol could have some funny shit going on in my server
     
  20. Offline

    uvbeenzaned

    It probably just me but can someone give me a really simple example of how to do a basic team tag system? Also, is there something wrong with this code?

    Registration of event class here:
    Code:java
    1.  
    2. public void onEnable()
    3. {
    4. sbr = new MyListener(this);
    5. this.log = getLogger();
    6. PluginManager pm = getServer().getPluginManager();
    7. pm.registerEvents(this.sbr, this);
    8. if (pm.getPlugin("TagAPI") != null){
    9. pm.registerEvents(new TagListener(), this);
    10. } else {
    11. HandlerList.unregisterAll(new TagListener());
    12. }
    13. log.info(pg + "All config loaded!");
    14. }
    15.  


    Actual Listener:
    Code:java
    1.  
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.EventPriority;
    5. import org.bukkit.event.Listener;
    6. import org.kitteh.tag.PlayerReceiveNameTagEvent;
    7.  
    8. public class TagListener implements Listener{
    9.  
    10. @EventHandler(priority = EventPriority.HIGH)
    11. public void onNameTag(PlayerReceiveNameTagEvent event)
    12. {
    13. if(SnowballerListener.teamcyan.contains(event.getPlayer().getName()))
    14. {
    15. if(SnowballerListener.teamcyan.contains(event.getNamedPlayer().getName()))
    16. {
    17. event.setTag(ChatColor.AQUA + event.getNamedPlayer().getName());
    18. }
    19. }
    20. if(SnowballerListener.teamlime.contains(event.getPlayer().getName()))
    21. {
    22. if(SnowballerListener.teamlime.contains(event.getNamedPlayer().getName()))
    23. {
    24. event.setTag(ChatColor.GREEN + event.getNamedPlayer().getName());
    25. }
    26. }
    27. }
    28. }
    29.  
     
  21. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    That looks fine, uvbeenzaned. Except there's generally no reason to listen on HIGH.
     
  22. Offline

    uvbeenzaned

    Oh lol I just figured it out! I had my if()'s checking the teams waaay wrong. Thanks for responding anyway!
     
  23. Offline

    cocoson

    lol uvbeenzaned post the fixed code so people can see how u did it. it might help some one down the way
     
  24. Offline

    dark navi

    mbaxter Could this be used to completely remove the name plate over a user's head?
     
  25. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    I've heard rumor doing four simoleons (ChatColor.COLOR_CHAR) in a row and nothing else, will wipe it. Note that this means no skin though, just default steve.
     
  26. Offline

    uvbeenzaned

    Sorry for not posting the fix but here it is.

    Example code (I made it waay harder than it had to be!):
    Code:java
    1. @EventHandler
    2. public void onNameTag(PlayerReceiveNameTagEvent event)
    3. {
    4. if(teamcyan.contains(event.getNamedPlayer().getName()))
    5. {
    6. event.setTag(ChatColor.AQUA + event.getNamedPlayer().getName());
    7. }
    8. if(teamlime.contains(event.getNamedPlayer().getName()))
    9. {
    10. event.setTag(ChatColor.GREEN + event.getNamedPlayer().getName());
    11. }
    12. }
     
  27. Offline

    dark navi

    How do colored named people normally keep there skins?
     
  28. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    Skin lookup strips the color from whatever it's passed as the name tag. So a blue colored mbaxter would still lookup mbaxter.
     
    dark navi likes this.
  29. Offline

    TommyPanhuyzen

    My console says:
    java.lang.NoSuchMethodError: com.comphenix.protocol.events.PacketContainer.getHandle()Lnet/minecraft/server/Packet;
    at org.kitteh.tag.handler.ProtocolLibHandler$1.onPacketSending(ProtocolLibHandler.java:28)
    at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:69)
    at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:402)
    at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:382)
    at com.comphenix.protocol.injector.player.PlayerInjector.handlePacketSending(PlayerInjector.java:533)
    at com.comphenix.protocol.injector.player.NetworkServerInjector.handlePacketSending(NetworkServerInjector.java:52)
    at com.comphenix.protocol.injector.player.NetworkServerInjector$1.intercept(NetworkServerInjector.java:158)
    at net.minecraft.server.NetServerHandler$$EnhancerByCGLIB$$a9dc69a7.sendPacket(<generated>)
    at net.minecraft.server.EntityTrackerEntry.updatePlayer(EntityTrackerEntry.java:306)
    at org.bukkit.craftbukkit.entity.CraftPlayer.showPlayer(CraftPlayer.java:651)
    at org.kitteh.tag.TagAPI$ShowBomb.run(TagAPI.java:92)
    at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:53)
    at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:529)
    at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)

    when I use any nametag plugin.

    Plz Help Guys!
     
  30. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    Update to the latest ProtocolLib?
     
Thread Status:
Not open for further replies.

Share This Page