From dd79254796c8b3f1666122ae0d7ef6ee23aed21a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 16 Aug 2016 21:19:51 +1000 Subject: [PATCH] Cleanup /tpa. --- Commands/other/CmdTpA.cs | 135 +++++++++++++++-------------------- Network/LevelChunkStream.cs | 1 - Network/Player.Networking.cs | 2 - 3 files changed, 59 insertions(+), 79 deletions(-) diff --git a/Commands/other/CmdTpA.cs b/Commands/other/CmdTpA.cs index 51f95d83e..448e5b94c 100644 --- a/Commands/other/CmdTpA.cs +++ b/Commands/other/CmdTpA.cs @@ -2,10 +2,8 @@ using System; using System.Threading; -namespace MCGalaxy.Commands { - - public sealed class CmdTpA : Command { - +namespace MCGalaxy.Commands { + public sealed class CmdTpA : Command { public override string name { get { return "tpa"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } @@ -13,67 +11,58 @@ namespace MCGalaxy.Commands { public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override void Use(Player p, string message) { - if (message == "") { - Help(p); return; + if (message == "") { Help(p); return; } + Player target = PlayerInfo.FindMatches(p, message); + if (target == null) return; + if (target == p) { Player.Message(p, "You cannot /tpa to yourself."); return; } + if (target.listignored.Contains(p.name)) { ShowSentMessage(p, target); return; } + + if (target.name == p.currentTpa) { + Player.Message(p, "You still have a pending teleport request with this player."); return; } - int number = message.Split(' ').Length; - if (number > 1) { Help(p); return; } - - Player who = PlayerInfo.FindMatches(p, message); - if (who == p) { Player.Message(p, "&cError:%S You cannot send yourself a request!"); return; } - if (who == null) return; - if (who.listignored.Contains(p.name)) - { - //Lies - Player.Message(p, "---------------------------------------------------------"); - Player.Message(p, "Your teleport request has been sent to " + who.ColoredName); - Player.Message(p, "This request will timeout after " + Colors.aqua + "90%S seconds."); - Player.Message(p, "---------------------------------------------------------"); - return; + if (p.level != target.level && target.level.IsMuseum) { + Player.Message(p, "Player \"{0}\" is in a museum.", target.ColoredName); return; } - if (who.name == p.currentTpa) { Player.Message(p, "&cError:%S You already have a pending request with this player."); return; } - if (p.level != who.level && who.level.IsMuseum) { - Player.Message(p, "Player \"" + who.ColoredName + "\" is in a museum!"); return; + if (target.Loading) { + Player.Message(p, "Waiting for {0} %Sto spawn...", target.ColoredName); + target.BlockUntilLoad(10); } - - if (who.Loading) - { - Player.Message(p, "Waiting for " + who.ColoredName + " %Sto spawn..."); - who.BlockUntilLoad(10); - } - - Player.Message(p, "---------------------------------------------------------"); - Player.Message(p, "Your teleport request has been sent to " + who.ColoredName); - Player.Message(p, "This request will timeout after " + Colors.aqua + "90 %Sseconds."); - Player.Message(p, "---------------------------------------------------------"); - Player.Message(who, "---------------------------------------------------------"); - Player.Message(who, p.ColoredName + " %Swould like to teleport to you!"); - Player.Message(who, "Type " + Colors.green + "/tpaccept %Sor " + Colors.maroon + "/tpdeny%S!"); - Player.Message(who, "This request will timeout after " + Colors.aqua + "90 %Sseconds."); - Player.Message(who, "---------------------------------------------------------"); - who.senderName = p.name; - who.Request = true; - p.currentTpa = who.name; + + ShowSentMessage(p, target); + ShowRequestMessage(p, target); + target.senderName = p.name; + target.Request = true; + p.currentTpa = target.name; Thread.Sleep(90000); - if (who.Request) { + if (target.Request) { Player.Message(p, "Your teleport request has timed out."); - Player.Message(who, "Pending teleport request has timed out."); - who.Request = false; - who.senderName = ""; + Player.Message(target, "Pending teleport request has timed out."); + target.Request = false; + target.senderName = ""; p.currentTpa = ""; } } + + static void ShowSentMessage(Player p, Player target) { + Player.Message(p, "Your teleport request has been sent to " + target.ColoredName); + Player.Message(p, "This request will timeout after &b90 %Sseconds."); + } + + static void ShowRequestMessage(Player p, Player target) { + Player.Message(target, p.ColoredName + " %Swould like to teleport to you."); + Player.Message(target, "Type &2/tpaccept %Sor &4/tpdeny%S."); + Player.Message(target, "This request will timeout after &b90 %Sseconds."); + } public override void Help(Player p) { - Player.Message(p, "/tpa - Sends a teleport request to the given player"); - Player.Message(p, "/tpaccept - Accepts a teleport request"); - Player.Message(p, "/tpdeny - Denies a teleport request"); + Player.Message(p, "%T/tpa [player] %H- Sends a teleport request to that player"); + Player.Message(p, "%T/tpaccept %H- Accepts a teleport request"); + Player.Message(p, "%T/tpdeny %H- Denies a teleport request"); } } public sealed class CmdTpAccept : Command { - public override string name { get { return "tpaccept"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } @@ -82,39 +71,35 @@ namespace MCGalaxy.Commands { public CmdTpAccept() { } public override void Use(Player p, string message) { - if (!p.Request) { - Player.Message(p, "&cError: %SYou do not have any pending teleport requests!"); return; - } + if (!p.Request) { Player.Message(p, "You do not have any pending teleport requests."); return; } - Player who = PlayerInfo.FindExact(p.senderName); + Player sender = PlayerInfo.FindExact(p.senderName); p.Request = false; p.senderName = ""; - if (who == null) { + if (sender == null) { Player.Message(p, "The player who requested to teleport to you isn't online anymore."); return; } - Player.Message(p, "You have accepted " + who.ColoredName + "%S's teleportation request."); - Player.Message(who, p.ColoredName + " %Shas accepted your request. Teleporting now..."); - who.currentTpa = ""; + Player.Message(p, "You have accepted {0}%S's teleportation request.", sender.ColoredName); + Player.Message(sender, "{0} %Shas accepted your request. Teleporting now...", p.ColoredName); + sender.currentTpa = ""; Thread.Sleep(1000); - if (p.level != who.level) - { + if (p.level != sender.level) { Level where = p.level; - PlayerActions.ChangeMap(who, where.name); + PlayerActions.ChangeMap(sender, where.name); Thread.Sleep(1000); } - who.SendOwnHeadPos(p.pos[0], p.pos[1], p.pos[2], p.rot[0], 0); + sender.SendOwnHeadPos(p.pos[0], p.pos[1], p.pos[2], p.rot[0], 0); } public override void Help(Player p) { - Player.Message(p, "/tpaccept - Accepts a teleport request"); - Player.Message(p, "For use with /tpa"); + Player.Message(p, "%T/tpaccept %H- Accepts a teleport request"); + Player.Message(p, "%HFor use with /tpa"); } } - public sealed class CmdTpDeny : Command { - + public sealed class CmdTpDeny : Command { public override string name { get { return "tpdeny"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } @@ -123,25 +108,23 @@ namespace MCGalaxy.Commands { public CmdTpDeny() { } public override void Use(Player p, string message) { - if (!p.Request ) { - Player.Message(p, "&cError: %SYou do not have any pending teleport requests!"); return; - } + if (!p.Request) { Player.Message(p, "You do not have any pending teleport requests."); return; } - Player who = PlayerInfo.FindExact(p.senderName); + Player sender = PlayerInfo.FindExact(p.senderName); p.Request = false; p.senderName = ""; - if (who == null) { + if (sender == null) { Player.Message(p, "The player who requested to teleport to you isn't online anymore."); return; } - Player.Message(p, "You have denied " + who.ColoredName + "%S's teleportation request."); - Player.Message(who, p.ColoredName + " %Shas denied your request."); - who.currentTpa = ""; + Player.Message(p, "You have denied {0}%S's teleportation request.", sender.ColoredName); + Player.Message(sender, "{0} %Shas denied your request.", p.ColoredName); + sender.currentTpa = ""; } public override void Help(Player p) { - Player.Message(p, "/tpdeny - Denies a teleport request"); - Player.Message(p, "For use with /tpa"); + Player.Message(p, "%T/tpdeny %H- Denies a teleport request"); + Player.Message(p, "%HFor use with /tpa"); } } } diff --git a/Network/LevelChunkStream.cs b/Network/LevelChunkStream.cs index bbea9f842..2458bf9e6 100644 --- a/Network/LevelChunkStream.cs +++ b/Network/LevelChunkStream.cs @@ -18,7 +18,6 @@ using System; using System.IO; using System.IO.Compression; -using System.Threading; namespace MCGalaxy { public sealed class LevelChunkStream : Stream { diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index c7a706f26..70f1756c9 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -15,10 +15,8 @@ permissions and limitations under the Licenses. using System; using System.Collections.Generic; using System.IO; -using System.IO.Compression; using System.Net.Sockets; using System.Text; -using System.Threading; namespace MCGalaxy { public sealed partial class Player : IDisposable {