9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0032-Command-block-parse-results-caching.patch
Artem Ostrasev 109c57a637 1.21.6 (#25)
* start 1.21.6 update

* change workflow

* apply some patches

* set experimental to true

* some compile fixes

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@5d3463aa Updated Upstream (Paper)

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@5d3463aa Updated Upstream (Paper)

* remove data converter for 1.21.6; move clumps to unapplied

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

* Update upstream

* Update upstream

* update to 1.21.6-pre4

* update patches

* fix compile

* set readme version to 1.21.6

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@439f15db Updated Upstream (Paper)
PurpurMC/Purpur@46a28b93 [ci/skip] update version in README
2025-06-18 17:36:28 +03:00

73 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 15 Mar 2025 22:01:08 +0300
Subject: [PATCH] Command block parse results caching
diff --git a/net/minecraft/world/level/BaseCommandBlock.java b/net/minecraft/world/level/BaseCommandBlock.java
index d823f95a823f599db2c80f888e4b1a411fa4d3aa..6438b98628bb8eaa1e57276de2bc6b8741731eab 100644
--- a/net/minecraft/world/level/BaseCommandBlock.java
+++ b/net/minecraft/world/level/BaseCommandBlock.java
@@ -34,6 +34,10 @@ public abstract class BaseCommandBlock implements CommandSource {
private String command = "";
@Nullable
private Component customName;
+ // DivineMC start - Caching command block parse results
+ private String lastExecutedCommand;
+ private com.mojang.brigadier.ParseResults<CommandSourceStack> parseResultsCache;
+ // DivineMC end - Caching command block parse results
// CraftBukkit start
@Override
public abstract org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper);
@@ -113,7 +117,35 @@ public abstract class BaseCommandBlock implements CommandSource {
this.successCount++;
}
});
- server.getCommands().dispatchServerCommand(commandSourceStack, this.command); // CraftBukkit
+ // DivineMC start - Command block parse results caching
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.commandBlockParseResultsCaching) {
+ String commandCache = this.command;
+ // noinspection DuplicatedCode
+ com.google.common.base.Joiner joiner = com.google.common.base.Joiner.on(" ");
+
+ if (commandCache.startsWith("/")) {
+ commandCache = commandCache.substring(1);
+ }
+
+ org.bukkit.event.server.ServerCommandEvent event = new org.bukkit.event.server.ServerCommandEvent(commandSourceStack.getBukkitSender(), commandCache);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ commandCache = event.getCommand();
+ String[] args = commandCache.split(" ");
+
+ if (args.length != 0) {
+ String newCommand = joiner.join(args);
+ if (!newCommand.equals(lastExecutedCommand) || parseResultsCache == null) {
+ MinecraftServer.LOGGER.info("Recompiling parse results cache for command block at ({}, {}, {})", this.getPosition().x, this.getPosition().y, this.getPosition().z);
+ this.cache(server.getCommands().getDispatcher(), commandSourceStack, newCommand);
+ }
+ server.getCommands().performCommand(parseResultsCache, newCommand);
+ }
+ }
+ } else {
+ server.getCommands().dispatchServerCommand(commandSourceStack, this.command); // CraftBukkit
+ }
+ // DivineMC end - Command block parse results caching
} catch (Throwable var6) {
CrashReport crashReport = CrashReport.forThrowable(var6, "Executing command block");
CrashReportCategory crashReportCategory = crashReport.addCategory("Command to be executed");
@@ -133,6 +165,13 @@ public abstract class BaseCommandBlock implements CommandSource {
}
}
+ // DivineMC start - Command block parse results caching
+ private void cache(com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher, CommandSourceStack commandSourceStack, String commandCache) {
+ this.parseResultsCache = dispatcher.parse(commandCache, commandSourceStack);
+ this.lastExecutedCommand = commandCache;
+ }
+ // DivineMC end - Command block parse results caching
+
public Component getName() {
return this.customName != null ? this.customName : DEFAULT_NAME;
}