Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the clippy warnings #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions crates/blocks/src/block_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ impl FromStr for ContainerType {
}
}

impl ToString for ContainerType {
fn to_string(&self) -> String {
match self {
impl std::fmt::Display for ContainerType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
ContainerType::Furnace => "minecraft:furnace",
ContainerType::Barrel => "minecraft:barrel",
ContainerType::Hopper => "minecraft:hopper",
}
.to_owned()
})
}
}

Expand Down
81 changes: 43 additions & 38 deletions crates/blocks/src/blocks/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ impl FromStr for ComparatorMode {
}
}

impl ToString for ComparatorMode {
fn to_string(&self) -> String {
match self {
ComparatorMode::Subtract => "subtract".to_owned(),
ComparatorMode::Compare => "compare".to_owned(),
}
impl std::fmt::Display for ComparatorMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
ComparatorMode::Subtract => "subtract",
ComparatorMode::Compare => "compare",
})
}
}

Expand Down Expand Up @@ -145,13 +145,13 @@ impl FromStr for LeverFace {
}
}

impl ToString for LeverFace {
fn to_string(&self) -> String {
match self {
LeverFace::Floor => "floor".to_owned(),
LeverFace::Ceiling => "ceiling".to_owned(),
LeverFace::Wall => "wall".to_owned(),
}
impl std::fmt::Display for LeverFace {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
LeverFace::Floor => "floor",
LeverFace::Ceiling => "ceiling",
LeverFace::Wall => "wall",
})
}
}

Expand Down Expand Up @@ -212,13 +212,13 @@ impl FromStr for ButtonFace {
}
}

impl ToString for ButtonFace {
fn to_string(&self) -> String {
match self {
ButtonFace::Floor => "floor".to_owned(),
ButtonFace::Ceiling => "ceiling".to_owned(),
ButtonFace::Wall => "wall".to_owned(),
}
impl std::fmt::Display for ButtonFace {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
ButtonFace::Floor => "floor",
ButtonFace::Ceiling => "ceiling",
ButtonFace::Wall => "wall",
})
}
}

Expand Down Expand Up @@ -266,13 +266,13 @@ impl FromStr for RedstoneWireSide {
}
}

impl ToString for RedstoneWireSide {
fn to_string(&self) -> String {
match self {
RedstoneWireSide::Up => "up".to_owned(),
RedstoneWireSide::Side => "side".to_owned(),
RedstoneWireSide::None => "none".to_owned(),
}
impl std::fmt::Display for RedstoneWireSide {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
RedstoneWireSide::Up => "up",
RedstoneWireSide::Side => "side",
RedstoneWireSide::None => "none",
})
}
}

Expand Down Expand Up @@ -371,12 +371,12 @@ impl TrapdoorHalf {
}
}

impl ToString for TrapdoorHalf {
fn to_string(&self) -> String {
match self {
TrapdoorHalf::Top => "top".to_owned(),
TrapdoorHalf::Bottom => "bottom".to_owned(),
}
impl std::fmt::Display for TrapdoorHalf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
TrapdoorHalf::Top => "top",
TrapdoorHalf::Bottom => "bottom",
})
}
}

Expand Down Expand Up @@ -513,9 +513,9 @@ impl Instrument {
}
}

impl ToString for Instrument {
fn to_string(&self) -> String {
match self {
impl std::fmt::Display for Instrument {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Instrument::Harp => "harp",
Instrument::Basedrum => "basedrum",
Instrument::Snare => "snare",
Expand All @@ -538,8 +538,7 @@ impl ToString for Instrument {
Instrument::Dragon => "dragon",
Instrument::WitherSkeleton => "wither_skeleton",
Instrument::Piglin => "piglin",
}
.to_owned()
})
}
}

Expand All @@ -564,6 +563,12 @@ impl FromStr for Instrument {
"bit" => Instrument::Bit,
"banjo" => Instrument::Banjo,
"pling" => Instrument::Pling,
"zombie" => Instrument::Zombie,
"skeleton" => Instrument::Skeleton,
"creeper" => Instrument::Creeper,
"dragon" => Instrument::Dragon,
"wither_skeleton" => Instrument::WitherSkeleton,
"piglin" => Instrument::Piglin,
_ => return Err(()),
})
}
Expand Down
36 changes: 18 additions & 18 deletions crates/blocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ impl FromStr for BlockDirection {
}
}

impl ToString for BlockDirection {
fn to_string(&self) -> String {
match self {
BlockDirection::North => "north".to_owned(),
BlockDirection::South => "south".to_owned(),
BlockDirection::East => "east".to_owned(),
BlockDirection::West => "west".to_owned(),
}
impl std::fmt::Display for BlockDirection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
BlockDirection::North => "north",
BlockDirection::South => "south",
BlockDirection::East => "east",
BlockDirection::West => "west",
})
}
}

Expand Down Expand Up @@ -401,16 +401,16 @@ impl BlockFacing {
}
}

impl ToString for BlockFacing {
fn to_string(&self) -> String {
match self {
BlockFacing::North => "north".to_owned(),
BlockFacing::South => "south".to_owned(),
BlockFacing::East => "east".to_owned(),
BlockFacing::West => "west".to_owned(),
BlockFacing::Up => "up".to_owned(),
BlockFacing::Down => "down".to_owned(),
}
impl std::fmt::Display for BlockFacing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
BlockFacing::North => "north",
BlockFacing::South => "south",
BlockFacing::East => "east",
BlockFacing::West => "west",
BlockFacing::Up => "up",
BlockFacing::Down => "down",
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl_simple_default!(String, i64, bool);

impl<T> ConfigSerializeDefault for Option<T> {
fn fix_config(self, _: &str, _: &mut DocumentMut) {
assert!(matches!(self, None), "`Some` as default is unimplemented");
assert!(self.is_none(), "`Some` as default is unimplemented");
}
}

Expand Down
9 changes: 5 additions & 4 deletions crates/core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ impl Player {

/// Sends a raw chat message to the player
pub fn send_chat_message(&self, message: &[TextComponent]) {
let mut component: TextComponent = Default::default();
component.extra = message.to_vec();
self.send_raw_chat(component);
self.send_raw_chat(TextComponent {
extra: message.to_vec(),
..Default::default()
});
}

pub fn send_no_permission_message(&self) {
Expand Down Expand Up @@ -533,7 +534,7 @@ impl Player {
window_id: 0,
state_id: 0,
slot: slot as i16,
slot_data: item.as_ref().map(|item| utils::encode_slot_data(item)),
slot_data: item.as_ref().map(utils::encode_slot_data),
}
.encode();
self.client.send_packet(&set_slot);
Expand Down
3 changes: 1 addition & 2 deletions crates/core/src/plot/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ static EMPTY_PLOT: Lazy<PlotData> = Lazy::new(|| {
to_be_ticked: Vec::new(),
packet_senders: Vec::new(),
};
let chunk_data: Vec<ChunkData> =
world.chunks.iter_mut().map(|c| ChunkData::new(c)).collect();
let chunk_data: Vec<ChunkData> = world.chunks.iter_mut().map(ChunkData::new).collect();
PlotData {
tps: Tps::Limited(10),
world_send_rate: WorldSendRate::default(),
Expand Down
32 changes: 12 additions & 20 deletions crates/core/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ impl World for PlotWorld {
}

fn get_block_entity(&self, pos: BlockPos) -> Option<&BlockEntity> {
let chunk_index = match self.get_chunk_index_for_block(pos.x, pos.z) {
Some(idx) => idx,
None => return None,
};
let chunk_index = self.get_chunk_index_for_block(pos.x, pos.z)?;
let chunk = &self.chunks[chunk_index];
chunk.get_block_entity(BlockPos::new(pos.x & 0xF, pos.y, pos.z & 0xF))
}
Expand Down Expand Up @@ -521,9 +518,7 @@ impl Plot {
if let Some(item) = &item_in_hand {
let has_permission = self.players[player].has_permission("worldedit.selection.pos");
if item.item_type == (Item::WEWand {}) && has_permission {
let same = self.players[player]
.second_position
.map_or(false, |p| p == block_pos);
let same = self.players[player].second_position == Some(block_pos);
if !same {
self.players[player].worldedit_set_second_position(block_pos);
}
Expand Down Expand Up @@ -695,7 +690,7 @@ impl Plot {
thread::scope(|s| {
let handle = s.spawn(|| {
self.redpiler
.compile(&mut self.world, bounds, options, ticks, monitor)
.compile(&self.world, bounds, options, ticks, monitor)
});
while !handle.is_finished() {
// We'll update the players so that they don't time out.
Expand Down Expand Up @@ -859,14 +854,13 @@ impl Plot {
let player_info = CPlayerInfoUpdate {
players: vec![CPlayerInfoUpdatePlayer {
uuid: player_join_info.uuid,
actions: {
let mut actions: CPlayerInfoActions = Default::default();
actions.add_player = Some(CPlayerInfoAddPlayer {
actions: CPlayerInfoActions {
add_player: Some(CPlayerInfoAddPlayer {
name: player_join_info.username,
properties: player_join_info.properties,
});
actions.update_gamemode = Some(player_join_info.gamemode.get_id());
actions
}),
update_gamemode: Some(player_join_info.gamemode.get_id()),
..Default::default()
},
}],
}
Expand Down Expand Up @@ -898,10 +892,9 @@ impl Plot {
let player_info = CPlayerInfoUpdate {
players: vec![CPlayerInfoUpdatePlayer {
uuid,
actions: {
let mut actions: CPlayerInfoActions = Default::default();
actions.update_gamemode = Some(gamemode.get_id());
actions
actions: CPlayerInfoActions {
update_gamemode: Some(gamemode.get_id()),
..Default::default()
},
}],
}
Expand Down Expand Up @@ -1186,8 +1179,7 @@ impl Plot {

fn save(&mut self) {
let world = &mut self.world;
let chunk_data: Vec<ChunkData> =
world.chunks.iter_mut().map(|c| ChunkData::new(c)).collect();
let chunk_data: Vec<ChunkData> = world.chunks.iter_mut().map(ChunkData::new).collect();
let data = PlotData {
tps: self.tps,
world_send_rate: self.world_send_rate,
Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/plot/packet_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ServerBoundPacketHandler for Plot {
let mut path = PathBuf::from("./schems");
if CONFIG.schemati {
let uuid = self.players[player_idx].uuid;
path.push(&HyphenatedUUID(uuid).to_string());
path.push(HyphenatedUUID(uuid).to_string());
}

let current = &packet.text[7..];
Expand All @@ -53,7 +53,7 @@ impl ServerBoundPacketHandler for Plot {
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
error!("There was an error completing //load");
error!("{}", err.to_string());
error!("{}", err);
}
return;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl ServerBoundPacketHandler for Plot {
let item = ItemStack {
count: slot_data.item_count as u8,
item_type: Item::from_id(slot_data.item_id as u32),
nbt: slot_data.nbt.map(|nbt| nbt::Blob::with_content(nbt)),
nbt: slot_data.nbt.map(nbt::Blob::with_content),
};
self.players[player].inventory[creative_inventory_action.slot as usize] = Some(item);
if creative_inventory_action.slot as u32 == self.players[player].selected_slot + 36 {
Expand All @@ -104,7 +104,7 @@ impl ServerBoundPacketHandler for Plot {
item: self.players[player].inventory
[creative_inventory_action.slot as usize]
.as_ref()
.map(|item| utils::encode_slot_data(&item)),
.map(utils::encode_slot_data),
}],
}
.encode();
Expand Down Expand Up @@ -413,7 +413,7 @@ impl ServerBoundPacketHandler for Plot {
slot: 0, // Main hand
item: self.players[player].inventory[held_item_change.slot as usize + 36]
.as_ref()
.map(|item| utils::encode_slot_data(item)),
.map(utils::encode_slot_data),
}],
}
.encode();
Expand Down
Loading