Skip to content

Commit 4aafecf

Browse files
committed
added init locator module and its configuration and did some restructuring
Signed-off-by: illyrius666 <28700752+illyrius666@users.noreply.github.com>
1 parent 1b9747f commit 4aafecf

5 files changed

Lines changed: 56 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod modules {
66
pub mod sample;
77
}
88
pub mod mechanics {
9+
pub mod locator;
910
pub mod motd;
1011
pub mod player;
1112
}

src/modules/enchantments/sample.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
#![warn(clippy::all)]
2-
#![forbid(unsafe_code)]
1+

src/modules/mechanics/locator.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::module::Module;
2+
use pumpkin::command::tree::CommandTree;
3+
use serde::{Deserialize, Serialize};
4+
use std::collections::HashSet;
5+
6+
/// Represents handling locator mechanics within the system.
7+
pub struct Locator {
8+
config: Config,
9+
}
10+
11+
impl Locator {
12+
pub fn new() -> Self {
13+
Self {
14+
config: Config::default(),
15+
}
16+
}
17+
}
18+
19+
impl Module for Locator {
20+
fn enabled(&self) -> bool {
21+
self.config.enabled
22+
}
23+
24+
fn cmds(&self) -> HashSet<CommandTree> {
25+
HashSet::from([CommandTree::new(
26+
["locator", "lc"],
27+
"Allows players to personalise their locator bar",
28+
)])
29+
}
30+
}
31+
32+
/// Represents the config of the module.
33+
#[derive(Debug, Clone, Serialize, Deserialize)]
34+
pub struct Config {
35+
pub enabled: bool,
36+
}
37+
38+
impl Default for Config {
39+
fn default() -> Self {
40+
Self { enabled: true }
41+
}
42+
}

src/modules/module.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use pumpkin::command::tree::CommandTree;
2+
use std::collections::HashSet;
3+
14
/// A trait representing a generic module with an `enabled` status.
25
///
36
/// This trait is intended to be implemented by types that represent
@@ -6,4 +9,12 @@
69
pub trait Module {
710
/// Returns `true` if the module is enabled, `false` otherwise.
811
fn enabled(&self) -> bool;
12+
13+
/// Returns a set of `CommandTree`s associated with the current instance.
14+
///
15+
/// # Returns
16+
/// - `HashSet<CommandTree>`: Returns an empty set in the default implementation.
17+
fn cmds(&self) -> HashSet<CommandTree> {
18+
HashSet::new()
19+
}
920
}

src/modules/recipes/sample.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
#![warn(clippy::all)]
2-
#![forbid(unsafe_code)]
1+

0 commit comments

Comments
 (0)