-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFurnaceNoOreStop.cs
80 lines (66 loc) · 2.6 KB
/
FurnaceNoOreStop.cs
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
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("FurnaceNoOreStop", "Tacman", "1.0.2")]
[Description("Stops furnaces when there are no more ores, retaining the fuel, and ensures lanterns are unaffected.")]
public class FurnaceNoOreStop : RustPlugin
{
private string usePerm = "furnacenoorestop.use";
void Init()
{
permission.RegisterPermission(usePerm, this);
}
private void OnOvenCooked(BaseOven oven)
{
if (oven == null || oven.inventory == null)
return;
if (!permission.UserHasPermission(oven.OwnerID.ToString(), usePerm))
return;
if (oven.ShortPrefabName.Contains("lantern") || oven.ShortPrefabName.Contains("bbq") || oven.ShortPrefabName.Contains("fire"))
return;
bool hasOres = false;
foreach (Item item in oven.inventory.itemList)
{
if (item.info.shortname.Contains("ore") || item.info.shortname.Contains("crude"))
{
hasOres = true;
break;
}
}
if (!hasOres)
{
oven.StopCooking();
BasePlayer player = BasePlayer.FindByID(oven.OwnerID);
if (player != null)
{
player.ChatMessage("Your cooking has stopped because there are no more cookables.");
}
}
}
void OnItemAddedToContainer(ItemContainer container, Item item)
{
if (container?.entityOwner == null || item == null)
return;
BaseOven oven = container.entityOwner as BaseOven;
if (oven == null || (!oven.ShortPrefabName.Contains("furnace") && !oven.ShortPrefabName.Contains("refinery")))
return;
if (!permission.UserHasPermission(oven.OwnerID.ToString(), usePerm))
return;
if (item.info.shortname.Contains("crude") || item.info.shortname.Contains("ore"))
{
if (!oven.IsOn())
{
oven.StartCooking();
BasePlayer player = BasePlayer.FindByID(oven.OwnerID);
if (player != null)
{
player.ChatMessage("Your cooking has resumed because cookable items were added.");
}
}
}
}
}
}