Fix all clippy lints

This commit is contained in:
Bjorn Beishline 2026-02-04 00:07:45 -07:00
parent b4fb3a1971
commit 08602f0010
6 changed files with 59 additions and 64 deletions

View File

@ -122,5 +122,3 @@ but in this project, it is very important. The build process is split into modul
1. `rust/build/main.rs` - Entry point that orchestrates the build
2. `rust/build/java.rs` - Embeds all transitive dependencies of the `paper-api` Java library and the PatchBukkit jar
3. `rust/build/protobufs.rs` - Generates Rust protobuf code and FFI entry points from `.proto` definitions
## Adding a new FFI method

View File

@ -63,7 +63,7 @@ impl FfiServiceGenerator {
fn package_to_module_path(&self, package: &str) -> String {
package
.split('.')
.map(|s| to_snake_case(s))
.map(to_snake_case)
.collect::<Vec<_>>()
.join("::")
}
@ -92,7 +92,13 @@ impl ServiceGenerator for FfiServiceGenerator {
});
buf.push_str(&format!(
r#"
r#"/// FFI function for {fn_name}
///
/// # Safety
///
/// - `input_ptr` must be a valid pointer to `input_len` bytes of memory
/// - `output_len` must be a valid pointer to write the output length
/// - The caller is responsible for freeing the returned pointer using `ffi_free_bytes`
#[unsafe(no_mangle)]
pub unsafe extern "C" fn {fn_name}(
input_ptr: *const u8,
@ -170,7 +176,13 @@ pub fn setup_protobufs(base: PathBuf) {
writeln!(
file,
r#"
r#"/// Frees bytes allocated by FFI functions
///
/// # Safety
///
/// - `ptr` must have been returned by an FFI function in this module
/// - `len` must be the length that was written to `output_len`
/// - The pointer must not have been freed previously
#[unsafe(no_mangle)]
pub unsafe extern "C" fn ffi_free_bytes(ptr: *mut u8, len: usize) {{
if !ptr.is_null() && len > 0 {{

View File

@ -7,22 +7,21 @@ use crate::proto::patchbukkit::{
pub fn ffi_native_bridge_get_abilities_impl(request: Uuid) -> Option<Abilities> {
let ctx = CALLBACK_CONTEXT.get()?;
let player_uuid = uuid::Uuid::parse_str(&request.value).ok()?;
let mut abilities = Abilities::default();
let player = ctx.plugin_context.server.get_player_by_uuid(player_uuid)?;
let pumpkin_abilities = tokio::task::block_in_place(|| {
let abilities = tokio::task::block_in_place(|| {
ctx.runtime
.block_on(async { player.abilities.lock().await })
});
abilities.invulnerable = pumpkin_abilities.invulnerable;
abilities.flying = pumpkin_abilities.flying;
abilities.allow_flying = pumpkin_abilities.allow_flying;
abilities.creative = pumpkin_abilities.creative;
abilities.allow_modify_world = pumpkin_abilities.allow_modify_world;
abilities.fly_speed = pumpkin_abilities.fly_speed;
abilities.walk_speed = pumpkin_abilities.walk_speed;
return Some(abilities);
Some(Abilities {
invulnerable: abilities.invulnerable,
flying: abilities.flying,
allow_flying: abilities.allow_flying,
creative: abilities.creative,
allow_modify_world: abilities.allow_modify_world,
fly_speed: abilities.fly_speed,
walk_speed: abilities.walk_speed,
})
}
pub fn ffi_native_bridge_set_abilities_impl(request: SetAbilitiesRequest) -> Option<bool> {

View File

@ -74,27 +74,19 @@ pub fn ffi_native_bridge_call_event_impl(request: CallEventRequest) -> Option<Ca
ctx.runtime.block_on(async {
match event_data {
EventData::PlayerJoin(player_join_event_data) => {
if let Ok(uuid) =
uuid::Uuid::parse_str(&player_join_event_data.player_uuid?.value)
{
if let Some(player) = context.server.get_player_by_uuid(uuid) {
let uuid =
uuid::Uuid::parse_str(&player_join_event_data.player_uuid?.value).ok()?;
let player = context.server.get_player_by_uuid(uuid)?;
let pumpkin_event = PlayerJoinEvent::new(
player,
TextComponent::from_legacy_string(
&player_join_event_data.join_message,
),
TextComponent::from_legacy_string(&player_join_event_data.join_message),
);
context.server.plugin_manager.fire(pumpkin_event).await;
return Some(true);
}
}
Some(false)
Some(true)
}
}
})
});
})?;
let mut response = CallEventResponse::default();
response.handled = handled?;
Some(response)
Some(CallEventResponse { handled })
}

View File

@ -28,24 +28,20 @@ pub fn ffi_native_bridge_get_location_impl(entity_uuid: Uuid) -> Option<Location
let yaw = entity.yaw.load();
let pitch = entity.pitch.load();
let mut response_position = Vec3::default();
response_position.x = position.x;
response_position.y = position.y;
response_position.z = position.z;
let mut world_uuid = Uuid::default();
world_uuid.value = world.to_string();
let mut response_world = World::default();
response_world.uuid = Some(world_uuid);
let mut location = Location::default();
location.pitch = pitch;
location.position = Some(response_position);
location.world = Some(response_world);
location.yaw = yaw;
return Some(location);
return Some(Location {
world: Some(World {
uuid: Some(Uuid {
value: world.to_string(),
}),
}),
position: Some(Vec3 {
x: position.x,
y: position.y,
z: position.z,
}),
yaw,
pitch,
});
}
None

View File

@ -10,21 +10,19 @@ pub fn ffi_native_bridge_get_registry_data_impl(
val if val == RegistryType::SoundEvent as i32 => {
let sounds = pumpkin_data::sound::Sound::slice()
.iter()
.map(|s| {
let mut sound_event = SoundEvent::default();
sound_event.id = *s as u32;
sound_event.name = s.to_name().to_string();
sound_event
.map(|s| SoundEvent {
id: *s as u32,
name: s.to_name().to_string(),
})
.collect::<Vec<_>>();
let mut data = SoundEventRegistryData::default();
data.sound_events = sounds;
Registry::SoundEvent(data)
Registry::SoundEvent(SoundEventRegistryData {
sound_events: sounds,
})
}
_ => unreachable!(),
};
let mut response = GetRegistryDataResponse::default();
response.registry = Some(registry);
Some(response)
Some(GetRegistryDataResponse {
registry: Some(registry),
})
}