Skip to content

Commit

Permalink
add load plugin unexpected exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MidCoard committed Oct 1, 2022
1 parent b511bc9 commit 4beed66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/main/java/top/focess/qq/api/plugin/PluginDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,20 @@ else if (yes.equalsIgnoreCase("no"))
}
}
for (String permission : permissions) {
Permission p = Permission.getPermission(permission);
if (p == null)
continue;
if (isAll == null) {
IOHandler.getConsoleIoHandler().outputLang("permission-request", this.name, permission);
try {
IOHandler.getConsoleIoHandler().hasInput(10);
String yes = IOHandler.getConsoleIoHandler().input();
if (yes.equalsIgnoreCase("yes")) {
yeses.add(permission);
this.permissions.put(Permission.getPermission(permission), true);
this.permissions.put(p, true);
} else if (yes.equalsIgnoreCase("no")) {
nos.add(permission);
this.permissions.put(Permission.getPermission(permission), false);
this.permissions.put(p, false);
}
} catch (InputTimeoutException ignored) {
IOHandler.getConsoleIoHandler().outputLang("permission-timeout");
Expand All @@ -144,7 +147,7 @@ else if (yes.equalsIgnoreCase("no"))
if (isAll)
yeses.add(permission);
else nos.add(permission);
this.permissions.put(Permission.getPermission(permission), isAll);
this.permissions.put(p, isAll);
}
}
permissionsStatus.setList("yes", yeses);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/top/focess/qq/core/permission/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.focess.qq.api.plugin.Plugin;
import top.focess.qq.core.plugin.PluginCoreClassLoader;
import top.focess.qq.core.util.MethodCaller;
Expand Down Expand Up @@ -98,9 +99,13 @@ public enum Permission {
this.priority = priority;
}

public static Permission getPermission(final @NotNull String name) {
public static @Nullable Permission getPermission(final @NotNull String name) {
String key = name.trim().replace(" ", "_").toUpperCase();
return Permission.valueOf(key);
try {
return Permission.valueOf(key);
} catch (IllegalArgumentException e) {
return null;
}
}

public static void checkPermission(@NotNull Plugin plugin, Permission permission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ public boolean load() {
} else if (e instanceof PluginLoadException)
// this plugin is null and PluginLoadException means there is something wrong in the new instance of the plugin
FocessQQ.getLogger().thrLang("exception-load-plugin-file", e);
else
FocessQQ.getLogger().thrLang("exception-load-plugin-unexpected-exception", e);
PluginCoreClassLoader.LOADERS.remove(this);
GC_SCHEDULER.run(System::gc, Duration.ofSeconds(1),"load-failed");
return false;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exception-scheduler-uncaught: Scheduler %s uncaught exception
exception-load-soft-depend-plugin: Load soft-dependent plugin file %s exception
exception-section: Section %s exception, %s
exception-get-null-caller-class: Get null caller class exception
exception-load-plugin-unexpected-exception: Load plugin with unexpected exception
setup-uncaught-exception-handler: Setup uncaught exception handler
setup-shutdown-hook: Setup shutdown hook
start-console-input-thread: Start console input thread
Expand Down

0 comments on commit 4beed66

Please sign in to comment.