public static void PatchOnDestroyRequest(MyCubeBlock __instance) { MyCubeBlock block = __instance; if (block as MyTerminalBlock == null) { return; } MyCubeGrid grid = block.CubeGrid; string gridName = grid.DisplayName; string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId); bool isOnline = PlayerUtils.isOnline(block.OwnerId); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId); string oldName = oldOwnerName + " " + onlineString + oldFactionTag; string causeName = "[Unknown]"; ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId); string additionalInfo = null; if (cause != null) { additionalInfo = cause.AdditionalInfo; if (!cause.IsPlanet) { long causeId; if (cause.Controller != 0L) { causeId = cause.Controller; } else { causeId = cause.Owner; } /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(causeId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } string causePlayerName = PlayerUtils.GetPlayerNameById(causeId); string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId); causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause; } else { causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause; } } string blockpairName = block.BlockDefinition.BlockPairName; blockpairName = ChangeName(additionalInfo, blockpairName); string location = GetLocationWhenNeeded(block); Log.Info(causeName.PadRight(45) + " destroyed block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " " + "".PadRight(20) + " of grid: " + gridName + location); }
public static bool PatchChangeOwnerRequest( MyCubeGrid grid, MyCubeBlock block, long playerId, MyOwnershipShareModeEnum shareMode) { string gridName = grid.DisplayName; string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId); string newOwnerName = PlayerUtils.GetPlayerNameById(playerId); /* Only shared mode was changed */ if (oldOwnerName == newOwnerName) { return(true); } bool isOnline = PlayerUtils.isOnline(block.OwnerId); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId); string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(playerId); string oldName = oldOwnerName + " " + onlineString + oldFactionTag; string newName = newOwnerName + " " + newFactionTag; string causeName = "[Unknown]"; ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId); string additionalInfo = null; if (playerId == 0L && cause != null) { additionalInfo = cause.AdditionalInfo; if (!cause.IsPlanet) { long causeId; if (cause.Controller != 0L) { causeId = cause.Controller; } else { causeId = cause.Owner; } /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(causeId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } string causePlayerName = PlayerUtils.GetPlayerNameById(causeId); string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId); causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause; } else { causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause; } } else if (playerId != 0L) { /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(playerId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } /* Must be Online then */ causeName = newOwnerName + " " + causeOnlineString + newFactionTag; } string blockpairName = block.BlockDefinition.BlockPairName; blockpairName = ChangeName(additionalInfo, blockpairName); string location = GetLocationWhenNeeded(block); Log.Info(causeName.PadRight(45) + " changed owner on block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + " on grid: " + gridName + location); return(true); }