Ai fixed issues hopefully

using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Oxide.Plugins
{
[Info("Quarry Craft Fixed", "Grok/xAI", "1.0.2")]
[Description("Allows players to craft mining quarry via /quarry - bypasses blueprints/NoBP - no workbench required")]
class QuarryCraft : RustPlugin
{
#region Config & Vars

private PluginConfig config;
private Dictionary<string, ItemAmount> ingredients = new Dictionary<string, ItemAmount>();

private class PluginConfig
{
[JsonProperty("Crafting price (shortname: amount)")]
public Dictionary<string, int> Price = new Dictionary<string, int>()
{
["wood"] = 10000,
["metal.fragments"] = 1750,
["cloth"] = 500
};

[JsonProperty("Amount of quarries to craft")]
public int Amount = 1;

[JsonProperty("Permission required to craft")]
public string Permission = "quarrycraft.use";

[JsonProperty("Chat command (without the /)")]
public string Command = "quarry";
}

protected override void LoadDefaultConfig()
{
config = new PluginConfig();
SaveConfig();
}

protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>() ?? new PluginConfig();

ingredients.Clear();
var allDefs = ItemManager.GetItemDefinitions();

foreach (var kvp in config.Price)
{
var def = allDefs.FirstOrDefault(x => x.shortname == kvp.Key);
if (def == null)
{
PrintWarning($"Invalid shortname in config: {kvp.Key} - skipping");
continue;
}

ingredients[kvp.Key] = new ItemAmount(def, kvp.Value * config.Amount);
}

if (ingredients.Count == 0)
{
PrintError("No valid ingredients loaded! Check your config shortnames.");
}
else
{
PrintWarning($"Loaded {ingredients.Count} ingredients for quarry crafting.");
}

cmd.AddChatCommand(config.Command, this, nameof(CmdCraft));
permission.RegisterPermission(config.Permission, this);
}

protected override void SaveConfig()
{
Config.WriteObject(config);
}

#endregion

#region Command Handler

private void CmdCraft(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, config.Permission))
{
player.ChatMessage("You don't have permission to craft a quarry.");
return;
}

// Check if player has all required items
var missing = new List<string>();
foreach (var ing in ingredients.Values)
{
if (ing.itemDef == null) continue;

int required = (int)ing.amount;
int have = player.inventory.GetAmount(ing.itemDef.itemid);

if (have < required)
{
missing.Add($"{ing.itemDef.displayName.english}: {required - have}/{required}");
}
}

if (missing.Count > 0)
{
player.ChatMessage("Missing resources:\n" + string.Join("\n", missing));
return;
}

// Consume the items
bool success = true;
foreach (var ing in ingredients.Values)
{
if (ing.itemDef == null)
{
success = false;
break;
}

int taken = player.inventory.Take(null, ing.itemDef.itemid, (int)ing.amount);
if (taken < (int)ing.amount)
{
success = false;
break;
}
}

if (!success)
{
player.ChatMessage("Failed to take resources (inventory may have changed). Try again.");
return;
}

// Create and give the quarry
var quarryItem = ItemManager.CreateByName("mining.quarry", config.Amount);
if (quarryItem == null)
{
PrintError("Failed to create mining.quarry item!");
player.ChatMessage("Craft failed - contact admin.");
return;
}

player.inventory.GiveItem(quarryItem, player.inventory.containerMain);
player.ChatMessage($"<color=#55ff55>Success!</color> Crafted {config.Amount}x Mining Quarry!");
}

#endregion
}
}using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Oxide.Plugins
{
[Info("Quarry Craft Fixed", "Grok/xAI", "1.0.2")]
[Description("Allows players to craft mining quarry via /quarry - bypasses blueprints/NoBP - no workbench required")]
class QuarryCraft : RustPlugin
{
#region Config & Vars

private PluginConfig config;
private Dictionary<string, ItemAmount> ingredients = new Dictionary<string, ItemAmount>();

private class PluginConfig
{
[JsonProperty("Crafting price (shortname: amount)")]
public Dictionary<string, int> Price = new Dictionary<string, int>()
{
["wood"] = 10000,
["metal.fragments"] = 1750,
["cloth"] = 500
};

[JsonProperty("Amount of quarries to craft")]
public int Amount = 1;

[JsonProperty("Permission required to craft")]
public string Permission = "quarrycraft.use";

[JsonProperty("Chat command (without the /)")]
public string Command = "quarry";
}

protected override void LoadDefaultConfig()
{
config = new PluginConfig();
SaveConfig();
}

protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>() ?? new PluginConfig();

ingredients.Clear();
var allDefs = ItemManager.GetItemDefinitions();

foreach (var kvp in config.Price)
{
var def = allDefs.FirstOrDefault(x => x.shortname == kvp.Key);
if (def == null)
{
PrintWarning($"Invalid shortname in config: {kvp.Key} - skipping");
continue;
}

ingredients[kvp.Key] = new ItemAmount(def, kvp.Value * config.Amount);
}

if (ingredients.Count == 0)
{
PrintError("No valid ingredients loaded! Check your config shortnames.");
}
else
{
PrintWarning($"Loaded {ingredients.Count} ingredients for quarry crafting.");
}

cmd.AddChatCommand(config.Command, this, nameof(CmdCraft));
permission.RegisterPermission(config.Permission, this);
}

protected override void SaveConfig()
{
Config.WriteObject(config);
}

#endregion

#region Command Handler

private void CmdCraft(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, config.Permission))
{
player.ChatMessage("You don't have permission to craft a quarry.");
return;
}

// Check if player has all required items
var missing = new List<string>();
foreach (var ing in ingredients.Values)
{
if (ing.itemDef == null) continue;

int required = (int)ing.amount;
int have = player.inventory.GetAmount(ing.itemDef.itemid);

if (have < required)
{
missing.Add($"{ing.itemDef.displayName.english}: {required - have}/{required}");
}
}

if (missing.Count > 0)
{
player.ChatMessage("Missing resources:\n" + string.Join("\n", missing));
return;
}

// Consume the items
bool success = true;
foreach (var ing in ingredients.Values)
{
if (ing.itemDef == null)
{
success = false;
break;
}

int taken = player.inventory.Take(null, ing.itemDef.itemid, (int)ing.amount);
if (taken < (int)ing.amount)
{
success = false;
break;
}
}

if (!success)
{
player.ChatMessage("Failed to take resources (inventory may have changed). Try again.");
return;
}

// Create and give the quarry
var quarryItem = ItemManager.CreateByName("mining.quarry", config.Amount);
if (quarryItem == null)
{
PrintError("Failed to create mining.quarry item!");
player.ChatMessage("Craft failed - contact admin.");
return;
}

player.inventory.GiveItem(quarryItem, player.inventory.containerMain);
player.ChatMessage($"<color=#55ff55>Success!</color> Crafted {config.Amount}x Mining Quarry!");
}

#endregion
}
}

removed requiremnet for workbencd and BP

Merged post

oxide.grant group default QuarryCraft.use  permissions worked