forked from PenisBlistashiq/Rust-plugins-236-240-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildingInfo.cs
More file actions
249 lines (206 loc) · 8.68 KB
/
Copy pathBuildingInfo.cs
File metadata and controls
249 lines (206 loc) · 8.68 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Building Info", "misticos", "1.0.7")]
[Description("Scan buildings and get their owners")]
class BuildingInfo : RustPlugin
{
#region Variables
private const string PermScan = "buildinginfo.scan";
private const string PermOwner = "buildinginfo.owner";
private const string PermAuthed = "buildinginfo.authed";
private const string PermBypass = "buildinginfo.bypass";
#endregion
#region Configuration
private Configuration _config = new Configuration();
public class Configuration
{
[JsonProperty(PropertyName = "Command Scan")]
public string CommandScan = "scan";
[JsonProperty(PropertyName = "Command Scan Owner")]
public string CommandOwner = "owner";
[JsonProperty(PropertyName = "Command Scan Authorized Players")]
public string CommandAuthed = "authed";
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
}
catch
{
PrintError("Your configuration file contains an error. Using default configuration values.");
LoadDefaultConfig();
}
}
protected override void LoadDefaultConfig() => _config = new Configuration();
protected override void SaveConfig() => Config.WriteObject(_config);
#endregion
#region Commands
private void CommandChatScan(BasePlayer player, string command, string[] args)
{
var id = player.UserIDString;
if (!permission.UserHasPermission(id, PermScan))
{
player.ChatMessage(GetMsg("No Permissions", id));
return;
}
var entity = GetBuilding(player);
if (entity == null)
{
player.ChatMessage(GetMsg("Cannot Find", id));
return;
}
var owner = BasePlayer.FindByID(entity.OwnerID);
if (owner != null && permission.UserHasPermission(owner.UserIDString, PermBypass))
{
player.ChatMessage(GetMsg("Scan Unavailable", id));
return;
}
var entities = entity.GetBuildingPrivilege()?.GetBuilding()?.buildingBlocks;
if (entities == null || entities.Count == 0)
{
player.ChatMessage(GetMsg("Cannot Find", id));
return;
}
var dict = new Dictionary<string, ushort>();
var entitiesCount = entities.Count;
for (var i = 0; i < entitiesCount; i++)
{
var ent = entities[i];
if (permission.UserHasPermission(ent.OwnerID.ToString(), PermBypass))
continue;
var shortname = ent.ShortPrefabName + $" ({ent.currentGrade.gradeBase.type})";
if (dict.ContainsKey(shortname))
// ReSharper disable once RedundantAssignment
dict[shortname]++;
else
dict[shortname] = 1;
}
var ex = GetMsg("Scan Info", id);
var builder = new StringBuilder(GetMsg("Scan Title", id));
foreach (var el in dict)
{
builder.Append(ex);
builder = builder.Replace("{name}", el.Key).Replace("{amount}", el.Value.ToString());
}
player.ChatMessage(builder.ToString());
}
private void CommandChatOwner(BasePlayer player, string command, string[] args)
{
var id = player.UserIDString;
if (!permission.UserHasPermission(id, PermOwner))
{
player.ChatMessage(GetMsg("No Permissions", id));
return;
}
var entity = GetBuilding(player);
if (entity == null)
{
player.ChatMessage(GetMsg("Cannot Find", id));
return;
}
var owner = covalence.Players.FindPlayerById(entity.OwnerID.ToString());
if (owner == null)
{
player.ChatMessage(GetMsg("Cannot Find Owner", id));
return;
}
if (permission.UserHasPermission(owner.Id, PermBypass))
{
player.ChatMessage(GetMsg("Owner Unavailable", id));
return;
}
player.ChatMessage(GetMsg("Owner Info", id).Replace("{name}", owner.Name)
.Replace("{id}", owner.Id));
}
private void CommandChatAuthed(BasePlayer player, string command, string[] args)
{
var id = player.UserIDString;
if (!permission.UserHasPermission(id, PermAuthed))
{
player.ChatMessage(GetMsg("No Permissions", id));
return;
}
var entity = GetBuilding(player);
if (entity == null)
{
player.ChatMessage(GetMsg("Cannot Find", id));
return;
}
var privilege = entity.GetBuildingPrivilege();
if (privilege == null)
{
player.ChatMessage(GetMsg("Cannot Find Authed", id));
return;
}
if (!privilege.AnyAuthed())
{
player.ChatMessage(GetMsg("Authed Zero", id));
return;
}
var ex = GetMsg("Authed Info", id);
var builder = new StringBuilder(GetMsg("Authed Title", id));
var i = 0;
foreach (var authorizedPlayer in privilege.authorizedPlayers)
{
builder.Append(ex);
builder = builder
.Replace("{number}", $"{++i}")
.Replace("{name}", authorizedPlayer.username)
.Replace("{id}", authorizedPlayer.userid.ToString());
}
player.ChatMessage(builder.ToString());
}
#endregion
#region Hooks
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
{ "No Permissions", "You don't have enough permissions." },
{ "Scan Title", "Scan result:" },
{ "Scan Info", "\n{name} x{amount}" },
{ "Scan Unavailable", "Sorry, there was an error. You cannot scan this building." },
{ "Owner Info", "Owner: {name} ({id})" },
{ "Owner Unavailable", "Sorry, there was an error. You cannot get an owner of this building." },
{ "Authed Title", "Authed Players:" },
{ "Authed Info", "\n#{number} - {name} ({id})" },
{ "Authed Unavailable", "" },
{ "Authed Zero", "Nobody is authed here." },
{ "Cannot Find", "Excuse me, where is the building you are looking for?" },
{ "Cannot Find Owner", "Sorry, I don't know who owns this building." },
{ "Cannot Find Authed", "I don't know who is authed there." }
}, this);
}
// ReSharper disable once UnusedMember.Local
private void Init()
{
LoadConfig();
permission.RegisterPermission(PermScan, this);
permission.RegisterPermission(PermOwner, this);
permission.RegisterPermission(PermAuthed, this);
permission.RegisterPermission(PermBypass, this);
cmd.AddChatCommand(_config.CommandScan, this, CommandChatScan);
cmd.AddChatCommand(_config.CommandOwner, this, CommandChatOwner);
cmd.AddChatCommand(_config.CommandAuthed, this, CommandChatAuthed);
}
#endregion
#region Helpers
private string GetMsg(string key, string userId = null) => lang.GetMessage(key, this, userId);
private BaseEntity GetBuilding(BasePlayer player)
{
RaycastHit info;
Physics.Raycast(player.eyes.HeadRay(), out info, LayerMask.GetMask("Construction"));
return info.GetEntity();
}
#endregion
}
}