Skip to content

Commit c461ff0

Browse files
Stop hardcoding 'signs' directory everywhere
1 parent 44c6aa7 commit c461ff0

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

fCraft/Commands/ZoneCommands.cs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,13 @@ static void SignAddHandler(Player player, CommandReader cmd)
270270
}
271271
else
272272
{
273-
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
274-
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
275-
File.WriteAllText("./Signs/" + player.World.Name + "/" + newZone.Name + ".txt", cmd.NextAll());
273+
string path = Paths.SignsPath;
274+
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
275+
path = Path.Combine(path, player.World.Name);
276+
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
277+
278+
path = Path.Combine(path, newZone.Name + ".txt");
279+
File.WriteAllText(path, newZone.Sign);
276280
player.Message("Message for sign {0}&S is: {1}", newZone.ClassyName, newZone.Sign);
277281
newZone.Sign = null;
278282
}
@@ -369,27 +373,26 @@ static void ZoneEditHandler( Player player, CommandReader cmd ) {
369373

370374
//player.Message(cmd.RawMessage);
371375
//player.Message(cmd.RawMessage.Substring(cmd.Offset));
372-
if (cmd.RawMessage.Substring(cmd.Offset + 1).StartsWith("#"))
373-
{
374-
zone.Sign = cmd.NextAll().Substring(1);
375-
if (zone.Sign.Length == 0 || zone.Sign == null)
376-
{
377-
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
378-
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
379-
if (File.Exists("./Signs/" + player.World.Name + "/" + zone.Name + ".txt")) File.Delete("./Signs/" + player.World.Name + "/" + zone.Name + ".txt");
380-
player.Message("Sign Text for zone {0}&S was removed.", zone.ClassyName);
381-
zone.Sign = null;
382-
}
383-
else
384-
{
385-
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
386-
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
387-
File.WriteAllText("./Signs/" + player.World.Name + "/" + zone.Name + ".txt", cmd.NextAll().Substring(1));
388-
player.Message("Sign Text for zone {0}&S changed to {1}", zone.ClassyName, zone.Sign);
389-
zone.Sign = null;
390-
}
391-
return;
376+
if (cmd.RawMessage.Substring(cmd.Offset + 1).StartsWith("#")) {
377+
zone.Sign = cmd.NextAll().Substring(1);
378+
379+
string path = Paths.SignsPath;
380+
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
381+
path = Path.Combine(path, player.World.Name);
382+
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
383+
384+
path = Path.Combine(path, zone.Name + ".txt");
385+
if (zone.Sign.Length == 0 || zone.Sign == null) {
386+
if (File.Exists(path)) File.Delete(path);
387+
player.Message("Sign Text for zone {0}&S was removed.", zone.ClassyName);
388+
zone.Sign = null;
389+
} else {
390+
File.WriteAllText(path, zone.Sign);
391+
player.Message("Sign Text for zone {0}&S changed to {1}", zone.ClassyName, zone.Sign);
392+
zone.Sign = null;
392393
}
394+
return;
395+
}
393396

394397
string nextToken;
395398
while( (nextToken = cmd.Next()) != null ) {

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 = SignPath(p, zone);
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 = SignPath(p, zone);
5959
if (File.Exists(path)) {
6060
p.SignLines = File.ReadAllLines(path);
6161

fCraft/Zone/SpecialZone.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ 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";
58-
if (!File.Exists(path)) return null;
59-
57+
string path = SignPath(p, zone);
58+
if (!File.Exists(path)) return null;
6059
string[] lines = File.ReadAllLines(path);
6160
return String.Join("&N", lines);
6261
}
6362

63+
static string SignPath(Player p, Zone zone) {
64+
string path = Path.Combine(Paths.SignsPath, p.World.Name);
65+
return Path.Combine(path, zone.Name + ".txt");
66+
}
67+
6468
static void SendZoneMessage(Player p, string message) {
6569
if ((DateTime.UtcNow - p.LastZoneNotification).Seconds <= 2) return;
6670
p.Message(message);

0 commit comments

Comments
 (0)