Skip to content

Commit

Permalink
Add PlayerOperations class, initially with just login/logout messages
Browse files Browse the repository at this point in the history
Fixes
1) can't remove login/logout message while muted
2) if you buy a login/logout message while muted, you are still charged even though the message does not change
  • Loading branch information
UnknownShadow200 committed Jul 18, 2021
1 parent 4670fa6 commit 0aaa939
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
8 changes: 1 addition & 7 deletions MCGalaxy/Commands/Chat/CmdLoginMessage.cs
Expand Up @@ -28,17 +28,11 @@ public sealed class CmdLoginMessage : EntityPropertyCmd {
}

public override void Use(Player p, string message, CommandData data) {
if (!MessageCmd.CanSpeak(p, name)) return;
UsePlayer(p, data, message, "login message");
}

protected override void SetPlayerData(Player p, string target, string msg) {
PlayerDB.SetLoginMessage(target, msg);
if (msg.Length == 0) {
p.Message("Login message of {0} &Swas removed.", p.FormatNick(target));
} else {
p.Message("Login message of {0} &Swas changed to: {1}", p.FormatNick(target), msg);
}
PlayerOperations.SetLoginMessage(p, target, msg);
}

public override void Help(Player p) {
Expand Down
8 changes: 1 addition & 7 deletions MCGalaxy/Commands/Chat/CmdLogoutMessage.cs
Expand Up @@ -28,17 +28,11 @@ public sealed class CmdLogoutMessage : EntityPropertyCmd {
}

public override void Use(Player p, string message, CommandData data) {
if (!MessageCmd.CanSpeak(p, name)) return;
UsePlayer(p, data, message, "logout message");
}

protected override void SetPlayerData(Player p, string target, string msg) {
PlayerDB.SetLogoutMessage(target, msg);
if (msg.Length == 0) {
p.Message("Logout message of {0} &Swas removed.", p.FormatNick(target));
} else {
p.Message("Logout message of {0} &Swas changed to: {1}", p.FormatNick(target), msg);
}
PlayerOperations.SetLogoutMessage(p, target, msg);
}

public override void Help(Player p) {
Expand Down
12 changes: 6 additions & 6 deletions MCGalaxy/Economy/MessageItems.cs
Expand Up @@ -35,15 +35,15 @@ public sealed class LoginMessageItem : SimpleItem {
return;
}

if (!CheckPrice(p)) return;
if (!CheckPrice(p)) return;
if (msg == PlayerDB.GetLoginMessage(p)) {
p.Message("&WYou already have that login message."); return;
}
if (msg.Length > NetUtils.StringSize) {
p.Message("&WLogin message must be 64 characters or less."); return;
}

UseCommand(p, "LoginMessage", "-own " + msg);
if (!PlayerOperations.SetLoginMessage(p, p.name, msg)) return;
Economy.MakePurchase(p, Price, "%3LoginMessage: %f" + msg);
}
}
Expand All @@ -61,17 +61,17 @@ public sealed class LogoutMessageItem : SimpleItem {
PlayerDB.SetLogoutMessage(p.name, "");
p.Message("&aYour logout message was removed for free.");
return;
}
}

if (!CheckPrice(p)) return;
if (!CheckPrice(p)) return;
if (msg == PlayerDB.GetLogoutMessage(p)) {
p.Message("&WYou already have that logout message."); return;
}
}
if (msg.Length > NetUtils.StringSize) {
p.Message("&WLogin message must be 64 characters or less."); return;
}

UseCommand(p, "LogoutMessage", "-own " + msg);
if (!PlayerOperations.SetLogoutMessage(p, p.name, msg)) return;
Economy.MakePurchase(p, Price, "%3LogoutMessage: %f" + msg);
}
}
Expand Down
1 change: 1 addition & 0 deletions MCGalaxy/MCGalaxy_.csproj
Expand Up @@ -620,6 +620,7 @@
<Compile Include="Player\PlayerActions.cs" />
<Compile Include="Player\PlayerIgnores.cs" />
<Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\PlayerOperations.cs" />
<Compile Include="Player\PlayerPhysics.cs" />
<Compile Include="Player\SpamChecker.cs" />
<Compile Include="Player\Warp.cs" />
Expand Down
62 changes: 62 additions & 0 deletions MCGalaxy/Player/PlayerOperations.cs
@@ -0,0 +1,62 @@
/*
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;
using System.Threading;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Games;
using MCGalaxy.Commands.World;
using MCGalaxy.DB;

namespace MCGalaxy {
public static class PlayerOperations {

/// <summary> Attempts to change the login message of the target player </summary>
/// <remarks> Not allowed when players who cannot speak (e.g. muted) </remarks>
public static bool SetLoginMessage(Player p, string target, string message) {
if (message.Length == 0) {
p.Message("Login message of {0} &Swas removed", p.FormatNick(target));
} else {
// Don't allow changing while muted
if (!p.CheckCanSpeak("change login messages")) return false;

p.Message("Login message of {0} &Swas changed to: {1}",
p.FormatNick(target), message);
}

PlayerDB.SetLoginMessage(target, message);
return true;
}

/// <summary> Attempts to change the logout message of the target player </summary>
/// <remarks> Not allowed when players who cannot speak (e.g. muted) </remarks>
public static bool SetLogoutMessage(Player p, string target, string message) {
if (message.Length == 0) {
p.Message("Logout message of {0} &Swas removed", p.FormatNick(target));
} else {
// Don't allow changing while muted
if (!p.CheckCanSpeak("change logout messages")) return false;

p.Message("Loggout message of {0} &Swas changed to: {1}",
p.FormatNick(target), message);
}

PlayerDB.SetLogoutMessage(target, message);
return true;
}
}
}

0 comments on commit 0aaa939

Please sign in to comment.