Skip to content

Commit 9f5d235

Browse files
Integrate /mrd into /wset, make /wset mrd save world list and immediately update reach distance to players in the world
1 parent e6f2505 commit 9f5d235

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

fCraft/Commands/CpeCommands.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ internal static void Init() {
2424
CommandManager.RegisterCommand(CdLevelBlock);
2525
CommandManager.RegisterCommand(CdHackControl);
2626
CommandManager.RegisterCommand(CdListClients);
27-
CommandManager.RegisterCommand(CdMRD);
2827
CommandManager.RegisterCommand(Cdtex);
2928
CommandManager.RegisterCommand(CdtextHotKey);
3029
CommandManager.RegisterCommand(CdZoneShow);
@@ -2249,49 +2248,6 @@ static void ListClientsHandler(Player player, CommandReader cmd) {
22492248

22502249
#endregion
22512250

2252-
#region MaxReachDistance
2253-
2254-
static readonly CommandDescriptor CdMRD = new CommandDescriptor {
2255-
Name = "MaxReachDistance",
2256-
Aliases = new[] { "MaxReach", "MRD" },
2257-
Category = CommandCategory.CPE | CommandCategory.World | CommandCategory.New,
2258-
Permissions = new[] { Permission.ManageWorlds },
2259-
Help = "Changes the max reachdistance for a world",
2260-
Usage = "/MRD [Distance] (world)",
2261-
Handler = MRDHandler
2262-
};
2263-
2264-
private static void MRDHandler([NotNull] Player player, [NotNull] CommandReader cmd) {
2265-
string disString = cmd.Next();
2266-
if (disString == null) {
2267-
CdMRD.PrintUsage(player);
2268-
return;
2269-
}
2270-
string worldString = cmd.Next();
2271-
short distance = 160;
2272-
World world = player.World;
2273-
if (!short.TryParse(disString, out distance)) {
2274-
if (disString.CaselessEquals("normal") || disString.CaselessEquals("reset") ||
2275-
disString.CaselessEquals("default")) {
2276-
distance = -1;
2277-
} else {
2278-
player.Message("Invalid distance!");
2279-
return;
2280-
}
2281-
}
2282-
if (worldString != null) {
2283-
world = WorldManager.FindWorldOrPrintMatches(player, worldString);
2284-
if (world == null) {
2285-
return;
2286-
}
2287-
}
2288-
player.Message("Set max reach distance for world &f{0}&S to &f{1} &S(&f{2}&S blocks)", world.ClassyName, distance, distance / 32);
2289-
world.MaxReach = distance;
2290-
2291-
}
2292-
2293-
#endregion
2294-
22952251
#region TextHotKey
22962252

22972253
static readonly CommandDescriptor CdtextHotKey = new CommandDescriptor {

fCraft/Commands/WorldCommands.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,8 @@ static void WorldClearSaveHandler(Player player, CommandReader cmd) {
28452845
"Whether any blocks can be placed by players in the world." },
28462846
{ "deletable", "&H/WSet <WorldName> Deletable On/Off&N&S" +
28472847
"Whether any blocks can be deleted by players in the world." },
2848+
{ "maxreach", "&H/WSet <WorldName> MaxReach <Distance>/reset&N&S" +
2849+
"Sets maximum reach distance players may click/reach up to." },
28482850
},
28492851
Handler = WorldSetHandler
28502852
};
@@ -2886,6 +2888,10 @@ static void WorldSetHandler( Player player, CommandReader cmd ) {
28862888
case "messageoftheday":
28872889
case "motd":
28882890
SetMOTD(player, world, value); break;
2891+
case "mrd":
2892+
case "maxreach":
2893+
case "maxreachdistance":
2894+
SetMaxReach(player, world, value); break;
28892895
default:
28902896
CdWorldSet.PrintUsage(player); break;
28912897
}
@@ -3064,7 +3070,37 @@ static void SetGreeting(Player player, World world, string value) {
30643070
world.Greeting = null;
30653071
}
30663072
}
3067-
3073+
3074+
static void SetMaxReach(Player player, World world, string value) {
3075+
short dist = world.MaxReach;
3076+
if (String.IsNullOrEmpty(value)) {
3077+
if (dist == -1) {
3078+
player.Message("Max reach distance for world {0}&S currently not set", world.ClassyName);
3079+
} else {
3080+
player.Message("Max reach distance for world {0}&S currently &f{1} &S(&f{2}&S blocks)",
3081+
world.ClassyName, dist, dist / 32);
3082+
}
3083+
return;
3084+
}
3085+
3086+
if (value.CaselessEquals("normal") || value.CaselessEquals("reset") || value.CaselessEquals("default")) {
3087+
dist = -1;
3088+
} else if (!short.TryParse(value, out dist)) {
3089+
player.Message("Invalid distance!");
3090+
return;
3091+
}
3092+
3093+
player.Message("Max reach distance for world {0}&S set to &f{1} &S(&f{2}&S blocks)",
3094+
world.ClassyName, dist, dist / 32);
3095+
world.MaxReach = dist;
3096+
WorldManager.SaveWorldList();
3097+
3098+
foreach (Player p in world.Players) {
3099+
if (!p.Supports(CpeExt.ClickDistance)) continue;
3100+
p.Send(Packet.MakeSetClickDistance(p.ReachDistance));
3101+
}
3102+
}
3103+
30683104
#endregion
30693105
#region WorldUnload
30703106

0 commit comments

Comments
 (0)