46 lines
1.5 KiB
Java
46 lines
1.5 KiB
Java
package dev.itxiaohui.contentguard;
|
|
|
|
import dev.itxiaohui.contentguard.core.CompatibilityManager;
|
|
import java.util.Objects;
|
|
import java.util.logging.Level;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
public final class ContentGuardPlugin extends JavaPlugin {
|
|
private CompatibilityManager compatibility;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
try {
|
|
compatibility = CompatibilityManager.initialize(this);
|
|
} catch (IllegalStateException | LinkageError failure) {
|
|
getLogger().log(Level.SEVERE, "兼容性检查失败,正在停用插件", failure);
|
|
getServer().getPluginManager().disablePlugin(this);
|
|
return;
|
|
}
|
|
getLogger().info(compatibility.info().summary());
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
if (compatibility != null) {
|
|
compatibility.close();
|
|
getLogger().info("ICG_LIFECYCLE scheduler=closed");
|
|
}
|
|
}
|
|
|
|
public CompatibilityManager compatibility() {
|
|
return Objects.requireNonNull(compatibility, "Compatibility manager is not initialized");
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("info"))) {
|
|
sender.sendMessage(compatibility().info().summary());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|