pumpkinplus/modules/mechanics/entity/griefing.rs
1//! Griefing module - prevents mob griefing (block changes and explosions).
2//!
3//! ## Configuration
4//!
5//! | Field | Default | Description |
6//! |---------------------|--------------------------------------------------------------------------|-----------------------------------------------------|
7//! | `enabled` | `false` | Whether this module is active |
8//! | `cancelled_entities`| `["Blaze", "Creeper", "EnderDragon", "Enderman", "Fireball", "SmallFireball", "Wither"]` | Entity types whose griefing is blocked |
9//!
10//! ## Notes
11//!
12//! This module is currently a stub. The Pumpkin plugin API does not yet expose
13//! `EntityChangeBlockEvent` or `EntityExplodeEvent` (or equivalents), so mob
14//! griefing prevention cannot be hooked until upstream support is added.
15
16use crate::EntityType;
17use crate::config::ConfigManager;
18use crate::mechanics::mechanic::Mechanic;
19use pumpkin_plugin_api::Context;
20use serde::{Deserialize, Serialize};
21
22/// Handles mob griefing prevention.
23#[derive(Default)]
24pub struct Griefing;
25
26impl Mechanic for Griefing {
27 fn enabled(&self) -> bool {
28 ConfigManager::get()
29 .map(|cm| cm.get_config::<GriefingConfig>().enabled)
30 .unwrap_or(false)
31 }
32
33 fn events(&self, _context: &Context) {
34 // TODO: Implement when EntityChangeBlockEvent and EntityExplodeEvent
35 // (or equivalents) are available in the Pumpkin plugin API.
36 //
37 // The intended logic is:
38 //
39 // 1. Listen for entity change block events.
40 // - If the entity type is in `config.cancelled_entities`, cancel the event.
41 //
42 // 2. Listen for entity explode events.
43 // - If the entity type is in `config.cancelled_entities`, clear the block list.
44 }
45}
46
47/// Configuration for the griefing mechanics module.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct GriefingConfig {
50 /// Whether this module is active.
51 pub enabled: bool,
52 /// Entity types whose griefing actions (block changes and explosions) are blocked.
53 /// Leave empty to disable entity filtering.
54 pub cancelled_entities: Vec<EntityType>,
55}
56
57impl Default for GriefingConfig {
58 fn default() -> Self {
59 Self {
60 enabled: false,
61 cancelled_entities: vec![
62 EntityType::Blaze,
63 EntityType::Creeper,
64 EntityType::EnderDragon,
65 EntityType::Enderman,
66 EntityType::Fireball,
67 EntityType::SmallFireball,
68 EntityType::Wither,
69 ],
70 }
71 }
72}