From 1d8ac4bc89a7cf3333a2c7c12e80f801de045fb2 Mon Sep 17 00:00:00 2001 From: Koert Lichtendonk Date: Mon, 23 Nov 2026 19:02:48 +0100 Subject: [PATCH 1/2] Fix the findings from the review of #13 - Fishing: PublishFishCaught returns Task, the net item is only taken once the net exists, net dialogs re-check the character and access - Vehicles: /park keeps the world and interior, the editor saves the live vehicle, deleting a vehicle uses a short-lived context and publishes OnVehicleDeleted, which Fishing and Radios handle - Maps: despawning skips objects that are gone, a bulk replace of an unloaded map applies its removed buildings - /government sets binding to what the menu showed; the bank fee cap prompt no longer shows a thousands separator - Docs: fishing limitation, CatchWeight and seed ids for hosts, OnVehicleDeleted, /deletevehicle notation Database: Vehicles.VirtualWorld and Interior default to 0, Vehicles.ServerVehicle defaults to false, FishLoot.LootKind, SizeClass, RequiredFishingLevel and IsNetOnly get database defaults. Hosts need a migration. --- docs/commands.md | 4 +- docs/database.md | 11 +++- docs/features/fishing.md | 4 +- docs/features/radios.md | 2 +- docs/features/vehicles.md | 10 +-- docs/server-events.md | 1 + .../Banking/Entities/MaxMonthlyFeeSetting.cs | 4 +- .../Models/FishLootModelConfiguration.cs | 14 ++-- .../Dialogs/FishingNetDialogService.cs | 18 +++-- .../Features/Fishing/Services/FishService.cs | 2 +- .../Fishing/Services/FishingNetService.cs | 3 +- .../Fishing/Services/FishingService.cs | 2 +- .../Features/Fishing/Services/IFishService.cs | 2 +- .../Features/Fishing/Services/TrawlService.cs | 2 +- .../Fishing/Systems/FishingNetServerSystem.cs | 19 ++++++ .../JurisdictionDialogService.Settings.cs | 7 +- .../Features/Maps/Services/MapBulkService.cs | 23 +++++++ .../Features/Maps/Services/MapService.cs | 6 ++ .../Radios/Systems/RadioServerSystem.cs | 10 +++ .../Vehicles/Commands/DeleteVehicleCommand.cs | 2 +- .../Features/Vehicles/Commands/ParkCommand.cs | 7 ++ .../CreateOrUpdateVehicleDialog.Save.cs | 21 ++++++ .../VehicleModelConfiguration.cs | 14 ++-- .../Vehicles/Services/VehicleManager.cs | 66 +++++++------------ .../EventArgs/OnVehicleDeletedEventArgs.cs | 11 ++++ 25 files changed, 189 insertions(+), 76 deletions(-) create mode 100644 src/OpenRP.Framework/Features/Fishing/Systems/FishingNetServerSystem.cs create mode 100644 src/OpenRP.Framework/Shared/ServerEvents/Entities/EventArgs/OnVehicleDeletedEventArgs.cs diff --git a/docs/commands.md b/docs/commands.md index 411ecb9..3760173 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -235,7 +235,7 @@ All player commands of the Framework, grouped as in `/help`. `[argument]` is req | Command | Groups | Description | Feature | |---|---|---|---| -| `/park` | Default | Make your vehicle spawn here from now on; only the owner or a key holder can. | [Vehicles](features/vehicles.md) | +| `/park` | Default | Make your vehicle spawn here, in this virtual world and interior, from now on; only the owner or a key holder can. | [Vehicles](features/vehicles.md) | | `/savecar` | Default | Park your currently owned vehicle. Use /savecar to save your vehicle in a new parking spot. | [Vehicles](features/vehicles.md) | ## Ungrouped @@ -243,7 +243,7 @@ All player commands of the Framework, grouped as in `/help`. `[argument]` is req | Command | Groups | Description | Feature | |---|---|---|---| | `/createvehicle` | Admin | Create a persistent vehicle that can be owned. | [Vehicles](features/vehicles.md) | -| `/deletevehicle [vehicle id]` | Admin | Delete a persistent vehicle for good. Without an id, it deletes the vehicle you sit in, else the nearest saved one within 5 m in your virtual world and interior. | [Vehicles](features/vehicles.md) | +| `/deletevehicle ` | Admin | Delete a persistent vehicle for good. Without an id, it deletes the vehicle you sit in, else the nearest saved one within 5 m in your virtual world and interior. | [Vehicles](features/vehicles.md) | | `/editvehicle` | Admin | Edit a persistent vehicle that can be owned. | [Vehicles](features/vehicles.md) | | `/inv` | Default | Open your character's inventory. Use this command to view, manage, and interact with the items you possess. | [Inventories](features/inventories.md) | | `/inventory` | Default | Open your character's inventory. Use this command to view, manage, and interact with the items you possess. | [Inventories](features/inventories.md) | diff --git a/docs/database.md b/docs/database.md index 070ec6c..373fae4 100644 --- a/docs/database.md +++ b/docs/database.md @@ -216,7 +216,7 @@ Persistent vehicles. | `IsEngineOn`, `AreLightsOn`, `IsAlarmOn`, `AreDoorsLocked`, `IsBonnetOpen`, `IsBootOpen` | bool | State | | `Is…DoorOpen`, `Is…WindowClosed` | bool | Per door and window | | `CurrentHealth`, `MaxHealth` | float | | -| `ServerVehicle` | bool | Belongs to the server, not a player. No database default | +| `ServerVehicle` | bool | Belongs to the server, not a player. Database default false: an older Framework leaves the column out of an insert when it's false. Before, the default was true, so vehicles saved then may be marked as server vehicles by mistake | | `OwnerCharacterId` | ulong? | → `Characters` | | `VirtualWorld`, `Interior` | int | The virtual world and the GTA interior the vehicle is in. Default 0 | | `JurisdictionId` | ulong? | → `Jurisdictions` (set null). Where it's registered; its plate starts with that country's tag. Null = none, an `SA` plate | @@ -250,7 +250,14 @@ Table `FishLoot`, with the `DbSet` named `FishSpecies` (`FishLootModel`). Column - `CatchWeight`: how likely it is, relative to the other possible catches; - `ItemId` → `Items`. -The Framework seeds 26 rows. Hosts can add their own. +`LootKind`, `SizeClass`, `RequiredFishingLevel` and `IsNetOnly` have database defaults (Fish, None, 0, false), so servers on an older Framework sharing the database can still insert rows. + +The Framework seeds ids 1 to 26. Hosts can add their own: +- **Ids from 1000 up.** The Framework may seed more of the low ids later. +- **Remove your own seeds of ids 1 to 26.** Hosts used to seed the fish themselves, and EF refuses two seeds with the same id. +- **Set `SizeClass` on your fish.** A trawl net only brings up Small, Medium and Large fish, so a row left at None is never caught by a net. + +**`CatchWeight` used to be `OddsToCatch`**, with the opposite meaning: "1 in N", so a higher number was rarer. Now a higher number is more common. A migration that only renames the column turns rare fish into common ones. Convert your own rows, for example with `UPDATE FishLoot SET CatchWeight = GREATEST(1, ROUND(100 / CatchWeight))`, or set new weights. Table `VehicleFishingNets` (`VehicleFishingNetModel`) holds the nets fitted to Reefers: - `VehicleId` → `Vehicles` (cascade, unique); diff --git a/docs/features/fishing.md b/docs/features/fishing.md index 08166c9..bb40305 100644 --- a/docs/features/fishing.md +++ b/docs/features/fishing.md @@ -82,6 +82,7 @@ The driver's fishing level decides the result, and the driver gets the experienc - **"Use" wears out a rod.** Choosing Use on a rod in the inventory costs one use, like any item with a use limit. - **Fish lost at sea.** A catch that doesn't fit lands below you, which from a boat is the sea floor. - **Long catches.** `/netstorage` lists the first 50 fish, because a dialog holds a limited amount of text. +- **Net-only fish are stuck in the net.** They weigh 25 kg or more, and a character carries 10 kg, so they can't be taken out. A net with fish in it can't be removed with `/removenet`, so such a net stays on the Reefer until the vehicle is deleted. ## Deep dive @@ -94,7 +95,8 @@ The driver's fishing level decides the result, and the driver gets the experienc - `IFishHotspotService`: places and moves hotspots; - `IFishingNetService` and `IFishingNetManager`: fitted nets and their storage; - `ITrawlService`: the trawl; - - `IFishingNetDialogService`: the storage dialog. + - `IFishingNetDialogService`: the storage dialog. Each answer checks again that the player is still at the Reefer, still playing their character and still allowed to use the net. +- **Systems:** `FishingNetServerSystem` deletes the net of a deleted vehicle on [`OnVehicleDeleted`](../server-events.md#onvehicledeleted). - **Water zones:** `Helpers/WaterTypeHelper`. - **Skill:** the host seeds a skill named `Fishing`. Without it, players stay at level 0. - **Tables:** [`FishLoot` and `VehicleFishingNets`](../database.md#fishing). The Framework seeds the catch table and its items. diff --git a/docs/features/radios.md b/docs/features/radios.md index 13e5f9a..b3bd440 100644 --- a/docs/features/radios.md +++ b/docs/features/radios.md @@ -13,7 +13,7 @@ Two-way radios on numbered frequencies: a handheld radio item, and a radio an ad | `/giveearpiece [player]` | Admin | Gives the player a radio earpiece | | `/editfrequencies` | Admin | Creates protected and encrypted frequencies and picks their factions. See [Frequencies](radios/frequencies.md) | -**Vehicle radios:** an admin sets the **Radio** row in [`/createvehicle` or `/editvehicle`](vehicles.md). Everyone inside can then use `/radio`, `/freq` and `/r`. +**Vehicle radios:** an admin sets the **Radio** row in [`/createvehicle` or `/editvehicle`](vehicles.md). Everyone inside can then use `/radio`, `/freq` and `/r`. Deleting the vehicle removes its radio too, on [`OnVehicleDeleted`](../server-events.md#onvehicledeleted). ## Who can use a frequency diff --git a/docs/features/vehicles.md b/docs/features/vehicles.md index 35438f5..00b5459 100644 --- a/docs/features/vehicles.md +++ b/docs/features/vehicles.md @@ -13,7 +13,7 @@ Persistent vehicles: saved in the database, spawned at startup, started with a k | `/repairvehicle`, `/fixveh` | Admin | Repairs the vehicle to full health. See [Repairing](#repairing) | | `/createvehicle` | Admin | Creates a vehicle in front of you, in the [vehicle editor](vehicles/editor.md) | | `/editvehicle` | Admin | Edits the vehicle you're in, in the [vehicle editor](vehicles/editor.md) | -| `/deletevehicle [vehicle id]` | Admin | Deletes a saved vehicle for good, after you confirm. Without an id, see [Deleting a vehicle](#deleting-a-vehicle) | +| `/deletevehicle ` | Admin | Deletes a saved vehicle for good, after you confirm. Without an id, see [Deleting a vehicle](#deleting-a-vehicle) | Without a key: [Hotwire](hotwire.md). Turn signals: [Turn signals](vehicles/indicators.md). Temporary vehicles: `/sv` ([Admins](admins.md)). @@ -51,7 +51,7 @@ Locking a locked vehicle says "The doors are already locked." ## Parking -`/park` and `/savecar` set the spot where the vehicle spawns from now on. Only the owner or a key holder can do it, and admins too. You must be in the driver's seat. +`/park` and `/savecar` set the spot where the vehicle spawns from now on, including your virtual world and interior, so a car parked inside a building stays there. Only the owner or a key holder can do it, and admins too. You must be in the driver's seat. | Who | Saved vehicle | Server vehicle | |---|---|---| @@ -93,10 +93,12 @@ Temporary `/sv` vehicles can't be parked. `/deletevehicle` (Admin) deletes a saved vehicle for good. With an id, it deletes that vehicle. Without one, it deletes the vehicle you sit in, else the nearest saved vehicle within 5 m of its body, in your virtual world and interior. If there's none, it says so. It then asks you to confirm. On Delete it: - deletes the vehicle's row; -- removes its radio, and the vehicle keys that are loaded in the game; -- removes its [fishing net](fishing.md#reefer-net), with the net's storage and the fish in it; +- removes the vehicle keys that are loaded in the game; +- publishes [`OnVehicleDeleted`](../server-events.md#onvehicledeleted): its radio is removed, and its [fishing net](fishing.md#reefer-net) with the net's storage and the fish in it; - ejects the people inside, and destroys the vehicle in the world. +**Why an event:** the radio and the net belong to other features, which clean up after themselves instead of Vehicles reaching into them. + Keys in the inventories of offline characters aren't removed (see the known limitations). A temporary `/spawnveh` vehicle has no row, so the command refuses it. ## Known limitations diff --git a/docs/server-events.md b/docs/server-events.md index 4655d99..f46d79f 100644 --- a/docs/server-events.md +++ b/docs/server-events.md @@ -26,6 +26,7 @@ public void OnCharacterSelected(OnCharacterSelectedEventArgs args, ISkillService | `OnResourceHarvested` | a player harvested a resource | [Harvestables](features/harvestables.md) | nothing yet: for gamemodes to give rewards | | `OnFishCaught` | a player brought up a fish, junk or a treasure, with a rod or a net (`Loot`, `WeightInGrams`, `Method`) | [Fishing](features/fishing.md) | nothing yet: for gamemodes to give rewards | | `OnPropertyDeleted` | an admin deleted a property | [Properties](features/properties.md) | [Actors](features/actors.md) (actors inside it move outside) | +| `OnVehicleDeleted` | an admin deleted a saved vehicle; its row is already gone (`VehicleId`) | [Vehicles](features/vehicles.md) | [Radios](features/radios.md) (forget its radio), [Fishing](features/fishing.md) (delete its net, storage and fish) | | `OnJurisdictionsLoaded` | the jurisdictions were loaded at startup | [Jurisdictions](features/jurisdictions.md) | [Vehicles](features/vehicles.md) (set plates again) | | `OnJurisdictionPlateTagChanged` | a jurisdiction's tags changed, or it moved to another country | [Jurisdictions](features/jurisdictions.md) | [Vehicles](features/vehicles.md) (set plates again) | | `OnJurisdictionGovernmentChanged` | a jurisdiction got another government of its own (old and new faction id, null = none) | [Jurisdictions](features/jurisdictions.md) | nothing yet: for police, laws and taxes later | diff --git a/src/OpenRP.Framework/Features/Banking/Entities/MaxMonthlyFeeSetting.cs b/src/OpenRP.Framework/Features/Banking/Entities/MaxMonthlyFeeSetting.cs index c4708e0..fd6fa0d 100644 --- a/src/OpenRP.Framework/Features/Banking/Entities/MaxMonthlyFeeSetting.cs +++ b/src/OpenRP.Framework/Features/Banking/Entities/MaxMonthlyFeeSetting.cs @@ -28,7 +28,7 @@ public MaxMonthlyFeeSetting(IJurisdictionService jurisdictionService, ICurrencyS public override string Name => "Bank account fee cap"; - public override string Prompt => "Enter the highest monthly fee a bank in this jurisdiction may charge per account, from 0 to 10,000:"; + public override string Prompt => "Enter the highest monthly fee a bank in this jurisdiction may charge per account, from 0 to 10000:"; public override decimal Default => BankingRules.DefaultMaxMonthlyFee; @@ -36,7 +36,7 @@ public MaxMonthlyFeeSetting(IJurisdictionService jurisdictionService, ICurrencyS { decimal? fee = BankAmounts.ParseFee(input, BankingRules.HighestMaxMonthlyFee); value = fee ?? 0; - return fee.HasValue ? null : "The fee is an amount from 0 to 10,000, with at most 2 decimals."; + return fee.HasValue ? null : "The fee is an amount from 0 to 10000, with at most 2 decimals and no thousands separators."; } public override string Format(decimal value, Jurisdiction jurisdiction) diff --git a/src/OpenRP.Framework/Features/Fishing/Models/FishLootModelConfiguration.cs b/src/OpenRP.Framework/Features/Fishing/Models/FishLootModelConfiguration.cs index dc29d34..7282c5c 100644 --- a/src/OpenRP.Framework/Features/Fishing/Models/FishLootModelConfiguration.cs +++ b/src/OpenRP.Framework/Features/Fishing/Models/FishLootModelConfiguration.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore; using OpenRP.Framework.Database.Models; +using OpenRP.Framework.Features.Fishing.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -39,17 +40,22 @@ public void Configure(EntityTypeBuilder builder) builder.Property(f => f.CatchWeight) .IsRequired(); + // Database defaults, so servers on an older Framework sharing the database can still insert rows. builder.Property(f => f.LootKind) - .IsRequired(); + .IsRequired() + .HasDefaultValue(FishLootKind.Fish); builder.Property(f => f.SizeClass) - .IsRequired(); + .IsRequired() + .HasDefaultValue(FishSizeClass.None); builder.Property(f => f.RequiredFishingLevel) - .IsRequired(); + .IsRequired() + .HasDefaultValue(0u); builder.Property(f => f.IsNetOnly) - .IsRequired(); + .IsRequired() + .HasDefaultValue(false); // Configure the relationship with ItemModel. builder.HasOne(f => f.Item) diff --git a/src/OpenRP.Framework/Features/Fishing/Services/Dialogs/FishingNetDialogService.cs b/src/OpenRP.Framework/Features/Fishing/Services/Dialogs/FishingNetDialogService.cs index f535eb4..67a7068 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/Dialogs/FishingNetDialogService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/Dialogs/FishingNetDialogService.cs @@ -18,6 +18,7 @@ public class FishingNetDialogService : IFishingNetDialogService { private const string DialogTitle = "Net Storage"; private const string LeftTheBoatError = "You moved too far away from the Reefer."; + private const string NoLongerAllowedError = "You can no longer use the net of this Reefer."; private readonly IDialogService _dialogService; private readonly IFishingNetService _fishingNetService; @@ -163,17 +164,24 @@ private void PutFish(Player player, Vehicle reefer, VehicleFishingNet net, Inven } /// - /// The player can walk off, or the net can be removed, while a dialog is open. + /// While a dialog is open the player can walk off, stop playing their character or lose their key, and the + /// net can be removed. /// private bool CanStillUseNet(Player player, Vehicle reefer, VehicleFishingNet net) { - if (net.IsComponentAlive && !net.IsDeleted() && _fishingNetService.IsPlayerAtVehicle(player, reefer)) + if (!net.IsComponentAlive || net.IsDeleted() || !_fishingNetService.IsPlayerAtVehicle(player, reefer)) { - return true; + player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, LeftTheBoatError); + return false; } - player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, LeftTheBoatError); - return false; + if (!_fishingNetService.CanUseNetOf(player, reefer)) + { + player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, NoLongerAllowedError); + return false; + } + + return true; } private static void SendMoveResult(Player player, string? error, string successMessage) diff --git a/src/OpenRP.Framework/Features/Fishing/Services/FishService.cs b/src/OpenRP.Framework/Features/Fishing/Services/FishService.cs index 5fc0c4a..b46c86c 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/FishService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/FishService.cs @@ -110,7 +110,7 @@ public void AddFishingExperience(Player player, uint experience) return _entityManager.GetComponent(ItemEntities.GetItemId((int)loot.ItemId)); } - public async void PublishFishCaught(Player player, FishLootModel loot, uint weightInGrams, FishCatchMethod method) + public async Task PublishFishCaught(Player player, FishLootModel loot, uint weightInGrams, FishCatchMethod method) { try { diff --git a/src/OpenRP.Framework/Features/Fishing/Services/FishingNetService.cs b/src/OpenRP.Framework/Features/Fishing/Services/FishingNetService.cs index 0a6d65e..774554f 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/FishingNetService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/FishingNetService.cs @@ -53,9 +53,10 @@ public void FitNet(Player player) } ulong vehicleId = reefer!.GetComponent()!.VehicleData.Id; - player.GetPlayerCurrentlyPlayingAsCharacter().GetInventory()!.TakeItem(GetNetItem()!, 1); Inventory storage = _inventoryManager.CreateInventory($"Fishing Net of Vehicle {vehicleId}", FishingSettings.NetStorageMaxWeightInGrams); _fishingNetManager.CreateNet(vehicleId, storage.GetId()); + // Taken only once the net exists: creating it saves to the database and can fail. + player.GetPlayerCurrentlyPlayingAsCharacter().GetInventory()!.TakeItem(GetNetItem()!, 1); // Saved now, like the net itself: a crash must not leave the player with both the item and a fitted net. _inventoryItemManager.SaveNow(); player.SendPlayerInfoMessage(PlayerInfoMessageType.INFO, "The net is fitted. Use /trawl while driving to lower it, and /netstorage to see the catch."); diff --git a/src/OpenRP.Framework/Features/Fishing/Services/FishingService.cs b/src/OpenRP.Framework/Features/Fishing/Services/FishingService.cs index 16e6d7b..1a037c4 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/FishingService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/FishingService.cs @@ -263,7 +263,7 @@ private void GiveCatch(Player player, FishLootModel loot) _chatService.SendPlayerChatMessage(player, PlayerChatMessageType.ME, $"reels in the line and pulls up: {loot.Name}."); SendCatchMessage(player, loot, weightInGrams, isInInventory); _fishService.AddFishingExperience(player, _fishService.GetExperienceForCatch(loot)); - _fishService.PublishFishCaught(player, loot, weightInGrams, FishCatchMethod.Rod); + _ = _fishService.PublishFishCaught(player, loot, weightInGrams, FishCatchMethod.Rod); } /// diff --git a/src/OpenRP.Framework/Features/Fishing/Services/IFishService.cs b/src/OpenRP.Framework/Features/Fishing/Services/IFishService.cs index 31557e2..360bc94 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/IFishService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/IFishService.cs @@ -51,6 +51,6 @@ public interface IFishService /// /// Tells other features that the player brought something up. /// - void PublishFishCaught(Player player, FishLootModel loot, uint weightInGrams, FishCatchMethod method); + Task PublishFishCaught(Player player, FishLootModel loot, uint weightInGrams, FishCatchMethod method); } } diff --git a/src/OpenRP.Framework/Features/Fishing/Services/TrawlService.cs b/src/OpenRP.Framework/Features/Fishing/Services/TrawlService.cs index 0fb10aa..e686bf1 100644 --- a/src/OpenRP.Framework/Features/Fishing/Services/TrawlService.cs +++ b/src/OpenRP.Framework/Features/Fishing/Services/TrawlService.cs @@ -209,7 +209,7 @@ private int StoreCatches(Player player, Inventory storage, IReadOnlyList 0) diff --git a/src/OpenRP.Framework/Features/Fishing/Systems/FishingNetServerSystem.cs b/src/OpenRP.Framework/Features/Fishing/Systems/FishingNetServerSystem.cs new file mode 100644 index 0000000..842bd27 --- /dev/null +++ b/src/OpenRP.Framework/Features/Fishing/Systems/FishingNetServerSystem.cs @@ -0,0 +1,19 @@ +using OpenRP.Framework.Features.Fishing.Services; +using OpenRP.Framework.Shared.ServerEvents.Attributes; +using OpenRP.Framework.Shared.ServerEvents.Entities; +using OpenRP.Framework.Shared.ServerEvents.Entities.EventArgs; + +namespace OpenRP.Framework.Features.Fishing.Systems +{ + public class FishingNetServerSystem : IServerSystem + { + /// + /// The net's row went with the vehicle (cascade), but its storage and the fish in it did not. + /// + [ServerEvent] + public void OnVehicleDeleted(OnVehicleDeletedEventArgs args, IFishingNetService fishingNetService) + { + fishingNetService.RemoveNetOfDeletedVehicle(args.VehicleId); + } + } +} diff --git a/src/OpenRP.Framework/Features/Jurisdictions/Services/Dialogs/JurisdictionDialogService.Settings.cs b/src/OpenRP.Framework/Features/Jurisdictions/Services/Dialogs/JurisdictionDialogService.Settings.cs index f63bbcf..41d7271 100644 --- a/src/OpenRP.Framework/Features/Jurisdictions/Services/Dialogs/JurisdictionDialogService.Settings.cs +++ b/src/OpenRP.Framework/Features/Jurisdictions/Services/Dialogs/JurisdictionDialogService.Settings.cs @@ -176,7 +176,8 @@ private void OpenSettingActions(Player player, Jurisdiction jurisdiction, IJuris else if (response.ItemIndex == clearRow) ClearOwnValue(player, jurisdiction, setting, reopenSettings, canEdit); else if (response.ItemIndex == bindRow) - ToggleBinding(player, jurisdiction, setting, state.BindsSubJurisdictions, reopenActions, reopenSettings, canEdit); + // The row showed the binding as it was when the menu opened; the player chose its opposite. + SetBinding(player, jurisdiction, setting, !state.BindsSubJurisdictions, reopenActions, reopenSettings, canEdit); else reopenSettings(); }); @@ -201,10 +202,10 @@ private void ClearOwnValue(Player player, Jurisdiction jurisdiction, IJurisdicti ContinueAfter(player, _jurisdictionSettingService.ClearValue(jurisdiction, setting), reopenSettings, reopenSettings)); } - private void ToggleBinding(Player player, Jurisdiction country, IJurisdictionSetting setting, bool currentlyBinds, Action reopenActions, Action reopenSettings, Func canEdit) + private void SetBinding(Player player, Jurisdiction country, IJurisdictionSetting setting, bool binds, Action reopenActions, Action reopenSettings, Func canEdit) { WithEditPermission(player, canEdit, reopenSettings, () => - ContinueAfter(player, _jurisdictionSettingService.SetBindsSubJurisdictions(country, setting, !currentlyBinds), reopenActions, reopenActions)); + ContinueAfter(player, _jurisdictionSettingService.SetBindsSubJurisdictions(country, setting, binds), reopenActions, reopenActions)); } /// diff --git a/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs b/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs index c4b0bff..6dd4a29 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs @@ -122,10 +122,15 @@ private async Task ShowReplacedObjectsAsync(Map map, IReadOnlyLis { try { + bool wasLoaded = map.IsLoaded(); await RemoveOldObjectsAsync(map, progress); await AddNewObjectsAsync(map, objects, rowIds, progress); _mapStore.MarkMapLoadedInMemory(map); await _mapService.SpawnMapAsync(map, ToSliceProgress(MapBulkProgress.SpawningObjects, objects.Count, progress)); + if (!wasLoaded) + { + ApplyRemovedBuildings(map); + } return null; } catch (Exception ex) @@ -135,6 +140,24 @@ private async Task ShowReplacedObjectsAsync(Map map, IReadOnlyLis } } + /// + /// A replace loads a map that wasn't in the game, so its removed buildings go too, as when the map is loaded. + /// A map that was already in the game has them applied; applying them twice would count twice against the + /// player's limit. + /// + private void ApplyRemovedBuildings(Map map) + { + if (!map.IsComponentAlive) + { + return; + } + + foreach (MapRemovedBuilding removal in map.GetRemovedBuildings()) + { + _mapService.ApplyRemovedBuilding(removal); + } + } + /// /// Despawns the old objects, then forgets them, a slice at a time. Forgetting destroys their entities, so they must be despawned first. /// diff --git a/src/OpenRP.Framework/Features/Maps/Services/MapService.cs b/src/OpenRP.Framework/Features/Maps/Services/MapService.cs index 4644ab5..2819ae7 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/MapService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/MapService.cs @@ -111,6 +111,12 @@ public void RespawnObject(MapObject mapObject) public void DespawnObject(MapObject mapObject) { + // Despawning a big map awaits between slices, and an object deleted meanwhile took its children with it. + if (!mapObject.IsComponentAlive) + { + return; + } + DestroyDynamicObjects(mapObject); } diff --git a/src/OpenRP.Framework/Features/Radios/Systems/RadioServerSystem.cs b/src/OpenRP.Framework/Features/Radios/Systems/RadioServerSystem.cs index c9f720f..c38d10e 100644 --- a/src/OpenRP.Framework/Features/Radios/Systems/RadioServerSystem.cs +++ b/src/OpenRP.Framework/Features/Radios/Systems/RadioServerSystem.cs @@ -22,5 +22,15 @@ public void OnPlayerInventoryItemUsed(OnPlayerInventoryItemUsedEventArgs args, I radioDialogService.OpenRadio(args.Player, radio); } } + + /// + /// The radio's row went with the vehicle (cascade). Marking its component deleted keeps the next save from + /// writing to that row. + /// + [ServerEvent] + public void OnVehicleDeleted(OnVehicleDeletedEventArgs args, IRadioEditorService radioEditorService) + { + radioEditorService.RemoveVehicleRadio(args.VehicleId); + } } } diff --git a/src/OpenRP.Framework/Features/Vehicles/Commands/DeleteVehicleCommand.cs b/src/OpenRP.Framework/Features/Vehicles/Commands/DeleteVehicleCommand.cs index 40706e8..92aad52 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Commands/DeleteVehicleCommand.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Commands/DeleteVehicleCommand.cs @@ -39,7 +39,7 @@ public void DeleteVehicle(Player player, BaseDataContext dataContext) Vehicle? vehicle = player.InAnyVehicle ? player.Vehicle : NearbyVehicleFinder.FindNearestSavedVehicle(_entityManager, _vehicleInfoService, player); if (vehicle == null) { - player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, "Sit in the vehicle, or stand within 5 metres of it, or use /deletevehicle [vehicle id]."); + player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, "Sit in the vehicle, or stand within 5 metres of it, or use /deletevehicle ."); return; } diff --git a/src/OpenRP.Framework/Features/Vehicles/Commands/ParkCommand.cs b/src/OpenRP.Framework/Features/Vehicles/Commands/ParkCommand.cs index 3417d62..8286b05 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Commands/ParkCommand.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Commands/ParkCommand.cs @@ -54,6 +54,11 @@ public void Park(Player player, IEntityManager entityManager, BaseDataContext da vehicleData.Y = vehiclePosition.Y; vehicleData.Z = vehiclePosition.Z; vehicleData.Rotation = vehicleAngle; + // The vehicle spawns in these again, so a car parked inside an interior stays there. + int virtualWorld = player.VirtualWorld; + int interior = player.Interior; + vehicleData.VirtualWorld = virtualWorld; + vehicleData.Interior = interior; ulong id = vehicleData.Id; dataContext.Vehicles @@ -63,6 +68,8 @@ public void Park(Player player, IEntityManager entityManager, BaseDataContext da .SetProperty(row => row.Y, vehiclePosition.Y) .SetProperty(row => row.Z, vehiclePosition.Z) .SetProperty(row => row.Rotation, vehicleAngle) + .SetProperty(row => row.VirtualWorld, virtualWorld) + .SetProperty(row => row.Interior, interior) .SetProperty(row => row.UpdatedOn, DateTime.UtcNow)); // Notify the player that the vehicle has been parked and saved diff --git a/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs b/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs index 25eac88..dcb9e11 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs @@ -16,6 +16,12 @@ public partial class CreateOrUpdateVehicleDialog private void SaveVehicleData() { + if (!RefreshEditedVehicle()) + { + _player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, "This vehicle was deleted or despawned while you edited it, so nothing was saved."); + return; + } + string? error = GetValidationError(Data) ?? GetLockChangeWaitError(); if (error != null) { @@ -53,6 +59,21 @@ private void SaveVehicleData() SendSavedMessage(isNewVehicle); } + /// + /// Another admin can replace (a model change) or delete the vehicle while this editor is open, so the save looks + /// the live vehicle up again. False when the editor had a live vehicle and it's gone. + /// + private bool RefreshEditedVehicle() + { + if (Data.Id == 0 || _component.EditedVehicle == null) + { + return true; + } + + _component.EditedVehicle = _vehicleManager.FindLoadedVehicle(Data.Id); + return _component.EditedVehicle != null; + } + /// /// A lock change that is still being saved would be overwritten by this copy's door state, so the save waits for it. /// diff --git a/src/OpenRP.Framework/Features/Vehicles/Models/Configurations/VehicleModelConfiguration.cs b/src/OpenRP.Framework/Features/Vehicles/Models/Configurations/VehicleModelConfiguration.cs index d7130c0..fe68e77 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Models/Configurations/VehicleModelConfiguration.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Models/Configurations/VehicleModelConfiguration.cs @@ -87,15 +87,19 @@ public void Configure(EntityTypeBuilder builder) builder.Property(v => v.MaxHealth) .IsRequired(); - // Server Vehicle (the model's default, false, is the only default) + // Database defaults, so servers on an older Framework sharing the database can still insert rows. The + // ServerVehicle default must be false: an older Framework leaves the column out when it's false. builder.Property(v => v.ServerVehicle) - .IsRequired(); + .IsRequired() + .HasDefaultValue(false); - // Where the vehicle is (required) + // Where the vehicle is builder.Property(v => v.VirtualWorld) - .IsRequired(); + .IsRequired() + .HasDefaultValue(0); builder.Property(v => v.Interior) - .IsRequired(); + .IsRequired() + .HasDefaultValue(0); // Configure the optional relationship to OwnerCharacter builder.HasOne(v => v.OwnerCharacter) diff --git a/src/OpenRP.Framework/Features/Vehicles/Services/VehicleManager.cs b/src/OpenRP.Framework/Features/Vehicles/Services/VehicleManager.cs index 9e96715..d118ead 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Services/VehicleManager.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Services/VehicleManager.cs @@ -5,8 +5,6 @@ using Microsoft.Extensions.Logging; using OpenRP.Framework.Database.Models; using OpenRP.Framework.Database.Services; -using OpenRP.Framework.Features.Fishing.Services; -using OpenRP.Framework.Features.Radios.Services; using OpenRP.Framework.Features.Vehicles.Components; using OpenRP.Framework.Features.Vehicles.Helpers; using SampSharp.Entities.SAMP; @@ -19,6 +17,8 @@ using System.Threading.Tasks; using OpenRP.Framework.Database; using OpenRP.Framework.Features.Jurisdictions.Services; +using OpenRP.Framework.Shared.ServerEvents.Entities.EventArgs; +using OpenRP.Framework.Shared.ServerEvents.Services; namespace OpenRP.Framework.Features.Vehicles.Services { @@ -32,27 +32,25 @@ public class VehicleManager : IVehicleManager private readonly IWorldService _worldService; private readonly IEntityManager _entityManager; private readonly VehicleHelper _vehicleHelper; - // Shared for the whole server run, so it's only used to delete rows and to forget stale copies. Everything - // else goes through a short-lived context from _scopeFactory. + // Shared for the whole server run, so it's only used to load vehicles at startup and to forget stale copies. + // Everything else goes through a short-lived context from _scopeFactory. private readonly BaseDataContext _DataContext; private readonly IServiceScopeFactory _scopeFactory; private readonly IDataMemoryService _dataMemoryService; private readonly IJurisdictionService _jurisdictionService; private readonly IVehicleKeyService _vehicleKeyService; - private readonly IRadioEditorService _radioEditorService; - private readonly IFishingNetService _fishingNetService; + private readonly IServerEventAggregator _serverEventAggregator; private readonly ILogger _logger; // The saved vehicles whose lock is being saved right now, so a second lock or unlock waits for the first. private readonly HashSet _vehiclesWithLockChange = new HashSet(); public VehicleManager(IWorldService worldService, IEntityManager entityManager, BaseDataContext dataContext, IServiceScopeFactory scopeFactory, IDataMemoryService dataMemoryService, IJurisdictionService jurisdictionService, IVehicleKeyService vehicleKeyService, - IRadioEditorService radioEditorService, IFishingNetService fishingNetService, ILogger logger) + IServerEventAggregator serverEventAggregator, ILogger logger) { - _fishingNetService = fishingNetService; _jurisdictionService = jurisdictionService; _vehicleKeyService = vehicleKeyService; - _radioEditorService = radioEditorService; + _serverEventAggregator = serverEventAggregator; _worldService = worldService; _entityManager = entityManager; _vehicleHelper = new VehicleHelper(); @@ -396,16 +394,16 @@ private void DetachSharedVehicleRow(ulong vehicleId) public string? DeleteVehicle(ulong id) { - VehicleModel? vehicle = _DataContext.Vehicles.Find(id); - if (vehicle == null) + // The row goes first: if that fails, nothing in game or in the inventories has been touched yet. + int? deletedRows = TryDeleteVehicleRow(id); + if (deletedRows == null) { - return $"There's no vehicle #{id}."; + return "The vehicle couldn't be deleted."; } - // The row goes first: if that fails, nothing in game or in the inventories has been touched yet. - if (!TryRemoveVehicleRow(vehicle)) + if (deletedRows == 0) { - return "The vehicle couldn't be deleted."; + return $"There's no vehicle #{id}."; } RemoveVehicleLeftovers(id); @@ -413,53 +411,39 @@ private void DetachSharedVehicleRow(ulong vehicleId) } /// - /// Runs once the row is gone. A failure in the keys or the radio is logged, and the loaded vehicle is still destroyed. + /// Runs once the row is gone. A failure in the keys is logged, and the loaded vehicle is still destroyed. + /// Other features clean up what they fitted to the vehicle through OnVehicleDeleted; its handlers don't await, + /// so they run before the loaded vehicle is destroyed. /// private void RemoveVehicleLeftovers(ulong vehicleId) { try { _vehicleKeyService.RemoveVehicleKeys(vehicleId); - // The radio's row went with the vehicle (cascade). Marking its component deleted keeps the next save from writing to that row. - _radioEditorService.RemoveVehicleRadio(vehicleId); } catch (Exception ex) { - _logger.LogError(ex, "Removing the keys and radio of deleted vehicle {VehicleId} failed.", vehicleId); + _logger.LogError(ex, "Removing the keys of deleted vehicle {VehicleId} failed.", vehicleId); } - RemoveVehicleFishingNet(vehicleId); + _ = _serverEventAggregator.PublishAsync(new OnVehicleDeletedEventArgs { VehicleId = vehicleId }); DestroyLoadedVehicle(vehicleId); } /// - /// The net's row went with the vehicle (cascade), but its storage and the fish in it did not. + /// The number of rows deleted (0 when there was no such vehicle), or null when the delete failed. /// - private void RemoveVehicleFishingNet(ulong vehicleId) + private int? TryDeleteVehicleRow(ulong vehicleId) { try { - _fishingNetService.RemoveNetOfDeletedVehicle(vehicleId); + using IServiceScope scope = _scopeFactory.CreateScope(); + BaseDataContext dataContext = scope.ServiceProvider.GetRequiredService(); + return dataContext.Vehicles.Where(row => row.Id == vehicleId).ExecuteDelete(); } catch (Exception ex) { - _logger.LogError(ex, "Removing the fishing net of deleted vehicle {VehicleId} failed.", vehicleId); - } - } - - private bool TryRemoveVehicleRow(VehicleModel vehicle) - { - try - { - _DataContext.Vehicles.Remove(vehicle); - _DataContext.SaveChanges(); - return true; - } - catch (Exception ex) - { - _logger.LogError(ex, "Deleting vehicle {VehicleId} failed.", vehicle.Id); - // Forget the failed delete, so later saves on this context don't repeat it. - _DataContext.ChangeTracker.Clear(); - return false; + _logger.LogError(ex, "Deleting vehicle {VehicleId} failed.", vehicleId); + return null; } } diff --git a/src/OpenRP.Framework/Shared/ServerEvents/Entities/EventArgs/OnVehicleDeletedEventArgs.cs b/src/OpenRP.Framework/Shared/ServerEvents/Entities/EventArgs/OnVehicleDeletedEventArgs.cs new file mode 100644 index 0000000..46bdd5a --- /dev/null +++ b/src/OpenRP.Framework/Shared/ServerEvents/Entities/EventArgs/OnVehicleDeletedEventArgs.cs @@ -0,0 +1,11 @@ +namespace OpenRP.Framework.Shared.ServerEvents.Entities.EventArgs +{ + /// + /// An admin deleted a saved vehicle. Its row is already gone; things fitted to it, such as a radio or a fishing net, + /// clean up what the database cascade doesn't reach. + /// + public class OnVehicleDeletedEventArgs : ServerEventArgs + { + public ulong VehicleId { get; set; } + } +} From 5869780a5c61735134104829324eeaef136ecc6b Mon Sep 17 00:00:00 2001 From: Koert Lichtendonk Date: Mon, 23 Nov 2026 19:08:33 +0100 Subject: [PATCH 2/2] Apply the review comments on #20 - IMapService.ApplyRemovedBuildings(Map) applies a map's removed buildings; loading a map and a bulk replace both use it - The vehicle editor's LoadEditedVehicle (was RefreshEditedVehicle) follows the verb vocabulary - Docs: OnVehicleDeleted handlers must do their work before any await, because the vehicle is destroyed right after publishing --- docs/server-events.md | 2 +- .../Features/Maps/Services/IMapService.cs | 5 ++++ .../Features/Maps/Services/MapBulkService.cs | 26 ++++--------------- .../Maps/Services/MapEditorService.cs | 5 +--- .../Features/Maps/Services/MapService.cs | 8 ++++++ .../CreateOrUpdateVehicleDialog.Save.cs | 4 +-- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/docs/server-events.md b/docs/server-events.md index f46d79f..6915f0d 100644 --- a/docs/server-events.md +++ b/docs/server-events.md @@ -26,7 +26,7 @@ public void OnCharacterSelected(OnCharacterSelectedEventArgs args, ISkillService | `OnResourceHarvested` | a player harvested a resource | [Harvestables](features/harvestables.md) | nothing yet: for gamemodes to give rewards | | `OnFishCaught` | a player brought up a fish, junk or a treasure, with a rod or a net (`Loot`, `WeightInGrams`, `Method`) | [Fishing](features/fishing.md) | nothing yet: for gamemodes to give rewards | | `OnPropertyDeleted` | an admin deleted a property | [Properties](features/properties.md) | [Actors](features/actors.md) (actors inside it move outside) | -| `OnVehicleDeleted` | an admin deleted a saved vehicle; its row is already gone (`VehicleId`) | [Vehicles](features/vehicles.md) | [Radios](features/radios.md) (forget its radio), [Fishing](features/fishing.md) (delete its net, storage and fish) | +| `OnVehicleDeleted` | an admin deleted a saved vehicle; its row is already gone (`VehicleId`). The loaded vehicle is destroyed right after publishing, so do your work before any `await` in the handler | [Vehicles](features/vehicles.md) | [Radios](features/radios.md) (forget its radio), [Fishing](features/fishing.md) (delete its net, storage and fish) | | `OnJurisdictionsLoaded` | the jurisdictions were loaded at startup | [Jurisdictions](features/jurisdictions.md) | [Vehicles](features/vehicles.md) (set plates again) | | `OnJurisdictionPlateTagChanged` | a jurisdiction's tags changed, or it moved to another country | [Jurisdictions](features/jurisdictions.md) | [Vehicles](features/vehicles.md) (set plates again) | | `OnJurisdictionGovernmentChanged` | a jurisdiction got another government of its own (old and new faction id, null = none) | [Jurisdictions](features/jurisdictions.md) | nothing yet: for police, laws and taxes later | diff --git a/src/OpenRP.Framework/Features/Maps/Services/IMapService.cs b/src/OpenRP.Framework/Features/Maps/Services/IMapService.cs index 84aab40..36dd176 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/IMapService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/IMapService.cs @@ -90,5 +90,10 @@ public interface IMapService /// Removes the building for every online player. /// void ApplyRemovedBuilding(MapRemovedBuilding removal); + + /// + /// Removes all of this map's buildings for every online player, when the map comes into the game. + /// + void ApplyRemovedBuildings(Map map); } } diff --git a/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs b/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs index 6dd4a29..dca1fa1 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/MapBulkService.cs @@ -127,9 +127,12 @@ private async Task ShowReplacedObjectsAsync(Map map, IReadOnlyLis await AddNewObjectsAsync(map, objects, rowIds, progress); _mapStore.MarkMapLoadedInMemory(map); await _mapService.SpawnMapAsync(map, ToSliceProgress(MapBulkProgress.SpawningObjects, objects.Count, progress)); - if (!wasLoaded) + // A replace loads a map that wasn't in the game, so its removed buildings go too, as when the map is + // loaded. A map that was already in the game has them applied; applying them twice would count twice + // against the player's limit. + if (!wasLoaded && map.IsComponentAlive) { - ApplyRemovedBuildings(map); + _mapService.ApplyRemovedBuildings(map); } return null; } @@ -139,25 +142,6 @@ private async Task ShowReplacedObjectsAsync(Map map, IReadOnlyLis return InGameFailedMessage; } } - - /// - /// A replace loads a map that wasn't in the game, so its removed buildings go too, as when the map is loaded. - /// A map that was already in the game has them applied; applying them twice would count twice against the - /// player's limit. - /// - private void ApplyRemovedBuildings(Map map) - { - if (!map.IsComponentAlive) - { - return; - } - - foreach (MapRemovedBuilding removal in map.GetRemovedBuildings()) - { - _mapService.ApplyRemovedBuilding(removal); - } - } - /// /// Despawns the old objects, then forgets them, a slice at a time. Forgetting destroys their entities, so they must be despawned first. /// diff --git a/src/OpenRP.Framework/Features/Maps/Services/MapEditorService.cs b/src/OpenRP.Framework/Features/Maps/Services/MapEditorService.cs index 342539b..294b551 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/MapEditorService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/MapEditorService.cs @@ -120,10 +120,7 @@ public MapEditorService(IMapStore mapStore, IMapService mapService, IMapEditingS { return MapGoneMessage; } - foreach (MapRemovedBuilding removal in map.GetRemovedBuildings()) - { - _mapService.ApplyRemovedBuilding(removal); - } + _mapService.ApplyRemovedBuildings(map); return null; } diff --git a/src/OpenRP.Framework/Features/Maps/Services/MapService.cs b/src/OpenRP.Framework/Features/Maps/Services/MapService.cs index 2819ae7..9002f06 100644 --- a/src/OpenRP.Framework/Features/Maps/Services/MapService.cs +++ b/src/OpenRP.Framework/Features/Maps/Services/MapService.cs @@ -158,6 +158,14 @@ public void ApplyRemovedBuilding(MapRemovedBuilding removal) } } + public void ApplyRemovedBuildings(Map map) + { + foreach (MapRemovedBuilding removal in map.GetRemovedBuildings()) + { + ApplyRemovedBuilding(removal); + } + } + private IEnumerable GetLoadedRemovedBuildings() { return GetMaps().Where(map => map.IsLoaded()).SelectMany(map => map.GetRemovedBuildings()); diff --git a/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs b/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs index dcb9e11..b21f861 100644 --- a/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs +++ b/src/OpenRP.Framework/Features/Vehicles/Dialogs/CreateOrUpdateVehicleDialog.Save.cs @@ -16,7 +16,7 @@ public partial class CreateOrUpdateVehicleDialog private void SaveVehicleData() { - if (!RefreshEditedVehicle()) + if (!LoadEditedVehicle()) { _player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, "This vehicle was deleted or despawned while you edited it, so nothing was saved."); return; @@ -63,7 +63,7 @@ private void SaveVehicleData() /// Another admin can replace (a model change) or delete the vehicle while this editor is open, so the save looks /// the live vehicle up again. False when the editor had a live vehicle and it's gone. /// - private bool RefreshEditedVehicle() + private bool LoadEditedVehicle() { if (Data.Id == 0 || _component.EditedVehicle == null) {