-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignHistory.cs
More file actions
109 lines (87 loc) · 2.82 KB
/
SignHistory.cs
File metadata and controls
109 lines (87 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Oxide.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("SignHistory", "Kisuka", "1.0.1")]
[Description("Creates a changelog for signs.")]
class SignHistory : RustPlugin
{
private const string AdminPerm = "signhistory.allow";
private Dictionary<string, Sign> signs = new Dictionary<string, Sign>();
#region Data
class Sign
{
public string Owner;
public List<string> Changes = new List<string>();
}
private void LoadData() => signs = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, Sign>>("SignHistory");
private void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("SignHistory", signs);
#endregion
void Init()
{
permission.RegisterPermission(AdminPerm, this);
lang.RegisterMessages(new Dictionary<string, string>
{
["NotAllowed"] = "You don't have permission to use this command.",
["NoHistory"] = "No history found for this sign.",
["Owner"] = "Owner: {0}",
["Changes"] = "Changes:"
}, this);
LoadData();
}
void Unload()
{
SaveData();
}
void OnSignUpdated(Signage sign, BasePlayer player, string text)
{
logSignChange(sign, player);
}
void logSignChange(Signage sign, BasePlayer player)
{
var entityID = getEntityID(sign);
if (!signs.ContainsKey(entityID)) {
var owner = BasePlayer.FindByID(sign.OwnerID);
signs.Add(entityID, new Sign() {
Owner = owner.displayName +" (" +sign.OwnerID+")",
Changes = new List<string>()
});
}
if (signs.ContainsKey(entityID)) {
signs[entityID].Changes.Add(DateTime.Now + " : " + player.displayName + " (" + player.userID + ")");
}
SaveData();
}
public string getEntityID(BaseEntity entity)
{
return $"({entity.transform.localPosition.x};{entity.transform.localPosition.y};{entity.transform.localPosition.z})";
}
#region Command
[ChatCommand("history")]
void cmdHistory(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, AdminPerm)) {
SendReply(player, lang.GetMessage("NotAllowed", this, player.UserIDString));
return;
}
RaycastHit hit;
if (player == null || !Physics.Raycast(player.eyes.HeadRay(), out hit, 2.0f)) return;
var sign = hit.transform.GetComponentInParent<Signage>();
if (sign == null) return;
var entityID = getEntityID(sign);
if (!signs.ContainsKey(entityID)) {
SendReply(player, lang.GetMessage("NoHistory", this, player.UserIDString));
return;
}
SendReply(player, lang.GetMessage("Owner", this, player.UserIDString), signs[entityID].Owner);
SendReply(player, lang.GetMessage("Changes", this, player.UserIDString));
foreach (var change in signs[entityID].Changes) {
SendReply(player, change);
}
return;
}
#endregion
}
}