pumpkinplus/mirror_types/
gamemode.rs1use serde::{Deserialize, Serialize};
6use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
12#[serde(rename_all = "PascalCase")]
13pub enum GameMode {
14 Survival,
15 Creative,
16 Adventure,
17 Spectator,
18}
19
20impl GameMode {
21 pub fn matches_config(&self, allowed: &[Self]) -> bool {
23 allowed.is_empty() || allowed.contains(self)
24 }
25}
26
27impl fmt::Display for GameMode {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{:?}", self)
30 }
31}
32
33impl From<pumpkin_plugin_api::player::GameMode> for GameMode {
38 fn from(value: pumpkin_plugin_api::player::GameMode) -> Self {
39 #[allow(unreachable_patterns)]
40 match value {
41 pumpkin_plugin_api::player::GameMode::Survival => Self::Survival,
42 pumpkin_plugin_api::player::GameMode::Creative => Self::Creative,
43 pumpkin_plugin_api::player::GameMode::Adventure => Self::Adventure,
44 pumpkin_plugin_api::player::GameMode::Spectator => Self::Spectator,
45 _ => Self::Survival,
46 }
47 }
48}