Skip to content

Commit

Permalink
Add a stop command
Browse files Browse the repository at this point in the history
Note that this command does not stop gracefully for now
  • Loading branch information
lukas0008 committed Aug 13, 2024
1 parent ade661d commit 96b86f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pumpkin/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use gamemode::GamemodeCommand;
use pumpkin::PumpkinCommand;
use pumpkin_text::TextComponent;
use stop::StopCommand;

use crate::client::Client;

mod gamemode;
mod pumpkin;
mod stop;

/// I think it would be great to split this up into a seperate crate, But idk how i should do that, Because we have to rely on Client and Server
pub trait Command<'a> {
Expand Down Expand Up @@ -72,6 +74,10 @@ pub fn handle_command(sender: &mut CommandSender, command: &str) {
GamemodeCommand::on_execute(sender, command);
return;
}
if command.starts_with(StopCommand::NAME) {
StopCommand::on_execute(sender, command);
return;
}
// TODO: red color
sender.send_message("Command not Found".into());
}
17 changes: 17 additions & 0 deletions pumpkin/src/commands/stop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use super::Command;

pub struct StopCommand {

}

impl<'a> Command<'a> for StopCommand {
const NAME: &'static str = "stop";
const DESCRIPTION: &'static str = "Stops the server";

fn on_execute(sender: &mut super::CommandSender<'a>, command: String) {
std::process::exit(0);
}
fn player_required() -> bool {
true
}
}

0 comments on commit 96b86f1

Please sign in to comment.