mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-31 15:59:35 +01:00
fix: oops, forgot to remove some stuff
This commit is contained in:
parent
e1140b5856
commit
04ae4117be
@ -1,69 +0,0 @@
|
|||||||
package net.minestom.demo.commands;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.command.CommandSender;
|
|
||||||
import net.minestom.server.command.builder.Command;
|
|
||||||
import net.minestom.server.command.builder.CommandContext;
|
|
||||||
import net.minestom.server.command.builder.arguments.ArgumentString;
|
|
||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
|
||||||
import net.minestom.server.extensions.ExtensionManager;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class LoadExtensionCommand extends Command {
|
|
||||||
|
|
||||||
private final ArgumentString extensionName;
|
|
||||||
|
|
||||||
public LoadExtensionCommand() {
|
|
||||||
super("load");
|
|
||||||
|
|
||||||
setDefaultExecutor(this::usage);
|
|
||||||
|
|
||||||
extensionName = ArgumentType.String("extensionName");
|
|
||||||
|
|
||||||
setArgumentCallback(this::extensionCallback, extensionName);
|
|
||||||
addSyntax(this::execute, extensionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void usage(CommandSender sender, CommandContext context) {
|
|
||||||
sender.sendMessage(Component.text("Usage: /load <extension file name>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void execute(CommandSender sender, CommandContext context) {
|
|
||||||
final String name = context.get(extensionName);
|
|
||||||
sender.sendMessage(Component.text("extensionFile = " + name + "...."));
|
|
||||||
|
|
||||||
ExtensionManager extensionManager = MinecraftServer.getExtensionManager();
|
|
||||||
Path extensionFolder = extensionManager.getExtensionFolder().toPath().toAbsolutePath();
|
|
||||||
Path extensionJar = extensionFolder.resolve(name);
|
|
||||||
try {
|
|
||||||
if (!extensionJar.toFile().getCanonicalPath().startsWith(extensionFolder.toFile().getCanonicalPath())) {
|
|
||||||
sender.sendMessage(Component.text("File name '" + name + "' does not represent a file inside the extensions folder. Will not load"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
sender.sendMessage(Component.text("Failed to load extension: " + e.getMessage()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean managed = extensionManager.loadDynamicExtension(extensionJar.toFile());
|
|
||||||
if (managed) {
|
|
||||||
sender.sendMessage(Component.text("Extension loaded!"));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Component.text("Failed to load extension, check your logs."));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
sender.sendMessage(Component.text("Failed to load extension: " + e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void extensionCallback(CommandSender sender, ArgumentSyntaxException exception) {
|
|
||||||
sender.sendMessage(Component.text("'" + exception.getInput() + "' is not a valid extension name!"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package net.minestom.demo.extension;
|
|
||||||
|
|
||||||
import net.minestom.server.extensions.Extension;
|
|
||||||
|
|
||||||
public class TestExtension extends Extension {
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
System.out.println("Initialize test extension");
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver", true, getOrigin().getClassLoader());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void terminate() {
|
|
||||||
System.out.println("Terminate test extension");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"entrypoint": "net.minestom.demo.extension.TestExtension",
|
|
||||||
"name": "TestExtension",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"externalDependencies": {
|
|
||||||
"repositories": [
|
|
||||||
{ "name": "Central", "url": "https://repo1.maven.org/maven2/" }
|
|
||||||
],
|
|
||||||
"artifacts": [
|
|
||||||
"mysql:mysql-connector-java:8.0.26"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user