Skip to content
Permalink
Browse files

Stop hardcoding 'signs' directory everywhere

  • Loading branch information...
UnknownShadow200 committed Jul 1, 2017
1 parent 44c6aa7 commit c461ff0c0c9c474083ab02a312f64d5bcbc443b8
Showing with 35 additions and 28 deletions.
  1. +26 −23 fCraft/Commands/ZoneCommands.cs
  2. +2 −2 fCraft/Zone/SpecialZone.Affect.cs
  3. +7 −3 fCraft/Zone/SpecialZone.cs
@@ -270,9 +270,13 @@ static void SignAddHandler(Player player, CommandReader cmd)
}
else
{
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
File.WriteAllText("./Signs/" + player.World.Name + "/" + newZone.Name + ".txt", cmd.NextAll());
string path = Paths.SignsPath;
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
path = Path.Combine(path, player.World.Name);
if (!Directory.Exists(path)) Directory.CreateDirectory(path);

path = Path.Combine(path, newZone.Name + ".txt");
File.WriteAllText(path, newZone.Sign);
player.Message("Message for sign {0}&S is: {1}", newZone.ClassyName, newZone.Sign);
newZone.Sign = null;
}
@@ -369,27 +373,26 @@ static void SignAddCallback(Player player, Vector3I[] marks, object tag)

//player.Message(cmd.RawMessage);
//player.Message(cmd.RawMessage.Substring(cmd.Offset));
if (cmd.RawMessage.Substring(cmd.Offset + 1).StartsWith("#"))
{
zone.Sign = cmd.NextAll().Substring(1);
if (zone.Sign.Length == 0 || zone.Sign == null)
{
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
if (File.Exists("./Signs/" + player.World.Name + "/" + zone.Name + ".txt")) File.Delete("./Signs/" + player.World.Name + "/" + zone.Name + ".txt");
player.Message("Sign Text for zone {0}&S was removed.", zone.ClassyName);
zone.Sign = null;
}
else
{
if (!Directory.Exists("./Signs/")) Directory.CreateDirectory("./Signs/");
if (!Directory.Exists("./Signs/" + player.World.Name + "/")) Directory.CreateDirectory("./Signs/" + player.World.Name + "/");
File.WriteAllText("./Signs/" + player.World.Name + "/" + zone.Name + ".txt", cmd.NextAll().Substring(1));
player.Message("Sign Text for zone {0}&S changed to {1}", zone.ClassyName, zone.Sign);
zone.Sign = null;
}
return;
if (cmd.RawMessage.Substring(cmd.Offset + 1).StartsWith("#")) {
zone.Sign = cmd.NextAll().Substring(1);

string path = Paths.SignsPath;
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
path = Path.Combine(path, player.World.Name);
if (!Directory.Exists(path)) Directory.CreateDirectory(path);

path = Path.Combine(path, zone.Name + ".txt");
if (zone.Sign.Length == 0 || zone.Sign == null) {
if (File.Exists(path)) File.Delete(path);
player.Message("Sign Text for zone {0}&S was removed.", zone.ClassyName);
zone.Sign = null;
} else {
File.WriteAllText(path, zone.Sign);
player.Message("Sign Text for zone {0}&S changed to {1}", zone.ClassyName, zone.Sign);
zone.Sign = null;
}
return;
}

string nextToken;
while( (nextToken = cmd.Next()) != null ) {
@@ -34,7 +34,7 @@ public static partial class SpecialZone {
if (TextCooldown(p)) return;

if (zone.Sign == null) {
string path = "./Signs/" + p.World.Name + "/" + zone.Name + ".txt";
string path = SignPath(p, zone);
if (File.Exists(path)) {
p.SignLines = File.ReadAllLines(path);
p.Message(String.Join("&N", p.SignLines));
@@ -55,7 +55,7 @@ public static partial class SpecialZone {
if (p.IsCommandBlockRunning || TextCooldown(p)) return;

if (zone.Sign == null) {
string path = "./Signs/" + p.World.Name + "/" + zone.Name + ".txt";
string path = SignPath(p, zone);
if (File.Exists(path)) {
p.SignLines = File.ReadAllLines(path);

@@ -54,13 +54,17 @@ public static partial class SpecialZone {
}

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

string path = SignPath(p, zone);
if (!File.Exists(path)) return null;
string[] lines = File.ReadAllLines(path);
return String.Join("&N", lines);
}

static string SignPath(Player p, Zone zone) {
string path = Path.Combine(Paths.SignsPath, p.World.Name);
return Path.Combine(path, zone.Name + ".txt");
}

static void SendZoneMessage(Player p, string message) {
if ((DateTime.UtcNow - p.LastZoneNotification).Seconds <= 2) return;
p.Message(message);

0 comments on commit c461ff0

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