Cleanup /follow.

This commit is contained in:
UnknownShadow200 2016-06-23 21:51:58 +10:00
parent b94db39578
commit f8f17d69e8
4 changed files with 54 additions and 82 deletions

View File

@ -185,14 +185,14 @@ namespace MCGalaxy.Commands
if (!LevelInfo.ExistsOffline(map)) {
Player.Message(p, "You don't have a map with that map number."); return;
}
LevelActions.Delete(map);
Command.all.Find("deletelvl").Use(p, map);
Player.Message(p, "Map 1 has been removed.");
} else if (byte.TryParse(value, out mapNum)) {
string map = p.name.ToLower() + value;
if (!LevelInfo.ExistsOffline(map)) {
Player.Message(p, "You don't have a map with that map number."); return;
}
LevelActions.Delete(map);
Command.all.Find("deletelvl").Use(p, map);
Player.Message(p, "Map " + value + " has been removed.");
} else {
Help(p);

View File

@ -70,7 +70,7 @@ namespace MCGalaxy {
MessageNeedMinPerm(p, action, perm);
}
protected void MessageNeedMinPerm(Player p, string action, int perm) {
protected static void MessageNeedMinPerm(Player p, string action, int perm) {
Group grp = Group.findPermInt(perm);
if (grp == null)
Player.Message(p, "Only ranks with permissions greater than &a{0}%Scan {1}", perm, action);
@ -78,11 +78,11 @@ namespace MCGalaxy {
Player.Message(p, "Only {0}%S+ can {1}", grp.ColoredName, action);
}
protected void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) {
protected static void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) {
MessageTooHighRank(p, action, p.group, canAffectOwnRank);
}
protected void MessageTooHighRank(Player p, string action, Group grp, bool canAffectGroup) {
protected static void MessageTooHighRank(Player p, string action, Group grp, bool canAffectGroup) {
if (canAffectGroup)
Player.Message(p, "Can only {0} players ranked {1} %Sor below", action, grp.ColoredName);
else

View File

@ -16,10 +16,8 @@
permissions and limitations under the Licenses.
*/
using System;
namespace MCGalaxy.Commands
{
public sealed class CmdFollow : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdFollow : Command {
public override string name { get { return "follow"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
@ -27,93 +25,64 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdFollow() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (!p.canBuild)
{
Player.Message(p, "You're currently being &4possessed%S!");
return;
}
if (!p.canBuild) { Player.Message(p, "You're currently being &4possessed%S!"); return; }
string[] args = message.SplitSpaces(2);
string name = args[0];
bool stealth = false;
if (message != "")
{
if (message == "#")
{
if (p.following != "")
{
stealth = true;
message = "";
}
else
{
Help(p);
return;
}
}
else if (message.IndexOf(' ') != -1)
{
if (message.Split(' ')[0] == "#")
{
if (p.hidden) stealth = true;
message = message.Split(' ')[1];
}
}
if (message == "#") {
if (p.following != "") { stealth = true; name = ""; }
else { Help(p); return; }
} else if (args.Length > 1 && args[0] == "#") {
if (p.hidden) stealth = true;
name = args[1];
}
Player who = PlayerInfo.Find(message);
if (message == "" && p.following == "") {
Help(p);
return;
if (name == "" && p.following == "") { Help(p); return; }
if (name.CaselessEq(p.following) || (name == "" && p.following != ""))
Unfollow(p, name, stealth);
else
Follow(p, name, stealth);
}
static void Unfollow(Player p, string name, bool stealth) {
Player who = PlayerInfo.FindExact(p.following);
Player.Message(p, "Stopped following ", who == null ? p.following : who.ColoredName);
p.following = "";
if (who != null) Entities.Spawn(p, who);
if (!p.hidden) return;
if (!stealth) {
Command.all.Find("hide").Use(p, "");
} else {
Player.Message(p, "You are still hidden.");
}
else if (message == "" && p.following != "" || message == p.following)
{
who = PlayerInfo.Find(p.following);
p.following = "";
if (p.hidden)
{
if (who != null)
p.SpawnEntity(who, who.id, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]);
if (!stealth)
{
Command.all.Find("hide").Use(p, "");
}
else
{
if (who != null)
{
Player.Message(p, "You have stopped following " + who.ColoredName + " %Sand remained hidden.");
}
else
{
Player.Message(p, "Following stopped.");
}
}
return;
}
}
if (who == null) { Player.Message(p, "Could not find player."); return; }
else if (who == p) { Player.Message(p, "Cannot follow yourself."); return; }
else if (who.group.Permission >= p.group.Permission) { MessageTooHighRank(p, "follow", false); return;}
else if (who.following != "") { Player.Message(p, who.DisplayName + " is already following " + who.following); return; }
}
static void Follow(Player p, string name, bool stealth) {
Player who = PlayerInfo.FindMatches(p, name);
if (who == null) return;
if (who == p) { Player.Message(p, "Cannot follow yourself."); return; }
if (who.group.Permission >= p.group.Permission) { MessageTooHighRank(p, "follow", false); return;}
if (who.following != "") { Player.Message(p, who.DisplayName + " is already following " + who.following); return; }
if (!p.hidden) Command.all.Find("hide").Use(p, "");
if (p.level != who.level) Command.all.Find("tp").Use(p, who.name);
if (p.following != "")
{
who = PlayerInfo.Find(p.following);
p.SpawnEntity(who, who.id, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]);
if (p.following != "") {
Player old = PlayerInfo.FindExact(p.following);
if (old != null)
p.SpawnEntity(old, old.id, old.pos[0], old.pos[1], old.pos[2], old.rot[0], old.rot[1]);
}
who = PlayerInfo.Find(message);
p.following = who.name;
Player.Message(p, "Following " + who.ColoredName + "%S. Use \"/follow\" to stop.");
p.DespawnEntity(who.id);
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.Message(p, "%T/follow <name>");
Player.Message(p, "%HFollows <name> until the command is cancelled");
Player.Message(p, "%T/follow # <name>");

View File

@ -67,7 +67,10 @@ namespace MCGalaxy {
}
}
internal static void Spawn(Player dst, Player p) {
Spawn(dst, p, p.id, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]);
}
internal static void Spawn(Player dst, Player p, byte id, ushort x, ushort y, ushort z,
byte rotx, byte roty, string possession = "") {
if (!Server.TablistGlobal)