First batch of command code cleanups.

This commit is contained in:
UnknownShadow200 2016-03-29 17:17:45 +11:00
parent 68b6b546f7
commit 2b68b93aba
13 changed files with 189 additions and 247 deletions

View File

@ -33,18 +33,15 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, "You must provide a name when using the command from console."); return;
}
if (message != "") {
Player who = PlayerInfo.Find(message);
if (who == null) {
ecos = Economy.RetrieveEcoStats(message);
Player.SendMessage(p, "%3===Economy stats for: %f" + ecos.playerName + "%7(offline)%3===");
} else {
ecos = Economy.RetrieveEcoStats(who.name);
Player.SendMessage(p, "%3===Economy stats for: " + who.color + who.name + "%3===");
}
int matches = 1;
Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message, out matches);
if (matches > 1) return;
if (matches == 0) {
ecos = Economy.RetrieveEcoStats(message);
Player.SendMessage(p, "%3===Economy stats for: %f" + ecos.playerName + "%7(offline)%3===");
} else {
ecos = Economy.RetrieveEcoStats(p.name);
Player.SendMessage(p, "%3===Economy stats for: " + p.color + p.name + "%3===");
ecos = Economy.RetrieveEcoStats(who.name);
Player.SendMessage(p, "%3===Economy stats for: " + who.color + who.name + "%3===");
}
Player.SendMessage(p, "Current balance: %f" + ecos.money + " %3" + Server.moneys);

View File

@ -14,11 +14,10 @@
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 CmdSlap : Command
{
*/
namespace MCGalaxy.Commands {
public sealed class CmdSlap : Command {
public override string name { get { return "slap"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
@ -26,32 +25,24 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public CmdSlap() { }
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)
{
Level which = LevelInfo.Find(message);
if (which == null)
{
Player.SendMessage(p, "Could not find player or map specified");
return;
int matches;
Player who = PlayerInfo.FindOrShowMatches(p, message, out matches);
if (matches > 1) return;
if (who == null) {
Level lvl = LevelInfo.Find(message);
if (lvl == null) {
Player.SendMessage(p, "Could not find player or map specified"); return;
}
else
{
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.level == which && pl.group.Permission < p.group.Permission)
Command.all.Find("slap").Use(p, pl.name);
}
return;
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.level == lvl && pl.group.Permission < p.group.Permission)
Command.all.Find("slap").Use(p, pl.name);
}
}
if (!Player.CanSee(p, who)) {
Player.SendMessage(p, "Could not find player or map specified"); return;
return;
}
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "You cannot slap someone ranked higher than you!"); return;
@ -72,7 +63,7 @@ namespace MCGalaxy.Commands
if (foundHeight == ushort.MaxValue) {
who.level.ChatLevel(who.color + who.DisplayName + " %Swas slapped sky high by " + src);
foundHeight = 1000;
}
}
who.SendPos(0xFF, who.pos[0], (ushort)(foundHeight * 32), who.pos[2], who.rot[0], who.rot[1]);
}

View File

@ -25,21 +25,20 @@ namespace MCGalaxy.Commands
public override string shortcut { get { return ""; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override string type { get { return CommandTypes.Moderation; } }
public override string type { get { return CommandTypes.Information; } }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
Player pl = PlayerInfo.Find(message);
if (pl != null && Player.CanSee(p, pl)) {
Player.SendMessage(p, pl.color + pl.name + " %Sis currently online.");
return;
int matches;
Player pl = PlayerInfo.FindOrShowMatches(p, message, out matches);
if (matches > 1) return;
if (matches == 1) {
Player.SendMessage(p, pl.color + pl.name + " %Sis currently online."); return;
}
OfflinePlayer target = PlayerInfo.FindOffline(message);
if (target == null) {
Player.SendMessage(p, "Unable to find player"); return;
}
if (target == null) { Player.SendMessage(p, "Unable to find player"); return; }
Player.SendMessage(p, message + " was last seen: " + target.lastLogin);
}

View File

@ -33,14 +33,15 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
Player pl = PlayerInfo.Find(message);
if (pl != null && Player.CanSee(p, pl)) {
int matches;
Player pl = PlayerInfo.FindOrShowMatches(p, message, out matches);
if (matches > 1) return;
if (matches == 1) {
Player.SendMessage(p, pl.color + pl.name + " %Sis online, using /whois instead.");
Command.all.Find("whois").Use(p, message);
return;
Command.all.Find("whois").Use(p, message); return;
}
if (message.IndexOf("'") != -1) { Player.SendMessage(p, "Cannot parse request."); return; }
if (!Player.ValidName(message)) { Player.SendMessage(p, "\"" + message + "\" is not a valid player name."); return; }
OfflinePlayer target = PlayerInfo.FindOffline(message, true);
string plGroup = Group.findPlayer(message.ToLower());

View File

@ -1,20 +1,20 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
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.
*/
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
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.IO;
namespace MCGalaxy.Commands
@ -23,61 +23,46 @@ namespace MCGalaxy.Commands
{
public override string name { get { return "jail"; } }
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 LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdJail() { }
public override void Use(Player p, string message)
{
if ((message.ToLower() == "set") && p != null)
{
public override void Use(Player p, string message) {
if (message.ToLower() == "set" && p != null) {
p.level.jailx = p.pos[0]; p.level.jaily = p.pos[1]; p.level.jailz = p.pos[2];
p.level.jailrotx = p.rot[0]; p.level.jailroty = p.rot[1];
Player.SendMessage(p, "Set Jail point.");
return;
}
else
{
Player who = PlayerInfo.Find(message);
if (who != null)
{
if (!who.jailed)
{
if (p != null)
{
if (who.group.Permission >= p.group.Permission) { Player.SendMessage(p, "Cannot jail someone of equal or greater rank."); return; }
Player.SendMessage(p, "You jailed " + who.DisplayName);
}
Player.GlobalDespawn(who, false);
who.jailed = true;
Player.GlobalSpawn(who, who.level.jailx, who.level.jaily, who.level.jailz, who.level.jailrotx, who.level.jailroty, true);
if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close();
Extensions.DeleteLineWord("ranks/jailed.txt", who.name);
using (StreamWriter writer = new StreamWriter("ranks/jailed.txt", true))
{
writer.WriteLine(who.name.ToLower() + " " + who.level.name);
}
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &8jailed", false);
}
else
{
if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close();
Extensions.DeleteLineWord("ranks/jailed.txt", who.name.ToLower());
who.jailed = false;
Command.all.Find("spawn").Use(who, "");
Player.SendMessage(p, "You freed " + who.name + " from jail");
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &afreed" + Server.DefaultColor + " from jail", false);
}
}
else
{
Player.SendMessage(p, "Could not find specified player.");
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) return;
if (!who.jailed) {
if (p != null &&who.group.Permission >= p.group.Permission) {
Player.SendMessage(p, "Cannot jail someone of equal or greater rank."); return;
}
Player.SendMessage(p, "You jailed " + who.DisplayName);
Player.GlobalDespawn(who, false);
who.jailed = true;
Player.GlobalSpawn(who, who.level.jailx, who.level.jaily, who.level.jailz, who.level.jailrotx, who.level.jailroty, true);
if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close();
Extensions.DeleteLineWord("ranks/jailed.txt", who.name);
using (StreamWriter writer = new StreamWriter("ranks/jailed.txt", true))
writer.WriteLine(who.name.ToLower() + " " + who.level.name);
Player.SendChatFrom(who, who.color + who.DisplayName + " %Swas &8jailed", false);
} else {
if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close();
Extensions.DeleteLineWord("ranks/jailed.txt", who.name.ToLower());
who.jailed = false;
Command.all.Find("spawn").Use(who, "");
Player.SendMessage(p, "You freed " + who.name + " from jail");
Player.SendChatFrom(who, who.color + who.DisplayName + " %Swas &afreed %Sfrom jail", false);
}
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/jail [user] - Places [user] in jail unable to use commands.");
Player.SendMessage(p, "/jail [set] - Creates the jail point for the map.");
Player.SendMessage(p, "This command has been deprecated in favor of /xjail.");

View File

@ -47,9 +47,9 @@ namespace MCGalaxy.Commands
if (param.Length == 2) // /move name map
{
Player who = PlayerInfo.Find(param[0]);
Player who = PlayerInfo.FindOrShowMatches(p, param[0]);
Level where = LevelInfo.Find(param[1]);
if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; }
if (who == null) return;
if (where == null) { Player.SendMessage(p, "Could not find level specified"); return; }
if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; }
@ -68,8 +68,8 @@ namespace MCGalaxy.Commands
if (param.Length == 4)
{
who = PlayerInfo.Find(param[0]);
if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; }
who = PlayerInfo.FindOrShowMatches(p, param[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; }
message = message.Substring(message.IndexOf(' ') + 1);
}

View File

@ -34,8 +34,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 nick of someone of greater rank"); return;
}

View File

@ -30,11 +30,8 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) {
string[] parts = message.Split(trimChars, 3);
Player target = PlayerInfo.Find(parts[0]);
if (target == null) {
Player.SendMessage(p, "No online player found matching: " + parts[0]); return;
}
Player target = PlayerInfo.FindOrShowMatches(p, parts[0]);
if (target == null) return;
if (p != null && p.group.Permission < target.group.Permission) {
Player.SendMessage(p, "Cannot use this on someone of equal or greater rank."); return;
}

View File

@ -86,7 +86,7 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You do not have any pending teleport requests!"); return;
}
Player who = PlayerInfo.Find(p.senderName);
Player who = PlayerInfo.FindExact(p.senderName);
p.Request = false;
p.senderName = "";
if (who == null) {
@ -127,7 +127,7 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You do not have any pending teleport requests!"); return;
}
Player who = PlayerInfo.Find(p.senderName);
Player who = PlayerInfo.FindExact(p.senderName);
p.Request = false;
p.senderName = "";
if (who == null) {

View File

@ -1,117 +1,97 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
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.
*/
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
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.IO;
namespace MCGalaxy.Commands
{
public sealed class CmdXJail : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdXJail : Command {
public override string name { get { return "xjail"; } }
public override string shortcut { get { return "xj"; } }
public override string type { get { return CommandTypes.Other; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override bool museumUsable { get { return true; } }
public override void Help(Player p)
{
Player.SendMessage(p, "/xjail <player> - Mutes <player>, freezes <player> and sends <player> to the XJail map (shortcut = /xj)");
Player.SendMessage(p, "If <player> is already jailed, <player> will be spawned, unfrozen and unmuted");
Player.SendMessage(p, "/xjail set - Sets the map to be used for xjail to your current map and sets jail to current location");
}
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
string dir = "extra/jail/";
string jailMapFile = dir + "xjail.map.xjail";
if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); }
if (!File.Exists(jailMapFile))
{
if (!File.Exists(jailMapFile)) {
using (StreamWriter SW = new StreamWriter(jailMapFile))
{
SW.WriteLine(Server.mainLevel.name);
}
}
if (message == "") { Help(p); return; }
else
{
using (StreamReader SR = new StreamReader(jailMapFile))
{
string xjailMap = SR.ReadLine();
SR.Close();
Command jail = Command.all.Find("jail");
if (message == "set")
{
if (!p.level.IsMuseum)
{
jail.Use(p, "create");
using (StreamWriter SW = new StreamWriter(jailMapFile))
{
SW.WriteLine(p.level.name);
}
Player.SendMessage(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'");
return;
}
else { Player.SendMessage(p, "You are in a museum!"); return; }
using (StreamReader SR = new StreamReader(jailMapFile)) {
string xjailMap = SR.ReadLine();
SR.Close();
Command jail = Command.all.Find("jail");
if (message == "set") {
if (!p.level.IsMuseum) {
jail.Use(p, "create");
using (StreamWriter SW = new StreamWriter(jailMapFile))
SW.WriteLine(p.level.name);
Player.SendMessage(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'");
} else {
Player.SendMessage(p, "You are in a museum!");
}
else
{
Player player = PlayerInfo.Find(message);
return;
}
Player pl = PlayerInfo.FindOrShowMatches(p, message);
if (pl == null) return;
if (player != null)
{
Command move = Command.all.Find("move");
Command spawn = Command.all.Find("spawn");
Command freeze = Command.all.Find("freeze");
Command mute = Command.all.Find("mute");
string playerFile = dir + player.name + "_temp.xjail";
if (!File.Exists(playerFile))
{
using (StreamWriter writeFile = new StreamWriter(playerFile))
{
writeFile.WriteLine(player.level.name);
}
if (!player.muted) { mute.Use(p, message); }
if (!player.frozen) { freeze.Use(p, message); }
move.Use(p, message + " " + xjailMap);
player.BlockUntilLoad(10);
if (!player.jailed) { jail.Use(p, message); }
Player.GlobalMessage(player.color + player.DisplayName + Server.DefaultColor + " was XJailed!");
return;
}
else
{
using (StreamReader readFile = new StreamReader(playerFile))
{
string playerMap = readFile.ReadLine();
readFile.Close();
File.Delete(playerFile);
move.Use(p, message + " " + playerMap);
player.BlockUntilLoad(10);
mute.Use(p, message);
jail.Use(p, message);
freeze.Use(p, message);
spawn.Use(player, "");
Player.GlobalMessage(player.color + player.DisplayName + Server.DefaultColor + " was released from XJail!");
}
return;
}
}
else { Player.SendMessage(p, "Player not found"); return; }
Command move = Command.all.Find("move");
Command spawn = Command.all.Find("spawn");
Command freeze = Command.all.Find("freeze");
Command mute = Command.all.Find("mute");
string playerFile = dir + pl.name + "_temp.xjail";
if (!File.Exists(playerFile)) {
using (StreamWriter writeFile = new StreamWriter(playerFile))
writeFile.WriteLine(pl.level.name);
if (!pl.muted) { mute.Use(p, message); }
if (!pl.frozen) { freeze.Use(p, message); }
move.Use(p, message + " " + xjailMap);
pl.BlockUntilLoad(10);
if (!pl.jailed) { jail.Use(p, message); }
Player.GlobalMessage(pl.color + pl.DisplayName + Server.DefaultColor + " was XJailed!");
} else {
using (StreamReader readFile = new StreamReader(playerFile)) {
string playerMap = readFile.ReadLine();
readFile.Close();
File.Delete(playerFile);
move.Use(p, message + " " + playerMap);
pl.BlockUntilLoad(10);
mute.Use(p, message);
jail.Use(p, message);
freeze.Use(p, message);
spawn.Use(pl, "");
Player.GlobalMessage(pl.color + pl.DisplayName + Server.DefaultColor + " was released from XJail!");
}
}
}
}
public override void Help(Player p) {
Player.SendMessage(p, "/xjail <player> - Mutes <player>, freezes <player> and sends <player> to the XJail map (shortcut = /xj)");
Player.SendMessage(p, "If <player> is already jailed, <player> will be spawned, unfrozen and unmuted");
Player.SendMessage(p, "/xjail set - Sets the map to be used for xjail to your current map and sets jail to current location");
}
}
}

View File

@ -19,39 +19,31 @@
*/
using System;
namespace MCGalaxy.Commands
{
public class CmdXspawn : Command
{
namespace MCGalaxy.Commands {
public class CmdXspawn : Command {
public override string name { get { return "xspawn"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override void Use(Player p, string message)
{
Player player = PlayerInfo.Find(message.Split(' ')[0]);
if (player == null)
{
Player.SendMessage(p, "Error: " + player.color + player.name + Server.DefaultColor + " was not found");
return;
public override void Use(Player p, string message) {
Player pl = PlayerInfo.FindOrShowMatches(p, message);
if (pl == null) return;
if (pl == p) {
Player.SendMessage(p, "Use /spawn to respawn yourself."); return;
}
if (player == p)
{
Player.SendMessage(p, "Error: Seriously? Just use /spawn!");
return;
if (p != null && pl.group.Permission >= p.group.Permission) {
Player.SendMessage(p, "Cannot respawn someone of greater or same rank"); return;
}
if (player.group.Permission > p.group.Permission)
{
Player.SendMessage(p, "Cannot move someone of greater rank");
return;
}
Command.all.Find("spawn").Use(player, "");
Player.SendMessage(p, "Succesfully spawned " + player.color + player.DisplayName + Server.DefaultColor + ".");
Player.GlobalMessage(player.color + player.name + Server.DefaultColor + " was respawned by " + p.color + p.DisplayName + Server.DefaultColor + ".");
Command.all.Find("spawn").Use(pl, "");
Player.SendMessage(p, "Succesfully spawned " + pl.color + pl.DisplayName + "%S.");
string src = p == null ? "(console)" : p.color + p.DisplayName;
Player.GlobalMessage(pl.color + pl.name + " %Swas respawned by " + src + "%S.");
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/xspawn [player] - Spawn another player.");
Player.SendMessage(p, "WARNING: It says who used it!");
}

View File

@ -103,7 +103,7 @@ namespace MCGalaxy.Games {
Player first = null;
do {
first = QueuedZombie != null ?
PlayerInfo.Find(QueuedZombie) : players[random.Next(players.Count)];
PlayerInfo.FindExact(QueuedZombie) : players[random.Next(players.Count)];
QueuedZombie = null;
} while (first == null || !first.level.name.CaselessEq(CurLevelName));
return first;

View File

@ -227,6 +227,7 @@
<Compile Include="Commands\Information\CmdPlayers.cs" />
<Compile Include="Commands\Information\CmdRules.cs" />
<Compile Include="Commands\Information\CmdSearch.cs" />
<Compile Include="Commands\Information\CmdSeen.cs" />
<Compile Include="Commands\Information\CmdServerReport.cs" />
<Compile Include="Commands\Information\CmdStaff.cs" />
<Compile Include="Commands\Information\CmdTime.cs" />
@ -289,7 +290,6 @@
<Compile Include="Commands\Moderation\CmdRestart.cs" />
<Compile Include="Commands\Moderation\CmdRestoreSelection.cs" />
<Compile Include="Commands\Moderation\CmdReveal.cs" />
<Compile Include="Commands\Moderation\CmdSeen.cs" />
<Compile Include="Commands\Moderation\CmdSetRank.cs" />
<Compile Include="Commands\Moderation\CmdShutdown.cs" />
<Compile Include="Commands\Moderation\CmdTempBan.cs" />