Skip to content

Commit

Permalink
Finalized extension system
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Oct 3, 2024
1 parent 88b19ef commit 385c11a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 1 addition & 8 deletions src/main/java/net/coreprotect/command/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1279,14 +1279,7 @@ else if (corecommand.equals("migrate-db")) {
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 {
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/net/coreprotect/extensions/Extensions.java
Original file line number Diff line number Diff line change
@@ -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));
}
}

}

0 comments on commit 385c11a

Please sign in to comment.