Skip to content
Merged
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
30 changes: 28 additions & 2 deletions src/default_commands/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use temper_command_infra::args::EntitiesArg;
use temper_command_infra::{CommandHandler, CommandResult, CommandSource};
use temper_components::entity_identity::Identity;
use temper_components::player::player_marker::PlayerMarker;
use temper_core::mq;
use temper_macros::Command;
use temper_permissions::Access::Allow;
use temper_permissions::Permissions;
use temper_permissions::player::PlayerPermission;
use temper_text::TextComponent;
use temper_text::{Color, NamedColor, TextComponent, TextContent};

#[derive(Debug, Command)]
#[command(name = "op", permission = Permissions::Op)]
Expand All @@ -30,8 +31,33 @@ impl CommandHandler for OpCommand {

for entity in self.target.resolve(entities.iter()) {
if let Ok(mut player_permission) = permissions.get_mut(entity) {
if player_permission.permissions.get(&Permissions::ALL) == Some(&Allow) {
source.send_message(TextComponent {
content: TextContent::Text {
text: "Nothing changed. The player is already an operator".to_string(),
},
color: Some(Color::Named(NamedColor::Red)),
..Default::default()
});
continue;
}

player_permission.set_permission(Permissions::ALL, Allow);
source.send_message(TextComponent::from("You have been opped".to_string()));

let Ok(Some(player_name)) = entities.get(entity).map(|e| &e.1.name) else {
return Err("player entity does not have a name".into());
};

source.send_message(TextComponent::from(format!(
"Made {} a server operator",
player_name
)));

mq::queue(
TextComponent::from("You have been opped".to_string()),
false,
entity,
);
}
}

Expand Down
Loading