QuiCM / EssentialsPlus

Essentials and MoreAdminCommands plugins for Terraria, merged and bettered
12 stars 28 forks source link

Version 1.2.0 - API 2.1 Update #10

Closed jujaga closed 7 years ago

jujaga commented 7 years ago

Attempt fixes on /find and /pvp commands Update references to 1.3.5.3 Update README.md

Signed-off-by: Jeremy Ho jujaga@gmail.com

jujaga commented 7 years ago

These modifications are by no means total fixes for /find and /pvp. These were mainly flagged because the updated libraries changed the signatures. They should not crash the server anymore when executed, but I suspect their behaviors are not back in line with intended effects.

QuiCM commented 7 years ago

Thanks for the PR - I've identified the issues and I'll provide you with the code so you can read over it and learn. If you could then add it in another commit, I'll accept this PR :)

PvP Command

{
    e.TPlayer.hostile = !e.TPlayer.hostile;
    TSPlayer.All.SendData(PacketTypes.TogglePvp, "", e.Player.Index);
    string hostile = Language.GetTextValue("LegacyMultiplayer.11", e.Player.Name);
    string unhostile = Language.GetTextValue("LegacyMultiplayer.12", e.Player.Name);
    TSPlayer.All.SendMessage(e.TPlayer.hostile ? hostile : unhostile, Main.teamColor[e.Player.Team]);
}

Lang.mp[11] has been exported to a file and can now be fetched with Language.GetTextValue("LegacyMultiplayer.12");. This provides a string in the format "{0} has enabled pvp", and GetTextValue allows us to provide the format arguments directly. Relevant files:

Find Command -item switch

for (int i = 0; i < ItemID.Count; i++)
{
    if (Lang.GetItemNameValue(i).ContainsInsensitive(match.Groups[2].Value))
    {
        items.Add(String.Format("{0} (ID: {1})", Lang.GetItemNameValue(i), i));
    }
}

Main.itemName was an array that no longer exists. Instead, we can use Lang.GetItemNameValue(int id) to retrieve the name of an Item by its ID. ItemID is a class that contains IDs for every item. ItemID.Count is the highest ID + 1 Relevant files:

Find Command -npc switch

for (int i = 0; i < NPCID.Count; i++)
{
    if (Lang.GetNPCNameValue(i).ContainsInsensitive(match.Groups[2].Value))
    {
        npcs.Add(String.Format("{0} (ID: {1})", Lang.GetNPCNameValue(i), i));
    }
}

Pretty much the same as before, but we use NPCID.Count and Lang.GetNPCNameValue Relevant files:

Let me know if any of this is unclear or you'd like further explanation!

jujaga commented 7 years ago

Thanks @WhiteXZ! It's good to know that I should refer to https://github.com/NyxStudios/Sources. I've integrated your suggested changes in the latest commit.