Finalized extension system

This commit is contained in:
Intelli 2024-10-03 15:51:18 -06:00
parent 88b19efc89
commit 385c11a3aa
3 changed files with 19 additions and 11 deletions

3
.gitignore vendored
View File

@ -198,4 +198,5 @@ hs_err_pid*
docs/dev/
# Extensions
/src/main/java/net/coreprotect/extensions/*.java
/src/main/java/net/coreprotect/extensions/*.java
!/src/main/java/net/coreprotect/extensions/Extensions.java

View File

@ -1279,14 +1279,7 @@ public class CommandHandler implements CommandExecutor {
Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DONATION_KEY_REQUIRED));
}
else {
try {
Class.forName("net.coreprotect.extensions.DatabaseMigration");
Extensions.runDatabaseMigration(user, argumentArray);
}
catch (Exception e) {
// plugin not compiled with extension
Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.COMMAND_NOT_FOUND, Color.WHITE, "/co " + corecommand));
}
Extensions.runDatabaseMigration(corecommand, user, argumentArray);
}
}
else {

View File

@ -1,11 +1,25 @@
package net.coreprotect.extensions;
import java.lang.reflect.Method;
import org.bukkit.command.CommandSender;
import net.coreprotect.language.Phrase;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.Color;
public class Extensions {
public static void runDatabaseMigration(CommandSender user, String[] argumentArray) {
DatabaseMigration.runCommand(user, argumentArray);
public static void runDatabaseMigration(String command, CommandSender user, String[] argumentArray) {
try {
Class<?> patchClass = Class.forName("net.coreprotect.extensions.DatabaseMigration");
Method patchMethod = patchClass.getDeclaredMethod("runCommand", CommandSender.class, String[].class);
patchMethod.invoke(null, user, argumentArray);
}
catch (Exception e) {
// plugin not compiled with extension
Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.COMMAND_NOT_FOUND, Color.WHITE, "/co " + command));
}
}
}