mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
Merge branch 'Xiao-MoMi:dev' into dev
This commit is contained in:
@@ -432,13 +432,13 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
|
||||
// give flags back on 1.21.2+
|
||||
if (VersionHelper.isVersionNewerThan1_21_2() && this.stolenFeatureFlagSet != null) {
|
||||
Reflections.field$RecipeManager$featureflagset.set(nmsRecipeManager, this.stolenFeatureFlagSet);
|
||||
this.stolenFeatureFlagSet = false;
|
||||
Reflections.field$RecipeManager$featureflagset.set(nmsRecipeManager(), this.stolenFeatureFlagSet);
|
||||
this.stolenFeatureFlagSet = null;
|
||||
}
|
||||
|
||||
// refresh recipes
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
Reflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager);
|
||||
Reflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager());
|
||||
}
|
||||
|
||||
// send to players
|
||||
|
||||
@@ -34,43 +34,64 @@ public class ReloadCommand extends BukkitCommandFeature<CommandSender> {
|
||||
argument = optional.get();
|
||||
}
|
||||
if (argument == ReloadArgument.CONFIG) {
|
||||
plugin().scheduler().executeAsync(() -> {
|
||||
try {
|
||||
RELOAD_PACK_FLAG = true;
|
||||
plugin().reload((a, b) -> handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_SUCCESS, Component.text(a + b), Component.text(a), Component.text(b)));
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_FAILURE);
|
||||
plugin().logger().warn("Failed to reload config", e);
|
||||
}
|
||||
});
|
||||
try {
|
||||
RELOAD_PACK_FLAG = true;
|
||||
plugin().reloadPlugin(plugin().scheduler().async(), r -> plugin().scheduler().sync().run(r), false).thenAccept(reloadResult -> {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_SUCCESS,
|
||||
Component.text(reloadResult.asyncTime() + reloadResult.syncTime()),
|
||||
Component.text(reloadResult.asyncTime()),
|
||||
Component.text(reloadResult.syncTime())
|
||||
);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_FAILURE);
|
||||
plugin().logger().warn("Failed to reload config", e);
|
||||
}
|
||||
} else if (argument == ReloadArgument.RECIPE) {
|
||||
try {
|
||||
RELOAD_PACK_FLAG = true;
|
||||
plugin().reloadPlugin(plugin().scheduler().async(), r -> plugin().scheduler().sync().run(r), true).thenAccept(reloadResult -> {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_SUCCESS,
|
||||
Component.text(reloadResult.asyncTime() + reloadResult.syncTime()),
|
||||
Component.text(reloadResult.asyncTime()),
|
||||
Component.text(reloadResult.syncTime())
|
||||
);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_CONFIG_FAILURE);
|
||||
plugin().logger().warn("Failed to reload config", e);
|
||||
}
|
||||
} else if (argument == ReloadArgument.PACK) {
|
||||
plugin().scheduler().executeAsync(() -> {
|
||||
try {
|
||||
long time1 = System.currentTimeMillis();
|
||||
plugin().packManager().generateResourcePack();
|
||||
long time2 = System.currentTimeMillis();
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_SUCCESS, Component.text(time2 - time1));
|
||||
long packTime = time2 - time1;
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_SUCCESS, Component.text(packTime));
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_PACK_FAILURE);
|
||||
plugin().logger().warn("Failed to generate resource pack", e);
|
||||
}
|
||||
});
|
||||
} else if (argument == ReloadArgument.ALL) {
|
||||
plugin().scheduler().executeAsync(() -> {
|
||||
plugin().reload((a, b) -> {
|
||||
plugin().scheduler().async().execute(() -> {
|
||||
try {
|
||||
long time1 = System.currentTimeMillis();
|
||||
plugin().packManager().generateResourcePack();
|
||||
long time2 = System.currentTimeMillis();
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_ALL_SUCCESS, Component.text(a + b + time2 - time1), Component.text(a), Component.text(b), Component.text(time2 - time1));
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_ALL_FAILURE);
|
||||
plugin().logger().warn("Failed to generate resource pack", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
try {
|
||||
plugin().reloadPlugin(plugin().scheduler().async(), r -> plugin().scheduler().sync().run(r), true).thenAcceptAsync(reloadResult -> {
|
||||
long time1 = System.currentTimeMillis();
|
||||
plugin().packManager().generateResourcePack();
|
||||
long time2 = System.currentTimeMillis();
|
||||
long packTime = time2 - time1;
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_ALL_SUCCESS,
|
||||
Component.text(reloadResult.asyncTime() + reloadResult.syncTime() + packTime),
|
||||
Component.text(reloadResult.asyncTime()),
|
||||
Component.text(reloadResult.syncTime()),
|
||||
Component.text(packTime)
|
||||
);
|
||||
}, plugin().scheduler().async());
|
||||
} catch (Exception e) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_RELOAD_ALL_FAILURE);
|
||||
plugin().logger().warn("Failed to generate resource pack", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -82,6 +103,7 @@ public class ReloadCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public enum ReloadArgument {
|
||||
CONFIG,
|
||||
RECIPE,
|
||||
PACK,
|
||||
ALL
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static net.momirealms.craftengine.core.util.MiscUtils.castToMap;
|
||||
|
||||
@@ -136,8 +137,6 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
this.loadPacks();
|
||||
this.loadConfigs();
|
||||
this.calculateHash();
|
||||
if (Config.hostMode() == HostMode.SELF_HOST) {
|
||||
Path path = Config.hostResourcePackPath().startsWith(".") ? plugin.dataFolderPath().resolve(Config.hostResourcePackPath()) : Path.of(Config.hostResourcePackPath());
|
||||
@@ -148,6 +147,12 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadResources(boolean recipe) {
|
||||
this.loadPacks();
|
||||
this.loadResourceConfigs(recipe ? (p) -> true : (p) -> p.loadingSequence() != LoadingSequence.RECIPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.loadedPacks.clear();
|
||||
@@ -372,7 +377,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/gui/sprites/tooltip/topaz_frame.png.mcmeta");
|
||||
}
|
||||
|
||||
private void loadConfigs() {
|
||||
private void loadResourceConfigs(Predicate<ConfigSectionParser> predicate) {
|
||||
long o1 = System.nanoTime();
|
||||
for (Pack pack : loadedPacks()) {
|
||||
Pair<List<Path>, List<Path>> files = FileUtils.getConfigsDeeply(pack.configurationFolder());
|
||||
@@ -412,7 +417,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
Key id = Key.withDefaultNamespace(key, cached.pack().namespace());
|
||||
if (parser.isTemplate()) {
|
||||
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
|
||||
} else {
|
||||
} else if (predicate.test(parser)) {
|
||||
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
|
||||
Map<String, Object> configSection1 = castToMap(configSection0, false);
|
||||
if ((boolean) configSection1.getOrDefault("enable", true)) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.Collection;
|
||||
|
||||
public interface PackManager extends Manageable {
|
||||
|
||||
void loadResources(boolean recipe);
|
||||
|
||||
@NotNull
|
||||
Collection<Pack> loadedPacks();
|
||||
|
||||
|
||||
@@ -138,11 +138,12 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.worldManager.reload();
|
||||
this.vanillaLootManager.reload();
|
||||
this.guiManager.reload();
|
||||
this.packManager.reload();
|
||||
if (reloadRecipe) {
|
||||
this.recipeManager.reload();
|
||||
}
|
||||
// now we load resources
|
||||
this.packManager.reload();
|
||||
this.packManager.loadResources(reloadRecipe);
|
||||
// handle some special client lang for instance block_name
|
||||
this.translationManager.delayedLoad();
|
||||
// init suggestions and packet mapper
|
||||
@@ -161,12 +162,13 @@ public abstract class CraftEngine implements Plugin {
|
||||
long asyncTime = time2 - time1;
|
||||
syncExecutor.execute(() -> {
|
||||
try {
|
||||
long time3 = System.currentTimeMillis();
|
||||
// register songs
|
||||
this.soundManager.runDelayedSyncTasks();
|
||||
// register recipes
|
||||
this.recipeManager.runDelayedSyncTasks();
|
||||
long time3 = System.currentTimeMillis();
|
||||
long syncTime = time3 - time2;
|
||||
long time4 = System.currentTimeMillis();
|
||||
long syncTime = time4 - time3;
|
||||
this.reloadEventDispatcher.accept(this);
|
||||
future.complete(ReloadResult.success(asyncTime, syncTime));
|
||||
} finally {
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.42
|
||||
project_version=0.0.43
|
||||
config_version=19
|
||||
lang_version=3
|
||||
project_group=net.momirealms
|
||||
@@ -40,7 +40,7 @@ geantyref_version=1.3.16
|
||||
zstd_version=1.5.7-2
|
||||
commons_io_version=2.18.0
|
||||
sparrow_nbt_version=0.3
|
||||
sparrow_util_version=0.35
|
||||
sparrow_util_version=0.36
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.119.Final
|
||||
joml_version=1.10.8
|
||||
|
||||
Reference in New Issue
Block a user