为getAllWeapons加入空值判定

This commit is contained in:
Light_Quanta 2025-03-10 02:43:58 +08:00
parent eb9fc3b1a4
commit 80a53089a4
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -234,7 +234,7 @@ public abstract class VehicleEntity extends Entity {
this.entityData.define(LAST_ATTACKER_UUID, "undefined");
this.entityData.define(LAST_DRIVER_UUID, "undefined");
if (this instanceof WeaponVehicleEntity weaponVehicle) {
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
this.availableWeapons = new VehicleWeapon[this.getMaxPassengers()][];
var weapons = weaponVehicle.getAllWeapons();
@ -256,7 +256,7 @@ public abstract class VehicleEntity extends Entity {
this.entityData.set(LAST_DRIVER_UUID, compound.getString("LastDriver"));
this.entityData.set(HEALTH, compound.getFloat("Health"));
if (this instanceof WeaponVehicleEntity) {
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
var selected = compound.getIntArray("SelectedWeapon");
this.entityData.set(SELECTED_WEAPON, IntList.of(selected));
}
@ -268,7 +268,7 @@ public abstract class VehicleEntity extends Entity {
compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID));
compound.putString("LastDriver", this.entityData.get(LAST_DRIVER_UUID));
if (this instanceof WeaponVehicleEntity) {
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
compound.putIntArray("SelectedWeapon", this.entityData.get(SELECTED_WEAPON).toIntArray());
}
}