Update more commands to use PlayerInfo.FindOrShowMatches, cleanup some commands.

This commit is contained in:
UnknownShadow200 2016-03-11 11:59:02 +11:00
parent ec0080c586
commit 464d66443f
25 changed files with 238 additions and 367 deletions

View File

@ -34,8 +34,8 @@ namespace MCGalaxy.Commands {
string[] args = message.Split(trimChars, 2);
if (args.Length > 1) {
who = PlayerInfo.Find(args[0]);
if (who == null) { Player.SendMessage(p, "Player \"" + args[0] + "\" does not exist"); return; }
who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) return;
} else {
if (p == null) { Player.SendMessage(p, "Console can't use this command on itself."); return; }
}

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
Player who = PlayerInfo.FindOrShowMatches(message);
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
string giver = (p == null) ? "(console)" : p.color + p.DisplayName;

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
Player who = PlayerInfo.FindOrShowMatches(message);
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (p != null && p.muted) { Player.SendMessage(p, "Cannot use /hug while muted."); return; }

View File

@ -92,15 +92,10 @@ namespace MCGalaxy.Commands
Command.all.Find("goto").Use(pl, Server.mainLevel.name);
}
} else if (cmd == "KICK") {
if (arg == "") {
p.SendMessage("You must specify a player to kick.");
return;
}
if (arg == "") { p.SendMessage("You must specify a player to kick."); return; }
Player kicked = PlayerInfo.Find(arg);
if (kicked == null) {
p.SendMessage("Error: Player not found.");
} else {
Player kicked = PlayerInfo.FindOrShowMatches(p, arg);
if (kicked != null) {
if (kicked.level.name == p.level.name)
Command.all.Find("goto").Use(kicked, Server.mainLevel.name);
else
@ -320,11 +315,10 @@ namespace MCGalaxy.Commands
string path = "levels/blacklists/" + p.level.name + ".txt";
EnsureFileExists(path);
value = value.Replace("+", "");
if (!value.EndsWith("+")) value += "+";
if (!File.ReadAllText(path).Contains(value)) {
Player.SendMessage(p, value + " is not blacklisted."); return;
}
value = value + "+";
try {
var oldLines = File.ReadAllLines(path);

View File

@ -15,57 +15,35 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
public sealed class CmdFakePay : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdFakePay : Command {
public override string name { get { return "fakepay"; } }
public override string shortcut { get { return "fpay"; } }
public override string type { get { return CommandTypes.Economy; } }
public override bool museumUsable { get { return true; } }
public override void Help(Player p)
{
Player.SendMessage(p, "/fakepay <name> <amount> - Sends a fake give change message.");
}
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
var split = message.Split(' ');
Player who = PlayerInfo.Find(split[0]);
if (who == null)
{
Player.SendMessage(p, Server.DefaultColor + "Player not found!");
return;
}
string[] args = message.Split(' ');
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) return;
int amount = 0;
try
{
amount = int.Parse(split[1]);
if (args.Length == 1 || !int.TryParse(args[1], out amount)) {
Player.SendMessage(p, "You must specify an integer amount to fakepay."); return;
}
catch/* (Exception ex)*/
{
Player.SendMessage(p, "How much do you want to fakepay them?");
return;
if (amount < 0) { Player.SendMessage(p, "You can't fakepay a negative amount."); return; }
if (amount >= 16777215) { Player.SendMessage(p, "You can only fakepay up to 16777215."); return; }
Player.GlobalMessage(who.color + who.prefix + who.DisplayName + " %Swas given " + amount + " " + Server.moneys);
}
if (amount < 0)
{
Player.SendMessage(p, Server.DefaultColor + "You can't fakepay a negative amount.");
return;
}
if (amount >= 16777215)
{
Player.SendMessage(p, "Whoa, that's too much money. Try less than 16777215.");
return;
}
Player.GlobalMessage(who.color + who.prefix + who.DisplayName + Server.DefaultColor + " was given " + amount + " " + Server.moneys);
public override void Help(Player p) {
Player.SendMessage(p, "/fakepay <name> <amount> - Sends a fake give change message.");
}
}
}

View File

@ -200,10 +200,9 @@ namespace MCGalaxy.Commands {
return;
}
Player who = PlayerInfo.Find(target);
if (who == null) {
Player.SendMessage(p, "That wasn't an online player."); return;
} else if (p.group.Permission < who.group.Permission) {
Player who = PlayerInfo.FindOrShowMatches(p, target);
if (who == null) return;
if (p.group.Permission < who.group.Permission) {
Player.SendMessage(p, "You can't send rules to someone of a higher rank than yourself!!"); return;
} else {
Player.SendMessage(who, "Countdown rules sent to you by " + p.color + p.name);

View File

@ -27,10 +27,8 @@ namespace MCGalaxy.Commands {
public CmdDisInfect() { }
public override void Use(Player p, string message) {
Player who = message == "" ? p : PlayerInfo.Find(message);
if (who == null) {
Player.SendMessage(p, "There is no player \"" + message + "\"!"); return;
}
Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (!who.infected || !Server.zombie.GameInProgess()) {
Player.SendMessage(p, "Cannot disinfect player");

View File

@ -27,10 +27,8 @@ namespace MCGalaxy.Commands {
public CmdInfect() { }
public override void Use(Player p, string message) {
Player who = message == "" ? p : PlayerInfo.Find(message);
if (who == null) {
Player.SendMessage(p, "There is no player \"" + message + "\"!"); return;
}
Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (who.infected || !Server.zombie.GameInProgess()) {
Player.SendMessage(p, "Cannot infect player");

View File

@ -33,24 +33,14 @@ namespace MCGalaxy.Commands
string value = args[1];
if (args[0] == "zombie") {
Player who = PlayerInfo.Find(value);
if (who == null) {
p.SendMessage(value + " is not online.");
} else {
Player who = PlayerInfo.FindOrShowMatches(p, value);
if (who == null) return;
p.SendMessage(value + " was queued.");
Server.zombie.queZombie = true;
Server.zombie.nextZombie = value;
}
} else if (args[0] == "level") {
bool match = false;
DirectoryInfo di = new DirectoryInfo("levels/");
FileInfo[] fi = di.GetFiles("*.lvl");
foreach (FileInfo file in fi) {
if (file.Name.Replace(".lvl", "").ToLower() == value.ToLower())
match = true;
}
if (match) {
if (LevelInfo.ExistsOffline(value)) {
p.SendMessage(value + " was queued.");
Server.zombie.queLevel = true;
Server.zombie.nextLevel = value.ToLower();

View File

@ -315,7 +315,7 @@ namespace MCGalaxy.Commands
default:
if (text[1] != null && (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1))
{
Player who = PlayerInfo.Find(text[1]);
Player who = PlayerInfo.FindOrShowMatches(p, text[1]);
if (who != null)
{
Player.SendMessage(who, "TNT Wars Rules: (sent to you by " + p.color + p.name + Server.DefaultColor + " )");
@ -324,14 +324,9 @@ namespace MCGalaxy.Commands
Player.SendMessage(who, "During the game the amount of TNT placable at one time may be limited!");
Player.SendMessage(who, "You are not allowed to use hacks of any sort during the game!");
Player.SendMessage(p, "TNT Wars: Sent rules to " + who.color + who.name);
return;
}
else
{
Player.SendMessage(p, "TNT Wars Error: Couldn't find player '" + text[1] + "' to send rules to!");
return;
}
}
else
{
Player.SendMessage(p, "TNT Wars Rules:");

View File

@ -14,13 +14,13 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
*/
using System.Collections.Generic;
using System.IO;
namespace MCGalaxy.Commands
{
public sealed class CmdFaq : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdFaq : Command {
public override string name { get { return "faq"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } }
@ -30,39 +30,26 @@ namespace MCGalaxy.Commands
get { return new[] { new CommandPerm(LevelPermission.Builder, "The lowest rank that can send the faq to other players") }; }
}
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (!File.Exists("text/faq.txt")) {
CP437Writer.WriteAllText("text/faq.txt", "Example: What does this server run on? This server runs on &bMCGalaxy");
}
List<string> faq = CP437Reader.ReadAllLines("text/faq.txt");
Player who = null;
if (message != "")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this))
{ Player.SendMessage(p, "You can't send the FAQ to another player!"); return; }
who = PlayerInfo.Find(message);
}
else
{
who = p;
Player who = p;
if (message != "") {
if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) {
Player.SendMessage(p, "Your rank cannot send the FAQ to other players."); return; }
who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
}
if (who != null)
{
who.SendMessage("&cFAQ&f:");
foreach (string s in faq)
who.SendMessage("&f" + s);
}
else
{
Player.SendMessage(p, "There is no player \"" + message + "\"!");
}
Player.SendMessage(who, "&cFAQ&f:");
foreach (string line in faq)
Player.SendMessage(who, "&f" + line);
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/faq [player]- Displays frequently asked questions");
}
}

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands
}
else
{
Player who = PlayerInfo.FindOrShowMatches(message);
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (who.lastCMD.Contains("setpass") || who.lastCMD.Contains("pass"))
{

View File

@ -14,7 +14,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
*/
using System.Collections.Generic;
using System.IO;
@ -31,49 +31,38 @@ namespace MCGalaxy.Commands
get { return new[] { new CommandPerm(LevelPermission.Operator, "The lowest rank that can send the news to everyone") }; }
}
public override void Use(Player p, string message)
{
string newsFile = "text/news.txt";
if (!File.Exists(newsFile))
{
CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'.");
return;
const string newsFile = "text/news.txt";
public override void Use(Player p, string message) {
if (!File.Exists(newsFile)) {
CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'."); return;
}
List<string> lines = CP437Reader.ReadAllLines(newsFile);
if (message == "")
{
foreach (string t in lines)
{
Player.SendMessage(p, t);
if (message == "") {
foreach (string line in lines)
Player.SendMessage(p, line);
return;
}
}
else
{
string[] split = message.Split(' ');
if (split[0] == "all") {
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) {
string[] args = message.Split(' ');
if (args[0] == "all") {
if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) {
Player.SendMessage(p, "You must be at least " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " to send this to all players.");
return;
}
for (int k = 0; k < lines.Count; k++) {
Player.GlobalMessage(lines[k]);
}
foreach (string line in lines)
Player.GlobalMessage(line);
return;
}
Player player = PlayerInfo.Find(split[0]);
if (player == null) { Player.SendMessage(p, "Could not find player \"" + split[0] + "\"!"); return; }
foreach (string t in lines)
{
Player.SendMessage(player, t);
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) return;
foreach (string line in lines)
Player.SendMessage(who, line);
Player.SendMessage(p, "The News were successfully sent to " + who.name + ".");
}
Player.SendMessage(p, "The News were successfully sent to " + player.name + ".");
}
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/news - Shows server news.");
Player.SendMessage(p, "/news <player> - Sends the News to <player>.");
Player.SendMessage(p, "/news all - Sends the News to everyone.");

View File

@ -37,7 +37,7 @@ namespace MCGalaxy.Commands
Player who = p;
if (message != "") {
who = PlayerInfo.FindOrShowMatches(message);
who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (p != null && p.group.Permission < who.group.Permission) {
Player.SendMessage(p, "You cannot send /oprules to a higher or same ranked player."); return;

View File

@ -32,14 +32,10 @@ namespace MCGalaxy.Commands {
string[] args = message.Split(' ');
if (args.Length > 2) { Help(p); return; }
if (args.Length == 1) { Player.SendMessage(p, "You did not specify the target player."); return; }
Player source = PlayerInfo.Find(args[0]), target = PlayerInfo.Find(args[1]);
if ((source == null || !Player.CanSee(p, source)) && (target == null || !Player.CanSee(p, target))) {
Player.SendMessage(p, "Neither of the players specified are online."); return;
}
if (source == null || !Player.CanSee(p, source)) { Player.SendMessage(p, "The source player is not online."); return; }
if (target == null || !Player.CanSee(p, target)) { Player.SendMessage(p, "The target player is not online."); return; }
Player source = PlayerInfo.FindOrShowMatches(p, args[0]);
Player target = PlayerInfo.FindOrShowMatches(p, args[1]);
if (source == null || target == null) return;
if (p.group.Permission < source.group.Permission) {
Player.SendMessage(p, "You cannot force a player of higher rank to tp to another player."); return;
}

View File

@ -56,9 +56,9 @@ namespace MCGalaxy.Commands {
ReloadMap(p, who, true);
}
} else {
Player who = PlayerInfo.Find(parts[0]);
Player who = PlayerInfo.FindOrShowMatches(p, parts[0]);
if (who == null) {
Player.SendMessage(p, "Could not find player."); return;
return;
} else if (who.group.Permission > p.group.Permission && p != who) {
Player.SendMessage(p, "Cannot reload the map of someone higher than you."); return;
}

View File

@ -14,7 +14,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
*/
namespace MCGalaxy.Commands
{
public sealed class CmdVoice : Command
@ -26,34 +26,24 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdVoice() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
Player who = PlayerInfo.Find(message);
if (who != null)
{
if (who.voice)
{
who.voice = false;
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (who.voice) {
Player.SendMessage(p, "Removing voice status from " + who.color + who.DisplayName);
who.SendMessage("Your voice status has been revoked.");
who.voicestring = "";
}
else
{
who.voice = true;
} else {
Player.SendMessage(p, "Giving voice status to " + who.color + who.DisplayName);
who.SendMessage("You have received voice status.");
who.voicestring = "&f+";
}
who.voice = !who.voice;
}
else
{
Player.SendMessage(p, "There is no player online named \"" + message + "\"");
}
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/voice <name> - Toggles voice status on or off for specified player.");
}
}

View File

@ -33,12 +33,8 @@ namespace MCGalaxy.Commands
if (Server.voteKickInProgress) { Player.SendMessage(p, "Please wait for the current vote to finish!"); return; }
Player who = PlayerInfo.Find(message);
if (who == null)
{
Player.SendMessage(p, "Could not find player specified!");
return;
}
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (who.group.Permission >= p.group.Permission)
{

View File

@ -15,87 +15,48 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
public sealed class CmdWarn : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdWarn : Command {
public override string name { get { return "warn"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
string reason;
public override void Use(Player p, string message)
{
string warnedby;
static char[] trimChars = { ' ' };
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.Split(trimChars, 2);
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
Player who = PlayerInfo.Find(message.Split(' ')[0]);
// Make sure we have a valid player
if (who == null)
{
Player.SendMessage(p, "Player not found!");
return;
if (who == null) return;
if (who == p) { Player.SendMessage(p, "you can't warn yourself"); return; }
if (p != null && p.group.Permission <= who.group.Permission) {
Player.SendMessage(p, "Cannot warn a player of equal or higher rank."); return;
}
// Don't warn yourself... derp
if (who == p)
{
Player.SendMessage(p, "you can't warn yourself");
return;
}
// Check the caller's rank
if (p != null && p.group.Permission <= who.group.Permission)
{
Player.SendMessage(p, "Cannot warn a player of equal or higher rank.");
return;
}
// We need a reason
if (message.Split(' ').Length == 1)
{
// No reason was given
reason = "you know why.";
}
else
{
reason = message.Substring(message.IndexOf(' ') + 1).Trim();
}
warnedby = (p == null) ? "<CONSOLE>" : p.color + p.DisplayName;
string reason = args.Length == 1 ? "you know why." : args[1];
string warnedby = (p == null) ? "<CONSOLE>" : p.color + p.DisplayName;
Player.GlobalMessage(warnedby + " %ewarned " + who.color + who.DisplayName + " %ebecause:");
Player.GlobalMessage("&c" + reason);
Server.IRC.Say(warnedby + " %ewarned " + who.color + who.DisplayName + " %efor: %c" + reason);
Server.s.Log(warnedby + " warned " + who.name);
//Player.SendMessage(who, "Do it again ");
if (who.warn == 0)
{
if (who.warn == 0) {
Player.SendMessage(who, "Do it again twice and you will get kicked!");
who.warn = 1;
return;
}
if (who.warn == 1)
{
} else if (who.warn == 1) {
Player.SendMessage(who, "Do it one more time and you will get kicked!");
who.warn = 2;
return;
}
if (who.warn == 2)
{
Player.GlobalMessage(who.color + who.DisplayName + " " + Server.DefaultColor + "was warn-kicked by " + warnedby);
who.warn = 0;
} else if (who.warn == 2) {
Player.GlobalMessage(who.color + who.DisplayName + " " + "%Swas warn-kicked by " + warnedby);
who.Kick("KICKED BECAUSE " + reason + "");
return;
}
who.warn++;
}
public override void Help(Player p)
{
Player.SendMessage(p, "/warn <player> - Warns a player.");
public override void Help(Player p) {
Player.SendMessage(p, "/warn <player> <reason> - Warns a player.");
Player.SendMessage(p, "Player will get kicked after 3 warnings.");
}
}

View File

@ -31,8 +31,8 @@ namespace MCGalaxy.Commands {
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
Player who = PlayerInfo.Find(args[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the color of someone of greater rank"); return;
}

View File

@ -29,15 +29,11 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message)
{
Player who = message == "" ? p : PlayerInfo.Find(message);
if (who == null || !Player.CanSee(p, who)) {
Player.SendMessage(p, "Cannot find player."); return;
}
Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission)
{
Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank");
return;
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank");return;
}
if (who.invincible)

View File

@ -45,13 +45,12 @@ namespace MCGalaxy.Commands
return;
}
Player who = PlayerInfo.Find(message);
if (who == null || !Player.CanSee(p, who)) { Player.SendMessage(p, "There is no player \"" + message + "\"!"); return; }
if (p.group.Permission < who.group.Permission)
{
Player.SendMessage(p, "You cannot summon someone ranked higher than you!");
return;
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (p.group.Permission < who.group.Permission) {
Player.SendMessage(p, "You cannot summon someone ranked higher than you!"); return;
}
if (p.level != who.level)
{
Player.SendMessage(p, who.DisplayName + " is in a different Level. Forcefetching has started!");

View File

@ -31,8 +31,8 @@ namespace MCGalaxy.Commands {
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
Player who = PlayerInfo.Find(args[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the title color of someone of greater rank"); return;
}

View File

@ -32,8 +32,8 @@ namespace MCGalaxy.Commands {
if (message == "") { Help(p); return; }
string[] parts = message.Split(trimChars, 2);
Player who = PlayerInfo.Find(parts[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
Player who = PlayerInfo.FindOrShowMatches(p, parts[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the title of someone of greater rank"); return;
}

View File

@ -83,8 +83,13 @@ namespace MCGalaxy {
}
public static Player FindOrShowMatches(Player pl, string name, bool onlyCanSee = true) {
int matches = 0;
return FindOrShowMatches(pl, name, out matches, onlyCanSee);
}
public static Player FindOrShowMatches(Player pl, string name, out int matches, bool onlyCanSee = true) {
Player[] players = PlayerInfo.Online;
Player match = null; int matches = 0;
Player match = null; matches = 0;
name = name.ToLower();
StringBuilder matchNames = new StringBuilder();