Skip to main content

pumpkinplus/modules/mechanics/player/
locator.rs

1//! Locator module - personalize locator bar color.
2//!
3//! ## Commands
4//!
5//! | Command                        | Aliases | Permission                    | Description                |
6//! |--------------------------------|---------|-------------------------------|----------------------------|
7//! | `/locator <color\|hex\|reset>` | `lc`    | `pumpkinplus:command.locator` | Set locator bar color      |
8//!
9//! ## Configuration
10//!
11//! | Field     | Default | Description                   |
12//! |-----------|---------|-------------------------------|
13//! | `enabled` | `false` | Whether this module is active |
14
15use crate::{PLUGIN_ID, config::ConfigManager, mechanics::mechanic::Mechanic};
16use pumpkin_plugin_api::{
17    Server,
18    command::{Command, CommandError, CommandNode, CommandSender, ConsumedArgs},
19    commands::CommandHandler,
20    text::TextComponent,
21};
22use serde::{Deserialize, Serialize};
23use std::collections::HashSet;
24
25/// Handles locator bar mechanics.
26#[derive(Default)]
27pub struct Locator;
28
29impl Mechanic for Locator {
30    fn enabled(&self) -> bool {
31        ConfigManager::get()
32            .map(|cm| cm.get_config::<LocatorConfig>().enabled)
33            .unwrap_or(true)
34    }
35
36    fn cmds(&self) -> Vec<Command> {
37        let command = Command::new(
38            &["locator".to_string(), "lc".to_string()],
39            "Allows players to personalise their locator bar",
40        );
41        command.then(CommandNode::literal("color").execute(LocatorExecutor));
42        command.then(CommandNode::literal("hex").execute(LocatorExecutor));
43        command.then(CommandNode::literal("reset").execute(LocatorExecutor));
44        vec![command]
45    }
46
47    fn perms(&self) -> HashSet<String> {
48        HashSet::from([format!("{}:command.locator", PLUGIN_ID)])
49    }
50}
51
52struct LocatorExecutor;
53
54impl CommandHandler for LocatorExecutor {
55    fn handle(
56        &self,
57        sender: CommandSender,
58        _server: Server,
59        _args: ConsumedArgs,
60    ) -> Result<i32, CommandError> {
61        // TODO: figure out the api to adjust the locator bar.
62        sender.send_message(TextComponent::text("Not yet implemented."));
63        Ok(1)
64    }
65}
66
67/// Configuration for the locator mechanics module.
68#[derive(Debug, Default, Clone, Serialize, Deserialize)]
69pub struct LocatorConfig {
70    /// Whether this module is active.
71    pub enabled: bool,
72}