9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-22 00:19:17 +00:00

增强访问权限管理

This commit is contained in:
XiaoMoMi
2025-06-01 23:31:45 +08:00
parent 68ee62ed5f
commit 3ece1a9bb4
4 changed files with 23 additions and 15 deletions

View File

@@ -9,7 +9,6 @@ public class BukkitCraftEnginePlugin extends JavaPlugin {
this.plugin = new BukkitCraftEngine(this); this.plugin = new BukkitCraftEngine(this);
this.plugin.applyDependencies(); this.plugin.applyDependencies();
this.plugin.setUpConfig(); this.plugin.setUpConfig();
this.plugin.injectRegistries();
} }
@Override @Override

View File

@@ -8,6 +8,7 @@ import net.momirealms.craftengine.bukkit.plugin.classpath.PaperClassPathAppender
import net.momirealms.craftengine.core.plugin.logger.PluginLogger; import net.momirealms.craftengine.core.plugin.logger.PluginLogger;
import net.momirealms.craftengine.core.plugin.logger.Slf4jPluginLogger; import net.momirealms.craftengine.core.plugin.logger.Slf4jPluginLogger;
import net.momirealms.craftengine.core.util.ReflectionUtils; import net.momirealms.craftengine.core.util.ReflectionUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -44,13 +45,15 @@ public class PaperCraftEngineBootstrap implements PluginBootstrap {
); );
this.plugin.applyDependencies(); this.plugin.applyDependencies();
this.plugin.setUpConfig(); this.plugin.setUpConfig();
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, (e) -> { if (VersionHelper.isOrAbove1_21_4()) {
try { context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, (e) -> {
this.plugin.injectRegistries(); try {
} catch (Throwable ex) { this.plugin.injectRegistries();
logger.warn("Failed to inject registries", ex); } catch (Throwable ex) {
} logger.warn("Failed to inject registries", ex);
}); }
});
}
} }
@Override @Override

View File

@@ -91,8 +91,10 @@ public class BukkitBlockManager extends AbstractBlockManager {
this.blockParser = new BlockParser(); this.blockParser = new BlockParser();
this.initVanillaRegistry(); this.initVanillaRegistry();
this.loadMappingsAndAdditionalBlocks(); this.loadMappingsAndAdditionalBlocks();
this.registerBlocks(); if (!plugin.requiresRestart()) {
this.registerEmptyBlock(); this.registerBlocks();
this.registerEmptyBlock();
}
} }
@Override @Override
@@ -718,7 +720,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
Object blockHolder; Object blockHolder;
Object resourceLocation = createResourceLocation(realBlockKey); Object resourceLocation = createResourceLocation(realBlockKey);
if (plugin.hasMod()) { if (this.plugin.hasMod()) {
newRealBlock = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, resourceLocation); newRealBlock = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, resourceLocation);
newBlockState = getOnlyBlockState(newRealBlock); newBlockState = getOnlyBlockState(newRealBlock);
@@ -729,7 +731,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
try { try {
newRealBlock = BlockGenerator.generateBlock(clientSideBlockType, clientSideBlock, blockProperties); newRealBlock = BlockGenerator.generateBlock(clientSideBlockType, clientSideBlock, blockProperties);
} catch (Throwable throwable) { } catch (Throwable throwable) {
plugin.logger().warn("Failed to generate dynamic block class", throwable); this.plugin.logger().warn("Failed to generate dynamic block class", throwable);
continue; continue;
} }

View File

@@ -74,12 +74,12 @@ public class BukkitCraftEngine extends CraftEngine {
private JavaPlugin javaPlugin; private JavaPlugin javaPlugin;
private final Path dataFolderPath; private final Path dataFolderPath;
public BukkitCraftEngine(JavaPlugin plugin) { protected BukkitCraftEngine(JavaPlugin plugin) {
this(new JavaPluginLogger(plugin.getLogger()), plugin.getDataFolder().toPath().toAbsolutePath(), new ReflectionClassPathAppender(plugin.getClass().getClassLoader())); this(new JavaPluginLogger(plugin.getLogger()), plugin.getDataFolder().toPath().toAbsolutePath(), new ReflectionClassPathAppender(plugin.getClass().getClassLoader()));
this.setJavaPlugin(plugin); this.setJavaPlugin(plugin);
} }
public BukkitCraftEngine(PluginLogger logger, Path dataFolderPath, ClassPathAppender classPathAppender) { protected BukkitCraftEngine(PluginLogger logger, Path dataFolderPath, ClassPathAppender classPathAppender) {
super((p) -> { super((p) -> {
CraftEngineReloadEvent event = new CraftEngineReloadEvent((BukkitCraftEngine) p); CraftEngineReloadEvent event = new CraftEngineReloadEvent((BukkitCraftEngine) p);
EventUtils.fireAndForget(event); EventUtils.fireAndForget(event);
@@ -128,6 +128,10 @@ public class BukkitCraftEngine extends CraftEngine {
@Override @Override
public void onPluginLoad() { public void onPluginLoad() {
if (super.blockManager == null) {
injectRegistries();
}
if (this.requiresRestart) return;
try { try {
WorldStorageInjector.init(); WorldStorageInjector.init();
} catch (Exception e) { } catch (Exception e) {
@@ -172,7 +176,7 @@ public class BukkitCraftEngine extends CraftEngine {
return; return;
} }
this.successfullyEnabled = true; this.successfullyEnabled = true;
if (this.hasMod && this.requiresRestart) { if (this.requiresRestart) {
logger().warn(" "); logger().warn(" ");
logger().warn(" "); logger().warn(" ");
logger().warn(" "); logger().warn(" ");