Fix all clippy lints
This commit is contained in:
parent
b4fb3a1971
commit
08602f0010
@ -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
|
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
|
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
|
3. `rust/build/protobufs.rs` - Generates Rust protobuf code and FFI entry points from `.proto` definitions
|
||||||
|
|
||||||
## Adding a new FFI method
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ impl FfiServiceGenerator {
|
|||||||
fn package_to_module_path(&self, package: &str) -> String {
|
fn package_to_module_path(&self, package: &str) -> String {
|
||||||
package
|
package
|
||||||
.split('.')
|
.split('.')
|
||||||
.map(|s| to_snake_case(s))
|
.map(to_snake_case)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("::")
|
.join("::")
|
||||||
}
|
}
|
||||||
@ -92,7 +92,13 @@ impl ServiceGenerator for FfiServiceGenerator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
buf.push_str(&format!(
|
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)]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn {fn_name}(
|
pub unsafe extern "C" fn {fn_name}(
|
||||||
input_ptr: *const u8,
|
input_ptr: *const u8,
|
||||||
@ -170,7 +176,13 @@ pub fn setup_protobufs(base: PathBuf) {
|
|||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
file,
|
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)]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn ffi_free_bytes(ptr: *mut u8, len: usize) {{
|
pub unsafe extern "C" fn ffi_free_bytes(ptr: *mut u8, len: usize) {{
|
||||||
if !ptr.is_null() && len > 0 {{
|
if !ptr.is_null() && len > 0 {{
|
||||||
|
|||||||
@ -7,22 +7,21 @@ use crate::proto::patchbukkit::{
|
|||||||
pub fn ffi_native_bridge_get_abilities_impl(request: Uuid) -> Option<Abilities> {
|
pub fn ffi_native_bridge_get_abilities_impl(request: Uuid) -> Option<Abilities> {
|
||||||
let ctx = CALLBACK_CONTEXT.get()?;
|
let ctx = CALLBACK_CONTEXT.get()?;
|
||||||
let player_uuid = uuid::Uuid::parse_str(&request.value).ok()?;
|
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 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
|
ctx.runtime
|
||||||
.block_on(async { player.abilities.lock().await })
|
.block_on(async { player.abilities.lock().await })
|
||||||
});
|
});
|
||||||
|
|
||||||
abilities.invulnerable = pumpkin_abilities.invulnerable;
|
Some(Abilities {
|
||||||
abilities.flying = pumpkin_abilities.flying;
|
invulnerable: abilities.invulnerable,
|
||||||
abilities.allow_flying = pumpkin_abilities.allow_flying;
|
flying: abilities.flying,
|
||||||
abilities.creative = pumpkin_abilities.creative;
|
allow_flying: abilities.allow_flying,
|
||||||
abilities.allow_modify_world = pumpkin_abilities.allow_modify_world;
|
creative: abilities.creative,
|
||||||
abilities.fly_speed = pumpkin_abilities.fly_speed;
|
allow_modify_world: abilities.allow_modify_world,
|
||||||
abilities.walk_speed = pumpkin_abilities.walk_speed;
|
fly_speed: abilities.fly_speed,
|
||||||
|
walk_speed: abilities.walk_speed,
|
||||||
return Some(abilities);
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ffi_native_bridge_set_abilities_impl(request: SetAbilitiesRequest) -> Option<bool> {
|
pub fn ffi_native_bridge_set_abilities_impl(request: SetAbilitiesRequest) -> Option<bool> {
|
||||||
|
|||||||
@ -74,27 +74,19 @@ pub fn ffi_native_bridge_call_event_impl(request: CallEventRequest) -> Option<Ca
|
|||||||
ctx.runtime.block_on(async {
|
ctx.runtime.block_on(async {
|
||||||
match event_data {
|
match event_data {
|
||||||
EventData::PlayerJoin(player_join_event_data) => {
|
EventData::PlayerJoin(player_join_event_data) => {
|
||||||
if let Ok(uuid) =
|
let uuid =
|
||||||
uuid::Uuid::parse_str(&player_join_event_data.player_uuid?.value)
|
uuid::Uuid::parse_str(&player_join_event_data.player_uuid?.value).ok()?;
|
||||||
{
|
let player = context.server.get_player_by_uuid(uuid)?;
|
||||||
if let Some(player) = context.server.get_player_by_uuid(uuid) {
|
let pumpkin_event = PlayerJoinEvent::new(
|
||||||
let pumpkin_event = PlayerJoinEvent::new(
|
player,
|
||||||
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;
|
||||||
),
|
Some(true)
|
||||||
);
|
|
||||||
context.server.plugin_manager.fire(pumpkin_event).await;
|
|
||||||
return Some(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
})?;
|
||||||
|
|
||||||
let mut response = CallEventResponse::default();
|
Some(CallEventResponse { handled })
|
||||||
response.handled = handled?;
|
|
||||||
Some(response)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,24 +28,20 @@ pub fn ffi_native_bridge_get_location_impl(entity_uuid: Uuid) -> Option<Location
|
|||||||
let yaw = entity.yaw.load();
|
let yaw = entity.yaw.load();
|
||||||
let pitch = entity.pitch.load();
|
let pitch = entity.pitch.load();
|
||||||
|
|
||||||
let mut response_position = Vec3::default();
|
return Some(Location {
|
||||||
response_position.x = position.x;
|
world: Some(World {
|
||||||
response_position.y = position.y;
|
uuid: Some(Uuid {
|
||||||
response_position.z = position.z;
|
value: world.to_string(),
|
||||||
|
}),
|
||||||
let mut world_uuid = Uuid::default();
|
}),
|
||||||
world_uuid.value = world.to_string();
|
position: Some(Vec3 {
|
||||||
|
x: position.x,
|
||||||
let mut response_world = World::default();
|
y: position.y,
|
||||||
response_world.uuid = Some(world_uuid);
|
z: position.z,
|
||||||
|
}),
|
||||||
let mut location = Location::default();
|
yaw,
|
||||||
location.pitch = pitch;
|
pitch,
|
||||||
location.position = Some(response_position);
|
});
|
||||||
location.world = Some(response_world);
|
|
||||||
location.yaw = yaw;
|
|
||||||
|
|
||||||
return Some(location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|||||||
@ -10,21 +10,19 @@ pub fn ffi_native_bridge_get_registry_data_impl(
|
|||||||
val if val == RegistryType::SoundEvent as i32 => {
|
val if val == RegistryType::SoundEvent as i32 => {
|
||||||
let sounds = pumpkin_data::sound::Sound::slice()
|
let sounds = pumpkin_data::sound::Sound::slice()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| {
|
.map(|s| SoundEvent {
|
||||||
let mut sound_event = SoundEvent::default();
|
id: *s as u32,
|
||||||
sound_event.id = *s as u32;
|
name: s.to_name().to_string(),
|
||||||
sound_event.name = s.to_name().to_string();
|
|
||||||
sound_event
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut data = SoundEventRegistryData::default();
|
Registry::SoundEvent(SoundEventRegistryData {
|
||||||
data.sound_events = sounds;
|
sound_events: sounds,
|
||||||
Registry::SoundEvent(data)
|
})
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut response = GetRegistryDataResponse::default();
|
Some(GetRegistryDataResponse {
|
||||||
response.registry = Some(registry);
|
registry: Some(registry),
|
||||||
Some(response)
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user