Add Multiplayer support
This commit is contained in:
1 parent
d1c3b2f10c
commit
32569bafe5
34 files changed
+445
-243
No files matched your search
@@ -13,17 +13,13 @@ impl<'a> Command<'a> for GamemodeCommand {
|
||||
|
||||
const DESCRIPTION: &'a str = "Changes the gamemode for a Player";
|
||||
|
||||
fn on_execute(
|
||||
sender: &mut super::CommandSender<'a>,
|
||||
command: String,
|
||||
_server: &mut crate::server::Server,
|
||||
) {
|
||||
fn on_execute(sender: &mut super::CommandSender<'a>, command: String) {
|
||||
let player = sender.as_mut_player().unwrap();
|
||||
let args: Vec<&str> = command.split_whitespace().collect();
|
||||
|
||||
if args.len() != 2 {
|
||||
// todo red
|
||||
player.send_message("Usage: /gamemode <mode>".into());
|
||||
player.send_system_message("Usage: /gamemode <mode>".into());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,11 +27,11 @@ impl<'a> Command<'a> for GamemodeCommand {
|
||||
match mode_str.parse() {
|
||||
Ok(mode) => {
|
||||
player.set_gamemode(mode);
|
||||
player.send_message(format!("Set own game mode to {mode_str}").into());
|
||||
player.send_system_message(format!("Set own game mode to {mode_str}").into());
|
||||
}
|
||||
Err(_) => {
|
||||
// todo red
|
||||
player.send_message("Invalid gamemode".into());
|
||||
player.send_system_message("Invalid gamemode".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use gamemode::GamemodeCommand;
|
||||
use pumpkin::PumpkinCommand;
|
||||
use pumpkin_protocol::text::TextComponent;
|
||||
|
||||
use crate::{client::Client, server::Server};
|
||||
use crate::client::Client;
|
||||
|
||||
mod gamemode;
|
||||
mod pumpkin;
|
||||
@@ -13,7 +13,7 @@ pub trait Command<'a> {
|
||||
const NAME: &'a str;
|
||||
const DESCRIPTION: &'a str;
|
||||
|
||||
fn on_execute(sender: &mut CommandSender<'a>, command: String, server: &mut Server);
|
||||
fn on_execute(sender: &mut CommandSender<'a>, command: String);
|
||||
|
||||
/// Specifies wether the Command Sender has to be a Player
|
||||
fn player_required() -> bool {
|
||||
@@ -31,7 +31,7 @@ impl<'a> CommandSender<'a> {
|
||||
match self {
|
||||
// todo: add color and stuff to console
|
||||
CommandSender::Console => log::info!("{}", text.text),
|
||||
CommandSender::Player(c) => c.send_message(text),
|
||||
CommandSender::Player(c) => c.send_system_message(text),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,15 +55,15 @@ impl<'a> CommandSender<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn handle_command(sender: &mut CommandSender, command: String, server: &mut Server) {
|
||||
pub fn handle_command(sender: &mut CommandSender, command: String) {
|
||||
let command = command.to_lowercase();
|
||||
// an ugly mess i know
|
||||
if command.starts_with(PumpkinCommand::NAME) {
|
||||
PumpkinCommand::on_execute(sender, command, server);
|
||||
PumpkinCommand::on_execute(sender, command);
|
||||
return;
|
||||
}
|
||||
if command.starts_with(GamemodeCommand::NAME) {
|
||||
GamemodeCommand::on_execute(sender, command, server);
|
||||
GamemodeCommand::on_execute(sender, command);
|
||||
return;
|
||||
}
|
||||
// todo: red color
|
||||
|
||||
@@ -17,11 +17,7 @@ impl<'a> Command<'a> for PumpkinCommand {
|
||||
|
||||
const DESCRIPTION: &'a str = "Displays information about Pumpkin";
|
||||
|
||||
fn on_execute(
|
||||
sender: &mut super::CommandSender<'a>,
|
||||
_command: String,
|
||||
_server: &mut crate::server::Server,
|
||||
) {
|
||||
fn on_execute(sender: &mut super::CommandSender<'a>, _command: String) {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let description = env!("CARGO_PKG_DESCRIPTION");
|
||||
sender.send_message(TextComponent::from(format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")))
|
||||
|
||||
Reference in new issue
Block a user