Advertisement
Krythic

PreventLooting

Sep 6th, 2022
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 35.15 KB | None | 0 0
  1. using Oxide.Core.Plugins;
  2. using System;
  3. using System.Collections.Generic;
  4. using Oxide.Core;
  5. using Oxide.Game.Rust;
  6. using UnityEngine;
  7. using System.Reflection;
  8. using Oxide.Core.Libraries.Covalence;
  9. using System.Linq;
  10.  
  11. namespace Oxide.Plugins
  12. {
  13.     [Info("PreventLooting", "CaseMan", "1.12.1", ResourceId = 2469)]
  14.     [Description("Prevent looting by other players")]
  15.  
  16.     class PreventLooting : RustPlugin
  17.     {  
  18.         #region Variables
  19.         [PluginReference] Plugin Friends;
  20.         [PluginReference] Plugin ZoneManager;      
  21.        
  22.         bool UsePermission;
  23.         bool UseFriendsAPI;
  24.         bool UseTeams;
  25.         bool AdminCanLoot;
  26.         bool CanAuthCB;
  27.         bool CanLootPl;
  28.         bool CanLootCorpse;
  29.         bool CanLootEnt;
  30.         bool CanLootBackpack;
  31.         bool CanLootBackpackPlugin;
  32.         bool CanPickup;
  33.         bool CanOvenToggle;
  34.         bool IncludeZoneMode;
  35.         bool UseZoneManager;
  36.         bool UseExcludeEntities;
  37.         bool UseCupboard;
  38.         List<object> UseCupboardInclude;
  39.         bool UseOnlyInCupboardRange;       
  40.         List<object> UseOnlyInCupboardRangeInclude;
  41.         bool WipeDetected = false;
  42.         List<object> ZoneID;
  43.         List<object> ExcludeEntities;
  44.         string PLPerm = "preventlooting.use";
  45.         string PlayerPerm = "preventlooting.player";
  46.         string CorpsePerm = "preventlooting.corpse";
  47.         string BackpackPerm = "preventlooting.backpack";
  48.         string StoragePerm = "preventlooting.storage";
  49.         string AdmPerm = "preventlooting.admin";
  50.    
  51.         class StoredData
  52.         {
  53.             public Dictionary<ulong, EntityData> Data = new Dictionary<ulong, EntityData>();
  54.             public StoredData()
  55.             {
  56.             }
  57.         }
  58.  
  59.         class EntityData
  60.         {
  61.             public List<ulong> Share = new List<ulong>();
  62.             public Dictionary<string, List<ulong>> Quarry = new Dictionary<string, List<ulong>>();
  63.             public EntityData(){}
  64.         }
  65.        
  66.         StoredData storedData;
  67.        
  68.         #endregion
  69.         #region Initialization
  70.         void Init()
  71.         {
  72.             LoadDefaultConfig();
  73.             permission.RegisterPermission(PLPerm, this);
  74.             permission.RegisterPermission(AdmPerm, this);
  75.             permission.RegisterPermission(PlayerPerm, this);
  76.             permission.RegisterPermission(CorpsePerm, this);
  77.             permission.RegisterPermission(BackpackPerm, this);
  78.             permission.RegisterPermission(StoragePerm, this);
  79.             storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("PreventLooting");
  80.            
  81.         }
  82.         void OnServerInitialized()
  83.         {
  84.             if(WipeDetected)       
  85.             {
  86.                 PrintWarning("Wipe detected! Clearing all share data!");
  87.                 storedData.Data.Clear();
  88.                 Interface.Oxide.DataFileSystem.WriteObject("PreventLooting", storedData);
  89.             }  
  90.         }  
  91.         void OnServerSave() => Interface.Oxide.DataFileSystem.WriteObject("PreventLooting", storedData);
  92.         void Unload() => Interface.Oxide.DataFileSystem.WriteObject("PreventLooting", storedData);
  93.         void OnNewSave(string filename) => WipeDetected = true;
  94.         #endregion
  95.         #region Configuration
  96.         protected override void LoadDefaultConfig()
  97.         {
  98.             Config["UsePermission"] = UsePermission = GetConfig("UsePermission", false);
  99.             Config["UseFriendsAPI"] = UseFriendsAPI = GetConfig("UseFriendsAPI", true);
  100.             Config["UseTeams"] = UseTeams = GetConfig("UseTeams", true);
  101.             Config["AdminCanLoot"] = AdminCanLoot = GetConfig("AdminCanLoot", true);
  102.             Config["CanAuthorizeCupboard"] = CanAuthCB = GetConfig("CanAuthorizeCupboard", true);
  103.             Config["CanLootPlayer"] = CanLootPl = GetConfig("CanLootPlayer", false);
  104.             Config["CanLootCorpse"] = CanLootCorpse = GetConfig("CanLootCorpse", false);
  105.             Config["CanLootEntity"] = CanLootEnt = GetConfig("CanLootEntity", false);
  106.             Config["CanLootBackpack"] = CanLootBackpack = GetConfig("CanLootBackpack", false);
  107.             Config["CanLootBackpackPlugin"] = CanLootBackpackPlugin = GetConfig("CanLootBackpackPlugin", false);
  108.             Config["CanPickup"] = CanPickup = GetConfig("CanPickup", false);
  109.             Config["CanOvenToggle"] = CanOvenToggle = GetConfig("CanOvenToggle", false);
  110.             Config["UseZoneManager"] = UseZoneManager = GetConfig("UseZoneManager", false);
  111.             Config["ZoneManagerIncludeMode"] = IncludeZoneMode = GetConfig("ZoneManagerIncludeMode", false);
  112.             Config["ZoneID"] = ZoneID = GetConfig("ZoneID", new List<object>{"12345678"});
  113.             Config["UseExcludeEntities"] = UseExcludeEntities = GetConfig("UseExcludeEntities", true);
  114.             Config["ExcludeEntities"] = ExcludeEntities = GetConfig("ExcludeEntities", new List<object>{"mailbox.deployed"});
  115.             Config["UseCupboard"] = UseCupboard = GetConfig("UseCupboard", false);
  116.             Config["UseCupboardInclude"] = UseCupboardInclude = GetConfig("UseCupboardInclude", new List<object>{"storage"});
  117.             Config["UseOnlyInCupboardRange"] = UseOnlyInCupboardRange = GetConfig("UseOnlyInCupboardRange", false);
  118.             Config["UseOnlyInCupboardRangeInclude"] = UseOnlyInCupboardRangeInclude = GetConfig("UseOnlyInCupboardRangeInclude", new List<object>{"storage"});
  119.  
  120.             SaveConfig();
  121.         }      
  122.         #endregion     
  123.         #region Localization
  124.        
  125.         void LoadDefaultMessages()
  126.         {
  127.             lang.RegisterMessages(new Dictionary<string, string>
  128.             {
  129.                 ["OnTryLootPlayer"] = "You can not loot players!",
  130.                 ["OnTryLootCorpse"] = "You can not loot corpses of players!",
  131.                 ["OnTryLootEntity"] = "You can not use this entity because it is not yours!",
  132.                 ["OnTryLootBackpack"] = "You can not open this backpack because it is not yours!",
  133.                 ["OnTryPickup"] = "You can not pickup this because it is not yours!",
  134.                 ["NoAccess"] = "This entity is not yours!",
  135.                 ["PlayerNotFound"] = "Player {0} not found!",
  136.                 ["ShareAll"] = "All players were given permission to use this entity!",
  137.                 ["SharePlayer"] = "The player {0} was given permission to use this entity!",
  138.                 ["NoShare"] = "No permissions have been found for this entity!",
  139.                 ["ListShare"] = "List of permissions for this entity:",
  140.                 ["EntityNotFound"] = "You are not standing in front of the entity or away from it!",
  141.                 ["HasShareAllList"] = "All players are allowed to use this entity!",
  142.                 ["ShareClear"] = "All permissions for this entity have been deleted!",
  143.                 ["HasShareAll"] = "All players already have permission to use this entity!",
  144.                 ["HasSharePlayer"] = "Player {0} already has permission to use this entity!",
  145.                 ["HasUnShareAll"] = "Permission to use this entity has not been issued to all players!",
  146.                 ["HasUnSharePlayer"] = "Player {0} has not been granted permission to use this entity!",
  147.                 ["WasUnShareAll"] = "All players have been removed permission for this entity!",
  148.                 ["WasUnSharePlayer"] = "The permission to use this entity has been removed from player {0}!",
  149.                 ["MultiplePlayerFind"]="Multiple players found:",
  150.                 ["OwnEntity"]="This object is yours!",
  151.                 ["NoPermission"]="You do not have enough rights to execute this command!",
  152.                 ["EntPrevent"] = "This entity is protected!",
  153.                 ["EntNoPrevent"] = "This entity is not protected!",
  154.                 ["OnTryOnOff"] = "You can not turn on or off this entity because it is not yours!",
  155.                 ["OnTryAuthCB"] = "You can not authorize in cupboard because it is not yours!",
  156.             }, this);
  157.             lang.RegisterMessages(new Dictionary<string, string>
  158.             {
  159.                 ["OnTryLootPlayer"] = "Вы не можете обворовывать игроков!",
  160.                 ["OnTryLootCorpse"] = "Вы не можете обворовывать трупы игроков!",
  161.                 ["OnTryLootEntity"] = "Вы не можете использовать этот объект, потому что он вам не принадлежит!",
  162.                 ["OnTryLootBackpack"] = "Вы не можете открыть чужой рюкзак!",
  163.                 ["OnTryPickup"] = "Вы не можете взять чужое!",
  164.                 ["NoAccess"]="Этот объект не принадлежит вам!",
  165.                 ["PlayerNotFound"]="Игрок с именем {0} не найден!",
  166.                 ["ShareAll"]="Всем игрокам было выдано разрешение на использование этого объекта!",
  167.                 ["SharePlayer"]="Игроку {0} было выдано разрешение на использование этого объекта!",
  168.                 ["NoShare"]="Не найдено разрешений для этого объекта!",
  169.                 ["ListShare"]="Список разрешений для этого объекта:",
  170.                 ["EntityNotFound"]="Вы стоите не перед хранилищем или далеко от него!",
  171.                 ["HasShareAllList"]="Всем игрокам разрешено использовать этот объект!",
  172.                 ["ShareClear"]="Все разрешения для этого объекта были удалены!",
  173.                 ["HasShareAll"]="Все игроки уже имеют разрешение на использование этого объекта!",
  174.                 ["HasSharePlayer"]="Игрок {0} уже имеет разрешение на использование этого объекта!",
  175.                 ["HasUnShareAll"]="Разрешение на использование этого объекта не было выдано для всех игроков!",
  176.                 ["HasUnSharePlayer"]="Игроку {0} не было выдано разрешение на использование этого объекта!",
  177.                 ["WasUnShareAll"]="Всем игрокам было удалено разрешение на использование этого объекта!",
  178.                 ["WasUnSharePlayer"]="Игроку {0} было удалено разрешение на использование этого объекта!",
  179.                 ["MultiplePlayerFind"]="Найдено несколько игроков:",
  180.                 ["OwnEntity"]="Этот объект принадлежит вам!",
  181.                 ["NoPermission"]="У вас недостаточно прав для выполнения этой команды!",
  182.                 ["EntPrevent"]="Этот предмет защищен от воровства!",
  183.                 ["EntNoPrevent"]="Этот предмет не защищен от воровства!",
  184.                 ["OnTryOnOff"] = "Вы не можете включить или выключить этот объект, потому что он вам не принадлежит!",
  185.                 ["OnTryAuthCB"] = "Вы не можете авторизоваться в чужом шкафу, потому что он вам не принадлежит!",
  186.             }, this, "ru");
  187.  
  188.         }
  189.         #endregion
  190.         #region Hooks
  191.         private object CanLootEntity(BasePlayer player, LootableCorpse corpse)
  192.         {
  193.             if(corpse == null || player == null) return null;
  194.             if(CanLootCorpse) return null;
  195.             if(CheckHelper(player, corpse as BaseEntity)) return null;
  196.             if(IsFriend(corpse.playerSteamID, player.userID)) return null;
  197.             if(UsePermission && !permission.UserHasPermission(corpse.playerSteamID.ToString(), CorpsePerm)) return null;
  198.             if(corpse.playerSteamID < 76561197960265728L || player.userID == corpse.playerSteamID) return null;
  199.             if(UseCupboard || UseOnlyInCupboardRange)
  200.                     if(CheckAuthCupboard(corpse, player)) return null;
  201.             SendReply(player, lang.GetMessage("OnTryLootCorpse", this, player.UserIDString));  
  202.             return true;
  203.         }      
  204.         private object CanLootEntity(BasePlayer player, DroppedItemContainer container)
  205.         {
  206.             if(container == null || player == null) return null;
  207.             if(CanLootBackpack && CanLootBackpackPlugin) return null;
  208.             if(CheckHelper(player, container as BaseEntity)) return null;
  209.             if(((container as BaseEntity).name.Contains("item_drop_backpack") && !CanLootBackpack) || ((container as BaseEntity).name.Contains("droppedbackpack") && !CanLootBackpackPlugin))
  210.             {
  211.                 if(IsFriend(container.playerSteamID, player.userID)) return null;
  212.                 if(UsePermission && !permission.UserHasPermission(container.playerSteamID.ToString(), BackpackPerm)) return null;
  213.                 if(container.playerSteamID < 76561197960265728L || player.userID == container.playerSteamID) return null;
  214.                 if(UseCupboard || UseOnlyInCupboardRange)
  215.                     if(CheckAuthCupboard(container, player)) return null;
  216.                 SendReply(player, lang.GetMessage("OnTryLootBackpack", this, player.UserIDString));
  217.                 return true;
  218.             }
  219.             return null;
  220.         }
  221.         private object CanLootPlayer(BasePlayer target, BasePlayer player)
  222.         {
  223.             if(target == null || player == null) return null;
  224.             if(CanLootPl) return null;
  225.             if(CheckHelper(player, target as BaseEntity)) return null;
  226.             if(IsFriend(target.userID, player.userID)) return null;
  227.             if(UsePermission && !permission.UserHasPermission(target.userID.ToString(), PlayerPerm)) return null;
  228.             if(player.userID == target.userID) return null;
  229.             if(UseCupboard || UseOnlyInCupboardRange)
  230.                     if(CheckAuthCupboard(target, player)) return null;
  231.             SendReply(player, lang.GetMessage("OnTryLootPlayer", this, player.UserIDString));
  232.             return false;
  233.         }  
  234.         private bool CheckHelper(BasePlayer player, BaseEntity entity)
  235.         {
  236.             if(entity == null || player == null) return true;
  237.             if(player.IsAdmin && AdminCanLoot) return true;
  238.             if(permission.UserHasPermission(player.userID.ToString(), AdmPerm)) return true;
  239.             if(UseZoneManager && ZoneManager != null)
  240.             {
  241.                 if((string[])ZoneManager.Call("GetPlayerZoneIDs", player) != null)
  242.                 {                  
  243.                     if(!IncludeZoneMode)
  244.                     {                  
  245.                         foreach(var zoneID in ZoneID)
  246.                         {
  247.                             if((bool)ZoneManager.Call("isPlayerInZone", zoneID, player)) return true;              
  248.                         }
  249.                     }
  250.                     else
  251.                     {
  252.                         foreach(var zoneID in ZoneID)
  253.                         {
  254.                             if((bool)ZoneManager.Call("isPlayerInZone", zoneID, player)) return false;             
  255.                         }      
  256.                         return true;
  257.                     }
  258.                 }              
  259.             }
  260.             if(entity is SupplyDrop) return true;
  261.             return false;
  262.         }      
  263.         private object CanLootEntity(BasePlayer player, StorageContainer container)
  264.         {
  265.             if(container == null || player == null) return null;
  266.             if(CanLootEnt) return null;
  267.             BaseEntity entity = container as BaseEntity;
  268.             if(CheckHelper(player, entity)) return null;
  269.             BaseEntity childentity = entity;
  270.             entity = CheckParent(entity);
  271.             if(entity.OwnerID == player.userID) return null;
  272.             if(UsePermission && !permission.UserHasPermission(entity.OwnerID.ToString(), StoragePerm)) return null;
  273.             if(UseExcludeEntities)
  274.             {
  275.                 if(ExcludeEntities.Contains(entity.ShortPrefabName)) return null;
  276.             }          
  277.             if(IsVendingOpen(player, entity) || IsDropBoxOpen(player, entity)) return null;
  278.             if(IsFriend(entity.OwnerID, player.userID)) return null;
  279.             if(storedData.Data.ContainsKey(entity.net.ID))
  280.             {
  281.                 if(childentity == entity)
  282.                 {              
  283.                     if(storedData.Data[entity.net.ID].Share.Contains(player.userID) || storedData.Data[entity.net.ID].Share.Contains(0)) return null;
  284.                 }
  285.                 else
  286.                 {
  287.                     if(storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName))
  288.                         if(storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Contains(player.userID) || storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Contains(0)) return null;
  289.                 }  
  290.             }
  291.             if(entity.OwnerID != player.userID && entity.OwnerID != 0)
  292.             {          
  293.                 if(UseCupboard || UseOnlyInCupboardRange)
  294.                     if(CheckAuthCupboard(entity, player)) return null;
  295.                 SendReply(player, lang.GetMessage("OnTryLootEntity", this, player.UserIDString));
  296.                 return false;  
  297.             }
  298.             return null;
  299.         }
  300.         private object OnOvenToggle(BaseOven oven, BasePlayer player)
  301.         {
  302.             if(oven == null || player == null) return null;
  303.             if(CanOvenToggle) return null;
  304.             BaseEntity entity = oven as BaseEntity;
  305.             if(CheckHelper(player, entity)) return null;
  306.             if(entity.OwnerID == player.userID) return null;
  307.             if(entity.OwnerID != 0 && entity.OwnerID != player.userID && !IsFriend(entity.OwnerID, player.userID))
  308.             {  
  309.                 if(UseCupboard || UseOnlyInCupboardRange)
  310.                     if(CheckAuthCupboard(entity, player)) return null;
  311.                 SendReply(player, lang.GetMessage("OnTryOnOff", this, player.UserIDString));
  312.                 return false;
  313.             }  
  314.             return null;
  315.         }
  316.         private object CanPickupEntity(BasePlayer player, BaseCombatEntity ent)
  317.         {
  318.             if(ent == null || player == null) return null;
  319.             if(CanPickup) return null;
  320.             BaseEntity entity = ent as BaseEntity;
  321.             if(CheckHelper(player, entity)) return null;
  322.             if(entity.OwnerID != 0 && entity.OwnerID != player.userID && !IsFriend(entity.OwnerID, player.userID))
  323.             {  
  324.                 if(UseCupboard || UseOnlyInCupboardRange)
  325.                     if(CheckAuthCupboard(entity, player)) return null;
  326.                 SendReply(player, lang.GetMessage("OnTryPickup", this, player.UserIDString));
  327.                 return false;
  328.             }  
  329.             return null;
  330.         }
  331.         private object OnCupboardAuthorize(BuildingPrivlidge privilege, BasePlayer player)
  332.         {
  333.             if(CanAuthCB) return null;
  334.             BaseEntity entity = privilege as BaseEntity;
  335.             if(CheckHelper(player, entity)) return null;
  336.             if(entity.OwnerID != 0 && entity.OwnerID != player.userID && !IsFriend(entity.OwnerID, player.userID))
  337.             {  
  338.                 SendReply(player, lang.GetMessage("OnTryAuthCB", this, player.UserIDString));
  339.                 return false;
  340.             }
  341.             return null;
  342.         }
  343.         private BaseEntity CheckParent(BaseEntity entity)
  344.         {
  345.             if(entity.HasParent())
  346.             {
  347.                 BaseEntity parententity = entity.GetParentEntity();
  348.                 if(parententity is MiningQuarry)   
  349.                 {
  350.                     entity.OwnerID=parententity.OwnerID;
  351.                     entity=parententity;
  352.                 }  
  353.             }
  354.             return entity; 
  355.         }
  356.         object CanAdministerVending(BasePlayer player, VendingMachine machine)
  357.         {
  358.             if(machine == null || player == null) return null;
  359.             if(CanLootEnt) return null;
  360.             BaseEntity entity = machine as BaseEntity;
  361.             if(CheckHelper(player, entity)) return null;
  362.             if(UsePermission && !permission.UserHasPermission(entity.OwnerID.ToString(), StoragePerm)) return null;
  363.             if(entity.OwnerID == player.userID) return null;
  364.             if(UseExcludeEntities)
  365.             {
  366.                 if(ExcludeEntities.Contains(entity.ShortPrefabName)) return null;
  367.             }      
  368.             if(IsFriend(entity.OwnerID, player.userID)) return null;
  369.             if(entity.OwnerID != player.userID && entity.OwnerID != 0)
  370.             {          
  371.                 if(UseCupboard || UseOnlyInCupboardRange)
  372.                     if(CheckAuthCupboard(entity, player)) return null;
  373.                 SendReply(player, lang.GetMessage("OnTryLootEntity", this, player.UserIDString));
  374.                 return false;  
  375.             }
  376.             return null;
  377.         }
  378.         bool IsVendingOpen(BasePlayer player, BaseEntity entity)
  379.         {
  380.             if(entity is VendingMachine)
  381.             {  
  382.                 VendingMachine shopFront = entity as VendingMachine;
  383.                 if(shopFront.PlayerInfront(player)) return true;
  384.                 return false;  
  385.             }
  386.             return false;
  387.         }
  388.         bool IsDropBoxOpen(BasePlayer player, BaseEntity entity)
  389.         {
  390.             if(entity is DropBox)
  391.             {  
  392.                 DropBox dropboxFront = entity as DropBox;
  393.                 if(dropboxFront.PlayerInfront(player)) return true;
  394.                 return false;      
  395.             }
  396.             return false;
  397.         }      
  398.         bool IsFriend(ulong friendid, ulong playerid)
  399.         {
  400.             if(UseFriendsAPI && Friends != null)   
  401.             {
  402.                 var fr = Friends.CallHook("AreFriends", friendid, playerid);
  403.                 if (fr != null && (bool)fr) return true;
  404.             }
  405.             if(UseTeams)
  406.             {
  407.                 BasePlayer player = BasePlayer.FindByID(playerid);
  408.                 if(player == null) return false;
  409.                 if (player.currentTeam != (long)0)
  410.                 {
  411.                     RelationshipManager.PlayerTeam playerTeam = RelationshipManager.ServerInstance.FindTeam(player.currentTeam);
  412.                     if(playerTeam == null) return false;
  413.                     if(playerTeam.members.Contains(friendid)) return true; 
  414.                 }      
  415.             }
  416.             return false;
  417.         }      
  418.         bool FindEntityFromRay(BasePlayer player, out object success)
  419.         {
  420.             success = null;
  421.             RaycastHit hit;
  422.             if (!Physics.Raycast(player.eyes.HeadRay(), out hit, 2.2f))
  423.                 return false;
  424.             success = hit.GetEntity();
  425.             return true;
  426.         }
  427.         bool CheckAuthCupboard(object ent, BasePlayer player)
  428.         {      
  429.             BaseEntity entity = ent as BaseEntity;
  430.             ulong ownerid = 0;
  431.             string type = "";
  432.             if(ent is BaseCombatEntity)
  433.                 if((ent as BaseCombatEntity).pickup.enabled) type = "pickup";
  434.             if(ent is StorageContainer || ent is MiningQuarry)
  435.             {
  436.                 ownerid = entity.OwnerID;
  437.                 type = "storage";
  438.             }              
  439.             else if(ent is BasePlayer)
  440.             {
  441.                 ownerid = (ent as BasePlayer).userID;
  442.                 type = "player";
  443.             }              
  444.             else if(ent is LootableCorpse)
  445.             {
  446.                 ownerid = (ent as LootableCorpse).playerSteamID;
  447.                 type = "corpse";
  448.             }          
  449.             else if(ent is DroppedItemContainer)
  450.             {
  451.                 ownerid = (ent as DroppedItemContainer).playerSteamID;
  452.                 if(entity.name.Contains("item_drop_backpack")) type = "backpack";
  453.                 else if (entity.name.Contains("droppedbackpack")) type = "backpackplugin";
  454.             }              
  455.             BuildingPrivlidge bprev = player.GetBuildingPrivilege(new OBB(entity.transform.position, entity.transform.rotation, entity.bounds));
  456.             if(UseOnlyInCupboardRangeInclude.Contains(type) && bprev == null)  
  457.             {              
  458.                 if(UseOnlyInCupboardRange) return true;
  459.                 if(!UseOnlyInCupboardRange) return false;
  460.             }
  461.             if(UseCupboard && UseCupboardInclude.Contains(type) && bprev != null)  
  462.             {
  463.                 if(ownerid != 0)
  464.                 {
  465.                     if(bprev.IsAuthed(player) && bprev.authorizedPlayers.Any<ProtoBuf.PlayerNameID>((ProtoBuf.PlayerNameID x) => x.userid == ownerid)) return true;
  466.                 }
  467.                 else
  468.                 {
  469.                     if(bprev.IsAuthed(player)) return true;
  470.                 }              
  471.             }                              
  472.             return false;
  473.         }
  474.         private IPlayer CheckPlayer(BasePlayer player, string[] args)
  475.         {
  476.             var playerlist = covalence.Players.FindPlayers(args[0]).ToList();
  477.             if(playerlist.Count > 1)
  478.             {
  479.                
  480.                 var message="<color=#FF0000>"+lang.GetMessage("MultiplePlayerFind", this, player.UserIDString)+"</color>\n";
  481.                 int i=0;
  482.                 foreach(var pl in playerlist)
  483.                 {
  484.                     i++;
  485.                     message+= string.Format("{0}. <color=#FFA500>{1}</color> ({2})\n\r", i, pl.Name, pl.Id);
  486.                 }
  487.                 SendReply(player, message);
  488.                 return null;
  489.             }
  490.             var player0 = covalence.Players.FindPlayer(args[0]);
  491.             if(player0==null)
  492.             {
  493.                 SendReply(player, string.Format(lang.GetMessage("PlayerNotFound", this, player.UserIDString), "<color=#FFA500>"+args[0]+"</color>"));
  494.                 return null;
  495.             }
  496.             return player0;
  497.         }  
  498.         #endregion
  499.         #region Commands   
  500.         [ChatCommand("share")]
  501.         void Share(BasePlayer player, string command, string[] args)
  502.         {  
  503.             if (UsePermission && !permission.UserHasPermission(player.UserIDString, PLPerm))
  504.             {
  505.                 SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  506.                 return;
  507.             }
  508.             IPlayer player0 = null;
  509.             ulong ID;                          
  510.             if (args == null || args.Length <= 0) ID=0;
  511.             else
  512.             {  
  513.                 player0 = CheckPlayer(player, args);
  514.                 if(player0 == null) return;
  515.                 ID=Convert.ToUInt64(player0.Id);
  516.             }
  517.             object success;
  518.             if (FindEntityFromRay(player, out success))
  519.             {
  520.                 if (success is StorageContainer)
  521.                 {  
  522.                     BaseEntity entity = success as BaseEntity;
  523.                     BaseEntity childentity = entity;
  524.                     entity = CheckParent(entity);
  525.                     if(entity.OwnerID == ID)
  526.                     {
  527.                         SendReply(player, lang.GetMessage("OwnEntity", this, player.UserIDString));
  528.                         return;
  529.                     }              
  530.                     if(entity.OwnerID != player.userID && (!player.IsAdmin || (player.IsAdmin && !AdminCanLoot)))
  531.                     {
  532.                         SendReply(player, lang.GetMessage("NoAccess", this, player.UserIDString));
  533.                         return;
  534.                     }
  535.                     if(!storedData.Data.ContainsKey(entity.net.ID))
  536.                     {
  537.                         var data = new EntityData();
  538.                         storedData.Data.Add(entity.net.ID, data);
  539.                         if(childentity != entity)
  540.                         {
  541.                             data.Quarry = new Dictionary<string, List<ulong>>();
  542.                             data.Quarry.Add(childentity.ShortPrefabName, new List<ulong>{ID});
  543.                         }
  544.                         else
  545.                         {
  546.                             data.Share = new List<ulong>();                        
  547.                             data.Share.Add(ID);
  548.                         }
  549.                         if(ID==0) SendReply(player, lang.GetMessage("ShareAll", this, player.UserIDString));
  550.                         else SendReply(player, string.Format(lang.GetMessage("SharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  551.                     }  
  552.                     else
  553.                     {
  554.                         if(childentity == entity)
  555.                         {
  556.                             if(storedData.Data[entity.net.ID].Share.Contains(ID))
  557.                             {
  558.                                 if(ID==0) SendReply(player, lang.GetMessage("HasShareAll", this, player.UserIDString));
  559.                                 else SendReply(player, string.Format(lang.GetMessage("HasSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  560.                             }                      
  561.                             else
  562.                             {
  563.                                 storedData.Data[entity.net.ID].Share.Add(ID);
  564.                                 if(ID==0) SendReply(player, lang.GetMessage("ShareAll", this, player.UserIDString));
  565.                                 else SendReply(player, string.Format(lang.GetMessage("SharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  566.                             }
  567.                         }
  568.                         else
  569.                         {
  570.                             if(!storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName)) storedData.Data[entity.net.ID].Quarry.Add(childentity.ShortPrefabName, new List<ulong>{});
  571.                             if(storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Contains(ID))
  572.                             {
  573.                                 if(ID==0) SendReply(player, lang.GetMessage("HasShareAll", this, player.UserIDString));
  574.                                 else SendReply(player, string.Format(lang.GetMessage("HasSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  575.                             }                      
  576.                             else
  577.                             {
  578.                                 if(storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName)) storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Add(ID);
  579.                                 else storedData.Data[entity.net.ID].Quarry.Add(childentity.ShortPrefabName, new List<ulong>{ID});
  580.                                 if(ID==0) SendReply(player, lang.GetMessage("ShareAll", this, player.UserIDString));
  581.                                 else SendReply(player, string.Format(lang.GetMessage("SharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  582.                             }
  583.                         }  
  584.                     }
  585.                 }
  586.                 else
  587.                 {
  588.                     SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  589.                 }  
  590.             }
  591.             else
  592.             {
  593.                 SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  594.             }  
  595.         }      
  596.         [ChatCommand("unshare")]
  597.         void Unshare(BasePlayer player, string command, string[] args)
  598.         {
  599.             if (UsePermission && !permission.UserHasPermission(player.UserIDString, PLPerm))
  600.             {
  601.                 SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  602.                 return;
  603.             }
  604.             IPlayer player0 = null;
  605.             ulong ID;                          
  606.             if (args == null || args.Length <= 0) ID=0;
  607.             else
  608.             {  
  609.                 player0 = CheckPlayer(player, args);
  610.                 if(player0 == null) return;
  611.                 ID=Convert.ToUInt64(player0.Id);
  612.             }
  613.             object success;
  614.             if (FindEntityFromRay(player, out success))        
  615.             {
  616.                 if (success is StorageContainer)
  617.                 {
  618.                     BaseEntity entity = success as BaseEntity;
  619.                     BaseEntity childentity = entity;
  620.                     entity = CheckParent(entity);
  621.                     if(entity.OwnerID != player.userID && (!player.IsAdmin || (player.IsAdmin &&!AdminCanLoot)))
  622.                     {
  623.                         SendReply(player, lang.GetMessage("NoAccess", this, player.UserIDString));
  624.                         return;
  625.                     }
  626.                     if(!storedData.Data.ContainsKey(entity.net.ID))
  627.                     {
  628.                         SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  629.                     }  
  630.                     else
  631.                     {
  632.                         if(childentity == entity)
  633.                         {
  634.                             if(!storedData.Data[entity.net.ID].Share.Contains(ID))
  635.                             {
  636.                                 if(ID==0) SendReply(player, lang.GetMessage("HasUnShareAll", this, player.UserIDString));  
  637.                                 else SendReply(player, string.Format(lang.GetMessage("HasUnSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));  
  638.                             }
  639.                             else
  640.                             {
  641.                                 storedData.Data[entity.net.ID].Share.Remove(ID);
  642.                                 if(storedData.Data[entity.net.ID].Share.Count==0) storedData.Data.Remove(entity.net.ID);
  643.                                 if(ID==0) SendReply(player, lang.GetMessage("WasUnShareAll", this, player.UserIDString));
  644.                                 else SendReply(player, string.Format(lang.GetMessage("WasUnSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  645.                             }
  646.                         }
  647.                         else
  648.                         {
  649.                             if(!storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName))
  650.                             {
  651.                                 SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  652.                                 return;
  653.                             }
  654.                             if(!storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Contains(ID))
  655.                             {
  656.                                 if(ID==0) SendReply(player, lang.GetMessage("HasUnShareAll", this, player.UserIDString));  
  657.                                 else SendReply(player, string.Format(lang.GetMessage("HasUnSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));  
  658.                             }
  659.                             else
  660.                             {
  661.                                 storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Remove(ID);
  662.                                 if(storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Count==0) storedData.Data[entity.net.ID].Quarry.Remove(childentity.ShortPrefabName);
  663.                                 if(ID==0) SendReply(player, lang.GetMessage("WasUnShareAll", this, player.UserIDString));
  664.                                 else SendReply(player, string.Format(lang.GetMessage("WasUnSharePlayer", this, player.UserIDString), "<color=#FFA500>"+player0.Name+"</color>"));
  665.                             }
  666.                         }
  667.                         Sharelist(player);
  668.                     }
  669.                 }
  670.                 else
  671.                 {
  672.                     SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  673.                 }  
  674.             }  
  675.             else
  676.             {
  677.                 SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  678.             }          
  679.         }      
  680.         [ChatCommand("sharelist")]
  681.         void Sharelist(BasePlayer player)
  682.         {
  683.             if (UsePermission && !permission.UserHasPermission(player.UserIDString, PLPerm))
  684.             {
  685.                 SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  686.                 return;
  687.             }          
  688.             object success;
  689.             if (FindEntityFromRay(player, out success))        
  690.             {          
  691.                 if (success is StorageContainer)
  692.                 {
  693.                     BaseEntity entity = success as BaseEntity;
  694.                     BaseEntity childentity = entity;
  695.                     entity = CheckParent(entity);
  696.                     if(entity.OwnerID != player.userID && (!player.IsAdmin || (player.IsAdmin &&!AdminCanLoot)))
  697.                     {
  698.                         SendReply(player, lang.GetMessage("NoAccess", this, player.UserIDString));
  699.                         return;
  700.                     }
  701.                     if(!storedData.Data.ContainsKey(entity.net.ID))
  702.                     {
  703.                         SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  704.                     }
  705.                     else
  706.                     {
  707.                         if(childentity == entity)
  708.                         {
  709.                             if(storedData.Data[entity.net.ID].Share.Contains(0))
  710.                             {
  711.                                 SendReply(player, lang.GetMessage("HasShareAllList", this, player.UserIDString));
  712.                                 return;
  713.                             }  
  714.                             var message="<color=#FFFF00>"+lang.GetMessage("ListShare", this, player.UserIDString)+"</color>\n";
  715.                             int i=0;
  716.                             foreach(var share in storedData.Data[entity.net.ID].Share)
  717.                             {
  718.                                 i++;
  719.                                 message+= string.Format("{0}. <color=#00FF00>{1}</color> ({2})\n\r", i, covalence.Players.FindPlayer(share.ToString()).Name, covalence.Players.FindPlayer(share.ToString()).Id);
  720.                             }  
  721.                             SendReply(player, message);
  722.                         }
  723.                         else
  724.                         {
  725.                             if(!storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName))
  726.                             {
  727.                                 SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  728.                                 return;
  729.                             }
  730.                             if(storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Contains(0))
  731.                             {
  732.                                 SendReply(player, lang.GetMessage("HasShareAllList", this, player.UserIDString));
  733.                                 return;
  734.                             }  
  735.                             var message="<color=#FFFF00>"+lang.GetMessage("ListShare", this, player.UserIDString)+"</color>\n";
  736.                             int i=0;
  737.                             foreach(var share in storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName])
  738.                             {
  739.                                 i++;
  740.                                 message+= string.Format("{0}. <color=#00FF00>{1}</color> ({2})\n\r", i, covalence.Players.FindPlayer(share.ToString()).Name, covalence.Players.FindPlayer(share.ToString()).Id);
  741.                             }  
  742.                             SendReply(player, message);
  743.                         }  
  744.                     }
  745.                 }
  746.                 else
  747.                 {
  748.                     SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  749.                 }
  750.             }
  751.             else
  752.             {
  753.                 SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  754.             }
  755.         }      
  756.         [ChatCommand("shareclear")]
  757.         void Shareclear(BasePlayer player)
  758.         {
  759.             if (UsePermission && !permission.UserHasPermission(player.UserIDString, PLPerm))
  760.             {
  761.                 SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  762.                 return;
  763.             }          
  764.             object success;
  765.             if (FindEntityFromRay(player, out success))        
  766.             {
  767.                 if (success is StorageContainer)
  768.                 {
  769.                     BaseEntity entity = success as BaseEntity;
  770.                     BaseEntity childentity = entity;
  771.                     entity = CheckParent(entity);
  772.                     if(entity.OwnerID != player.userID && (!player.IsAdmin || (player.IsAdmin &&!AdminCanLoot)))
  773.                     {
  774.                         SendReply(player, lang.GetMessage("NoAccess", this, player.UserIDString));
  775.                         return;
  776.                     }
  777.                     if(!storedData.Data.ContainsKey(entity.net.ID))
  778.                     {
  779.                         SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  780.                     }
  781.                     else
  782.                     {
  783.                         if(childentity == entity)
  784.                         {
  785.                             storedData.Data[entity.net.ID].Share.Clear();
  786.                             if(storedData.Data[entity.net.ID].Share.Count==0) storedData.Data.Remove(entity.net.ID);
  787.                             SendReply(player, lang.GetMessage("ShareClear", this, player.UserIDString));
  788.                         }
  789.                         else
  790.                         {
  791.                             if(!storedData.Data[entity.net.ID].Quarry.ContainsKey(childentity.ShortPrefabName))
  792.                             {
  793.                                 SendReply(player, lang.GetMessage("NoShare", this, player.UserIDString));
  794.                                 return;
  795.                             }
  796.                             storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Clear();
  797.                             if(storedData.Data[entity.net.ID].Quarry[childentity.ShortPrefabName].Count==0) storedData.Data[entity.net.ID].Quarry.Remove(childentity.ShortPrefabName);
  798.                             SendReply(player, lang.GetMessage("ShareClear", this, player.UserIDString));
  799.                         }
  800.                     }
  801.                 }
  802.                 else
  803.                 {
  804.                     SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  805.                 }              
  806.             }
  807.             else
  808.             {
  809.                 SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  810.             }
  811.         }
  812.         [ChatCommand("checkit")]
  813.         void CheckBP(BasePlayer player)
  814.         {
  815.             if (UsePermission && !permission.UserHasPermission(player.UserIDString, PLPerm))
  816.             {
  817.                 SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
  818.                 return;
  819.             }          
  820.             object success;
  821.             if (FindEntityFromRay(player, out success))        
  822.             {          
  823.                 if (success is StorageContainer)
  824.                 {
  825.                     BaseEntity entity = success as BaseEntity;
  826.                     entity = CheckParent(entity);
  827.                     if(entity.OwnerID != player.userID && (!player.IsAdmin || (player.IsAdmin &&!AdminCanLoot)))
  828.                     {
  829.                         SendReply(player, lang.GetMessage("NoAccess", this, player.UserIDString));
  830.                         return;
  831.                     }
  832.                     if(UseOnlyInCupboardRange)
  833.                     {
  834.                         BuildingPrivlidge bprev = player.GetBuildingPrivilege(new OBB(entity.transform.position, entity.transform.rotation, entity.bounds));
  835.                         if(bprev == null) SendReply(player, "<color=#FF0000>"+lang.GetMessage("EntNoPrevent", this, player.UserIDString)+"</color>\n");
  836.                         else SendReply(player, "<color=#CCFF00>"+lang.GetMessage("EntPrevent", this, player.UserIDString)+"</color>\n");       
  837.                     }  
  838.                     else SendReply(player, "<color=#CCFF00>"+lang.GetMessage("EntPrevent", this, player.UserIDString)+"</color>\n");   
  839.                 }
  840.             }
  841.             else
  842.             {
  843.                 SendReply(player, lang.GetMessage("EntityNotFound", this, player.UserIDString));
  844.             }
  845.         }
  846.         #endregion
  847.         #region Helpers
  848.         T GetConfig<T>(string name, T defaultValue) => Config[name] == null ? defaultValue : (T) Convert.ChangeType(Config[name], typeof(T));
  849.         #endregion
  850.     }
  851. }
  852.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement