Skip to content
Permalink
Browse files

Integrate /mrd into /wset, make /wset mrd save world list and immedia…

…tely update reach distance to players in the world
  • Loading branch information...
UnknownShadow200 committed Feb 9, 2018
1 parent e6f2505 commit 9f5d235be0a8d6dbf60bdce9972912af787218e0
Showing with 37 additions and 45 deletions.
  1. +0 −44 fCraft/Commands/CpeCommands.cs
  2. +37 −1 fCraft/Commands/WorldCommands.cs
@@ -24,7 +24,6 @@ static class CpeCommands {
CommandManager.RegisterCommand(CdLevelBlock);
CommandManager.RegisterCommand(CdHackControl);
CommandManager.RegisterCommand(CdListClients);
CommandManager.RegisterCommand(CdMRD);
CommandManager.RegisterCommand(Cdtex);
CommandManager.RegisterCommand(CdtextHotKey);
CommandManager.RegisterCommand(CdZoneShow);
@@ -2249,49 +2248,6 @@ static class CpeCommands {

#endregion

#region MaxReachDistance

static readonly CommandDescriptor CdMRD = new CommandDescriptor {
Name = "MaxReachDistance",
Aliases = new[] { "MaxReach", "MRD" },
Category = CommandCategory.CPE | CommandCategory.World | CommandCategory.New,
Permissions = new[] { Permission.ManageWorlds },
Help = "Changes the max reachdistance for a world",
Usage = "/MRD [Distance] (world)",
Handler = MRDHandler
};

private static void MRDHandler([NotNull] Player player, [NotNull] CommandReader cmd) {
string disString = cmd.Next();
if (disString == null) {
CdMRD.PrintUsage(player);
return;
}
string worldString = cmd.Next();
short distance = 160;
World world = player.World;
if (!short.TryParse(disString, out distance)) {
if (disString.CaselessEquals("normal") || disString.CaselessEquals("reset") ||
disString.CaselessEquals("default")) {
distance = -1;
} else {
player.Message("Invalid distance!");
return;
}
}
if (worldString != null) {
world = WorldManager.FindWorldOrPrintMatches(player, worldString);
if (world == null) {
return;
}
}
player.Message("Set max reach distance for world &f{0}&S to &f{1} &S(&f{2}&S blocks)", world.ClassyName, distance, distance / 32);
world.MaxReach = distance;

}

#endregion

#region TextHotKey

static readonly CommandDescriptor CdtextHotKey = new CommandDescriptor {
@@ -2845,6 +2845,8 @@ static void WorldClearHandler(Player player, CommandReader cmd)
"Whether any blocks can be placed by players in the world." },
{ "deletable", "&H/WSet <WorldName> Deletable On/Off&N&S" +
"Whether any blocks can be deleted by players in the world." },
{ "maxreach", "&H/WSet <WorldName> MaxReach <Distance>/reset&N&S" +
"Sets maximum reach distance players may click/reach up to." },
},
Handler = WorldSetHandler
};
@@ -2886,6 +2888,10 @@ static void WorldClearHandler(Player player, CommandReader cmd)
case "messageoftheday":
case "motd":
SetMOTD(player, world, value); break;
case "mrd":
case "maxreach":
case "maxreachdistance":
SetMaxReach(player, world, value); break;
default:
CdWorldSet.PrintUsage(player); break;
}
@@ -3064,7 +3070,37 @@ static void WorldClearHandler(Player player, CommandReader cmd)
world.Greeting = null;
}
}


static void SetMaxReach(Player player, World world, string value) {
short dist = world.MaxReach;
if (String.IsNullOrEmpty(value)) {
if (dist == -1) {
player.Message("Max reach distance for world {0}&S currently not set", world.ClassyName);
} else {
player.Message("Max reach distance for world {0}&S currently &f{1} &S(&f{2}&S blocks)",
world.ClassyName, dist, dist / 32);
}
return;
}

if (value.CaselessEquals("normal") || value.CaselessEquals("reset") || value.CaselessEquals("default")) {
dist = -1;
} else if (!short.TryParse(value, out dist)) {
player.Message("Invalid distance!");
return;
}

player.Message("Max reach distance for world {0}&S set to &f{1} &S(&f{2}&S blocks)",
world.ClassyName, dist, dist / 32);
world.MaxReach = dist;
WorldManager.SaveWorldList();

foreach (Player p in world.Players) {
if (!p.Supports(CpeExt.ClickDistance)) continue;
p.Send(Packet.MakeSetClickDistance(p.ReachDistance));
}
}

#endregion
#region WorldUnload

0 comments on commit 9f5d235

Please sign in to comment.
You can’t perform that action at this time.