I Need Help With Name Tag Plugin

Discussion in 'Plugin Development' started by CaptainUniverse, May 25, 2014.

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

    CaptainUniverse

    Hi I am currently making a plugin.
    It is suppost to set your name tag to "Jonny"
    What did i do wrong? I started the server with the plugin and it worked fine
    but the command doesn't work






    package me.SargentUniverse.DisplayTag;

    import java.util.logging.Logger;

    import net.minecraft.server.v1_7_R3.EntityPlayer;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;

    public class MainClass extends JavaPlugin {

    private static final Logger log = Logger.getLogger("Minecraft");

    @SuppressWarnings("unused")
    @Override
    public void onEnable()
    {
    log.info("[DisplayTag] has been enabled!");
    PluginManager pm = getServer().getPluginManager(); }
    @Override
    public void onDisable()
    {
    log.info("[BlockChanger] has been disabled!"); }


    public boolean onCommand(CommandSender sender, Command command,
    String commandlabel, String[] args) {
    if (commandlabel.equalsIgnoreCase("nameme")) {
    if (sender instanceof Player) {
    Player player = (Player) sender;
    String namebefore = player.getName();
    EntityPlayer ep = ((CraftPlayer) player).getHandle();

    ep.displayName = ChatColor.BLUE + "Jonny";
    player.setDisplayName(ChatColor.BLUE + "Jonny");

    ep.displayName = namebefore; } }
    return false;
    }
    }
     
  2. Offline

    Mindcraftson

    Error log from console?
     
  3. Offline

    CaptainUniverse

    Nope it just doesnt do anything
     
  4. Offline

    Garris0n

    Before I even begin to explain what's wrong, please tell me where you got the idea that setting the displayName directly in the server was a good idea.

    Is there something you read that suggested this?
     
  5. Offline

    CaptainUniverse

    Idk i just started coding today
     
  6. Offline

    Garris0n

    Did you come up with that completely on your own? If you just started out you should not even have CraftBukkit in your build path, please replace it with Bukkit, which you can download here.

    Then, instead of using an NMS class, use player.setDisplayName.
     
  7. Offline

    CaptainUniverse

    someone please help !
     
  8. Offline

    Garris0n

    You should bump once per 24 hours, not once per, uh...3 minutes.
     
  9. Offline

    CaptainUniverse

    hmmmmm btw i did use bukkit and could you please give me some code i could reference to i really need some help for this plugin on my server
     
  10. Offline

    Garris0n

    1. You didn't use Bukkit, you used CraftBukkit.
    2. You literally only need one line of code, and I told you what it is.
     
  11. Offline

    CaptainUniverse

    so do i just do
    String Jonny = Jonny;
    player.setDisplayName(Jonny);
     
  12. Offline

    Garris0n

    Well, first of all you should never name a variable "Jonny" because that starts with a capital letter. Read this.

    And second, yes, essentially. You should also make sure you remove CraftBukkit from your build path and replace it with Bukkit before you break something or confuse yourself to no end.
     
  13. Offline

    xMrPoi

    What exactly is wrong with using CraftBukkit instead of Bukkit?
     
  14. Offline

    CaptainUniverse

    ikr LISTEN TO DONALD (and please help me ^-^)
     
  15. Offline

    Garris0n

    It has all the NMS classes that he shouldn't be using. As an example of why beginners shouldn't have CraftBukkit in their build path, read the first post on this thread in which a beginner accesses an NMS class and sets the displayName variable for absolutely no reason. And he could've done far more damage than that by accident.
     
  16. Offline

    CaptainUniverse

    ok whatever ill change to bukkit but can you please post some code for me i need help
     
  17. Offline

    Garris0n

    Well, uh...
     
  18. Offline

    CaptainUniverse

    WOW i wasted my time talking to someone WHO DOESNT EVEN KNOW WHAT HE IS DOING
    (or is just a really slow typer)
     
  19. Offline

    xMrPoi

    Oh ok, thanks.

    CaptainUniverse You said nothing is happening. What do you mean by that? Is it saying the command doesn't exist? You also shouldn't be messing around with CraftPlayer. Stick with the normal player class. Try removing all of the CraftPlayer things you've used.

    I hope you're kidding.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  20. Offline

    Garris0n

    I'm not really sure who you're responding to, but you've had the same question answered multiple times and I honestly have no clue what you want.

    Also, you should really read my signature.
     
  21. Offline

    CaptainUniverse

    . . .

    Ok fine forget everything i said.
    I want a plugin that makes your nametag say Jonny

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  22. Offline

    mine-care

    CaptainUniverse I think Garris0n already replayed.. Use p.setdisaplayname();
    And it will probably cause a skin error once skins are based on name... (They will apear as Steve's)
    Also when posting code use the [.code] and [./code] without the dots or use de button
     
  23. Offline

    CaptainUniverse

    some one HALP

    is there any way of it not being a Steve

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  24. Offline

    61352151511

    mine-care First off I've seen you all over the forums here and it looks like you know nothing about making a bukkit plugin, if he wants to set the display name that's easily done and shouldn't mess with the skin considering you use player.setDisplayName("Bob") and it will set their display name, not their real name, so skins are fine.

    CaptainUniverse Don't spam "HALP" your question has been answered multiple times and you just can't figure it out, if you can't figure it out after it being answered 5 times then give up. I'll write quick code that I'm not even going to test and if it works, great, if it doesn't, stop spamming and try and figure it out.

    Code:
    package me.SargentUniverse.DisplayTag;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
     
    public class MainClass extends JavaPlugin {
     
    private static final Logger log = Logger.getLogger("Minecraft");
     
    @SuppressWarnings("unused")
    @Override
    public void onEnable()
    {
    log.info("[DisplayTag] has been enabled!");
    PluginManager pm = getServer().getPluginManager(); }
    @Override
    public void onDisable()
    {
    log.info("[DisplayCode] has been disabled!");
    }
     
     
    public boolean onCommand(CommandSender sender, Command command,
    String commandlabel, String[] args) {
    if (commandlabel.equalsIgnoreCase("nameme")) {
    if (sender instanceof Player) {
    Player player = (Player) sender;
    player.setDisplayName(ChatColor.BLUE + "Jonny");
    ep.displayName = namebefore; }}
    return false;
    }
    }
    
    Completely untested, try it, make sure you have a plugin.yml and all other requirements, make sure you aren't using craft bukkit but you are using bukkit, I'm not going to fix it if it doesn't work, it should be simple enough to figure out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
    Garris0n likes this.
  25. Offline

    Garris0n

    mrkirby153 likes this.
  26. Offline

    CaptainUniverse

    ok ill test it ;) ask in a sec

    namebefore isnt a varriable and ep we still need to have Entity ep = etc

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  27. Offline

    PreFiXAUT

    Just what the ...hack... are you doing?! This is a Forum and not a damn Blog, so post only relevant things in here.

    When you don't know how to code then watch some Tutorials on YouTube, and don't flame everyone because you can't figure out what they mean. Nobody is just getting born with the entire knowledge of Bukkit, so you also need to learn it.
     
    caseif, mrkirby153 and xMrPoi like this.
  28. Offline

    xMrPoi

    Please learn the basics of Java.
     
  29. CaptainUniverse
    Can you try not to be such an annoying little brat? The user Garris0n is probably one of the best coders here and if he's bothering to help you try and show at least a little appreciation. I personally will not even try to help you from now on.
     
  30. Offline

    Jade

    Removed some irrelevant posts and locking this considering it's been answered many times and it's become essentially useless and derailed to all hells.
     
    lol768, slipcor and ZeusAllMighty11 like this.
Thread Status:
Not open for further replies.

Share This Page