/// <inheritdoc /> public override void Init(ITorchBase torch) { base.Init(torch); Instance = this; SetUpConfig(); MyCubeGridPatch.ApplyLogging(); }
public static void OnCloseRequestImpl(MyEntity __instance) { MyCubeGrid grid = __instance as MyCubeGrid; if (grid == null) { return; } try { /* Never log Projections... */ if (grid.Physics == null) { return; } DeleteTrackerPlugin plugin = DeleteTrackerPlugin.Instance; DeleteConfig config = plugin.Config; /* No logging? then skip everything */ if (!config.EnableFullLogging && !config.EnableCompactLogging) { return; } /* Grid already closed, skip if we dont want duplicates */ if (grid.MarkedForClose && !config.LogDuplicates) { return; } string stacktrace = Environment.StackTrace; /* If we dont want closes on shutdown skip that. We detect it by looking for Unload() Method on MySession */ if (!config.RemovalOnShutdown) { if (stacktrace.Contains("at Sandbox.Game.World.MySession.Unload()")) { return; } } var gridOwnerList = grid.BigOwners; var ownerCnt = gridOwnerList.Count; var gridOwner = 0L; var hasNobodyOwner = false; if (ownerCnt > 0 && gridOwnerList[0] != 0) { gridOwner = gridOwnerList[0]; } else if (ownerCnt > 1) { hasNobodyOwner = true; gridOwner = gridOwnerList[1]; } /* If owned by nobody, and we dont want them, skip */ if (gridOwner == 0L && !config.RemovalNobodyGrids) { return; } bool isOnline = PlayerUtils.isOnline(gridOwner); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string ownerName = PlayerUtils.GetPlayerNameById(gridOwner); string factionTag = PlayerUtils.GetFactionTagStringForPlayer(gridOwner); string playerNameString = ownerName + " " + onlineString + factionTag; string messageString; string gridId = grid.EntityId.ToString().PadRight(20); if (hasNobodyOwner || gridOwner == 0) { if (gridOwner != 0) { messageString = "Entity " + gridId + " owned by nobody" + " but has blocks from" + " " + playerNameString.PadRight(25) + " was closed! (Grid: " + grid.DisplayName + ")"; } else { messageString = "Entity " + gridId + " owned by nobody" + "".PadRight(20) + " " + "".PadRight(25) + " was closed! (Grid: " + grid.DisplayName + ")"; } } else { messageString = "Entity " + gridId + " owned by player" + "".PadRight(20) + " " + playerNameString.PadRight(25) + " was closed! (Grid: " + grid.DisplayName + ")"; } if (config.EnableFullLogging) { FULL_LOGGER.Info(messageString + "\n" + stacktrace); } if (config.EnableCompactLogging) { SHORT_LOGGER.Info(messageString); } } catch (Exception e) { Log.Error(e, "Error on DeleteTracking Grid!"); } }
public Control(DeleteTrackerPlugin plugin) : this() { Plugin = plugin; DataContext = plugin.Config; }