Skip to content

Commit e6f2505

Browse files
Now big /reach persists across world joins, unless a map has specifically set a small /mrd
1 parent d88d70f commit e6f2505

File tree

7 files changed

+17
-26
lines changed

7 files changed

+17
-26
lines changed

fCraft/Commands/CpeCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ private static void MRDHandler([NotNull] Player player, [NotNull] CommandReader
22732273
if (!short.TryParse(disString, out distance)) {
22742274
if (disString.CaselessEquals("normal") || disString.CaselessEquals("reset") ||
22752275
disString.CaselessEquals("default")) {
2276-
distance = 160;
2276+
distance = -1;
22772277
} else {
22782278
player.Message("Invalid distance!");
22792279
return;
@@ -2286,7 +2286,7 @@ private static void MRDHandler([NotNull] Player player, [NotNull] CommandReader
22862286
}
22872287
}
22882288
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;
2289+
world.MaxReach = distance;
22902290

22912291
}
22922292

fCraft/Network/Player.Networking.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ void SendJoinCpeExtensions() {
12061206
}
12071207

12081208
if (Supports(CpeExt.ClickDistance)) {
1209-
short reach = (World.maxReach < Info.ReachDistance && !IsStaff) ? World.maxReach : Info.ReachDistance;
1210-
SendNow(Packet.MakeSetClickDistance(reach));
1209+
SendNow(Packet.MakeSetClickDistance(ReachDistance));
12111210
}
12121211

12131212
if (Supports(CpeExt.MessageType) && !IsPlayingCTF) {

fCraft/Player/Player.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ public void getLeftOverTime(Double maxTime, CommandReader cmd) {
182182
}
183183
Message("&WYou can use /" + cmd.Name + " again in " + timeLeft + " seconds");
184184
}
185+
186+
internal short ReachDistance {
187+
get { return (Info.ReachDistance < World.MaxReach || World.MaxReach == -1 || IsStaff) ? Info.ReachDistance : World.MaxReach; }
188+
}
185189

186190
/// <summary> The world that the player is currently on. May be null.
187191
/// Use .JoinWorld() to make players teleport to another world. </summary>

fCraft/Player/PlayerInfo.Actions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,7 @@ public void ChangeRank( [NotNull] Player player, [NotNull] Rank newRank, [CanBeN
790790
target.MaxCopySlots = target.Info.Rank.CopySlots;
791791

792792
if (target.Supports(CpeExt.ClickDistance) && target.World != null) {
793-
target.Send(Packet.MakeSetClickDistance((target.World.maxReach < ReachDistance
794-
&& !target.IsStaff) ? target.World.maxReach : ReachDistance));
793+
target.Send(Packet.MakeSetClickDistance(target.ReachDistance));
795794
}
796795
if (target.Supports(CpeExt.BlockPermissions) && target.World != null) {
797796
target.SendBlockPermissions();

fCraft/System/Utils/ExtensionMethods.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,6 @@ public static StringBuilder Digits( [NotNull] this StringBuilder builder, int nu
307307
}
308308

309309

310-
// Quicker Int32.Parse(string) by Karl Seguin
311-
public static int Parse( [NotNull] string stringToConvert ) {
312-
if( stringToConvert == null ) throw new ArgumentNullException( "stringToConvert" );
313-
int value = 0;
314-
int length = stringToConvert.Length;
315-
fixed( char* characters = stringToConvert ) {
316-
for( int i = 0; i < length; ++i ) {
317-
value = 10 * value + ( characters[i] - 48 );
318-
}
319-
}
320-
return value;
321-
}
322-
323-
324310
// UppercaseFirst by Sam Allen of http://www.dotnetperls.com
325311
[NotNull]
326312
public static string UppercaseFirst( this string s ) {

fCraft/World/World.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ public string GetTexture() {
10071007
#endregion
10081008

10091009
/// <summary> The max reachdistance of the map. </summary>
1010-
public short maxReach = 160;
1010+
public short MaxReach = -1;
10111011

10121012

10131013
/// <summary> Ensures that player name has the correct length (2-16 characters)

fCraft/World/WorldManager.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ static void LoadWorldListEntry([NotNull] XElement el)
255255
tempEl = el.Element("MOTD");
256256
if (tempEl != null) world.MOTD = tempEl.Value;
257257

258+
tempEl = el.Element("MaxReach");
259+
short reach;
260+
if (tempEl != null && Int16.TryParse(tempEl.Value, out reach)) world.MaxReach = reach;
261+
258262
//XElement bhEl = el.Element("BlockHunt");
259263
//if (bhEl != null) LoadBlockHuntSettings(world, worldName, bhEl);
260264

@@ -356,9 +360,6 @@ static void LoadEnvSettings(World world, string worldName, XElement el) {
356360
if ((attr = el.Attribute("terrain")) != null) {
357361
world.Texture = ParseString(attr, worldName);
358362
}
359-
if ((attr = el.Attribute("maxreach")) != null) {
360-
world.maxReach = ParseShort(attr, worldName, 160, "normal");
361-
}
362363
if ((attr = el.Attribute("weather")) != null) {
363364
world.Weather = ParseByte(attr, worldName, 0, "sunny");
364365
}
@@ -555,6 +556,9 @@ public static void SaveWorldList() {
555556
if (!world.Deletable) {
556557
temp.Add(new XAttribute("deletable", false));
557558
}
559+
if (world.MaxReach != -1) {
560+
temp.Add(new XElement("MaxReach", world.MaxReach));
561+
}
558562

559563
/*save BlockHunt settings
560564
XElement BHunt = new XElement("BlockHunt");
@@ -613,8 +617,7 @@ static void SaveEnvSettings(World world, XElement temp) {
613617
elEnv.Add(new XAttribute("water", world.HorizonBlock.GetHashCode()));
614618
elEnv.Add(new XAttribute("bedrock", world.EdgeBlock.GetHashCode()));
615619
if (world.Texture != null)
616-
elEnv.Add(new XAttribute("terrain", world.Texture));
617-
elEnv.Add(new XAttribute("maxreach", world.maxReach));
620+
elEnv.Add(new XAttribute("terrain", world.Texture));
618621
elEnv.Add(new XAttribute("weather", world.Weather));
619622

620623
if (world.CloudsHeight != short.MinValue)

0 commit comments

Comments
 (0)