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); string[] args = message.Split(trimChars, 2);
if (args.Length > 1) { if (args.Length > 1) {
who = PlayerInfo.Find(args[0]); who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) { Player.SendMessage(p, "Player \"" + args[0] + "\" does not exist"); return; } if (who == null) return;
} else { } else {
if (p == null) { Player.SendMessage(p, "Console can't use this command on itself."); return; } 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) { public override void Use(Player p, string message) {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
Player who = PlayerInfo.FindOrShowMatches(message); Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return; if (who == null) return;
string giver = (p == null) ? "(console)" : p.color + p.DisplayName; 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) { public override void Use(Player p, string message) {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
Player who = PlayerInfo.FindOrShowMatches(message); Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return; if (who == null) return;
if (p != null && p.muted) { Player.SendMessage(p, "Cannot use /hug while muted."); 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); Command.all.Find("goto").Use(pl, Server.mainLevel.name);
} }
} else if (cmd == "KICK") { } else if (cmd == "KICK") {
if (arg == "") { if (arg == "") { p.SendMessage("You must specify a player to kick."); return; }
p.SendMessage("You must specify a player to kick.");
return;
}
Player kicked = PlayerInfo.Find(arg); Player kicked = PlayerInfo.FindOrShowMatches(p, arg);
if (kicked == null) { if (kicked != null) {
p.SendMessage("Error: Player not found.");
} else {
if (kicked.level.name == p.level.name) if (kicked.level.name == p.level.name)
Command.all.Find("goto").Use(kicked, Server.mainLevel.name); Command.all.Find("goto").Use(kicked, Server.mainLevel.name);
else else
@ -320,11 +315,10 @@ namespace MCGalaxy.Commands
string path = "levels/blacklists/" + p.level.name + ".txt"; string path = "levels/blacklists/" + p.level.name + ".txt";
EnsureFileExists(path); EnsureFileExists(path);
value = value.Replace("+", ""); if (!value.EndsWith("+")) value += "+";
if (!File.ReadAllText(path).Contains(value)) { if (!File.ReadAllText(path).Contains(value)) {
Player.SendMessage(p, value + " is not blacklisted."); return; Player.SendMessage(p, value + " is not blacklisted."); return;
} }
value = value + "+";
try { try {
var oldLines = File.ReadAllLines(path); var oldLines = File.ReadAllLines(path);

View File

@ -1,71 +1,49 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdFakePay : Command public sealed class CmdFakePay : Command {
{
public override string name { get { return "fakepay"; } } public override string name { get { return "fakepay"; } }
public override string shortcut { get { return "fpay"; } } public override string shortcut { get { return "fpay"; } }
public override string type { get { return CommandTypes.Economy; } } public override string type { get { return CommandTypes.Economy; } }
public override bool museumUsable { get { return true; } } 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 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; } if (message == "") { Help(p); return; }
var split = message.Split(' '); string[] args = message.Split(' ');
Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
Player who = PlayerInfo.Find(split[0]); if (who == null) return;
if (who == null)
{ int amount = 0;
Player.SendMessage(p, Server.DefaultColor + "Player not found!"); if (args.Length == 1 || !int.TryParse(args[1], out amount)) {
return; Player.SendMessage(p, "You must specify an integer amount to fakepay."); return;
} }
if (amount < 0) { Player.SendMessage(p, "You can't fakepay a negative amount."); return; }
int amount = 0; if (amount >= 16777215) { Player.SendMessage(p, "You can only fakepay up to 16777215."); return; }
try
{
amount = int.Parse(split[1]);
}
catch/* (Exception ex)*/
{
Player.SendMessage(p, "How much do you want to fakepay them?");
return;
}
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);
Player.GlobalMessage(who.color + who.prefix + who.DisplayName + " %Swas 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; return;
} }
Player who = PlayerInfo.Find(target); Player who = PlayerInfo.FindOrShowMatches(p, target);
if (who == null) { if (who == null) return;
Player.SendMessage(p, "That wasn't an online player."); return; if (p.group.Permission < who.group.Permission) {
} else if (p.group.Permission < who.group.Permission) {
Player.SendMessage(p, "You can't send rules to someone of a higher rank than yourself!!"); return; Player.SendMessage(p, "You can't send rules to someone of a higher rank than yourself!!"); return;
} else { } else {
Player.SendMessage(who, "Countdown rules sent to you by " + p.color + p.name); 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 CmdDisInfect() { }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
Player who = message == "" ? p : PlayerInfo.Find(message); Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message);
if (who == null) { if (who == null) return;
Player.SendMessage(p, "There is no player \"" + message + "\"!"); return;
}
if (!who.infected || !Server.zombie.GameInProgess()) { if (!who.infected || !Server.zombie.GameInProgess()) {
Player.SendMessage(p, "Cannot disinfect player"); Player.SendMessage(p, "Cannot disinfect player");

View File

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

View File

@ -33,24 +33,14 @@ namespace MCGalaxy.Commands
string value = args[1]; string value = args[1];
if (args[0] == "zombie") { if (args[0] == "zombie") {
Player who = PlayerInfo.Find(value); Player who = PlayerInfo.FindOrShowMatches(p, value);
if (who == null) { if (who == null) return;
p.SendMessage(value + " is not online.");
} else {
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) { p.SendMessage(value + " was queued.");
Server.zombie.queZombie = true;
Server.zombie.nextZombie = value;
} else if (args[0] == "level") {
if (LevelInfo.ExistsOffline(value)) {
p.SendMessage(value + " was queued."); p.SendMessage(value + " was queued.");
Server.zombie.queLevel = true; Server.zombie.queLevel = true;
Server.zombie.nextLevel = value.ToLower(); Server.zombie.nextLevel = value.ToLower();

View File

@ -315,7 +315,7 @@ namespace MCGalaxy.Commands
default: default:
if (text[1] != null && (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) 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) if (who != null)
{ {
Player.SendMessage(who, "TNT Wars Rules: (sent to you by " + p.color + p.name + Server.DefaultColor + " )"); Player.SendMessage(who, "TNT Wars Rules: (sent to you by " + p.color + p.name + Server.DefaultColor + " )");
@ -324,13 +324,8 @@ namespace MCGalaxy.Commands
Player.SendMessage(who, "During the game the amount of TNT placable at one time may be limited!"); 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(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); 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;
} }
return;
} }
else else
{ {

View File

@ -1,26 +1,26 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdFaq : Command public sealed class CmdFaq : Command {
{
public override string name { get { return "faq"; } } public override string name { get { return "faq"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } } 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") }; } 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")) { if (!File.Exists("text/faq.txt")) {
CP437Writer.WriteAllText("text/faq.txt", "Example: What does this server run on? This server runs on &bMCGalaxy"); 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"); List<string> faq = CP437Reader.ReadAllLines("text/faq.txt");
Player who = null; Player who = p;
if (message != "") if (message != "") {
{ if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) {
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) Player.SendMessage(p, "Your rank cannot send the FAQ to other players."); return; }
{ Player.SendMessage(p, "You can't send the FAQ to another player!"); return; } who = PlayerInfo.FindOrShowMatches(p, message);
who = PlayerInfo.Find(message); if (who == null) return;
}
else
{
who = p;
}
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"); Player.SendMessage(p, "/faq [player]- Displays frequently asked questions");
} }
} }

View File

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

View File

@ -1,20 +1,20 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -31,52 +31,41 @@ namespace MCGalaxy.Commands
get { return new[] { new CommandPerm(LevelPermission.Operator, "The lowest rank that can send the news to everyone") }; } 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) const string newsFile = "text/news.txt";
{ public override void Use(Player p, string message) {
string newsFile = "text/news.txt"; if (!File.Exists(newsFile)) {
if (!File.Exists(newsFile)) CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'."); return;
{
CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'.");
return;
} }
List<string> lines = CP437Reader.ReadAllLines(newsFile); List<string> lines = CP437Reader.ReadAllLines(newsFile);
if (message == "") if (message == "") {
{ foreach (string line in lines)
foreach (string t in lines) Player.SendMessage(p, line);
{ return;
Player.SendMessage(p, t);
}
} }
else
{ string[] args = message.Split(' ');
string[] split = message.Split(' '); if (args[0] == "all") {
if (split[0] == "all") { if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) {
if ((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.");
Player.SendMessage(p, "You must be at least " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " to send this to all players."); return;
return;
}
for (int k = 0; k < lines.Count; k++) {
Player.GlobalMessage(lines[k]);
}
return;
} }
foreach (string line in lines)
Player player = PlayerInfo.Find(split[0]); Player.GlobalMessage(line);
if (player == null) { Player.SendMessage(p, "Could not find player \"" + split[0] + "\"!"); return; } return;
foreach (string t in lines)
{
Player.SendMessage(player, t);
}
Player.SendMessage(p, "The News were successfully sent to " + player.name + ".");
} }
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 + ".");
} }
public override void Help(Player p)
{ public override void Help(Player p) {
Player.SendMessage(p, "/news - Shows server news."); Player.SendMessage(p, "/news - Shows server news.");
Player.SendMessage(p, "/news <player> - Sends the News to <player>."); Player.SendMessage(p, "/news <player> - Sends the News to <player>.");
Player.SendMessage(p, "/news all - Sends the News to everyone."); Player.SendMessage(p, "/news all - Sends the News to everyone.");
} }
} }
} }

View File

@ -37,7 +37,7 @@ namespace MCGalaxy.Commands
Player who = p; Player who = p;
if (message != "") { if (message != "") {
who = PlayerInfo.FindOrShowMatches(message); who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return; if (who == null) return;
if (p != null && p.group.Permission < who.group.Permission) { if (p != null && p.group.Permission < who.group.Permission) {
Player.SendMessage(p, "You cannot send /oprules to a higher or same ranked player."); return; 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(' '); string[] args = message.Split(' ');
if (args.Length > 2) { Help(p); return; } if (args.Length > 2) { Help(p); return; }
if (args.Length == 1) { Player.SendMessage(p, "You did not specify the target player."); 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]); Player source = PlayerInfo.FindOrShowMatches(p, args[0]);
Player target = PlayerInfo.FindOrShowMatches(p, 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; }
if (source == null || target == null) return;
if (p.group.Permission < source.group.Permission) { if (p.group.Permission < source.group.Permission) {
Player.SendMessage(p, "You cannot force a player of higher rank to tp to another player."); return; 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); ReloadMap(p, who, true);
} }
} else { } else {
Player who = PlayerInfo.Find(parts[0]); Player who = PlayerInfo.FindOrShowMatches(p, parts[0]);
if (who == null) { if (who == null) {
Player.SendMessage(p, "Could not find player."); return; return;
} else if (who.group.Permission > p.group.Permission && p != who) { } else if (who.group.Permission > p.group.Permission && p != who) {
Player.SendMessage(p, "Cannot reload the map of someone higher than you."); return; Player.SendMessage(p, "Cannot reload the map of someone higher than you."); return;
} }

View File

@ -1,59 +1,49 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands
{ {
public sealed class CmdVoice : Command public sealed class CmdVoice : Command
{ {
public override string name { get { return "voice"; } } public override string name { get { return "voice"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdVoice() { } public CmdVoice() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
Player who = PlayerInfo.Find(message); Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who != null) if (who == null) return;
{
if (who.voice) if (who.voice) {
{ Player.SendMessage(p, "Removing voice status from " + who.color + who.DisplayName);
who.voice = false; who.SendMessage("Your voice status has been revoked.");
Player.SendMessage(p, "Removing voice status from " + who.color + who.DisplayName); who.voicestring = "";
who.SendMessage("Your voice status has been revoked."); } else {
who.voicestring = ""; Player.SendMessage(p, "Giving voice status to " + who.color + who.DisplayName);
} who.SendMessage("You have received voice status.");
else who.voicestring = "&f+";
{
who.voice = true;
Player.SendMessage(p, "Giving voice status to " + who.color + who.DisplayName);
who.SendMessage("You have received voice status.");
who.voicestring = "&f+";
}
}
else
{
Player.SendMessage(p, "There is no player online named \"" + message + "\"");
} }
who.voice = !who.voice;
} }
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."); 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; } if (Server.voteKickInProgress) { Player.SendMessage(p, "Please wait for the current vote to finish!"); return; }
Player who = PlayerInfo.Find(message); Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) if (who == null) return;
{
Player.SendMessage(p, "Could not find player specified!");
return;
}
if (who.group.Permission >= p.group.Permission) if (who.group.Permission >= p.group.Permission)
{ {

View File

@ -1,101 +1,62 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdWarn : Command public sealed class CmdWarn : Command {
{
public override string name { get { return "warn"; } } public override string name { get { return "warn"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
string reason; static char[] trimChars = { ' ' };
public override void Use(Player p, string message)
{
string warnedby;
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
string[] args = message.Split(trimChars, 2);
Player who = PlayerInfo.Find(message.Split(' ')[0]); Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
// Make sure we have a valid player if (who == null) return;
if (who == null) if (who == p) { Player.SendMessage(p, "you can't warn yourself"); return; }
{ if (p != null && p.group.Permission <= who.group.Permission) {
Player.SendMessage(p, "Player not found!"); Player.SendMessage(p, "Cannot warn a player of equal or higher rank."); return;
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 string reason = args.Length == 1 ? "you know why." : args[1];
if (message.Split(' ').Length == 1) string warnedby = (p == null) ? "<CONSOLE>" : p.color + p.DisplayName;
{
// No reason was given
reason = "you know why.";
}
else
{
reason = message.Substring(message.IndexOf(' ') + 1).Trim();
}
warnedby = (p == null) ? "<CONSOLE>" : p.color + p.DisplayName;
Player.GlobalMessage(warnedby + " %ewarned " + who.color + who.DisplayName + " %ebecause:"); Player.GlobalMessage(warnedby + " %ewarned " + who.color + who.DisplayName + " %ebecause:");
Player.GlobalMessage("&c" + reason); Player.GlobalMessage("&c" + reason);
Server.IRC.Say(warnedby + " %ewarned " + who.color + who.DisplayName + " %efor: %c" + reason); Server.IRC.Say(warnedby + " %ewarned " + who.color + who.DisplayName + " %efor: %c" + reason);
Server.s.Log(warnedby + " warned " + who.name); 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!"); Player.SendMessage(who, "Do it again twice and you will get kicked!");
who.warn = 1; } else if (who.warn == 1) {
return;
}
if (who.warn == 1)
{
Player.SendMessage(who, "Do it one more time and you will get kicked!"); Player.SendMessage(who, "Do it one more time and you will get kicked!");
who.warn = 2; } else if (who.warn == 2) {
return; Player.GlobalMessage(who.color + who.DisplayName + " " + "%Swas warn-kicked by " + warnedby);
}
if (who.warn == 2)
{
Player.GlobalMessage(who.color + who.DisplayName + " " + Server.DefaultColor + "was warn-kicked by " + warnedby);
who.warn = 0;
who.Kick("KICKED BECAUSE " + reason + ""); who.Kick("KICKED BECAUSE " + reason + "");
return;
} }
who.warn++;
} }
public override void Help(Player p)
{ public override void Help(Player p) {
Player.SendMessage(p, "/warn <player> - Warns a player."); Player.SendMessage(p, "/warn <player> <reason> - Warns a player.");
Player.SendMessage(p, "Player will get kicked after 3 warnings."); Player.SendMessage(p, "Player will get kicked after 3 warnings.");
} }
} }

View File

@ -31,8 +31,8 @@ namespace MCGalaxy.Commands {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
string[] args = message.Split(' '); string[] args = message.Split(' ');
Player who = PlayerInfo.Find(args[0]); Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; } if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) { if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the color of someone of greater rank"); return; 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) public override void Use(Player p, string message)
{ {
Player who = message == "" ? p : PlayerInfo.Find(message); Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message);
if (who == null || !Player.CanSee(p, who)) { if (who == null) return;
Player.SendMessage(p, "Cannot find player."); return;
}
if (p != null && who.group.Permission > p.group.Permission) if (p != null && who.group.Permission > p.group.Permission) {
{ Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank");return;
Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank");
return;
} }
if (who.invincible) if (who.invincible)

View File

@ -45,13 +45,12 @@ namespace MCGalaxy.Commands
return; return;
} }
Player who = PlayerInfo.Find(message); Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null || !Player.CanSee(p, who)) { Player.SendMessage(p, "There is no player \"" + message + "\"!"); return; } if (who == null) return;
if (p.group.Permission < who.group.Permission) if (p.group.Permission < who.group.Permission) {
{ Player.SendMessage(p, "You cannot summon someone ranked higher than you!"); return;
Player.SendMessage(p, "You cannot summon someone ranked higher than you!");
return;
} }
if (p.level != who.level) if (p.level != who.level)
{ {
Player.SendMessage(p, who.DisplayName + " is in a different Level. Forcefetching has started!"); 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; } if (message == "") { Help(p); return; }
string[] args = message.Split(' '); string[] args = message.Split(' ');
Player who = PlayerInfo.Find(args[0]); Player who = PlayerInfo.FindOrShowMatches(p, args[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; } if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) { if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the title color of someone of greater rank"); return; 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; } if (message == "") { Help(p); return; }
string[] parts = message.Split(trimChars, 2); string[] parts = message.Split(trimChars, 2);
Player who = PlayerInfo.Find(parts[0]); Player who = PlayerInfo.FindOrShowMatches(p, parts[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; } if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) { if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the title of someone of greater rank"); return; 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) { 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[] players = PlayerInfo.Online;
Player match = null; int matches = 0; Player match = null; matches = 0;
name = name.ToLower(); name = name.ToLower();
StringBuilder matchNames = new StringBuilder(); StringBuilder matchNames = new StringBuilder();