Cleanup /color, /xcolor, /title, /xtitle, /tcolor, and /xtcolor to have 78.4% less code duplication.

This commit is contained in:
UnknownShadow200 2016-01-29 14:14:24 +11:00
parent 1bac264497
commit b598359545
8 changed files with 191 additions and 536 deletions

View File

@ -68,7 +68,6 @@ namespace MCGalaxy
Add(Command.all.Find("draw"), (int)Command.all.Find("draw").defaultRank, "The lowest rank that can use pyramids with /draw", 2);
Add(Command.all.Find("draw"), (int)Command.all.Find("draw").defaultRank, "The lowest rank that can use spheres with /draw", 3);
Add(Command.all.Find("draw"), (int)Command.all.Find("draw").defaultRank, "The lowest rank that can use volcanos with /draw", 4);
Add(Command.all.Find("title"), (int)LevelPermission.Operator, "The lowest rank that can change other's titles");
Add(Command.core.Find("tntwars"), (int)LevelPermission.Operator, "The lowest rank that can use admin commands for tntwars", 1);
}

View File

@ -1,114 +1,91 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
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
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
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
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.
*/
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands {
public sealed class CmdColor : Command {
public override string name { get { return "color"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdColor() { }
public override void Use(Player p, string message) {
if ( message == "" || message.Split(' ').Length > 2 ) { Help(p); return; }
int pos = message.IndexOf(' ');
if ( pos != -1 ) {
Player who = Player.Find(message.Substring(0, pos));
if ( p != null && who.group.Permission > p.group.Permission ) { Player.SendMessage(p, "You cannot change the color of someone ranked higher than you!"); return; }
if ( who == null ) { Player.SendMessage(p, "There is no player \"" + message.Substring(0, pos) + "\"!"); return; }
if ( message.Substring(pos + 1) == "del" ) {
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET color = '' WHERE name = @Name");
Player.GlobalChat(who, who.color + "*" + Name(who.DisplayName) + " color reverted to " + who.group.color + "their group's default" + Server.DefaultColor + ".", false);
who.color = who.group.color;
Player.GlobalDespawn(who, false);
Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false);
who.SetPrefix();
return;
}
string color = Colors.Parse(message.Substring(pos + 1));
if ( color == "" ) { Player.SendMessage(p, "There is no color \"" + message + "\"."); }
else if ( color == who.color ) { Player.SendMessage(p, who.DisplayName + " already has that color."); }
else {
//Player.GlobalChat(who, p.color + "*" + p.name + "&e changed " + who.color + Name(who.name) +
// " color to " + color +
// c.Name(color) + "&e.", false);
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET color = @Color WHERE name = @Name");
Player.GlobalChat(who, who.color + "*" + Name(who.DisplayName) + " color changed to " + color + Colors.Name(color) + Server.DefaultColor + ".", false);
if ( p == null ) {
Player.SendMessage(p, "*" + Name(who.DisplayName) + " color was changed to " + Colors.Name(color) + ".");
}
who.color = color;
Player.GlobalDespawn(who, false);
Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false);
who.SetPrefix();
}
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
Player who = Player.Find(args[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the color of someone of greater rank"); return;
}
else {
if ( p != null ) {
if ( message == "del" ) {
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = '' WHERE name = @Name");
Player.GlobalChat(p, p.color + "*" + Name(p.DisplayName) + " color reverted to " + p.group.color + "their group's default" + Server.DefaultColor + ".", false);
p.color = p.group.color;
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
p.SetPrefix();
return;
}
string color = Colors.Parse(message);
if ( color == "" ) { Player.SendMessage(p, "There is no color \"" + message + "\"."); }
else if ( color == p.color ) { Player.SendMessage(p, "You already have that color."); }
else {
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = @Color WHERE name = @Name");
Player.GlobalChat(p, p.color + "*" + Name(p.DisplayName) + " color changed to " + color + Colors.Name(color) + Server.DefaultColor + ".", false);
p.color = color;
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
p.SetPrefix();
}
}
if (args.Length == 1) {
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " had their color removed.", false);
p.color = p.group.color;
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = '' WHERE name = @Name");
} else {
string color = Colors.Parse(args[1]);
if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); return; }
else if (color == p.color) { Player.SendMessage(p, who.DisplayName + " already has that color."); return; }
Player.GlobalChat(who, who.color + who.DisplayName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
p.color = color;
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = @Color WHERE name = @Name");
}
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
p.SetPrefix();
}
public override void Help(Player p) {
Player.SendMessage(p, "/color [player] <color/del>- Changes the nick color. Using 'del' removes color.");
Player.SendMessage(p, "/color <player> [color] - Gives <player> the nick color of [color].");
Player.SendMessage(p, "If no [color] is specified, player's nick color reverts to group default.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
static string Name(string name) {
string ch = name[name.Length - 1].ToString().ToLower();
if ( ch == "s" || ch == "x" ) { return name + Server.DefaultColor + "'"; }
else { return name + Server.DefaultColor + "'s"; }
}
}
public sealed class CmdXColor : Command {
public override string name { get { return "xcolor"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdXColor() { }
public override void Use(Player p, string message) {
Command.all.Find("color").Use(p, p.name + " " + message);
}
public override void Help(Player p) {
Player.SendMessage(p, "/xcolor [color] - Gives you the nick color of [color].");
Player.SendMessage(p, "If no [color] is specified, your nick color reverts to group default.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
}
}

View File

@ -1,25 +1,25 @@
/*
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
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.
*/
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdTColor : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdTColor : Command {
public override string name { get { return "tcolor"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
@ -27,52 +27,62 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdTColor() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
Player who = Player.Find(args[0]);
if (who == null)
{
Player.SendMessage(p, "Could not find player.");
return;
}
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "You cannot change the title color of someone ranked higher than you");
return;
}
if (args.Length == 1)
{
who.titlecolor = "";
Player.SendMessage(p, "Cannot change the title color of someone of greater rank"); return;
}
if (args.Length == 1) {
Player.GlobalChat(who, who.color + who.DisplayName + Server.DefaultColor + " had their title color removed.", false);
who.titlecolor = "";
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET title_color = '' WHERE Name = @Name");
who.SetPrefix();
return;
}
else
{
} else {
string color = Colors.Parse(args[1]);
if (color == "") { Player.SendMessage(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.titlecolor) { Player.SendMessage(p, who.DisplayName + " already has that title color."); return; }
else
{
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET title_color = @Color WHERE Name = @Name");
Player.GlobalChat(who, who.color + who.DisplayName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
who.titlecolor = color;
who.SetPrefix();
}
Player.GlobalChat(who, who.color + who.DisplayName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
who.titlecolor = color;
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET title_color = @Color WHERE Name = @Name");
}
who.SetPrefix();
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/tcolor <player> [color] - Gives <player> the title color of [color].");
Player.SendMessage(p, "If no [color] is specified, title color is removed.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
}
public sealed class CmdXTColor : Command {
public override string name { get { return "xtcolor"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdXTColor() { }
public override void Use(Player p, string message) {
Command.all.Find("tcolor").Use(p, p.name + " " + message);
}
public override void Help(Player p) {
Player.SendMessage(p, "/xtcolor [color] - Gives you the title color of [color].");
Player.SendMessage(p, "If no [color] is specified, title color is removed.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
}
}

View File

@ -1,186 +1,84 @@
using System.Text.RegularExpressions;
/*
Copyright 2011 MCGalaxy
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 MCGalaxy
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdTitle : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdTitle : Command {
public override string name { get { return "title"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdTitle() { }
static char[] trimChars = { ' ' };
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] parts = message.Split(trimChars, 2);
int pos = message.IndexOf(' ');
Player who = Player.Find(message.Split(' ')[0]);
Player who = Player.Find(parts[0]);
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
if (p != null && who.group.Permission > p.group.Permission)
{
Player.SendMessage(p, "Cannot change the title of someone of greater rank");
return;
if (p != null && who.group.Permission > p.group.Permission) {
Player.SendMessage(p, "Cannot change the title of someone of greater rank"); return;
}
if (who != p && (int)p.group.Permission >= CommandOtherPerms.GetPerm(this))
{
string query;
string newTitle = "";
if (message.Split(' ').Length > 1) newTitle = message.Substring(pos + 1);
else
{
who.title = "";
who.SetPrefix();
Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + " had their title removed.", false);
query = "UPDATE Players SET Title = '' WHERE Name = @Name";
Database.AddParams("@Name", who.name);
Database.executeQuery(query);
return;
}
string newTitle = parts.Length > 1 ? parts[1] : "";
if (newTitle != "")
newTitle = newTitle.Replace("[", "").Replace("]", "");
if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; }
if (newTitle != "")
{ //remove the brackets from the given title
newTitle = newTitle.ToString().Trim().Replace("[", "");
newTitle = newTitle.Replace("]", "");
}
if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; }
/*string title = newTitle.ToLower();
foreach (char c in Server.ColourCodesNoPercent) { title = title.Replace("%" + c, ""); title = title.Replace("&" + c, ""); }
foreach (string occur in Server.BadTitles) {
if (title.Contains(occur)) { Player.SendMessage(p, "%cYou're not a developer! Stop pretending you are!"); return; }
}*/
if (newTitle != "")
Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + " was given the title of &b[" + newTitle + "%b]", false);
else Player.GlobalChat(who, who.color + who.prefix + who.name + Server.DefaultColor + " had their title removed.", false);
if (!Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])"))
{
if (Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])(.+?).*"))
{
Regex rg = new Regex(@"%([0-9]|[a-f]|[k-r])(.+?)");
MatchCollection mc = rg.Matches(newTitle.ToLower());
if (mc.Count > 0)
{
Match ma = mc[0];
GroupCollection gc = ma.Groups;
newTitle.Replace("%" + gc[1].ToString().Substring(1), "&" + gc[1].ToString().Substring(1));
}
}
}
if (newTitle == "")
{
query = "UPDATE Players SET Title = '' WHERE Name = @Name";
Database.AddParams("@Name", who.name);
}
else
{
query = "UPDATE Players SET Title = @Title WHERE Name = @Name";
Database.AddParams("@Title", newTitle);
Database.AddParams("@Name", who.name);
}
Database.executeQuery(query);
who.title = newTitle;
who.SetPrefix();
}
else if (who == p)
{
string query;
string newTitle = "";
if (message.Split(' ').Length > 1) newTitle = message.Substring(pos + 1);
else
{
p.title = "";
p.SetPrefix();
Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + " had their title removed.", false);
query = "UPDATE Players SET Title = '' WHERE Name = @Name";
Database.AddParams("@Name", p.name);
Database.executeQuery(query);
return;
}
if (newTitle != "")
{ //remove the brackets from the given title
newTitle = newTitle.ToString().Trim().Replace("[", "");
newTitle = newTitle.Replace("]", "");
}
if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; }
/*string title = newTitle.ToLower();
foreach (char c in Server.ColourCodesNoPercent) { title = title.Replace("%" + c, ""); title = title.Replace("&" + c, ""); }
foreach (string occur in Server.BadTitles) {
if (title.Contains(occur)) { Player.SendMessage(p, "%cYou're not a developer! Stop pretending you are!"); return; }
}*/
if (newTitle != "")
Player.GlobalChat(who, who.color + who.name + Server.DefaultColor + " was given the title of &b[" + newTitle + "%b]", false);
else Player.GlobalChat(who, who.color + who.prefix + who.name + Server.DefaultColor + " had their title removed.", false);
if (!Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])"))
{
if (Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])(.+?).*"))
{
Regex rg = new Regex(@"%([0-9]|[a-f]|[k-r])(.+?)");
MatchCollection mc = rg.Matches(newTitle.ToLower());
if (mc.Count > 0)
{
Match ma = mc[0];
GroupCollection gc = ma.Groups;
newTitle.Replace("%" + gc[1].ToString().Substring(1), "&" + gc[1].ToString().Substring(1));
}
}
}
if (newTitle == "")
{
query = "UPDATE Players SET Title = '' WHERE Name = @Name";
Database.AddParams("@Name", p.name);
}
else
{
query = "UPDATE Players SET Title = @Title WHERE Name = @Name";
Database.AddParams("@Title", newTitle);
Database.AddParams("@Name", p.name);
}
Database.executeQuery(query);
p.title = newTitle;
p.SetPrefix();
}
else
{
Player.SendMessage(p, "Cannot change the title of someone else");
}
if (newTitle == "") {
Player.GlobalChat(who, who.color + who.prefix + who.name + " %Shad their title removed.", false);
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET Title = '' WHERE Name = @Name");
} else {
Player.GlobalChat(who, who.color + who.name + " %Swas given the title of &b[" + newTitle + "%b]", false);
Database.AddParams("@Title", newTitle);
Database.AddParams("@Name", who.name);
Database.executeQuery("UPDATE Players SET Title = @Title WHERE Name = @Name");
}
who.title = newTitle;
who.SetPrefix();
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/title <player> [title] - Gives <player> the [title].");
Player.SendMessage(p, "If no [title] is given, the player's title is removed.");
}
}
public class CmdXTitle : Command {
public override string name { get { return "xtitle"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdXTitle() { }
public override void Use(Player p, string message) {
Command.all.Find("title").Use(p, p.name + " " + message);
}
public override void Help(Player p) {
Player.SendMessage(p, "/xtitle [title] - Gives you the [title].");
Player.SendMessage(p, "If no [title] is given, your title is removed.");
}
}
}

View File

@ -1,75 +0,0 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdXColor : Command
{
public override string name { get { return "xcolor"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdXColor() { }
public override void Use(Player p, string message)
{
if (message == "")
{
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = '' WHERE name = @Name");
Player.GlobalChat(p, p.color + "*" + p.DisplayName + Server.DefaultColor + "'s color reverted to " + p.group.color + "their group's default" + Server.DefaultColor + ".", false);
p.color = p.group.color;
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
p.SetPrefix();
return;
}
string color = Colors.Parse(message);
if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); }
else if (color == p.color) { Player.SendMessage(p, "You already have that color."); }
else
{
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET color = @Color WHERE name = @Name");
Player.GlobalChat(p, p.color + "*" + p.DisplayName + Server.DefaultColor + "'s color changed to " + color + Colors.Name(color) + Server.DefaultColor + ".", false);
p.color = color;
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
p.SetPrefix();
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "/xcolor [color]- Changes your nick color.");
Player.SendMessage(p, "If no [color] is given, you will revert to your group's default.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
static string Name(string name)
{
string ch = name[name.Length - 1].ToString().ToLower();
if (ch == "s" || ch == "x") { return name + Server.DefaultColor + "'"; }
else { return name + Server.DefaultColor + "'s"; }
}
}
}

View File

@ -1,63 +0,0 @@
/*
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdXTColor : Command
{
public override string name { get { return "xtcolor"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdXTColor() { }
public override void Use(Player p, string message)
{
if (message == "")
{
p.titlecolor = "";
Player.GlobalChat(p, p.color + p.DisplayName + Server.DefaultColor + " had their title color removed.", false);
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET title_color = '' WHERE Name = @Name");
p.SetPrefix();
return;
}
string color = Colors.Parse(message);
if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); return; }
else if (color == p.titlecolor) { Player.SendMessage(p, "You already have that title color."); return; }
else
{
Database.AddParams("@Color", Colors.Name(color));
Database.AddParams("@Name", p.name);
Database.executeQuery("UPDATE Players SET title_color = @Color WHERE Name = @Name");
Player.GlobalChat(p, p.color + p.DisplayName + Server.DefaultColor + " had their title color changed to " + color + Colors.Name(color) + Server.DefaultColor + ".", false);
p.titlecolor = color;
p.SetPrefix();
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "/xtcolor [color] - Gives you the title color of [color].");
Player.SendMessage(p, "If no [color] is specified, title color is removed.");
Player.SendMessage(p, "&0black &1navy &2green &3teal &4maroon &5purple &6gold &7silver");
Player.SendMessage(p, "&8gray &9blue &alime &baqua &cred &dpink &eyellow &fwhite");
}
}
}

View File

@ -1,88 +0,0 @@
using System.Text.RegularExpressions;
/*
Copyright 2011 MCGalaxy
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 MCGalaxy.SQL;
namespace MCGalaxy.Commands
{
public sealed class CmdXTitle : Command
{
public override string name { get { return "xtitle"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdXTitle() { }
public override void Use(Player p, string message)
{
string query;
if (message == "")
{
p.title = "";
p.SetPrefix();
Player.GlobalChat(p, p.color + p.DisplayName + Server.DefaultColor + " had their title removed.", false);
query = "UPDATE Players SET Title = '' WHERE Name = @Name";
Database.AddParams("@Name", p.name);
Database.executeQuery(query);
return;
}
int pos = message.IndexOf(' ');
string newTitle = "";
newTitle = message;
if (newTitle != "")
{
newTitle = newTitle.ToString().Trim().Replace("[", "");
newTitle = newTitle.Replace("]", "");
}
if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; }
if (newTitle != "")
Player.GlobalChat(p, p.color + p.DisplayName + Server.DefaultColor + " gave themself the title of &b[" + newTitle + "%b]", false);
else Player.GlobalChat(p, p.color + p.prefix + p.DisplayName + Server.DefaultColor + " had their title removed.", false);
if (!Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])"))
{
if (Regex.IsMatch(newTitle.ToLower(), @".*%([0-9]|[a-f]|[k-r])(.+?).*"))
{
Regex rg = new Regex(@"%([0-9]|[a-f]|[k-r])(.+?)");
MatchCollection mc = rg.Matches(newTitle.ToLower());
if (mc.Count > 0)
{
Match ma = mc[0];
GroupCollection gc = ma.Groups;
newTitle.Replace("%" + gc[1].ToString().Substring(1), "&" + gc[1].ToString().Substring(1));
}
}
}
Database.AddParams("@Title", newTitle);
Database.AddParams("@Name", p.name);
query = "UPDATE Players SET Title = @Title WHERE Name = @Name";
Database.executeQuery(query);
p.title = newTitle;
p.SetPrefix();
}
public override void Help(Player p)
{
Player.SendMessage(p, "/xtitle [title] - Gives you the [title].");
Player.SendMessage(p, "If no [title] is given, your title is removed.");
}
}
}

View File

@ -361,11 +361,8 @@
<Compile Include="Commands\Other\CmdVote.cs" />
<Compile Include="Commands\Other\CmdWarp.cs" />
<Compile Include="Commands\Other\CmdWaypoint.cs" />
<Compile Include="Commands\Other\CmdXColor.cs" />
<Compile Include="Commands\Other\CmdXJail.cs" />
<Compile Include="Commands\Other\CmdXspawn.cs" />
<Compile Include="Commands\Other\CmdXTColor.cs" />
<Compile Include="Commands\Other\CmdXTitle.cs" />
<Compile Include="Commands\Other\CmdXundo.cs" />
<Compile Include="Commands\World\CmdClearBlockChanges.cs" />
<Compile Include="Commands\World\CmdCopyLVL.cs" />