← Back to changelog

What changed

TCStoreAnything · v1.2.2 → v1.2.3 (current)

Diff 2 added · 2 removed · 133 → 133 total lines
1 1 /*▄▄▄ ███▄ ▄███▓ ▄████ ▄▄▄██▀▀▀▓█████▄▄▄█████▓
2 2 ▓█████▄ ▓██▒▀█▀ ██▒ ██▒ ▀█▒ ▒██ ▓█ ▀▓ ██▒ ▓▒
3 3 ▒██▒ ▄██▓██ ▓██░▒██░▄▄▄░ ░██ ▒███ ▒ ▓██░ ▒░
4 4 ▒██░█▀ ▒██ ▒██ ░▓█ ██▓▓██▄██▓ ▒▓█ ▄░ ▓██▓ ░
5 5 ░▓█ ▀█▓▒██▒ ░██▒░▒▓███▀▒ ▓███▒ ░▒████▒ ▒██▒ ░
6 6 ░▒▓███▀▒░ ▒░ ░ ░ ░▒ ▒ ▒▓▒▒░ ░░ ▒░ ░ ▒ ░░
7 7 ▒░▒ ░ ░ ░ ░ ░ ░ ▒ ░▒░ ░ ░ ░ ░
8 8 ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
9 9 ░ ░ ░ ░ ░ ░ ░*/
10 10 using System;
11 11 using System.Collections.Generic;
12 12 using System.Linq;
13 13 using HarmonyLib;
14 14 using Newtonsoft.Json;
15 15 using Oxide.Core.Plugins;
16 16
17 17 namespace Oxide.Plugins
18 18 {
19 - [Info("TCStoreAnything", "bmgjet", "1.2.2")]
19 + [Info("TCStoreAnything", "bmgjet", "1.2.3")]
20 20 class TCStoreAnything : RustPlugin
21 21 {
22 22 public static TCStoreAnything plugin;
23 23 private readonly string PermUse = "TCStoreAnything.Use";
24 24
25 25 #region Configuration
26 26 private Configuration config;
27 27
28 28 private class Configuration
29 29 {
30 30 [JsonProperty("Limit To TCs That The Owner Has The 'TCStoreAnything.Use' Perm")]
31 31 public bool PermLimit = true;
32 32
33 33 [JsonProperty("Limit To Tool Slots Only")]
34 34 public bool SlotsOnly = true;
35 35
36 36 [JsonProperty("Limit To Whitelist")]
37 37 public bool UseWhiteList = true;
38 38
39 39 [JsonProperty("Whitelist Shortnames")]
40 40 public string[] LimitItems = new string[]
41 41 {
42 42 "hammer",
43 43 "toolgun",
44 44 "building.planner",
45 45 "hosetool",
46 46 "wiretool",
47 47 "jackhammer",
48 48 "chainsaw",
49 49 "ammo.rifle.explosive",
50 50 "explosives",
51 51 "explosive.satchel",
52 52 "explosive.timed",
53 53 "grenade.beancan",
54 54 "ammo.rocket"
55 55 };
56 56
57 57 public string ToJson() => JsonConvert.SerializeObject(this);
58 58
59 59 public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
60 60 }
61 61
62 62 protected override void LoadDefaultConfig() { config = new Configuration(); }
63 63
64 64 protected override void LoadConfig()
65 65 {
66 66 base.LoadConfig();
67 67 try
68 68 {
69 69 config = Config.ReadObject<Configuration>();
70 70 if (config == null) { throw new JsonException(); }
71 71
72 72 if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys))
73 73 {
74 74 PrintWarning("Configuration appears to be outdated; updating and saving");
75 75 SaveConfig();
76 76 }
77 77 }
78 78 catch
79 79 {
80 80 PrintWarning($"Configuration file {Name}.json is invalid; using defaults");
81 81 LoadDefaultConfig();
82 82 }
83 83 }
84 84
85 85 protected override void SaveConfig()
86 86 {
87 87 PrintWarning($"Configuration changes saved to {Name}.json");
88 88 Config.WriteObject(config, true);
89 89 }
90 90 #endregion Configuration
91 91
92 92 #region OxideHooks
93 93 private void Init()
94 94 {
95 95 plugin = this;
96 96 permission.RegisterPermission(PermUse, this);
97 97 }
98 98 private void Unload() { plugin = null; }
99 99
100 100 private object ItemFilter(Item item, int targetSlot, BuildingPrivlidge tc)
101 101 {
102 102 if (config.PermLimit && !permission.UserHasPermission(tc.OwnerID.ToString(), PermUse)) { return null; }
103 103 if (config.UseWhiteList && !config.LimitItems.Contains(item.info.shortname)) { return null; }
104 104 if (!config.SlotsOnly) { return true; }
105 105 if (targetSlot >= 24 && targetSlot <= 29) { return true; }
106 106 return null;
107 107 }
108 108 #endregion
109 109
110 110 #region Harmony
111 111 [AutoPatch]
112 - [HarmonyPatch(typeof(BuildingPrivlidge), "ItemFilter", new Type[] { typeof(Item), typeof(int) })]
112 + [HarmonyPatch(typeof(BuildingPrivlidge), "ItemFilter", new Type[] {typeof(BasePlayer), typeof(Item), typeof(int) })]
113 113 internal class BuildingPrivlidge_ItemFilter
114 114 {
115 115 [HarmonyPrefix]
116 116 private static bool Prefix(Item item, int targetSlot, BuildingPrivlidge __instance, ref bool __result)
117 117 {
118 118 try
119 119 {
120 120 object obj = plugin.ItemFilter(item, targetSlot, __instance);
121 121 if (obj != null)
122 122 {
123 123 __result = (bool)obj;
124 124 return false;
125 125 }
126 126 }
127 127 catch { }
128 128 return true;
129 129 }
130 130 }
131 131 #endregion
132 132 }
133 133 }