mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
73 lines
4.2 KiB
Diff
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 8c883ff13866d6416bd70cc61ab1e37dd1a5b33c..7bd3507837862b8afb8227a85a44c879692a9631 100644
|
|
--- a/net/minecraft/world/level/BaseCommandBlock.java
|
|
+++ b/net/minecraft/world/level/BaseCommandBlock.java
|
|
@@ -32,6 +32,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);
|
|
@@ -131,7 +135,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.DivineConfig.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");
|
|
@@ -151,6 +183,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;
|
|
}
|