mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
Remove: pumpkin-plugin
We will focus on other things by now. And extism just slows down compile and indexing times extremly
This commit is contained in:
1692
Cargo.lock
generated
1692
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@ members = [
|
||||
"pumpkin-entity",
|
||||
"pumpkin-inventory",
|
||||
"pumpkin-macros/",
|
||||
"pumpkin-plugin",
|
||||
"pumpkin-protocol/",
|
||||
"pumpkin-registry/",
|
||||
"pumpkin-world",
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "pumpkin-plugin"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
plugins = ["dep:extism"]
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
log.workspace = true
|
||||
extism = { version = "1.6.0", optional = true }
|
||||
@@ -1,17 +0,0 @@
|
||||
#[cfg(feature = "plugins")]
|
||||
use extism::{convert::Msgpack, host_fn, FromBytes, ToBytes};
|
||||
|
||||
/// Used to keep track of things created by plugins.
|
||||
/// This can include things like events, commands, etc.
|
||||
#[derive(Hash, PartialEq, Eq, ToBytes, FromBytes, serde::Serialize, serde::Deserialize)]
|
||||
#[cfg(feature = "plugins")]
|
||||
#[encoding(Msgpack)] // TODO: Switch to protocal buffers for smaller size
|
||||
struct Identifier {
|
||||
namespace: String,
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[cfg(feature = "plugins")]
|
||||
host_fn!(new(namespace: String, path: String) -> Result<Identifier, _> {
|
||||
Ok(Identifier { namespace, path })
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
mod identifer;
|
||||
@@ -1,65 +0,0 @@
|
||||
mod api;
|
||||
|
||||
#[cfg(feature = "plugins")]
|
||||
use extism::{Manifest, Plugin, Wasm};
|
||||
|
||||
pub const PLUGIN_DIR: &str = "plugins";
|
||||
|
||||
pub struct PumpkinPlugin {
|
||||
#[cfg(feature = "plugins")]
|
||||
_plugin: Plugin,
|
||||
}
|
||||
|
||||
pub struct PluginLoader {
|
||||
plugins: Vec<PumpkinPlugin>,
|
||||
}
|
||||
|
||||
impl PluginLoader {
|
||||
pub fn load() -> Self {
|
||||
#[cfg(feature = "plugins")]
|
||||
{
|
||||
use std::path::Path;
|
||||
let plugin_dir = Path::new(PLUGIN_DIR);
|
||||
if !plugin_dir.exists() || !plugin_dir.is_dir() {
|
||||
log::info!("Creating plugins dir...");
|
||||
std::fs::create_dir(plugin_dir).expect("Failed to create Plugin dir");
|
||||
return Self { plugins: vec![] };
|
||||
}
|
||||
let files = std::fs::read_dir(plugin_dir).expect("Failed to read plugin dir");
|
||||
let mut plugins = Vec::new();
|
||||
for file in files {
|
||||
let file = file.expect("Failed to get Plugin file");
|
||||
let path = file.path();
|
||||
if path
|
||||
.extension()
|
||||
.expect("Failed to get Plugin file extension")
|
||||
== "wasm"
|
||||
{
|
||||
log::info!(
|
||||
"Loading Plugin {:?}",
|
||||
path.file_name().expect("Failed to get Plugin file name")
|
||||
);
|
||||
let wasm = Wasm::file(path);
|
||||
let manifest = Manifest::new([wasm]);
|
||||
let mut plugin = Plugin::new(&manifest, [], true).unwrap();
|
||||
plugin
|
||||
.call::<(), ()>("on_enable", ())
|
||||
.expect("Failed to call on_enable funcation");
|
||||
let pumpkin_plugin = PumpkinPlugin { _plugin: plugin };
|
||||
plugins.push(pumpkin_plugin);
|
||||
}
|
||||
}
|
||||
|
||||
Self { plugins }
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "plugins"))]
|
||||
Self {
|
||||
plugins: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugins(&mut self) -> &mut Vec<PumpkinPlugin> {
|
||||
&mut self.plugins
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,10 @@ version = "0.1.0-dev"
|
||||
description = "Empowering everyone to host fast and efficient Minecraft servers."
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = ["plugins"]
|
||||
plugins = ["pumpkin-plugin/plugins"]
|
||||
|
||||
[dependencies]
|
||||
# pumpkin
|
||||
pumpkin-core = { path = "../pumpkin-core" }
|
||||
pumpkin-config = { path = "../pumpkin-config" }
|
||||
pumpkin-plugin = { path = "../pumpkin-plugin" }
|
||||
pumpkin-inventory = { path = "../pumpkin-inventory" }
|
||||
pumpkin-world = { path = "../pumpkin-world" }
|
||||
pumpkin-entity = { path = "../pumpkin-entity" }
|
||||
|
||||
@@ -7,7 +7,6 @@ use pumpkin_core::GameMode;
|
||||
use pumpkin_entity::EntityId;
|
||||
use pumpkin_inventory::drag_handler::DragHandler;
|
||||
use pumpkin_inventory::{Container, OpenContainer};
|
||||
use pumpkin_plugin::PluginLoader;
|
||||
use pumpkin_protocol::client::login::CEncryptionRequest;
|
||||
use pumpkin_protocol::client::status::CStatusResponse;
|
||||
use pumpkin_protocol::{client::config::CPluginMessage, ClientPacket};
|
||||
@@ -38,7 +37,6 @@ pub struct Server {
|
||||
key_store: KeyStore,
|
||||
server_listing: CachedStatus,
|
||||
server_branding: CachedBranding,
|
||||
pub plugin_loader: PluginLoader,
|
||||
|
||||
pub command_dispatcher: Arc<CommandDispatcher<'static>>,
|
||||
pub worlds: Vec<Arc<World>>,
|
||||
@@ -73,14 +71,12 @@ impl Server {
|
||||
// First register default command, after that plugins can put in their own
|
||||
let command_dispatcher = default_dispatcher();
|
||||
log::info!("Loading Plugins");
|
||||
let plugin_loader = PluginLoader::load();
|
||||
|
||||
let world = World::load(Dimension::OverWorld.into_level(
|
||||
// TODO: load form config
|
||||
"./world".parse().unwrap(),
|
||||
));
|
||||
Self {
|
||||
plugin_loader,
|
||||
cached_registry: Registry::get_static(),
|
||||
open_containers: RwLock::new(HashMap::new()),
|
||||
drag_handler: DragHandler::new(),
|
||||
|
||||
Reference in New Issue
Block a user