Prefixes and Accessing Player Info

  • Hello!

    I would like to create a few plugins to help server management, but I'm new to this whole plugin-creation business. I've seen my fair share of Bukkit Minecraft plugins, so I think I'll add some of those ideas to the Eco community! :D

    I'd like to make customizable prefixes, and a /tp command that teleports you to a specified player. I know the prefix part sounds a little too ambitious for a newbie, but I'm willing to work at it.

    However, I do have a lot of questions, and that's what this post is for! For starters (and please don't judge my lack of knowledge here :P):

    • Text - where would I find code about chat in the source code? I found User Handles, but I'm not sure if that's how I would go about changing what usernames look like. I'm also interested in chat color, and I know that's possible because building names show up in green and usernames show up in blue.
    • Other players - how would I access the username or coordinates of a specified player that is on a server? Is that possible? (If the command argument - a player's username - corresponds to the username of a player on the server I'd like to fetch their coordinates and set those coordinates to the coordinates of the player who sent the command.)
    • Accessing the user class - how can I add an array to every player who's been on / who is on the server?

    Thank you!!

  • Text
    ChatServer.SendServerMessage => send message to all online player
    'user'.player.SendMessage => send message to this user(must check player is null(offlin) or not
    Find other player

  • Also check out the Chat Command files, you can easily add special commands for doing things in the server.

  • @SLG_K @JohnK Thank you so much!

    SLG_K, how would I check if the player is null/offline or not, and where would text go in ChatServer.SendServerMessage? Would it be ChatServer.SendServerMessage("text goes here")?

  • @anna
    how would I check if the player is null/offline or not
    var user = UserManager.FindUser(username);
    if(user.player != null) // user is online
    // do some thing

    where would text go in ChatServer.SendServerMessage? Would it be ChatServer.SendServerMessage("text goes here")?
    public void SendServerMessage(string msg, float time = 3)


  • @SLG_K You guys are so helpful ... I can't deal with this...

    [updated, I don't want to spam] How do I know what to import for the plugin? (My current code is here:

  • @SLG_K said:

    var user = UserManager.FindUser(username);

    I've been doing a little research and I noticed that most times UserManager is used, it has .Obj attached to it. In fact, nowhere in the code does it ever have UserManager.FindUser. It only has UserManager.Obj.FindUser.

    Is this an exception, or should I add in .Obj?

  • @SLG_K

    Hi! :D I've been working and came across an error with displaying text... :/
    I worked off code you guys wrote for displaying various text... And here's what I got for one of my messages:

    player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Teleported.");

    Gave me an error with the $. What's wrong with this? (I realized that it's supposed to be 'user'.player.SendMessage but in this case, the user is a variable called player (when you type a command. So would I just do player.player.SendMessage?) - also I think it should be 'user'.Player.SendMessage... :/

    ^^ Even making it player.player.SendMessage didn't fix the $ error.

    Please help! Thank you!

  • did a quick look and .. so here is what i found :

    player.Player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Teleported.");

    player.Player is not realy working .. i guess thats the issue and not the $ sign
    it should look more like
    player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Teleported.");

    so your code should look more like this :

    using System;
    using Eco.Gameplay;
    using Eco.Gameplay.Players;
    using Eco.Shared.Math;
    using Mods.Misc;
    using Mods.Misc.PermissionsMaster;
    using Eco.Shared;
    using Eco.Shared.Utils.Text;

    namespace Eco.Server.Plugins
    class TPCommandHandler: IChatCommandHandler

        // permission names
        private const string TPPOS_PERMISSION = "";
        private const string TP_PERMISSION = "";
        private const string TPJUMP_PERMISSION = "";
        public bool Process(string command, string args, Player player, bool isAdminPlayer)
            switch (command)
                case "tppos":
                    // does the player have the correct permissions to execute this command?
                    if (PermissionsMaster.Obj.hasPermission(player.ToString(), TPPOS_PERMISSION, player) || isAdminPlayer)
                        var pos = args.Split(new[] { ' ' }, 3);
                        player.SetPosition(new Vector3(Convert.ToInt32(pos[0]), Convert.ToInt32(pos[1]), Convert.ToInt32(pos[2])));
                        player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Teleported.");
                        return true;
                case "tp":
                    // does the player have the correct permissions to execute this command?
                    if (PermissionsMaster.Instance.hasPermission(player.ToString(), TP_PERMISSION, player) || isAdminPlayer)
                        var tpto = UserManager.Obj.FindUser(args);
                        if (tpto.player != null) // user is online
                            player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Teleported.");
                            player.SendMessage($"{Text.Bold(Text.Color(0x000000, "["))}{Text.Bold(Text.Color(0x00cc00, "Teleport"))}{Text.Bold(Text.Color(0x000000, "]"))} Invalid arguments.");
                        return true;
            return false;


    also you forgot the break statement so that you got the following error " Control cannot fall through from one case label"

    hope that helps you

    PS: i took the code from your github .. but its missing most of it so i cant look future in to it or test it

    edit 2 : btw i think .. if i am not wrong ,, you can download visual studio community version create a new project and create your plugins there ( it will really help you get the code right ) if i am not wrong you can even add reference by just having the server exe and dll's . that can help you to peek into the classes and some of its code ( you can easily see what each thing needs and returns ) but you wont get the inner working code .. but you dont really need that =P just a tip =P

  • @anna $ is new shorthand in C# 6.0 for string.Format. The runtime compiler does not yet have support for this, so if your code is all in the mods project, you will have to compose the string the old way with string.Format.


    $"You got {someValue} berries!" => string.Format("You got {0} berries!", someValue);

  • @Metachronism Thank you so much!

  • @NoBlackThunder Okay wow, thank you so much! I'll look into Visual Studio Community Version... I've been kind of winging it on the code syntax and stuff :D

    What's the use of namespace Eco.Server.Plugins?

  • dependency possibly ... thats why i always use visual studio .. it tells you if you are missing reference .. it basically test your code in a basic but very efficient matter and helps you with awesome intellisense

  • @NoBlackThunder GRRRRR ITS A .EXE
    Is there a Mac equivalent???

  • ohhh...... you have a mac .. well that makes things different .. there is another tool called visual studio code ( that is for mac and linux) but i cant tell really if that has all the great features like the windows version has

  • sneaks in
    sneaks out

    Edit: The things missing in "code" are the designer and ALM tools. Besides that you will still have the full featured editor, debugger as well as the source code management.

  • *sneaks up behind @ThatGerman and @NoBlackThunder* thanks for the tip! *sneaks away*

  • @ThatGerman The visual code debugger isn't working, I think...Typing in a bunch of random words doesn't produce an error (and I know it should). This makes me think I could be missing some bugs. How do I go about spotting them?

  • @anna said:

    visual code debugger

    Debugger or lexer/syntax check (compiler)? I'm confused.

  • @ThatGerman Not quite sure. What I mean is, when I type my code in, it doesn't make a squiggly red line under any improper code segments like Eclipse does for Java.

    And then when I go to Debugger mode and press run, I get the error message "spawn mono ENOENT" :( suggestions?

Log in to reply