public static bool ProcessBlockChange(GameManager __instance, string _persistentPlayerId, List <BlockChangeInfo> _blocksToChange) { try { World _world = __instance.World; if (__instance != null && _blocksToChange != null && !string.IsNullOrEmpty(_persistentPlayerId) && _blocksToChange != null) { for (int i = 0; i < _blocksToChange.Count; i++) { BlockChangeInfo _newBlockInfo = _blocksToChange[i]; //new block info BlockValue _oldBlockValue = _world.GetBlock(_newBlockInfo.pos); //old block value Block _oldBlock = _oldBlockValue.Block; if (_newBlockInfo != null && _newBlockInfo.bChangeBlockValue) //new block value { Block _newBlock = _newBlockInfo.blockValue.Block; if (_oldBlockValue.type == BlockValue.Air.type) //old block was air { if (_newBlock is BlockSleepingBag) //placed a sleeping bag { if (POIProtection.IsEnabled && POIProtection.Bed && _world.IsPositionWithinPOI(_newBlockInfo.pos.ToVector3(), 5)) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { GameManager.Instance.World.SetBlockRPC(_newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(_cInfo, _newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue(1031, out string _phrase1031); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase1031 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } } else if (_newBlock is BlockLandClaim)//placed a land claim { if (POIProtection.IsEnabled && POIProtection.Claim && _world.IsPositionWithinPOI(_newBlockInfo.pos.ToVector3(), 5)) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { GameManager.Instance.World.SetBlockRPC(_newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(_cInfo, _newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue(1032, out string _phrase1032); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase1032 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } } if (BlockLogger.IsEnabled)//placed block { BlockLogger.Log(_persistentPlayerId, _newBlockInfo); } return(true); } if (IsEnabled) { if (_newBlockInfo.blockValue.type == BlockValue.Air.type) //new block is air { if (_oldBlockValue.type == BlockValue.Air.type) //replaced block { return(true); } if (_oldBlockValue.Block is BlockLandClaim) //removed claim { if (!string.IsNullOrEmpty(_persistentPlayerId)) //id is valid { if (!PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos)) { int _total = _oldBlock.MaxDamage - _oldBlockValue.damage; if (_oldBlock.MaxDamage - _oldBlockValue.damage >= Block_Damage_Limit) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level) { BlockPenalty(_total, _persistentPlayerId); return(false); } } } } } } if (!_oldBlock.CanPickup && !PersistentOperations.ClaimedByAllyOrSelf(_persistentPlayerId, _newBlockInfo.pos))//old block can not be picked up and unclaimed space { int _total = _oldBlock.MaxDamage - _oldBlockValue.damage; if (_total >= Block_Damage_Limit) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level) { BlockPenalty(_total, _persistentPlayerId); return(false); } } } } } else if (_oldBlock.blockID == _newBlock.blockID) //block is the same { if (_newBlockInfo.bChangeDamage) //block took damage { int _total = _newBlockInfo.blockValue.damage - _oldBlockValue.damage; if (_total >= Block_Damage_Limit) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level) { BlockPenalty(_total, _persistentPlayerId); return(false); } } } } if (_oldBlockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0)//block replaced { return(true); } } else if (_oldBlock.DowngradeBlock.Block.blockID == _newBlock.blockID)//downgraded { if (_oldBlockValue.damage == _newBlockInfo.blockValue.damage || _newBlockInfo.blockValue.damage == 0) { return(true); } int _total = _oldBlock.MaxDamage - _oldBlockValue.damage + _newBlockInfo.blockValue.damage; if (_total >= Block_Damage_Limit) { ClientInfo _cInfo = PersistentOperations.GetClientInfoFromSteamId(_persistentPlayerId); if (_cInfo != null) { if (GameManager.Instance.adminTools.GetUserPermissionLevel(_cInfo.playerId) > Admin_Level) { BlockPenalty(_total, _persistentPlayerId); return(false); } } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in ProcessDamage.ProcessBlockDamage: {0}", e.Message)); } return(true); }
public static bool ProcessBlockChange(GameManager __instance, PlatformUserIdentifierAbs _persistentPlayerId, List <BlockChangeInfo> _blocksToChange) { try { if (__instance != null && _persistentPlayerId != null && _blocksToChange != null) { ClientInfo cInfo = PersistentOperations.GetClientInfoFromUId(_persistentPlayerId); if (cInfo != null) { EntityPlayer player = PersistentOperations.GetEntityPlayer(cInfo.entityId); if (player != null) { World world = __instance.World; for (int i = 0; i < _blocksToChange.Count; i++) { BlockChangeInfo newBlockInfo = _blocksToChange[i]; //new block info BlockValue oldBlockValue = world.GetBlock(newBlockInfo.pos); //old block value Block oldBlock = oldBlockValue.Block; if (newBlockInfo != null && oldBlock != null && newBlockInfo.bChangeBlockValue) //has new block value { Block newBlock = newBlockInfo.blockValue.Block; if (newBlock != null) { if (newBlock is BlockSleepingBag)//placed a sleeping bag { if (POIProtection.IsEnabled && POIProtection.Bed && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 8)) { GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue("POI1", out string phrase); ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } else if (newBlock is BlockLandClaim)//placed a land claim { if (POIProtection.IsEnabled && POIProtection.Claim && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 5)) { GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air); PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1); Phrases.Dict.TryGetValue("POI2", out string _phrase); ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + _phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); return(false); } } if (BlockLogger.IsEnabled && !_blocksToChange[i].blockValue.Equals(BlockValue.Air)) { BlockLogger.PlacedBlock(cInfo, newBlock, newBlockInfo.pos); } } if (oldBlockValue.Block is BlockTrapDoor) { return(true); } else if (newBlockInfo.blockValue.Equals(BlockValue.Air.type))//new block is air { if (oldBlockValue.Block is BlockLandClaim) { if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None) { if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } if (BlockLogger.IsEnabled) { BlockLogger.BrokeBlock(cInfo, oldBlock, newBlockInfo.pos); } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } else if (BlockLogger.IsEnabled) { BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos); } } else if (!oldBlock.CanPickup)//old block can not be picked up { if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None) { if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } } if (BlockLogger.IsEnabled) { BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos); } } } else if (oldBlock.blockID == newBlock.blockID) //block is the same { if (newBlockInfo.bChangeDamage) //block took damage { if (DamageDetector.IsEnabled) { int total = newBlockInfo.blockValue.damage - oldBlockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } } else if (oldBlock.DowngradeBlock.Block.blockID == newBlock.blockID)//downgraded { if (oldBlockValue.damage == newBlockInfo.blockValue.damage || newBlockInfo.blockValue.damage == 0) { if (BlockLogger.IsEnabled) { BlockLogger.DowngradedBlock(cInfo, oldBlock, newBlock, newBlockInfo.pos); } return(true); } if (DamageDetector.IsEnabled) { int total = oldBlock.MaxDamage - oldBlockValue.damage + newBlockInfo.blockValue.damage; if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level && GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level)) { Penalty(total, player, cInfo); return(false); } } int slot = player.inventory.holdingItemIdx; ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue; if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue)) { return(false); } } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in BlockChange.ProcessBlockChange: {0}", e.Message)); } return(true); }