Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 888579f

Browse files
Added !updatename command to allow reloading colors in game
1 parent 08ce628 commit 888579f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

NamePlugin/Class1.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public class Entry : IPlugin {
1919
public void Initialize(IManager manager) {
2020
FileSystem fs = new FileSystem(typeof(Entry));
2121
try {
22-
System.IO.StreamReader sr = new System.IO.StreamReader(fs.OpenFile("name.txt"));
23-
colorData = new float[] { Convert.ToSingle(sr.ReadLine().Split(new string[] { "hue start: " }, StringSplitOptions.None)[1]) / 360f, Convert.ToSingle(sr.ReadLine().Split(new string[] { "hue end: " }, StringSplitOptions.None)[1]) / 360f, Convert.ToSingle(sr.ReadLine().Split(new string[] { "saturation: " }, StringSplitOptions.None)[1]) / 100, Convert.ToSingle(sr.ReadLine().Split(new string[] { "value: " }, StringSplitOptions.None)[1]) / 100 };
24-
sr.Dispose();
22+
LoadColors(fs);
2523
} catch (Exception ex) {
2624
fs.CreateFile("name.txt");
2725
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs.OpenFile("name.txt"));
@@ -49,6 +47,16 @@ public void Initialize(IManager manager) {
4947
Events.Network.DisconnectedFromServer.Subscribe(data => {
5048
alreadySet = false;
5149
});
50+
Spectrum.API.Game.Network.Chat.MessageSent += (sender, args) => {
51+
if (args.Author == username && args.Message.Contains("!updatename"))
52+
LoadColors(fs);
53+
};
54+
}
55+
56+
private void LoadColors(FileSystem fs) {
57+
System.IO.StreamReader sr = new System.IO.StreamReader(fs.OpenFile("name.txt"));
58+
colorData = new float[] { Convert.ToSingle(sr.ReadLine().Split(new string[] { "hue start: " }, StringSplitOptions.None)[1]) / 360f, Convert.ToSingle(sr.ReadLine().Split(new string[] { "hue end: " }, StringSplitOptions.None)[1]) / 360f, Convert.ToSingle(sr.ReadLine().Split(new string[] { "saturation: " }, StringSplitOptions.None)[1]) / 100, Convert.ToSingle(sr.ReadLine().Split(new string[] { "value: " }, StringSplitOptions.None)[1]) / 100 };
59+
sr.Dispose();
5260
}
5361

5462
private void UpdateName() {

0 commit comments

Comments
 (0)