From e34fc4733208e80dae0b3f6bd38d9a95350444fb Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Wed, 21 Aug 2024 20:43:09 +0200 Subject: [PATCH] refactor out double call to self.player --- pumpkin/src/client/player_packet.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index d2f855b0..2457f1a6 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -400,11 +400,12 @@ impl Client { } pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) { - let gamemode = self.player.as_ref().unwrap().gamemode; - if gamemode != GameMode::Creative { - self.kick("Invalid action, you can only do that if you are in creative") + let player = self.player.as_mut().unwrap(); + if player.gamemode != GameMode::Creative { + self.kick("Invalid action, you can only do that if you are in creative"); + return; } - let inventory = &mut self.player.as_mut().unwrap().inventory; + let inventory = &mut player.inventory; inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false); }