Skip to content

Commit

Permalink
feat: add PluginManager#registerCustomSource and `PluginManager#reg…
Browse files Browse the repository at this point in the history
…isterCustomLoaderFactory`, custom plugin loaders and sources can be registered by plugin now.
  • Loading branch information
smartcmd committed Jan 22, 2025
1 parent c6da52c commit 51f7389
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 83 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Added `WorldSettings.WorldSetting#runtimeOnly`, If set this to true, the information of this world will not be saved
to world-settings.yml, therefore it won't be loaded after the server restarted. This is useful for world created for game
room by plugin and will be deleted when shutdown.
- (API) Added `PluginManager#registerCustomSource` and `PluginManager#registerCustomLoaderFactory`, custom plugin loaders
and sources can be registered by plugin now.

### Changed

- (API) Renamed `FullContainerTypeBuilder` to `Builder`
- (API) Renamed `FullContainerTypeBuilder` to `Builder`.
- World will be skipped if failed to be load.
- Main thread will sleep a short time if gui is enabled when the server exits abnormally. This gives user time to see what goes wrong.
- Server won't crash if failed to load the descriptor of a plugin now. An error message will be print to the console instead.
Expand All @@ -40,6 +42,10 @@ Unless otherwise specified, any version comparison below is the comparison of se
initializing the dimension.
- Explosion now calculates entity exposure correctly. In previous version any non-air block will block the explosion ray.

### Removed

- Removed `Extension#afterServerStarted` method.

## [0.1.3](https://github.com/AllayMC/Allay/releases/tag/0.1.3) (API 0.4.0) - 2025-1-17

<small>[Compare with 0.1.2](https://github.com/AllayMC/Allay/compare/0.1.2...0.1.3)</small>
Expand Down
22 changes: 20 additions & 2 deletions api/src/main/java/org/allaymc/api/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
*/
public interface PluginManager {
/**
* Get all discovered plugins.
* Get all loaded plugins.
*
* @return the discovered plugins
*/
Map<String, PluginContainer> getPlugins();

/**
* Get a discovered plugin by name.
* Get a loaded plugin by name.
*
* @param name the name of the plugin.
*
Expand Down Expand Up @@ -48,4 +48,22 @@ public interface PluginManager {
* @return {@code true} if the plugin is enabled, {@code false} otherwise.
*/
boolean isPluginEnabled(String name);

/**
* Register a custom plugin source.
* <p>
* Plugin can register custom plugin source in {@link Plugin#onLoad()} method.
*
* @param customPluginSource the custom plugin source to register.
*/
void registerCustomSource(PluginSource customPluginSource);

/**
* Register a custom plugin loader factory.
* <p>
* Plugin can register custom plugin loader factory in {@link Plugin#onLoad()} method.
*
* @param customLoaderFactory the custom plugin loader factory to register.
*/
void registerCustomLoaderFactory(PluginLoader.Factory customLoaderFactory);
}
1 change: 0 additions & 1 deletion server/src/main/java/org/allaymc/server/AllayServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ public void start(long initialTime) {
if (SETTINGS.genericSettings().enableGui()) {
Allay.DASHBOARD.afterServerStarted();
}
Allay.EXTENSION_MANAGER.afterServerStarted();
this.gameLoop.startLoop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void prepareCommandTree(CommandTree tree) {
return context.fail();
}

var plugin = manager.getPlugin(name).plugin();
var plugin = manager.getEnabledPlugin(name).plugin();
if (!plugin.isReloadable()) {
context.addError("Plugin " + name + " is not reloadable!");
return context.fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
*/
public abstract class Extension {
public abstract void main(String[] args);

public void afterServerStarted() {
// noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public void loadExtensions(String[] args) {
this.extensionInstances.forEach(extension -> extension.main(args));
}

public void afterServerStarted() {
this.extensionInstances.forEach(Extension::afterServerStarted);
}

private void loadExtension(Path extensionPath, String[] args) {
log.info(I18n.get().tr(TrKeys.A_EXTENSION_LOADING, extensionPath));
Allay.EXTRA_RESOURCE_CLASS_LOADER.addJar(extensionPath);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/allaymc/server/gui/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void mouseClicked(MouseEvent e) {
if (pluginTable.getSelectedRow() == -1) return;
// Get the plugin
String pluginName = (String) pluginTable.getValueAt(pluginTable.getSelectedRow(), 0);
var pluginDescriptor = Server.getInstance().getPluginManager().getPlugin(pluginName).descriptor();
var pluginDescriptor = Server.getInstance().getPluginManager().getEnabledPlugin(pluginName).descriptor();
JOptionPane.showMessageDialog(null,
I18n.get().tr(TrKeys.A_GUI_PLUGIN_NAME) + ": " + pluginDescriptor.getName() + "\n" +
I18n.get().tr(TrKeys.A_GUI_PLUGIN_ENTRANCE) + ": " + pluginDescriptor.getEntrance() + "\n" +
Expand Down
Loading

0 comments on commit 51f7389

Please sign in to comment.