Skip to content

Commit 83a51e7

Browse files
committed
[6.2.3] 新增一个配置,用于在 PrimitiveLoader 启动失败时强制关闭服务器
1 parent ff8144f commit 83a51e7

File tree

5 files changed

+96
-37
lines changed

5 files changed

+96
-37
lines changed

common/src/main/java/taboolib/common/PrimitiveSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public class PrimitiveSettings {
8383
*/
8484
public static final boolean IS_DISABLE_ON_UNSUPPORTED_VERSION = RUNTIME_PROPERTIES.getProperty("disable-on-unsupported-version", "true").equals("true");
8585

86+
/**
87+
* 在原始加载器初始化失败时是否强制关闭服务器
88+
*/
89+
public static final boolean IS_DISABLE_WHEN_PRIMITIVE_LOADER_ERROR = RUNTIME_PROPERTIES.getProperty("disable-when-primitive-loader-error", "false").equals("true");
90+
8691
/**
8792
* 中央仓库
8893
*/

platform/platform-afybroker/src/main/java/taboolib/platform/AfyBrokerPlugin.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.jetbrains.annotations.Nullable;
66
import taboolib.common.LifeCycle;
77
import taboolib.common.PrimitiveIO;
8+
import taboolib.common.PrimitiveSettings;
89
import taboolib.common.TabooLib;
910
import taboolib.common.classloader.IsolatedClassLoader;
1011
import taboolib.common.platform.Platform;
@@ -36,16 +37,30 @@ public class AfyBrokerPlugin extends net.afyer.afybroker.server.plugin.Plugin {
3637
// 初始化 IsolatedClassLoader
3738
IsolatedClassLoader.init(AfyBrokerPlugin.class);
3839
} catch (Throwable ex) {
39-
// 提示信息
40-
PrimitiveIO.error(
41-
t(
42-
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
43-
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
44-
),
45-
PrimitiveIO.getRunningFileName()
46-
);
47-
// 重抛错误
48-
throw ex;
40+
if (PrimitiveSettings.IS_DISABLE_WHEN_PRIMITIVE_LOADER_ERROR) {
41+
// 提示信息
42+
PrimitiveIO.error(
43+
t(
44+
"无法初始化原始加载器,为避免数据丢失,服务器将会被强制关闭!",
45+
"Failed to initialize primitive loader. To avoid data loss, the server will be forced to shut down!"
46+
)
47+
);
48+
// 打印堆栈
49+
ex.printStackTrace();
50+
// 关闭程序
51+
Runtime.getRuntime().halt(-1);
52+
} else {
53+
// 提示信息
54+
PrimitiveIO.error(
55+
t(
56+
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
57+
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
58+
),
59+
PrimitiveIO.getRunningFileName()
60+
);
61+
// 重抛错误
62+
throw ex;
63+
}
4964
}
5065
// 生命周期任务
5166
TabooLib.lifeCycle(LifeCycle.CONST);

platform/platform-bukkit/src/main/java/taboolib/platform/BukkitPlugin.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.jetbrains.annotations.Nullable;
99
import taboolib.common.LifeCycle;
1010
import taboolib.common.PrimitiveIO;
11+
import taboolib.common.PrimitiveSettings;
1112
import taboolib.common.TabooLib;
1213
import taboolib.common.classloader.IsolatedClassLoader;
1314
import taboolib.common.platform.Platform;
@@ -42,15 +43,27 @@ public class BukkitPlugin extends JavaPlugin {
4243
IsolatedClassLoader.INSTANCE.addExcludedClass("taboolib.platform.BukkitWorldGenerator");
4344
IsolatedClassLoader.INSTANCE.addExcludedClass("taboolib.platform.BukkitBiomeProvider");
4445
} catch (Throwable ex) {
45-
TabooLib.setStopped(true);
46-
PrimitiveIO.error(
47-
t(
48-
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
49-
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
50-
),
51-
PrimitiveIO.getRunningFileName()
52-
);
53-
throw ex;
46+
if (PrimitiveSettings.IS_DISABLE_WHEN_PRIMITIVE_LOADER_ERROR) {
47+
TabooLib.setStopped(true);
48+
PrimitiveIO.error(
49+
t(
50+
"无法初始化原始加载器,为避免数据丢失,服务器将会被强制关闭!",
51+
"Failed to initialize primitive loader. To avoid data loss, the server will be forced to shut down!"
52+
)
53+
);
54+
ex.printStackTrace();
55+
Runtime.getRuntime().halt(-1);
56+
} else {
57+
TabooLib.setStopped(true);
58+
PrimitiveIO.error(
59+
t(
60+
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
61+
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
62+
),
63+
PrimitiveIO.getRunningFileName()
64+
);
65+
throw ex;
66+
}
5467
}
5568
// 生命周期任务
5669
TabooLib.lifeCycle(LifeCycle.CONST);

platform/platform-bungee/src/main/java/taboolib/platform/BungeePlugin.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.jetbrains.annotations.Nullable;
66
import taboolib.common.LifeCycle;
77
import taboolib.common.PrimitiveIO;
8+
import taboolib.common.PrimitiveSettings;
89
import taboolib.common.TabooLib;
910
import taboolib.common.classloader.IsolatedClassLoader;
1011
import taboolib.common.platform.Platform;
@@ -37,15 +38,27 @@ public class BungeePlugin extends net.md_5.bungee.api.plugin.Plugin {
3738
try {
3839
IsolatedClassLoader.init(BungeePlugin.class);
3940
} catch (Throwable ex) {
40-
TabooLib.setStopped(true);
41-
PrimitiveIO.error(
42-
t(
43-
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
44-
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
45-
),
46-
PrimitiveIO.getRunningFileName()
47-
);
48-
throw ex;
41+
if (PrimitiveSettings.IS_DISABLE_WHEN_PRIMITIVE_LOADER_ERROR) {
42+
TabooLib.setStopped(true);
43+
PrimitiveIO.error(
44+
t(
45+
"无法初始化原始加载器,为避免数据丢失,服务器将会被强制关闭!",
46+
"Failed to initialize primitive loader. To avoid data loss, the server will be forced to shut down!"
47+
)
48+
);
49+
ex.printStackTrace();
50+
Runtime.getRuntime().halt(-1);
51+
} else {
52+
TabooLib.setStopped(true);
53+
PrimitiveIO.error(
54+
t(
55+
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
56+
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
57+
),
58+
PrimitiveIO.getRunningFileName()
59+
);
60+
throw ex;
61+
}
4962
}
5063
// 生命周期任务
5164
TabooLib.lifeCycle(LifeCycle.CONST);

platform/platform-velocity/src/main/java/taboolib/platform/VelocityPlugin.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.Logger;
1212
import taboolib.common.LifeCycle;
1313
import taboolib.common.PrimitiveIO;
14+
import taboolib.common.PrimitiveSettings;
1415
import taboolib.common.TabooLib;
1516
import taboolib.common.classloader.IsolatedClassLoader;
1617
import taboolib.common.platform.Platform;
@@ -47,15 +48,27 @@ public class VelocityPlugin {
4748
// 初始化 IsolatedClassLoader
4849
IsolatedClassLoader.init(VelocityPlugin.class);
4950
} catch (Throwable ex) {
50-
TabooLib.setStopped(true);
51-
PrimitiveIO.error(
52-
t(
53-
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
54-
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
55-
),
56-
PrimitiveIO.getRunningFileName()
57-
);
58-
throw ex;
51+
if (PrimitiveSettings.IS_DISABLE_WHEN_PRIMITIVE_LOADER_ERROR) {
52+
TabooLib.setStopped(true);
53+
PrimitiveIO.error(
54+
t(
55+
"无法初始化原始加载器,为避免数据丢失,服务器将会被强制关闭!",
56+
"Failed to initialize primitive loader. To avoid data loss, the server will be forced to shut down!"
57+
)
58+
);
59+
ex.printStackTrace();
60+
Runtime.getRuntime().halt(-1);
61+
} else {
62+
TabooLib.setStopped(true);
63+
PrimitiveIO.error(
64+
t(
65+
"无法初始化原始加载器,插件 \"{0}\" 将被禁用!",
66+
"Failed to initialize primitive loader, the plugin \"{0}\" will be disabled!"
67+
),
68+
PrimitiveIO.getRunningFileName()
69+
);
70+
throw ex;
71+
}
5972
}
6073
// 生命周期任务
6174
TabooLib.lifeCycle(LifeCycle.CONST);

0 commit comments

Comments
 (0)