Skip to content

Commit b880b71

Browse files
committed
feat: add plugins management
1 parent 1f8a134 commit b880b71

File tree

10 files changed

+764
-16
lines changed

10 files changed

+764
-16
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ server.jar
33
eula.txt
44
mcsast.config.json
55
gate*
6-
.DS_Store
6+
.DS_Store
7+
plugins
8+
plugins.json

Cargo.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "mcsast"
33
authors = ["MagicTeaMC <maoyue@maoyue.tw>"]
4-
description = "Manage Minecraft server / proxy quickly and easily!"
5-
version = "2.2.2"
4+
description = "Manage Minecraft server / proxy / plugins quickly and easily!"
5+
version = "2.3.0"
66
edition = "2024"
77
license = "GPL-3.0"
88

@@ -18,5 +18,9 @@ clap = { version = "4.5", features = ["derive"] }
1818
colored = "3.0"
1919
inquire = "0.7"
2020
reqwest = { version = "0.12", features = ["blocking", "json"] }
21+
tokio = { version = "1.0", features = ["full"] }
2122
serde = { version = "1.0", features = ["derive"] }
22-
serde_json = "1.0"
23+
serde_json = "1.0"
24+
25+
[lints.rust]
26+
dead_code = "allow"

README.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Crates.io Total Downloads](https://img.shields.io/crates/d/mcsast?style=for-the-badge)](https://crates.io/crates/mcsast)
55
[![Crates.io Version](https://img.shields.io/crates/v/mcsast?style=for-the-badge)](https://crates.io/crates/mcsast)
66

7-
Manage Minecraft server / proxy quickly and easily!
7+
Manage Minecraft server / proxy / plugins quickly and easily!
88
## Quick start
99
### Install via Cargo
1010
```
@@ -27,25 +27,65 @@ Give information to us with terminal:
2727

2828
Want to add other software support? [Open an Issue](https://github.com/MagicTeaMC/Minecraft-server-auto-setup/issues).
2929

30-
## Commands
30+
## Servers commands
3131
### Setup a server
32-
```
32+
```bash
3333
mcsast setup
3434
```
3535
If you want it to setup automantic, here is a command
3636
Note: The `--mc-version` and `--eula` flags are only required for Java Edition servers (not proxies).
37-
```
37+
```bash
3838
mcsast setup --software=paper --mc-version=1.21.1 --eula=true -y
3939
```
4040
### Update to latest build of current Minecraft version
41-
```
41+
```bash
4242
mcsast update
4343
```
4444
### Upgrade Minecraft version
45-
```
45+
```bash
4646
mcsast upgrade
4747
```
4848
or
49-
```
49+
```bash
5050
mcsast upgrade --version 1.21.6
51+
```
52+
## Plugins commands
53+
### Help message
54+
```bash
55+
mcsast plugins
56+
```
57+
### List plugins
58+
```bash
59+
mcsast plugins list
60+
```
61+
### Add plugin
62+
Note: `--force` to install latest unstable version
63+
```bash
64+
mcsast plugins add <name>
65+
```
66+
### Load plugins setup
67+
```bash
68+
mcsast plugins load <file.json>
69+
```
70+
### Update plugins
71+
Note: `--force` to install latest unstable version
72+
```bash
73+
mcsast plugins update <name/all>
74+
```
75+
### Remove plugin
76+
```bash
77+
mcsast plugins remove <name>
78+
```
79+
### Search plugins
80+
```bash
81+
mcsast plugins search <name>
82+
```
83+
### Get plugin information
84+
```bash
85+
mcsast plugins info <name/ID>
86+
```
87+
### Export plugins setup
88+
Note: `--output <filename.json>` to custom output file name
89+
```bash
90+
mcsast plugins export
5191
```

clean.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
rm -rf ./server.jar
22
rm -rf ./eula.txt
33
rm -rf ./mcsast.config.json
4-
rm -rf ./gate
4+
rm -rf ./gate
5+
rm -rf plugins/*

src/cli.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use clap::{Parser, Subcommand};
33

44
#[derive(Parser)]
55
#[command(
6-
version = "2.2.2",
6+
version = "2.3.0",
77
author = "Maoyue (MagicTeaMC)",
8-
about = "Manage Minecraft server / proxy quickly and easily!"
8+
about = "Manage Minecraft server / proxy / plugins quickly and easily!"
99
)]
1010
pub struct CLI {
1111
#[command(subcommand)]
@@ -40,4 +40,60 @@ pub enum Commands {
4040
#[arg(short, long)]
4141
version: Option<String>,
4242
},
43+
/// manage plugins
44+
Plugins {
45+
#[command(subcommand)]
46+
action: PluginActions,
47+
},
48+
}
49+
50+
#[derive(Subcommand)]
51+
pub enum PluginActions {
52+
/// list installed plugins
53+
List,
54+
/// download and install a plugin
55+
Add {
56+
/// plugin name or project ID
57+
name: String,
58+
/// force install even if incompatible
59+
#[arg(short, long, default_value_t = false)]
60+
force: bool,
61+
},
62+
/// load plugins from config file
63+
Load {
64+
/// config file path
65+
config: String,
66+
},
67+
/// update plugins
68+
Update {
69+
/// plugin name or 'all' for all plugins
70+
target: String,
71+
/// include beta/alpha versions
72+
#[arg(short, long, default_value_t = false)]
73+
force: bool,
74+
},
75+
/// remove a plugin
76+
Remove {
77+
/// plugin name
78+
name: String,
79+
},
80+
/// search for plugins
81+
Search {
82+
/// search query
83+
query: String,
84+
/// number of results to show
85+
#[arg(short, long, default_value_t = 10)]
86+
limit: u32,
87+
},
88+
/// show plugin information
89+
Info {
90+
/// plugin name or project ID
91+
name: String,
92+
},
93+
/// export current plugins to config file
94+
Export {
95+
/// output file path
96+
#[arg(short, long, default_value = "plugins.json")]
97+
output: String,
98+
},
4399
}

src/config.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ use std::{fs, path::Path};
44

55
const CONFIG_FILE: &str = "mcsast.config.json";
66

7+
#[derive(Serialize, Deserialize, Clone)]
8+
pub struct PluginConfig {
9+
pub name: String,
10+
pub project_id: String,
11+
pub version: String,
12+
pub source: String,
13+
pub filename: String,
14+
pub loader: String,
15+
}
16+
717
#[derive(Serialize, Deserialize)]
818
pub struct Config {
919
pub software: Software,
1020
pub minecraft_version: String,
1121
pub eula_accepted: bool,
22+
#[serde(default)]
23+
pub plugins: Vec<PluginConfig>,
1224
}
1325

1426
impl Config {
@@ -31,4 +43,20 @@ impl Config {
3143
pub fn config_file() -> &'static str {
3244
CONFIG_FILE
3345
}
46+
47+
pub fn add_plugin(&mut self, plugin: PluginConfig) {
48+
// Remove existing plugin with same name if exists
49+
self.plugins.retain(|p| p.name != plugin.name);
50+
self.plugins.push(plugin);
51+
}
52+
53+
pub fn remove_plugin(&mut self, name: &str) -> bool {
54+
let initial_len = self.plugins.len();
55+
self.plugins.retain(|p| p.name != name);
56+
self.plugins.len() != initial_len
57+
}
58+
59+
pub fn get_plugin(&self, name: &str) -> Option<&PluginConfig> {
60+
self.plugins.iter().find(|p| p.name == name)
61+
}
3462
}

src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ mod cli;
88
mod config;
99
mod eula;
1010
mod get_files;
11+
mod modrinth;
12+
mod plugins;
1113
mod software;
1214
mod utils;
1315

14-
use cli::{CLI, Commands};
16+
use cli::{CLI, Commands, PluginActions};
1517
use config::Config;
1618
use software::Software;
1719
use utils::{get_current_directory_name, get_executable_extension, inquired, print_error_and_exit};
@@ -167,6 +169,7 @@ fn handle_setup(
167169
software: software.clone(),
168170
minecraft_version: version.clone(),
169171
eula_accepted: eula,
172+
plugins: Vec::new(),
170173
};
171174

172175
match config.save() {
@@ -329,6 +332,19 @@ fn handle_upgrade(target_version: Option<String>) -> Result<(), Box<dyn std::err
329332
Ok(())
330333
}
331334

335+
async fn handle_plugins(action: PluginActions) -> Result<(), Box<dyn std::error::Error>> {
336+
match action {
337+
PluginActions::List => plugins::list_plugins().await,
338+
PluginActions::Add { name, force } => plugins::get_plugin(&name, force).await,
339+
PluginActions::Load { config } => plugins::load_plugins_from_config(&config).await,
340+
PluginActions::Update { target, force } => plugins::update_plugins(&target, force).await,
341+
PluginActions::Remove { name } => plugins::remove_plugin(&name).await,
342+
PluginActions::Search { query, limit } => plugins::search_plugins(&query, limit).await,
343+
PluginActions::Info { name } => plugins::show_plugin_info(&name).await,
344+
PluginActions::Export { output } => plugins::export_plugins_config(&output).await,
345+
}
346+
}
347+
332348
fn main() -> Result<(), Box<dyn std::error::Error>> {
333349
let cli = CLI::parse();
334350

@@ -341,5 +357,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
341357
} => handle_setup(software, mc_version, eula, yes),
342358
Commands::Update => handle_update(),
343359
Commands::Upgrade { version } => handle_upgrade(version),
360+
Commands::Plugins { action } => {
361+
let rt = tokio::runtime::Runtime::new()?;
362+
rt.block_on(handle_plugins(action))
363+
}
344364
}
345365
}

0 commit comments

Comments
 (0)