Skip to content

Commit 44c6aa7

Browse files
Quick fix for /signadd on case-sensitive filesystems, remove hardcoding of 'WorldGreeting' directory in various places
1 parent 026ae2e commit 44c6aa7

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

fCraft/Commands/WorldCommands.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,13 +3030,14 @@ static void SetMOTD(Player player, World world, string value) {
30303030
}
30313031

30323032
static void SetGreeting(Player player, World world, string value) {
3033-
if (!Directory.Exists("./WorldGreeting/"))
3034-
Directory.CreateDirectory("./WorldGreeting/");
3033+
if (!Directory.Exists(Paths.WGreetingsPath))
3034+
Directory.CreateDirectory(Paths.WGreetingsPath);
3035+
string greetingsPath = Path.Combine(Paths.WGreetingsPath, world.Name + ".txt");
30353036

30363037
if (String.IsNullOrEmpty(value)) {
30373038
if (world.Greeting == null) {
3038-
if (File.Exists("./WorldGreeting/" + world.Name + ".txt")) {
3039-
world.Greeting = File.ReadAllText("./WorldGreeting/" + world.Name + ".txt");
3039+
if (File.Exists(greetingsPath)) {
3040+
world.Greeting = File.ReadAllText(greetingsPath);
30403041
if (world.Greeting.Length == 0)
30413042
player.Message("No greeting message is set for world {0}", world.ClassyName);
30423043
else
@@ -3048,13 +3049,13 @@ static void SetGreeting(Player player, World world, string value) {
30483049
}
30493050
} else if (value.CaselessEquals("remove")) {
30503051
player.Message("Greeting message removed for world {0}", world.ClassyName);
3051-
if (File.Exists("./WorldGreeting/" + world.Name + ".txt"))
3052-
File.Delete("./WorldGreeting/" + world.Name + ".txt");
3052+
if (File.Exists(greetingsPath))
3053+
File.Delete(greetingsPath);
30533054
world.Greeting = null;
30543055
} else {
30553056
world.Greeting = value;
30563057
player.Message("Greeting message for world {0}&S set to: {1}", world.ClassyName, world.Greeting);
3057-
File.WriteAllText("./WorldGreeting/" + world.Name + ".txt", world.Greeting);
3058+
File.WriteAllText(greetingsPath, world.Greeting);
30583059
world.Greeting = null;
30593060
}
30603061
}

fCraft/Network/Player.Networking.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,33 +1160,27 @@ void WriteWorldData(Map map) {
11601160
}
11611161

11621162
void SendJoinMessage(World oldWorld, World newWorld) {
1163-
if (oldWorld == newWorld)
1164-
{
1163+
if (oldWorld == newWorld) {
11651164
Message("&SRejoined world {0}", newWorld.ClassyName);
1165+
return;
11661166
}
1167-
else
1168-
{
1169-
Message("&SJoined world {0}", newWorld.ClassyName);
1170-
string greeting = newWorld.Greeting;
1171-
if (greeting != null)
1172-
{
1173-
greeting = Chat.ReplaceTextKeywords(this, greeting);
1174-
Message(greeting);
1175-
}
1176-
else
1177-
{
1178-
FileInfo GreetingInfo = new FileInfo("./WorldGreeting/" + World.Name + ".txt");
1179-
if (GreetingInfo.Exists)
1180-
{
1181-
string[] Greeting = File.ReadAllLines("./WorldGreeting/" + World.Name + ".txt");
1182-
string GreetingMessage = "";
1183-
foreach (string line in Greeting)
1184-
{
1185-
GreetingMessage += line + "&N";
1186-
}
1187-
Message(Chat.ReplaceTextKeywords(this, GreetingMessage));
1188-
}
1167+
1168+
Message("&SJoined world {0}", newWorld.ClassyName);
1169+
string greeting = newWorld.Greeting;
1170+
if (greeting != null) {
1171+
greeting = Chat.ReplaceTextKeywords(this, greeting);
1172+
Message(greeting);
1173+
return;
1174+
}
1175+
1176+
string greetingsPath = Path.Combine(Paths.WGreetingsPath, World.Name + ".txt");
1177+
if (File.Exists(greetingsPath)) {
1178+
string[] lines = File.ReadAllLines(greetingsPath);
1179+
greeting = "";
1180+
foreach (string line in lines) {
1181+
greeting += line + "&N";
11891182
}
1183+
Message(Chat.ReplaceTextKeywords(this, greeting));
11901184
}
11911185
}
11921186

fCraft/System/Utils/Paths.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,24 @@ static Paths() {
7979
public static readonly string WorkingPathDefault;
8080

8181
public const string FontsDirectory = "fonts";
82-
83-
public static string FontsPath
84-
{
82+
public static string FontsPath {
8583
get { return Path.Combine(WorkingPath, FontsDirectory); }
8684
}
8785

8886
public const string WClearDirectory = "WClearBackups";
89-
90-
public static string WClearPath
91-
{
87+
public static string WClearPath {
9288
get { return Path.Combine(WorkingPath, WClearDirectory); }
9389
}
90+
91+
public const string SignsDirectory = "Signs";
92+
public static string SignsPath {
93+
get { return Path.Combine(WorkingPath, SignsDirectory); }
94+
}
95+
96+
public const string WGreetingDirectory = "WorldGreeting";
97+
public static string WGreetingsPath {
98+
get { return Path.Combine(WorkingPath, WGreetingDirectory); }
99+
}
94100

95101
/// <summary> Path to save maps to (default: .\maps)
96102
/// Can be overridden at startup via command-line argument "--mappath=",

fCraft/Zone/SpecialZone.Affect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void HandleSign(Player p, Zone zone) {
3434
if (TextCooldown(p)) return;
3535

3636
if (zone.Sign == null) {
37-
string path = "./signs/" + p.World.Name + "/" + zone.Name + ".txt";
37+
string path = "./Signs/" + p.World.Name + "/" + zone.Name + ".txt";
3838
if (File.Exists(path)) {
3939
p.SignLines = File.ReadAllLines(path);
4040
p.Message(String.Join("&N", p.SignLines));
@@ -55,7 +55,7 @@ static void HandleCommandBlock(Player p, Zone zone) {
5555
if (p.IsCommandBlockRunning || TextCooldown(p)) return;
5656

5757
if (zone.Sign == null) {
58-
string path = "./signs/" + p.World.Name + "/" + zone.Name + ".txt";
58+
string path = "./Signs/" + p.World.Name + "/" + zone.Name + ".txt";
5959
if (File.Exists(path)) {
6060
p.SignLines = File.ReadAllLines(path);
6161

fCraft/Zone/SpecialZone.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static bool CanManage(string name, Player player, string action) {
5454
}
5555

5656
static string GetSignMessage(Player p, Zone zone) {
57-
string path = "./signs/" + p.World.Name + "/" + zone.Name + ".txt";
57+
string path = "./Signs/" + p.World.Name + "/" + zone.Name + ".txt";
5858
if (!File.Exists(path)) return null;
5959

6060
string[] lines = File.ReadAllLines(path);

0 commit comments

Comments
 (0)