Modularise more chat commands.

This commit is contained in:
UnknownShadow200 2016-06-30 22:07:18 +10:00
parent ff2b697805
commit e26d0c707d
9 changed files with 88 additions and 81 deletions

View File

@ -59,19 +59,19 @@ namespace MCGalaxy.Commands {
Level lvl = p.level;
switch (variable) {
case "fog":
LevelEnv.SetColour(p, value, 2, "fog", ref lvl.FogColor); break;
LevelEnv.SetColor(p, value, 2, "fog", ref lvl.FogColor); break;
case "cloud":
case "clouds":
LevelEnv.SetColour(p, value, 1, "cloud", ref lvl.CloudColor); break;
LevelEnv.SetColor(p, value, 1, "cloud", ref lvl.CloudColor); break;
case "sky":
LevelEnv.SetColour(p, value, 0, "sky", ref lvl.SkyColor); break;
LevelEnv.SetColor(p, value, 0, "sky", ref lvl.SkyColor); break;
case "dark":
case "shadow":
LevelEnv.SetColour(p, value, 3, "shadow", ref lvl.ShadowColor); break;
LevelEnv.SetColor(p, value, 3, "shadow", ref lvl.ShadowColor); break;
case "sun":
case "light":
case "sunlight":
LevelEnv.SetColour(p, value, 4, "sunlight", ref lvl.LightColor); break;
LevelEnv.SetColor(p, value, 4, "sunlight", ref lvl.LightColor); break;
case "weather":
LevelEnv.SetWeather(p, p.level, value); break;
case "cloudsheight":

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.CPE {
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the model of other players") }; }
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the model of others") }; }
}
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("xmodel", "-own") }; }
@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.CPE {
if (message == "") message = p.name;
Player who = p;
PlayerBot pBot = null;
PlayerBot bot = null;
bool isBot = message.CaselessStarts("bot ");
string[] args = message.SplitSpaces(isBot ? 3 : 2);
string model = null;
@ -51,8 +51,8 @@ namespace MCGalaxy.Commands.CPE {
}
if (isBot && args.Length > 2) {
pBot = PlayerBot.FindMatches(p, args[1]);
if (pBot == null) return;
bot = PlayerBot.FindMatches(p, args[1]);
if (bot == null) return;
model = args[2];
} else if (args.Length > 1) {
isBot = false;
@ -66,13 +66,13 @@ namespace MCGalaxy.Commands.CPE {
model = message;
}
model = model.ToLower();
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the model of other players."); return; }
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the model of others."); return; }
if (isBot) {
pBot.model = model;
Entities.UpdateModel(pBot.id, model, pBot.level, null);
Player.GlobalMessage("Bot " + pBot.name + "'s %Smodel was changed to a &c" + model);
BotsFile.UpdateBot(pBot);
bot.model = model;
Entities.UpdateModel(bot.id, model, bot.level, null);
Player.GlobalMessage("Bot " + bot.name + "'s %Smodel was changed to a &c" + model);
BotsFile.UpdateBot(bot);
} else {
who.model = model;
Entities.UpdateModel(who.id, model, who.level, who);

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.CPE {
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the skin of other players") }; }
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the skin of others") }; }
}
public override void Use(Player p, string message) {
@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.CPE {
}
if (!ValidName(p, skin, "skin")) return;
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the skin of other players."); return; }
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the skin of others."); return; }
if (skin[0] == '+')
skin = "http://skins.minecraft.net/MinecraftSkins/" + skin.Substring(1) + ".png";

View File

@ -16,16 +16,16 @@
permissions and limitations under the Licenses.
*/
using MCGalaxy.SQL;
namespace MCGalaxy.Commands {
public class CmdColor : Command {
public class CmdColor : Command {
public override string name { get { return "color"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Chat; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the color of other players") }; }
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the color of others") }; }
}
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("colour"), new CommandAlias("xcolor", "-own") }; }
@ -40,12 +40,16 @@ namespace MCGalaxy.Commands {
}
Player who = PlayerInfo.FindMatches(p, args[0]);
bool isBot = message.CaselessStarts("bot ");
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
MessageTooHighRank(p, "change the color of", true); return;
}
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the color of other players."); return; }
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the color of others."); return; }
SetColor(who, args);
}
static void SetColor(Player p, Player who, string[] args) {
ParameterisedQuery query = ParameterisedQuery.Create();
if (args.Length == 1) {
Player.SendChatFrom(who, who.ColoredName + " %Shad their color removed.", false);
@ -56,7 +60,7 @@ namespace MCGalaxy.Commands {
} else {
string color = Colors.Parse(args[1]);
if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.color) { Player.Message(p, p.DisplayName + " already has that color."); return; }
else if (color == who.color) { Player.Message(p, who.DisplayName + " already has that color."); return; }
Player.SendChatFrom(who, who.ColoredName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false);
who.color = color;

View File

@ -18,14 +18,13 @@
using System;
using MCGalaxy;
namespace MCGalaxy.Commands {
public class CmdNick : Command {
public override string name { get { return "nick"; } }
public override string shortcut { get { return "nickname"; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
namespace MCGalaxy.Commands {
public class CmdNick : Command {
public override string name { get { return "nick"; } }
public override string shortcut { get { return "nickname"; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the nick of other players") }; }
}
@ -33,41 +32,44 @@ namespace MCGalaxy.Commands {
get { return new[] { new CommandAlias("xnick", "-own") }; }
}
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2);
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2);
if (args[0].CaselessEq("-own")) {
if (Player.IsSuper(p)) { SuperRequiresArgs(p, "player name"); return; }
args[0] = p.name;
}
Player who = PlayerInfo.FindMatches(p, args[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
Player who = PlayerInfo.FindMatches(p, args[0]);
if (who == null) return;
if (p != null && who.group.Permission > p.group.Permission) {
MessageTooHighRank(p, "change the nick of", true); return;
}
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the nick of other players."); return; }
string newName = args.Length > 1 ? args[1] : "";
if (newName == "") {
who.DisplayName = who.truename;
Player.SendChatFrom(who, who.FullName + "%S reverted their nick to their original name.", false);
} else {
if (newName.Length >= 30) { Player.Message(p, "Nick must be under 30 letters."); return; }
Player.SendChatFrom(who, who.FullName + "%S changed their nick to " + who.color + newName + "%S.", false);
who.DisplayName = newName;
}
Entities.GlobalDespawn(who, false);
Entities.GlobalSpawn(who, false);
}
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the nick of others."); return; }
SetNick(p, who, args);
}
static void SetNick(Player p, Player who, string[] args) {
string newName = args.Length > 1 ? args[1] : "";
if (newName == "") {
who.DisplayName = who.truename;
Player.SendChatFrom(who, who.FullName + "%S reverted their nick to their original name.", false);
} else {
if (newName.Length >= 30) { Player.Message(p, "Nick must be under 30 letters."); return; }
Player.SendChatFrom(who, who.FullName + "%S changed their nick to " + who.color + newName + "%S.", false);
who.DisplayName = newName;
}
Entities.GlobalDespawn(who, false);
Entities.GlobalSpawn(who, false);
PlayerDB.Save(who);
}
public override void Help(Player p) {
Player.Message(p, "%T/nick <player> [nick]");
}
public override void Help(Player p) {
Player.Message(p, "%T/nick <player> [nick]");
Player.Message(p, "%HSets the nick of <player>");
Player.Message(p, "%HIf no [nick] is given, reverts player's nick to their original name.");
}
}
Player.Message(p, "%HIf no [nick] is given, reverts player's nick to their original name.");
}
}
}

View File

@ -25,7 +25,7 @@ namespace MCGalaxy.Commands {
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the title color of other players") }; }
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the title color of others") }; }
}
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("tcolour"), new CommandAlias("xtcolor", "-own") }; }
@ -44,8 +44,11 @@ namespace MCGalaxy.Commands {
if (p != null && who.group.Permission > p.group.Permission) {
MessageTooHighRank(p, "change the title color of", true); return;
}
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title color of other players."); return; }
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title color of others."); return; }
SetTColor(p, who, args);
}
static void SetTColor(Player p, player who, string[] args) {
ParameterisedQuery query = ParameterisedQuery.Create();
if (args.Length == 1) {
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color removed.", false);
@ -64,7 +67,7 @@ namespace MCGalaxy.Commands {
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET title_color = @Color WHERE Name = @Name");
}
who.SetPrefix();
who.SetPrefix();
}
public override void Help(Player p) {

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Commands {
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the title of other players") }; }
get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the title of others") }; }
}
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("xtitle", "-own") }; }
@ -45,26 +45,29 @@ namespace MCGalaxy.Commands {
if (p != null && who.group.Permission > p.group.Permission) {
MessageTooHighRank(p, "change the title of", true); return;
}
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title of other players."); return; }
string newTitle = args.Length > 1 ? args[1] : "";
if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title of others."); return; }
SetTitle(p, who, args);
}
static void SetTitle(Player p, Player who, string[] args) {
string title = args.Length > 1 ? args[1] : "";
ParameterisedQuery query = ParameterisedQuery.Create();
if (newTitle != "")
newTitle = newTitle.Replace("[", "").Replace("]", "");
if (newTitle.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; }
if (title != "")
title = title.Replace("[", "").Replace("]", "");
if (title.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; }
if (newTitle == "") {
if (title == "") {
Player.SendChatFrom(who, who.FullName + " %Shad their title removed.", false);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET Title = '' WHERE Name = @Name");
} else {
Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + newTitle + "%b]", false);
query.AddParam("@Title", newTitle);
Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + title + "%b]", false);
query.AddParam("@Title", title);
query.AddParam("@Name", who.name);
Database.executeQuery(query, "UPDATE Players SET Title = @Title WHERE Name = @Name");
}
who.title = newTitle;
who.SetPrefix();
who.title = title;
who.SetPrefix();
}
public override void Help(Player p) {

View File

@ -81,7 +81,7 @@ namespace MCGalaxy {
SendCurrentMapAppearance(p.level, prop, target);
}
public static void SetColour(Player p, string value, byte envType, string envTypeName, ref string target) {
public static void SetColor(Player p, string value, byte envType, string envTypeName, ref string target) {
if (IsResetString(value)) {
Player.Message(p, "Reset {0} color for {1}%S to normal", envTypeName, p.level.name);
target = null;

View File

@ -859,10 +859,5 @@ namespace MCGalaxy
}
return Group.standard.color;
}
public static bool canusegc = true; //badpokerface
public static int gcmultiwarns = 0, gcspamcount = 0, gccapscount = 0, gcfloodcount = 0;
public static DateTime gclastmsgtime = DateTime.MinValue;
public static string gclastmsg = "";
}
}