Fix being able to unmute yourself and a NullReferenceException being thrown when no online player matches the given name. Also /tree should not overwrite existing blocks. (Thanks goodlyay) Closes #122

This commit is contained in:
UnknownShadow200 2016-04-05 17:29:53 +10:00
parent 15d9aab358
commit dc9b1b4ca1
2 changed files with 27 additions and 55 deletions

View File

@ -1,28 +1,23 @@
/*
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
{
/// <summary>
/// Bug:
/// Doesn't save mute.txt
/// Players with the defaultRank can unmute themself
/// </summary>
public sealed class CmdMute : Command
{
public override string name { get { return "mute"; } }
@ -35,51 +30,29 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message)
{
if (message == "" || message.Split(' ').Length > 2) { Help(p); return; }
Player who = PlayerInfo.Find(message);
if (who == null)
{
if (Server.muted.Contains(message))
{
Player who = PlayerInfo.FindOrShowMatches(p, message);
if (who == null) {
if (Server.muted.Contains(message)) {
Server.muted.Remove(message);
Player.GlobalMessage(message + Server.DefaultColor + " is not online but is now &bun-muted");
Extensions.DeleteLineWord("ranks/muted.txt", who.name.ToLower());
return;
}
}
if (who == p)
{
if (p.muted)
{
p.muted = false;
Player.SendMessage(p, "You &bun-muted" + Server.DefaultColor + " yourself!");
Extensions.DeleteLineWord("ranks/muted.txt", p.name.ToLower());
return;
}
else
{
Player.SendMessage(p, "You cannot mute yourself!");
}
return;
}
if (who.muted)
{
if (who == p) { Player.SendMessage(p, "You cannot mute or unmute yourself."); return; }
if (who.muted) {
who.muted = false;
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &bun-muted", false);
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shas been &bun-muted", false);
Extensions.DeleteLineWord("ranks/muted.txt", who.name.ToLower());
}
else
{
if (p != null)
{
if (who != p) if (who.group.Permission >= p.group.Permission) { Player.SendMessage(p, "Cannot mute someone of a higher or equal rank."); return; }
} else {
if (p != null && who.group.Permission >= p.group.Permission) {
Player.SendMessage(p, "Cannot mute someone of a higher or equal rank."); return;
}
who.muted = true;
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " has been &8muted", false);
using (StreamWriter writer = new StreamWriter("ranks/muted.txt", true))
{
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shas been &8muted", false);
using (StreamWriter writer = new StreamWriter("ranks/muted.txt", true)) {
writer.WriteLine(who.name.ToLower());
}
Server.s.Log("SAVED: ranks/muted.txt");

View File

@ -64,7 +64,6 @@ namespace MCGalaxy.Commands {
TreeDrawOp op = new TreeDrawOp();
op.Type = cpos.mode;
op.random = p.random;
op.overwrite = true;
Brush brush = null;
if (cpos.brushMsg != "") {