mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 22:30:52 -04:00
Reduce code duplication in /mb.
This commit is contained in:
parent
8cad8ad507
commit
21d527e741
@ -23,7 +23,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
public override string name { get { return "aka"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public CmdAka() { }
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Copyright 2011 MCGalaxy
|
||||
|
||||
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
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
@ -14,119 +14,58 @@
|
||||
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;
|
||||
using System.Data;
|
||||
using System.Text.RegularExpressions;
|
||||
using MCGalaxy.SQL;
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdMessageBlock : Command
|
||||
{
|
||||
namespace MCGalaxy.Commands {
|
||||
|
||||
public sealed class CmdMessageBlock : Command {
|
||||
|
||||
public override string name { get { return "mb"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
public CmdMessageBlock() { }
|
||||
static char[] trimChars = { ' ' };
|
||||
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "") { Help(p); return; }
|
||||
|
||||
CatchPos cpos;
|
||||
cpos.message = "";
|
||||
|
||||
try
|
||||
{
|
||||
switch (message.Split(' ')[0])
|
||||
{
|
||||
cpos.message = null;
|
||||
string[] args = message.Split(trimChars, 2);
|
||||
switch (args[0].ToLower()) {
|
||||
case "air": cpos.type = Block.MsgAir; break;
|
||||
case "water": cpos.type = Block.MsgWater; break;
|
||||
case "lava": cpos.type = Block.MsgLava; break;
|
||||
case "black": cpos.type = Block.MsgBlack; break;
|
||||
case "white": cpos.type = Block.MsgWhite; break;
|
||||
case "show": showMBs(p); return;
|
||||
case "show": ShowMessageBlocks(p); return;
|
||||
default: cpos.type = Block.MsgWhite; cpos.message = message; break;
|
||||
}
|
||||
if (cpos.message == null)
|
||||
cpos.message = args[1];
|
||||
|
||||
foreach (Command com in Command.all.commands) {
|
||||
if (com.defaultRank <= p.group.Permission && !com.type.Contains("mod")) continue;
|
||||
|
||||
if (CaselessStarts(cpos.message, "/" + com.name)) {
|
||||
p.SendMessage("You cannot use that command in a messageblock."); return;
|
||||
}
|
||||
if (com.shortcut != "" && CaselessStarts(cpos.message, "/" + com.shortcut)) {
|
||||
p.SendMessage("You cannot use that command in a messageblock."); return;
|
||||
}
|
||||
}
|
||||
catch { cpos.type = Block.MsgWhite; cpos.message = message; }
|
||||
|
||||
string current = "";
|
||||
string cmdparts = "";
|
||||
|
||||
/*Fix by alecdent*/
|
||||
try
|
||||
{
|
||||
foreach (var com in Command.all.commands)
|
||||
{
|
||||
if (com.type.Contains("mod"))
|
||||
{
|
||||
current = "/" + com.name;
|
||||
|
||||
cmdparts = message.Split(' ')[0].ToLower().ToString();
|
||||
if (cmdparts[0] == '/')
|
||||
{
|
||||
if (current == cmdparts.ToLower())
|
||||
{
|
||||
p.SendMessage("You can't use that command in your messageblock!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cmdparts = message.Split(' ')[1].ToLower().ToString();
|
||||
if (cmdparts[0] == '/')
|
||||
{
|
||||
if (current == cmdparts.ToLower())
|
||||
{
|
||||
p.SendMessage("You can't use that command in your messageblock!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (com.shortcut != "")
|
||||
{
|
||||
current = "/" + com.name;
|
||||
|
||||
cmdparts = message.Split(' ')[0].ToLower().ToString();
|
||||
if (cmdparts[0] == '/')
|
||||
{
|
||||
if (current == cmdparts.ToLower())
|
||||
{
|
||||
p.SendMessage("You can't use that command in your messageblock!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cmdparts = message.Split(' ')[1].ToLower().ToString();
|
||||
if (cmdparts[0] == '/')
|
||||
{
|
||||
if (current == cmdparts.ToLower())
|
||||
{
|
||||
p.SendMessage("You can't use that command in your messageblock!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (cpos.message == "") cpos.message = message.Substring(message.IndexOf(' ') + 1);
|
||||
p.blockchangeObject = cpos;
|
||||
|
||||
Player.SendMessage(p, "Place where you wish the message block to go."); p.ClearBlockchange();
|
||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
}
|
||||
public override void Help(Player p)
|
||||
{
|
||||
Player.SendMessage(p, "/mb [block] [message] - Places a message in your next block.");
|
||||
Player.SendMessage(p, "Valid blocks: white, black, air, water, lava");
|
||||
Player.SendMessage(p, "/mb show shows or hides MBs");
|
||||
}
|
||||
|
||||
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
|
||||
{
|
||||
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
p.ClearBlockchange();
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
|
||||
@ -135,52 +74,47 @@ namespace MCGalaxy.Commands
|
||||
//safe against SQL injections because no user input is given here
|
||||
DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "` WHERE X=" + (int)x + " AND Y=" + (int)y + " AND Z=" + (int)z);
|
||||
Database.AddParams("@Message", cpos.message);
|
||||
|
||||
if (Messages.Rows.Count == 0)
|
||||
{
|
||||
Database.executeQuery("INSERT INTO `Messages" + p.level.name + "` (X, Y, Z, Message) VALUES (" + (int)x + ", " + (int)y + ", " + (int)z + ", @Message)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Database.executeQuery("UPDATE `Messages" + p.level.name + "` SET Message=@Message WHERE X=" + (int)x + " AND Y=" + (int)y + " AND Z=" + (int)z);
|
||||
}
|
||||
|
||||
Messages.Dispose();
|
||||
Player.SendMessage(p, "Message block placed.");
|
||||
p.level.Blockchange(p, x, y, z, cpos.type);
|
||||
p.SendBlockchange(x, y, z, cpos.type);
|
||||
|
||||
if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
if (p.staticCommands)
|
||||
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||
}
|
||||
|
||||
struct CatchPos { public string message; public byte type; }
|
||||
|
||||
static bool CaselessStarts(string a, string b) {
|
||||
return a.StartsWith(b, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public void showMBs(Player p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p.showMBs = !p.showMBs;
|
||||
//safe against SQL injections because no user input is given here
|
||||
using (DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "`"))
|
||||
{
|
||||
int i;
|
||||
|
||||
if (p.showMBs)
|
||||
{
|
||||
for (i = 0; i < Messages.Rows.Count; i++)
|
||||
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), Block.MsgWhite);
|
||||
Player.SendMessage(p, "Now showing &a" + i.ToString() + Server.DefaultColor + " MBs.");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < Messages.Rows.Count; i++)
|
||||
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), p.level.GetTile(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString())));
|
||||
Player.SendMessage(p, "Now hiding MBs.");
|
||||
}
|
||||
void ShowMessageBlocks(Player p) {
|
||||
p.showMBs = !p.showMBs;
|
||||
//safe against SQL injections because no user input is given here
|
||||
using (DataTable Messages = Database.fillData("SELECT * FROM `Messages" + p.level.name + "`")) {
|
||||
if (p.showMBs) {
|
||||
for (int i = 0; i < Messages.Rows.Count; i++)
|
||||
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), Block.MsgWhite);
|
||||
Player.SendMessage(p, "Now showing &a" + Messages.Rows.Count + " %SMBs.");
|
||||
} else {
|
||||
for (int i = 0; i < Messages.Rows.Count; i++)
|
||||
p.SendBlockchange(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString()), p.level.GetTile(ushort.Parse(Messages.Rows[i]["X"].ToString()), ushort.Parse(Messages.Rows[i]["Y"].ToString()), ushort.Parse(Messages.Rows[i]["Z"].ToString())));
|
||||
Player.SendMessage(p, "Now hiding MBs.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Server.ErrorLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.SendMessage(p, "/mb [block] [message] - Places a message in your next block.");
|
||||
Player.SendMessage(p, "Valid blocks: white, black, air, water, lava");
|
||||
Player.SendMessage(p, "/mb show shows or hides MBs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,7 @@
|
||||
<Compile Include="Commands\Economy\CmdGive.cs" />
|
||||
<Compile Include="Commands\Economy\CmdMoney.cs" />
|
||||
<Compile Include="Commands\Economy\CmdPay.cs" />
|
||||
<Compile Include="Commands\Fun\CmdAka.cs" />
|
||||
<Compile Include="Commands\Fun\CmdAlive.cs" />
|
||||
<Compile Include="Commands\Fun\CmdCountdown.cs" />
|
||||
<Compile Include="Commands\Fun\CmdCtf.cs" />
|
||||
@ -222,7 +223,6 @@
|
||||
<Compile Include="Commands\Information\CmdWhois.cs" />
|
||||
<Compile Include="Commands\Information\CmdWhoNick.cs" />
|
||||
<Compile Include="Commands\Information\CmdWhowas.cs" />
|
||||
<Compile Include="Commands\Moderation\CmdAka.cs" />
|
||||
<Compile Include="Commands\Moderation\CmdAllowGuns.cs" />
|
||||
<Compile Include="Commands\Moderation\CmdBan.cs" />
|
||||
<Compile Include="Commands\Moderation\CmdBanEdit.cs" />
|
||||
|
@ -640,15 +640,14 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
void SendHackControl( byte allowflying, byte allownoclip, byte allowspeeding, byte allowrespawning,
|
||||
byte allowthirdperson, byte allowchangingweather, short maxjumpheight ) {
|
||||
byte allowthirdperson, short maxjumpheight ) {
|
||||
byte[] buffer = new byte[7];
|
||||
buffer[0] = allowflying;
|
||||
buffer[1] = allownoclip;
|
||||
buffer[2] = allowspeeding;
|
||||
buffer[3] = allowrespawning;
|
||||
buffer[4] = allowthirdperson;
|
||||
buffer[5] = allowchangingweather;
|
||||
NetUtils.WriteI16(maxjumpheight, buffer, 6);
|
||||
NetUtils.WriteI16(maxjumpheight, buffer, 5);
|
||||
SendRaw( Opcode.CpeHackControl, buffer );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user