mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Added javadocs & fixed API version & more
This commit is contained in:
parent
6757437193
commit
805f7f666a
10 changed files with 214 additions and 154 deletions
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.api.extension;
|
||||
|
||||
import org.geysermc.api.GeyserApiBase;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface Extension {
|
||||
void onLoad();
|
||||
void onEnable();
|
||||
void onDisable();
|
||||
|
||||
boolean isEnabled();
|
||||
boolean isDisabled();
|
||||
|
||||
File dataFolder();
|
||||
ExtensionDescription description();
|
||||
String name();
|
||||
|
||||
InputStream getResource(String filename);
|
||||
void saveResource(String filename, boolean replace);
|
||||
|
||||
ClassLoader classLoader();
|
||||
ExtensionLoader extensionLoader();
|
||||
ExtensionLogger logger();
|
||||
GeyserApiBase geyserApi();
|
||||
}
|
|
@ -25,12 +25,41 @@
|
|||
|
||||
package org.geysermc.geyser.api.extension;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtensionDescription {
|
||||
/**
|
||||
* Gets the extension's name
|
||||
*
|
||||
* @return the extension's name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Gets the extension's main class
|
||||
*
|
||||
* @return the extension's main class
|
||||
*/
|
||||
String main();
|
||||
List<String> ApiVersions();
|
||||
|
||||
/**
|
||||
* Gets the extension's api version
|
||||
*
|
||||
* @return the extension's api version
|
||||
*/
|
||||
String ApiVersion();
|
||||
|
||||
/**
|
||||
* Gets the extension's description
|
||||
*
|
||||
* @return the extension's description
|
||||
*/
|
||||
String version();
|
||||
|
||||
/**
|
||||
* Gets the extension's authors
|
||||
*
|
||||
* @return the extension's authors
|
||||
*/
|
||||
List<String> authors();
|
||||
}
|
||||
|
|
|
@ -27,15 +27,47 @@ package org.geysermc.geyser.api.extension;
|
|||
|
||||
import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException;
|
||||
import org.geysermc.geyser.api.extension.exception.InvalidExtensionException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public interface ExtensionLoader {
|
||||
/**
|
||||
* Loads an extension from a given file
|
||||
*
|
||||
* @param file the file to load the extension from
|
||||
* @return the loaded extension
|
||||
* @throws InvalidExtensionException
|
||||
*/
|
||||
GeyserExtension loadExtension(File file) throws InvalidExtensionException;
|
||||
|
||||
/**
|
||||
* Gets an extension's description from a given file
|
||||
*
|
||||
* @param file the file to get the description from
|
||||
* @return the extension's description
|
||||
* @throws InvalidDescriptionException
|
||||
*/
|
||||
ExtensionDescription extensionDescription(File file) throws InvalidDescriptionException;
|
||||
Pattern[] extensionFilters();
|
||||
|
||||
/**
|
||||
* Gets a class by its name from the extension's classloader
|
||||
*
|
||||
* @param name the name of the class
|
||||
* @return the class
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
Class<?> classByName(final String name) throws ClassNotFoundException;
|
||||
void enableExtension(Extension extension);
|
||||
void disableExtension(Extension extension);
|
||||
|
||||
/**
|
||||
* Enables an extension
|
||||
*
|
||||
* @param extension the extension to enable
|
||||
*/
|
||||
void enableExtension(GeyserExtension extension);
|
||||
|
||||
/**
|
||||
* Disables an extension
|
||||
*
|
||||
* @param extension the extension to disable
|
||||
*/
|
||||
void disableExtension(GeyserExtension extension);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.geysermc.geyser.api.extension;
|
|||
public interface ExtensionLogger {
|
||||
/**
|
||||
* Get the logger prefix
|
||||
*
|
||||
* @return the logger prefix
|
||||
*/
|
||||
String prefix();
|
||||
|
|
|
@ -30,34 +30,52 @@ import java.io.*;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class GeyserExtension implements Extension {
|
||||
public class GeyserExtension {
|
||||
private boolean initialized = false;
|
||||
private boolean enabled = false;
|
||||
private File file = null;
|
||||
private File dataFolder = null;
|
||||
private ClassLoader classLoader = null;
|
||||
private ExtensionLoader loader;
|
||||
private ExtensionLogger logger;
|
||||
private ExtensionLoader loader = null;
|
||||
private ExtensionLogger logger = null;
|
||||
private ExtensionDescription description = null;
|
||||
private GeyserApiBase api = null;
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Called when the extension is loaded
|
||||
*/
|
||||
public void onLoad() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Called when the extension is enabled
|
||||
*/
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Called when the extension is disabled
|
||||
*/
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets if the extension is enabled
|
||||
*
|
||||
* @return true if the extension is enabled
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the extension is enabled
|
||||
*
|
||||
* @return true if the extension is enabled
|
||||
*/
|
||||
public void setEnabled(boolean value) {
|
||||
if (this.enabled != value) {
|
||||
this.enabled = value;
|
||||
|
@ -69,27 +87,34 @@ public class GeyserExtension implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
return !this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's data folder
|
||||
*
|
||||
* @return the extension's data folder
|
||||
*/
|
||||
public File dataFolder() {
|
||||
return this.dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's description
|
||||
*
|
||||
* @return the extension's description
|
||||
*/
|
||||
public ExtensionDescription description() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's name
|
||||
*
|
||||
* @return the extension's name
|
||||
*/
|
||||
public String name() {
|
||||
return this.description.name();
|
||||
}
|
||||
|
||||
public void init(GeyserApiBase api, ExtensionLogger logger, ExtensionLoader loader, ExtensionDescription description, File dataFolder, File file) {
|
||||
public void init(GeyserApiBase api, ExtensionLoader loader, ExtensionLogger logger, ExtensionDescription description, File dataFolder, File file) {
|
||||
if (!this.initialized) {
|
||||
this.initialized = true;
|
||||
this.file = file;
|
||||
|
@ -102,7 +127,12 @@ public class GeyserExtension implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets a resource from the extension jar file
|
||||
*
|
||||
* @param filename the file name
|
||||
* @return the input stream
|
||||
*/
|
||||
public InputStream getResource(String filename) {
|
||||
if (filename == null) {
|
||||
throw new IllegalArgumentException("Filename cannot be null");
|
||||
|
@ -123,7 +153,12 @@ public class GeyserExtension implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Saves a resource from the extension jar file to the extension's data folder
|
||||
*
|
||||
* @param filename the file name
|
||||
* @param replace whether to replace the file if it already exists
|
||||
*/
|
||||
public void saveResource(String filename, boolean replace) {
|
||||
if (filename == null || filename.equals("")) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
|
@ -161,22 +196,38 @@ public class GeyserExtension implements Extension {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's class loader
|
||||
*
|
||||
* @return the extension's class loader
|
||||
*/
|
||||
public ClassLoader classLoader() {
|
||||
return this.classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's loader
|
||||
*
|
||||
* @return the extension's loader
|
||||
*/
|
||||
public ExtensionLoader extensionLoader() {
|
||||
return this.loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the extension's logger
|
||||
*
|
||||
* @return the extension's logger
|
||||
*/
|
||||
public ExtensionLogger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Gets the {@link GeyserApiBase} instance
|
||||
*
|
||||
* @return the {@link GeyserApiBase} instance
|
||||
*/
|
||||
public GeyserApiBase geyserApi() {
|
||||
return this.api;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
package org.geysermc.geyser.api.extension.exception;
|
||||
|
||||
/**
|
||||
* Thrown when an extension's description is invalid.
|
||||
*/
|
||||
public class InvalidDescriptionException extends Exception {
|
||||
public InvalidDescriptionException(Throwable cause) {
|
||||
super(cause);
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
package org.geysermc.geyser.api.extension.exception;
|
||||
|
||||
/**
|
||||
* Thrown when an extension is invalid.
|
||||
*/
|
||||
public class InvalidExtensionException extends Exception {
|
||||
public InvalidExtensionException(Throwable cause) {
|
||||
super(cause);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue