9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 18:09:17 +00:00

Add config post load & Fix

This commit is contained in:
Dreeam
2025-03-17 23:07:42 -04:00
parent 7d6a28c96e
commit e77896f346
6 changed files with 31 additions and 15 deletions

View File

@@ -11,10 +11,10 @@ Add per world config
Add config reload
diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java
index 9aa664537cc37e44db46d5a2a64ae3116938c681..43842de34adda95e78025c2b00639b31b774a78b 100644
index 9aa664537cc37e44db46d5a2a64ae3116938c681..344d5ead46c33e303ac375922aad298481253ff2 100644
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -108,6 +108,7 @@ public class Main {
@@ -108,10 +108,12 @@ public class Main {
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
@@ -22,6 +22,11 @@ index 9aa664537cc37e44db46d5a2a64ae3116938c681..43842de34adda95e78025c2b00639b31
io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
+ org.dreeam.leaf.config.ConfigModules.loadAfterBootstrap(); // Leaf - Leaf config - post load
Path path1 = Paths.get("server.properties");
DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support
dedicatedServerSettings.forceSave();
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index f33fb9b30863dd8ff7207db905fcfb7547b09383..4ba85d704ffebae38f7a76a97a182e3674730c6f 100644
--- a/net/minecraft/server/MinecraftServer.java

View File

@@ -53,7 +53,7 @@ index f89d28595fa9ca12e414f7b3cc86085ff0769e72..29fd9cea422e1ee09f6983a9b72847fb
} else {
getBukkitEntity().setPlayerListName(prefix + scoreboardName + suffix, true);
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index f10946b641e0af144ca653850c5d5292c0095412..a069760d916da9dd9efa99fd01b41e5dfe88acf3 100644
index f10946b641e0af144ca653850c5d5292c0095412..90535f96479c936c516949ffc5def9e63b0daa95 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2272,6 +2272,7 @@ public class ServerGamePacketListenerImpl
@@ -110,14 +110,14 @@ index f10946b641e0af144ca653850c5d5292c0095412..a069760d916da9dd9efa99fd01b41e5d
this.player.resetLastActionTime();
// CraftBukkit start
if (sync) {
@@ -2443,6 +2450,46 @@ public class ServerGamePacketListenerImpl
@@ -2443,6 +2450,40 @@ public class ServerGamePacketListenerImpl
}
}
+ // Leaf start - Improve Purpur AFK system
+ public static final Map<java.util.UUID, Long> afkCooldown = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
+ private boolean performAfkCooldown(String command) {
+ if (!"afk".equals(command)) {
+ if (!org.dreeam.leaf.config.modules.gameplay.AfkCommand.enabled || !"afk".equals(command)) {
+ return false;
+ }
+
@@ -132,13 +132,7 @@ index f10946b641e0af144ca653850c5d5292c0095412..a069760d916da9dd9efa99fd01b41e5d
+ Long cooldown = afkCooldown.get(uuid);
+ long currentTime = System.nanoTime();
+
+ boolean ifnull = cooldown != null;
+ System.out.println(ifnull);
+ if (ifnull) {
+ System.out.println((currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown);
+ System.out.println((currentTime - cooldown) / 1_000_000_000);
+ }
+ if (ifnull && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) {
+ if (cooldown != null && (currentTime - cooldown) / 1_000_000_000 <= org.purpurmc.purpur.PurpurConfig.afkCommandCooldown) {
+ String msg = org.purpurmc.purpur.PurpurConfig.afkCooldown;
+
+ if (msg != null && !msg.isEmpty()) {

View File

@@ -42,6 +42,12 @@ public abstract class ConfigModules extends LeafConfig {
}
}
public static void loadAfterBootstrap() {
for (ConfigModules module : MODULES) {
module.onPostLoaded();
}
}
private static List<Field> getAnnotatedStaticFields(Class<?> clazz, Class<? extends Annotation> annotation) {
List<Field> fields = new ArrayList<>();
@@ -60,4 +66,7 @@ public abstract class ConfigModules extends LeafConfig {
}
public abstract void onLoaded();
public void onPostLoaded() {
}
}

View File

@@ -65,6 +65,7 @@ public class LeafConfig {
ConfigModules.clearModules();
loadConfig(false);
ConfigModules.loadAfterBootstrap();
final String success = String.format("Successfully reloaded config in %sms.", (System.nanoTime() - begin) / 1_000_000);
Command.broadcastCommandMessage(sender, Component.text(success, NamedTextColor.GREEN));

View File

@@ -23,6 +23,7 @@ public class HideItemComponent extends ConfigModules {
}
public static boolean enabled = false;
public static List<String> hiddenTypeStrings = new ArrayList<>();
public static List<DataComponentType<?>> hiddenTypes = List.of();
@Override
@@ -37,7 +38,7 @@ public class HideItemComponent extends ConfigModules {
可能会导致依赖物品组件的资源包/模组无法正常工作.
可以避免一些客户端动画效果.
注意: 此项与 Paper 的 item-obfuscation 不同, 我们只从玩家背包中隐藏物品指定的组件信息.""");
List<String> list = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
hiddenTypeStrings = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
Which type of components will be hidden from clients.
It needs a component type list, incorrect things will not work.""",
"""
@@ -47,10 +48,13 @@ public class HideItemComponent extends ConfigModules {
"If enabled, specified item component information from player's inventory will be hided.",
"启用后, 玩家背包内物品的指定组件信息会被隐藏."
));
}
final List<DataComponentType<?>> types = new ArrayList<>(list.size());
@Override
public void onPostLoaded() {
final List<DataComponentType<?>> types = new ArrayList<>(hiddenTypeStrings.size());
for (String componentType : list) {
for (String componentType : hiddenTypeStrings) {
BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(componentType)).ifPresentOrElse(
optional -> types.add(optional.value()),
() -> LeafConfig.LOGGER.warn("Unknown component type: {}", componentType)

View File

@@ -60,7 +60,10 @@ public class DynamicActivationofBrain extends ConfigModules {
"不会被 DAB 影响的实体列表"));
startDistanceSquared = startDistance * startDistance;
}
@Override
public void onPostLoaded() {
for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
entityType.dabEnabled = true; // reset all, before setting the ones to true
}