From 1e5d655205bfcdd8e1dedff3f6918705dba1f6cb Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Mon, 2 Jun 2025 20:12:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4ignite=20mod=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/block/BukkitBlockManager.java | 65 +++++++------------ .../bukkit/plugin/BukkitCraftEngine.java | 33 ---------- .../bukkit/util/BukkitReflectionUtils.java | 3 - .../craftengine/core/plugin/CraftEngine.java | 1 - .../core/plugin/config/Config.java | 14 ---- 5 files changed, 22 insertions(+), 94 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java index ed6627210..62c17ccaa 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java @@ -31,7 +31,6 @@ import net.momirealms.craftengine.core.pack.LoadingSequence; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.pack.ResourceLocation; import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration; -import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.config.ConfigParser; import net.momirealms.craftengine.core.plugin.context.event.EventFunctions; @@ -93,10 +92,8 @@ public class BukkitBlockManager extends AbstractBlockManager { this.blockParser = new BlockParser(); this.initVanillaRegistry(); this.loadMappingsAndAdditionalBlocks(); - if (!plugin.requiresRestart()) { - this.registerBlocks(); - this.registerEmptyBlock(); - } + this.registerBlocks(); + this.registerEmptyBlock(); } @Override @@ -276,19 +273,7 @@ public class BukkitBlockManager extends AbstractBlockManager { } private void initVanillaRegistry() { - int vanillaStateCount; - if (this.plugin.hasMod()) { - try { - Class modClass = ReflectionUtils.getClazz(CraftEngine.MOD_CLASS); - Field amountField = ReflectionUtils.getDeclaredField(modClass, "vanillaRegistrySize"); - vanillaStateCount = amountField.getInt(null); - } catch (Exception e) { - vanillaStateCount = RegistryUtils.currentBlockRegistrySize(); - this.plugin.logger().severe("Fatal error", e); - } - } else { - vanillaStateCount = RegistryUtils.currentBlockRegistrySize(); - } + int vanillaStateCount = RegistryUtils.currentBlockRegistrySize(); this.plugin.logger().info("Vanilla block count: " + vanillaStateCount); BlockStateUtils.init(vanillaStateCount); } @@ -350,7 +335,7 @@ public class BukkitBlockManager extends AbstractBlockManager { } public class BlockParser implements ConfigParser { - public static final String[] CONFIG_SECTION_NAME = new String[] {"blocks", "block"}; + public static final String[] CONFIG_SECTION_NAME = new String[]{"blocks", "block"}; @Override public String[] sectionId() { @@ -512,10 +497,13 @@ public class BukkitBlockManager extends AbstractBlockManager { throw new LocalizedResourceConfigException("warning.config.block.state.model.invalid_path", modelPath); } json.addProperty("model", modelPath); - if (singleModelMap.containsKey("x")) json.addProperty("x", ResourceConfigUtils.getAsInt(singleModelMap.get("x"), "x")); - if (singleModelMap.containsKey("y")) json.addProperty("y", ResourceConfigUtils.getAsInt(singleModelMap.get("y"), "y")); + if (singleModelMap.containsKey("x")) + json.addProperty("x", ResourceConfigUtils.getAsInt(singleModelMap.get("x"), "x")); + if (singleModelMap.containsKey("y")) + json.addProperty("y", ResourceConfigUtils.getAsInt(singleModelMap.get("y"), "y")); if (singleModelMap.containsKey("uvlock")) json.addProperty("uvlock", (boolean) singleModelMap.get("uvlock")); - if (singleModelMap.containsKey("weight")) json.addProperty("weight", ResourceConfigUtils.getAsInt(singleModelMap.get("weight"), "weight")); + if (singleModelMap.containsKey("weight")) + json.addProperty("weight", ResourceConfigUtils.getAsInt(singleModelMap.get("weight"), "weight")); Map generationMap = MiscUtils.castToMap(singleModelMap.get("generation"), true); if (generationMap != null) { prepareModelGeneration(ModelGeneration.of(Key.of(modelPath), generationMap)); @@ -723,29 +711,20 @@ public class BukkitBlockManager extends AbstractBlockManager { Object blockHolder; Object resourceLocation = createResourceLocation(realBlockKey); - if (this.plugin.hasMod()) { - newRealBlock = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, resourceLocation); - newBlockState = getOnlyBlockState(newRealBlock); - - @SuppressWarnings("unchecked") - Optional optionalHolder = (Optional) CoreReflections.method$Registry$getHolder1.invoke(MBuiltInRegistries.BLOCK, CoreReflections.method$ResourceKey$create.invoke(null, MRegistries.instance$Registries$BLOCK, resourceLocation)); - blockHolder = optionalHolder.get(); - } else { - try { - newRealBlock = BlockGenerator.generateBlock(clientSideBlockType, clientSideBlock, blockProperties); - } catch (Throwable throwable) { - this.plugin.logger().warn("Failed to generate dynamic block class", throwable); - continue; - } - - blockHolder = CoreReflections.method$Registry$registerForHolder.invoke(null, MBuiltInRegistries.BLOCK, resourceLocation, newRealBlock); - CoreReflections.method$Holder$Reference$bindValue.invoke(blockHolder, newRealBlock); - CoreReflections.field$Holder$Reference$tags.set(blockHolder, Set.of()); - - newBlockState = getOnlyBlockState(newRealBlock); - CoreReflections.method$IdMapper$add.invoke(CoreReflections.instance$Block$BLOCK_STATE_REGISTRY, newBlockState); + try { + newRealBlock = BlockGenerator.generateBlock(clientSideBlockType, clientSideBlock, blockProperties); + } catch (Throwable throwable) { + this.plugin.logger().warn("Failed to generate dynamic block class", throwable); + continue; } + blockHolder = CoreReflections.method$Registry$registerForHolder.invoke(null, MBuiltInRegistries.BLOCK, resourceLocation, newRealBlock); + CoreReflections.method$Holder$Reference$bindValue.invoke(blockHolder, newRealBlock); + CoreReflections.field$Holder$Reference$tags.set(blockHolder, Set.of()); + + newBlockState = getOnlyBlockState(newRealBlock); + CoreReflections.method$IdMapper$add.invoke(CoreReflections.instance$Block$BLOCK_STATE_REGISTRY, newBlockState); + if (isNoteBlock) { BlockStateUtils.CLIENT_SIDE_NOTE_BLOCKS.put(newBlockState, new Object()); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java index b441b5ba1..d00647089 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java @@ -53,7 +53,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jspecify.annotations.Nullable; import java.io.*; -import java.lang.reflect.Field; import java.net.URL; import java.net.URLConnection; import java.nio.file.Path; @@ -68,8 +67,6 @@ public class BukkitCraftEngine extends CraftEngine { private SchedulerTask tickTask; private boolean successfullyLoaded = false; private boolean successfullyEnabled = false; - private boolean requiresRestart = false; - private boolean hasMod = false; private AntiGriefLib antiGrief; private JavaPlugin javaPlugin; private final Path dataFolderPath; @@ -90,16 +87,6 @@ public class BukkitCraftEngine extends CraftEngine { super.logger = logger; super.platform = new BukkitPlatform(); super.scheduler = new BukkitSchedulerAdapter(this); - // find mod class if present - Class modClass = ReflectionUtils.getClazz(MOD_CLASS); - if (modClass != null) { - Field isSuccessfullyRegistered = ReflectionUtils.getDeclaredField(modClass, "isSuccessfullyRegistered"); - try { - requiresRestart = !(boolean) isSuccessfullyRegistered.get(null); - hasMod = true; - } catch (Exception ignore) { - } - } Class compatibilityClass = Objects.requireNonNull(ReflectionUtils.getClazz(COMPATIBILITY_CLASS), "Compatibility class not found"); try { super.compatibilityManager = (CompatibilityManager) Objects.requireNonNull(ReflectionUtils.getConstructor(compatibilityClass, 0)).newInstance(this); @@ -132,7 +119,6 @@ public class BukkitCraftEngine extends CraftEngine { if (super.blockManager == null) { injectRegistries(); } - if (this.requiresRestart) return; try { WorldStorageInjector.init(); } catch (Exception e) { @@ -177,17 +163,6 @@ public class BukkitCraftEngine extends CraftEngine { return; } this.successfullyEnabled = true; - if (this.requiresRestart) { - logger().warn(" "); - logger().warn(" "); - logger().warn(" "); - logger().warn("This is the first time you have installed CraftEngine. A restart is required to apply the changes."); - logger().warn(" "); - logger().warn(" "); - logger().warn(" "); - Bukkit.getServer().shutdown(); - return; - } if (!this.successfullyLoaded) { logger().severe(" "); logger().severe(" "); @@ -390,14 +365,6 @@ public class BukkitCraftEngine extends CraftEngine { ); } - public boolean hasMod() { - return hasMod; - } - - public boolean requiresRestart() { - return requiresRestart; - } - public AntiGriefLib antiGrief() { if (this.antiGrief == null) { this.antiGrief = AntiGriefLib.builder(this.javaPlugin) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BukkitReflectionUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BukkitReflectionUtils.java index 2d3a32de5..b7d10e671 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BukkitReflectionUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BukkitReflectionUtils.java @@ -2,11 +2,8 @@ package net.momirealms.craftengine.bukkit.util; import net.momirealms.craftengine.core.util.ReflectionUtils; import net.momirealms.craftengine.core.util.VersionHelper; -import org.bukkit.Bukkit; -import java.lang.reflect.Method; import java.util.List; -import java.util.Objects; import java.util.function.Function; public final class BukkitReflectionUtils { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java index 39ede4ecb..04c267afc 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java @@ -43,7 +43,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; public abstract class CraftEngine implements Plugin { - public static final String MOD_CLASS = "net.momirealms.craftengine.mod.CraftEnginePlugin"; private static CraftEngine instance; protected PluginLogger logger; protected Consumer> debugger = (s) -> {}; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java index e33d35e57..b0aa4e218 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java @@ -22,7 +22,6 @@ import net.momirealms.craftengine.core.plugin.logger.filter.DisconnectLogFilter; import net.momirealms.craftengine.core.util.AdventureHelper; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; -import net.momirealms.craftengine.core.util.ReflectionUtils; import net.momirealms.craftengine.core.world.InjectionTarget; import net.momirealms.craftengine.core.world.chunk.storage.CompressionMethod; @@ -30,8 +29,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -341,17 +338,6 @@ public class Config { emoji$book = config.getBoolean("emoji.book", true); emoji$sign = config.getBoolean("emoji.sign", true); - Class modClazz = ReflectionUtils.getClazz(CraftEngine.MOD_CLASS); - if (modClazz != null) { - Method setMaxChainMethod = ReflectionUtils.getStaticMethod(modClazz, void.class, new String[] {"setMaxChainUpdate"}, int.class); - try { - assert setMaxChainMethod != null; - setMaxChainMethod.invoke(null, performance$max_block_chain_update_limit); - } catch (IllegalAccessException | InvocationTargetException e) { - plugin.logger().warn("Failed to set max chain update", e); - } - } - firstTime = false; }