mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Make /awards [player] show all awards, green colour if they have the award, red if not
This commit is contained in:
parent
2b08731477
commit
7c30976868
@ -20,58 +20,43 @@ using System.Collections.Generic;
|
|||||||
using MCGalaxy.Eco;
|
using MCGalaxy.Eco;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Eco {
|
namespace MCGalaxy.Commands.Eco {
|
||||||
public sealed class CmdAwards : Command2 {
|
public sealed class CmdAwards : Command2 {
|
||||||
public override string name { get { return "Awards"; } }
|
public override string name { get { return "Awards"; } }
|
||||||
public override string type { get { return CommandTypes.Economy; } }
|
public override string type { get { return CommandTypes.Economy; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
string[] args = message.SplitSpaces();
|
string[] args = message.SplitSpaces();
|
||||||
if (args.Length > 2) { Help(p); return; }
|
if (args.Length > 2) { Help(p); return; }
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
List<Awards.Award> awards = Awards.AwardsList;
|
string name = "";
|
||||||
string name = "";
|
StringFormatter<Awards.Award> formatter = FormatServerAward;
|
||||||
|
|
||||||
if (args.Length == 2 || (message.Length > 0 && !IsListModifier(args[0]))) {
|
if (args.Length == 2 || (message.Length > 0 && !IsListModifier(args[0]))) {
|
||||||
offset = 1;
|
offset = 1;
|
||||||
name = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
name = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
|
||||||
|
|
||||||
if (name == null) return;
|
if (name == null) return;
|
||||||
awards = AwardsHas(name);
|
List<string> playerAwards = Awards.GetPlayerAwards(name);
|
||||||
|
formatter = (award) => FormatPlayerAward(award, playerAwards);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (awards.Count == 0) {
|
List<Awards.Award> awards = Awards.AwardsList;
|
||||||
if (name.Length > 0) {
|
if (awards.Count == 0) { p.Message("This server has no awards yet."); return; }
|
||||||
p.Message("{0} %Shas no awards.", PlayerInfo.GetColoredName(p, name));
|
|
||||||
} else {
|
|
||||||
p.Message("This server has no awards yet.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string cmd = name.Length == 0 ? "awards" : "awards " + name;
|
string cmd = name.Length == 0 ? "awards" : "awards " + name;
|
||||||
string modifier = args.Length > offset ? args[offset] : "";
|
string modifier = args.Length > offset ? args[offset] : "";
|
||||||
|
|
||||||
MultiPageOutput.Output(p, awards, FormatAward,
|
MultiPageOutput.Output(p, awards, formatter,
|
||||||
cmd, "Awards", modifier, true);
|
cmd, "Awards", modifier, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Awards.Award> AwardsHas(string name) {
|
static string FormatPlayerAward(Awards.Award award, List<string> awards) {
|
||||||
List<Awards.Award> awards = new List<Awards.Award>();
|
bool has = awards != null && awards.CaselessContains(award.Name);
|
||||||
List<string> playerAwards = Awards.GetPlayerAwards(name);
|
return (has ? "&a" : "&c") + award.Name + ": &7" + award.Description;
|
||||||
if (playerAwards == null) return awards;
|
|
||||||
|
|
||||||
foreach (string awardName in playerAwards) {
|
|
||||||
Awards.Award award = new Awards.Award();
|
|
||||||
award.Name = awardName;
|
|
||||||
|
|
||||||
Awards.Award match = Awards.FindExact(awardName);
|
|
||||||
if (match != null) award.Description = match.Description;
|
|
||||||
awards.Add(award);
|
|
||||||
}
|
|
||||||
return awards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string FormatAward(Awards.Award award) {
|
static string FormatServerAward(Awards.Award award) {
|
||||||
return "&6" + award.Name + ": &7" + award.Description;
|
return "&6" + award.Name + ": &7" + award.Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user