Skip to content

Commit 460a36f

Browse files
authored
Merge pull request #3 from 5Dev24/develop
2 parents 0cd2ead + 7ce4f22 commit 460a36f

2 files changed

Lines changed: 39 additions & 41 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
## Permissions
66

7-
* `recycle.use` -- Allows players to use `/recycle` chat command and `recycle` console command
7+
* `recycle.use` -- Allows players to use the recycler
88
* `recycle.admin` -- Allows players to destroy all recyclers or dropped bags currently created by **Recycle**
99
* `recycle.bypass` -- Allows players to bypass the cooldown of recycling
1010

1111
## Commands
1212

13-
* `/recycle` and `recycle` -- Opens a recycler
13+
* `/recycle` and `recycle` -- Opens a recycler, can be configured
1414
* `/purgerecyclers` -- Destroys all recyclers and drops their contents to a locked bag at the owner's position
1515
* `/purgebags` -- Destroys all bags created by **Recycle**
1616

@@ -25,6 +25,7 @@
2525
"NPCs Only": false,
2626
"Allowed In Safe Zones": true,
2727
"Instant Recycling": false,
28+
"Command To Open Recycler": "recycle",
2829
"NPC Ids": [],
2930
"Recyclable Types": [
3031
"Ammunition",
@@ -43,7 +44,7 @@
4344
],
4445
"Blacklisted Items": []
4546
},
46-
"VERSION": "3.0.0"
47+
"VERSION": "3.0.1"
4748
}
4849
```
4950

Recycle.cs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Oxide.Core.Libraries.Covalence;
12
using System.Collections.Generic;
23
using Newtonsoft.Json;
34
using UnityEngine;
@@ -7,7 +8,7 @@
78

89
namespace Oxide.Plugins {
910

10-
[Info("Recycle", "5Dev24", "3.0.0")]
11+
[Info("Recycle", "5Dev24", "3.0.1")]
1112
[Description("Recycle items into their resources")]
1213
public class Recycle : RustPlugin {
1314

@@ -29,6 +30,8 @@ private void Loaded() {
2930
this.ValidateConfig();
3031
this.Data = Config.ReadObject<ConfigData>();
3132

33+
this.AddCovalenceCommand(this.Data?.Settings?.RecycleCommand ?? "recycle", "RecycleCommand", null);
34+
3235
permission.RegisterPermission(Recycle.AdminPermission, this);
3336
permission.RegisterPermission(Recycle.RecyclerPermission, this);
3437
permission.RegisterPermission(Recycle.CooldownBypassPermission, this);
@@ -55,41 +58,25 @@ private object CanAcceptItem(ItemContainer con, Item i, int target) {
5558
Recycler r = con.entityOwner as Recycler;
5659
if (this.IsRecycleBox(r)) {
5760
BasePlayer p = this.PlayerFromRecycler(r.net.ID);
58-
if (target < 6 && (!this.Data.Settings.RecyclableTypes.Contains(Enum.GetName(typeof(ItemCategory), i.info.category)) ||
59-
this.Data.Settings.Blacklist.Contains(i.info.shortname))) {
60-
if (p != null) this.PrintToChat(p, this.GetMessage("Recycle", "Invalid", p));
61-
return ItemContainer.CanAcceptResult.CannotAcceptRightNow;
61+
if (target < 6) {
62+
if (!this.Data.Settings.RecyclableTypes.Contains(Enum.GetName(typeof(ItemCategory), i.info.category)) ||
63+
this.Data.Settings.Blacklist.Contains(i.info.shortname)) {
64+
if (p != null) this.PrintToChat(p, this.GetMessage("Recycle", "Invalid", p));
65+
return ItemContainer.CanAcceptResult.CannotAcceptRightNow;
66+
} else if (this.Data.Settings.InstantRecycling) {
67+
if (!r.IsOn()) {
68+
r.InvokeRepeating(new Action(r.RecycleThink), 0, 0);
69+
Effect.server.Run(r.startSound.resourcePath, r, 0U, Vector3.zero, Vector3.zero, null, false);
70+
r.SetFlag(BaseEntity.Flags.On, true, false, true);
71+
r.SendNetworkUpdateImmediate();
72+
}
73+
} else r.StartRecycling();
6274
}
6375
}
6476
}
6577
return null;
6678
}
6779

68-
private void OnItemAddedToContainer(ItemContainer con, Item i) {
69-
if (con.entityOwner is Recycler) {
70-
Recycler r = con.entityOwner as Recycler;
71-
if (this.IsRecycleBox(r)) {
72-
BasePlayer p = this.PlayerFromRecycler(r.net.ID);
73-
if (i == null || p == null || i.position >= 6) return;
74-
else if (!this.Data.Settings.RecyclableTypes.Contains(Enum.GetName(typeof(ItemCategory), i.info.category)) ||
75-
this.Data.Settings.Blacklist.Contains(i.info.shortname)) {
76-
this.PrintToChat(p, this.GetMessage("Recycle", "Invalid", p));
77-
return;
78-
}
79-
80-
if (this.Data.Settings.InstantRecycling) {
81-
if (!r.IsOn()) {
82-
r.InvokeRepeating(new Action(r.RecycleThink), 0, 0);
83-
Effect.server.Run(r.startSound.resourcePath, r, 0U, Vector3.zero, Vector3.zero, null, false);
84-
r.SetFlag(BaseEntity.Flags.On, true, false, true);
85-
r.SendNetworkUpdateImmediate();
86-
}
87-
} else
88-
r.StartRecycling();
89-
}
90-
}
91-
}
92-
9380
private object OnRecycleItem(Recycler r, Item i) {
9481
if (this.IsRecycleBox(r)) {
9582
BasePlayer p = this.PlayerFromRecycler(r.net.ID);
@@ -167,12 +154,9 @@ private void OnUseNPC(BasePlayer npc, BasePlayer p) {
167154

168155
#region Commands
169156

170-
[ConsoleCommand("recycle")]
171-
private void RecycleConsoleCommand(ConsoleSystem.Arg arg) =>
172-
this.RecycleChatCommand(arg.Connection.player as BasePlayer, arg.cmd.Name, arg.Args);
173-
174-
[ChatCommand("recycle")]
175-
private void RecycleChatCommand(BasePlayer p, string cmd, string[] args) {
157+
private void RecycleCommand(IPlayer iP, string cmd, string[] args) {
158+
BasePlayer p = iP.Object as BasePlayer;
159+
if (p == null) return;
176160
if (!this.Data.Settings.NPCOnly && this.CanPlayerOpenRecycler(p)) {
177161
this.OpenRecycler(p);
178162
if (this.Data.Settings.Cooldown > 0) {
@@ -211,6 +195,8 @@ public struct EntityAndPlayer {
211195

212196
public class ConfigData {
213197
public class SettingsWrapper {
198+
[JsonProperty("Command To Open Recycler")]
199+
public string RecycleCommand = "recycle";
214200
[JsonProperty("Cooldown (in minutes)")]
215201
public float Cooldown = 5.0f;
216202
[JsonProperty("Maximum Radiation")]
@@ -231,7 +217,7 @@ public class SettingsWrapper {
231217
public List<string> Blacklist = new List<string>();
232218
}
233219
public SettingsWrapper Settings = new SettingsWrapper();
234-
public string VERSION = "3.0.0";
220+
public string VERSION = "3.0.1";
235221
}
236222

237223
#endregion
@@ -244,6 +230,7 @@ protected override void LoadDefaultConfig() {
244230
"Ammunition", "Attire", "Common", "Component", "Construction", "Electrical",
245231
"Fun", "Items", "Medical", "Misc", "Tool", "Traps", "Weapon" };
246232
Config.WriteObject(tmp, true);
233+
this.Data = tmp;
247234
}
248235

249236
private T GetSetting<T>(string val, T defaultVal) {
@@ -286,6 +273,16 @@ private void ValidateConfig() {
286273
Config.Clear();
287274
Config.WriteObject(this.Data, true);
288275
Config.Save();
276+
} else if (version.Equals("3.0.0")) {
277+
this.Data = Config.ReadObject<ConfigData>();
278+
if (this.Data == null) this.LoadDefaultConfig();
279+
else {
280+
this.Data.VERSION = Version.ToString();
281+
this.Data.Settings.RecycleCommand = "recycle";
282+
Config.Clear();
283+
Config.WriteObject(this.Data, true);
284+
Config.Save();
285+
}
289286
}
290287
} catch (NullReferenceException) {}
291288
}
@@ -477,4 +474,4 @@ public void RemoveNPC(string id) {
477474

478475
}
479476

480-
}
477+
}

0 commit comments

Comments
 (0)