[Tutorial] Teams - Name color and Wool Hats asigned to Player

Discussion in 'Resources' started by ProFatal, Jun 14, 2012.

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

    JollyGiant16

    ProFatal
    Would you mind posting a source code of the whole thing because I'm getting errors while trying to load it.
     
  2. Offline

    p000ison

    K but anywais thanks nice idea to resend the package :p
    Works great
     
  3. Offline

    ProFatal

    Where about is the errors?
    Thanks :p
     
  4. Offline

    sutr90

    So does anyone have a solution for skin change?
    I have found out, that when you reload the world, e.g. go to Nehter or End, the skin is fixed. Is there any better option?
     
  5. Can you provide an example code (source on git-hub), Please.
    I am new to all this and even though I have gone through tutorials on how to make a plugin there are still things missing.
    The getcommand in the main class and the pInWorld is underlined red?

    I have already get got the Bukkit API and Craftbukkit in my library
     
  6. Offline

    JxAxVxAx

  7. I have that but there are still errors like the craftplayer is underlined and the craftplayer.java is in CraftBukkit also the EntityPlayer is in CraftBukkit?
     
  8. Offline

    p000ison

    .... EntityPlayer is from net.minecraft, CraftPlayer is from CraftBukkit; you have to use Player from the org.bukkit package
     
  9. Thanks, now that is sorted I still have errors at Playerteams and log:
    Show Spoiler

    ----------------------------------------------------------------------------------------------
    public class BukkitPlugin {

    public void onEnable(){
    this.getCommand("blue").setExecutor(new TeamExecutor(this));
    this.getCommand("red").setExecutor(new TeamExecutor(this));
    this.getCommand("leave").setExecutor(new TeamExecutor(this));
    }


    }

    ----------------------------------------------------------------------------------------------
    public class HashMap {

    private final PlayerListener playerListener = new PlayerListener(this);
    final HashMap<String, String> playerTeams = new HashMap<String, String>();


    plugin.playerTeams.put(changingName.name, team);

    for(Player pInWorld : plugin.getServer().getOnlinePlayers()){
    if(pInWorld != p){
    ((CraftPlayer) pInWorld).getHandle().netServerHandler.sendPacket(new Packet20NamedEntitySpawn(changingName));
    }
    }
    changingName.name = oldName;
    plugin.playerTeams.put(changingName.name, team);
    }

    PluginManager pm = this.getServer().getPluginManager();
    pm.registerEvents(this.playerListener,this);

    --------------------------------------------------------------------------------------------------

    public class PlayerListener implements Listener {
    private BukkitPlugin plugin;

    public PlayerListener(BukkitPlugin plugin){
    this.plugin = plugin;
    }

    }
    private void onPlayerJoin(PlayerJoinEvent e){
    Player player = e.getPlayer();
    plugin.playerTeams.put(player.getName(), "leave");
    if(plugin.playerTeams.get(player.getName())==null){
    plugin.log.info("An ERROR has occured in the onPlayerJoin function, report this asap.");
    }
    }

    private void onPlayerQuit(PlayerQuitEvent e){
    Player player = e.getPlayer();
    if(plugin.playerTeams.get(player.getName())!=null && plugin.playerTeams.get(player.getName())!="leave"){
    plugin.log.info(player.getName()+" was removed from the "+plugin.playerTeams.get(player.getName())+" team [Successful]");
    }else{
    plugin.log.info(player.getName()+" was removed from the internal DataBase [Successful]");
    }
    plugin.playerTeams.remove(player.getName());
    if(plugin.playerTeams.get(player.getName())!=null){
    plugin.log.info("An ERROR has occured in the onPlayerQuit function, report this asap.");
    }
    }

    }



    There are No errors on TeamExecute
     
  10. Offline

    FTWin01Gurl

    We should make a library out of this, so people can hook in and do some functionality. I can do that very simply.
     
  11. Go ahead, I would like that!
     
  12. Offline

    p000ison

  13. Offline

    ProFatal

    Can you tell me more as I am would like to help people with this since it looks like a lot of people are interested.
     
  14. Offline

    FTWin01Gurl

    I'll make it ATM.
     
  15. Offline

    ProFatal

    <font color="#ff0000">I ALSO ADDED THIS TO MAIN POST</font>
    Right people of the bukkit forum I have compacted this code so now it is more user friendly


    <font color="#3366ff">Download : <Edit by Moderator: Redacted mediafire url>
    <font color="#ff9900">or</font>

    Show Spoiler
    Code:
    import net.minecraft.server.EntityPlayer;
    import net.minecraft.server.Packet20NamedEntitySpawn;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.entity.Player;
     
    public class ColorNames {
     
        private Player player;
     
        public ColorNames(Player player,String color){
            this.player = player;
            for(ChatColor chatc  : ChatColor.values()){
                if(replaceString(chatc).equalsIgnoreCase(color)){
                    setPlayerName(chatc.toString());
                }
            }
        }
     
        private String replaceString(ChatColor color){
            String chatcolorReplace = color.name().replaceAll("_","");
            return chatcolorReplace;
        }
     
        private void setPlayerName(String color){
            String oldName = player.getName();
     
            EntityPlayer changingName = ((CraftPlayer)player).getHandle();
            changingName.name = color+player.getName();
            for(Player playerinworld : Bukkit.getOnlinePlayers()){
                if(playerinworld != player){
                    ((CraftPlayer)playerinworld).getHandle().netServerHandler.sendPacket(new Packet20NamedEntitySpawn(changingName));
                }
            }
            changingName.name = oldName;
        }
    }
    



    After you have created a class for this all you need to do to call it is
    Code:
    new ColorNames(player, COLORYOUWANT);
    so e.g
    Code:
    new ColorNames(player, "red");
     
    Last edited by a moderator: Nov 10, 2016
  16. Offline

    Steffion

    Hello, first good tutorial
    second I have a question.
    Does your skin won't show up? Because in the vid your skin does change...
    Please say how to do that.
     
  17. Offline

    ProFatal

    I can hardly understand what you are saying but im presuming that you are talking about how to stop the skin from changing on the player.

    Well lets just get this cleared out when the name gets changed it gets changed from e.g
    Player to &4Player
    but since &4 is the color code it gets represented as then it assigns the default minecraft skin to the player.

    I don't think there is a way around this unless there was a mod that the player had installed and went with the server plugin or something.
     
  18. Offline

    Steffion

    ProFatal Ok, damn notch... Btw thanks for the great tut it learnt me some more things!
     
  19. Offline

    roflcopter399

    Wait, so say like on a command /color red, can I see the code on how to apply that cus I am a bit confused with the whole new ColorName(player, "red")
     
  20. Offline

    ProFatal

    On the first post there is a section " Video Tutorial" and it will take you step by step on doing this
     
  21. Offline

    ProFatal

    I have included a download link to a test plugin where you can test this on your server including a name changer included in the plugin. hope you enjoy it and if you find any bugs please tell me and ill try and fix them.
     
  22. Offline

    DanielSturk

    AMAZING! You know your stuff! I've been looking all over the internet for little snippets of this code, and now I found all of it in one place? Thank you so much!
     
  23. Offline

    ProFatal

    No problem and thanks
     
  24. Offline

    Limeth

    Would you please help me out?
    import net.minecraft.server.EntityPlayer;
    import net.minecraft.server.Packet20NamedEntitySpawn;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    are underlined :( What should I do?
    it says "The import ... cannot be resolved)
     
  25. Offline

    Bent_9999

    Hi. Im a no0b at making plugins. Im trying to make it so that its not just one /<command>. I want it more to be like /<command> <color>.

    I understand, i suck. But thats why i need your help!!!

    all you need to do is import craftbukkit.jar as a referenced library

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

    Limeth

    It isnt all of them underlined, just those. and I got craftbukkit.jar installed already.
     
  27. Offline

    Kodfod

  28. Offline

    Steffion

    Kodfod Yup. It will will work.
     
  29. Offline

    Bent_9999

    did you import it as a referenced library?
     
  30. Offline

    Limeth

    yep, I did
     
Thread Status:
Not open for further replies.

Share This Page