1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
--- a/net/minecraft/world/level/BaseCommandBlock.java
+++ b/net/minecraft/world/level/BaseCommandBlock.java
@@ -19,6 +19,7 @@
import net.minecraft.world.phys.Vec3;
public abstract class BaseCommandBlock implements CommandSource {
+
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
private static final Component DEFAULT_NAME = Component.literal("@");
private long lastExecution = -1L;
@@ -28,8 +29,16 @@
@Nullable
private Component lastOutput;
private String command = "";
- private Component name = DEFAULT_NAME;
+ private Component name;
+ // CraftBukkit start
+ @Override
+ public abstract org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper);
+ // CraftBukkit end
+ public BaseCommandBlock() {
+ this.name = BaseCommandBlock.DEFAULT_NAME;
+ }
+
public int getSuccessCount() {
return this.successCount;
}
@@ -73,8 +82,8 @@
if (nbt.contains("LastOutput", 8) && this.trackOutput) {
try {
this.lastOutput = Component.Serializer.fromJson(nbt.getString("LastOutput"));
- } catch (Throwable var3) {
- this.lastOutput = Component.literal(var3.getMessage());
+ } catch (Throwable throwable) {
+ this.lastOutput = Component.literal(throwable.getMessage());
}
} else {
this.lastOutput = null;
@@ -89,6 +98,7 @@
} else {
this.lastExecution = -1L;
}
+
}
public void setCommand(String command) {
@@ -101,40 +111,48 @@
}
public boolean performCommand(Level level) {
- if (level.isClientSide || level.getGameTime() == this.lastExecution) {
- return false;
- } else if ("Searge".equalsIgnoreCase(this.command)) {
- this.lastOutput = Component.literal("#itzlipofutzli");
- this.successCount = 1;
- return true;
- } else {
- this.successCount = 0;
- MinecraftServer server = this.getLevel().getServer();
- if (server.isCommandBlockEnabled() && !StringUtil.isNullOrEmpty(this.command)) {
- try {
- this.lastOutput = null;
- CommandSourceStack commandSourceStack = this.createCommandSourceStack().withCallback((flag, i) -> {
- if (flag) {
- this.successCount++;
- }
- });
- server.getCommands().performPrefixedCommand(commandSourceStack, this.command);
- } catch (Throwable var6) {
- CrashReport crashReport = CrashReport.forThrowable(var6, "Executing command block");
- CrashReportCategory crashReportCategory = crashReport.addCategory("Command to be executed");
- crashReportCategory.setDetail("Command", this::getCommand);
- crashReportCategory.setDetail("Name", () -> this.getName().getString());
- throw new ReportedException(crashReport);
+ if (!level.isClientSide && level.getGameTime() != this.lastExecution) {
+ if ("Searge".equalsIgnoreCase(this.command)) {
+ this.lastOutput = Component.literal("#itzlipofutzli");
+ this.successCount = 1;
+ return true;
+ } else {
+ this.successCount = 0;
+ MinecraftServer minecraftserver = this.getLevel().getServer();
+
+ if (minecraftserver.isCommandBlockEnabled() && !StringUtil.isNullOrEmpty(this.command)) {
+ try {
+ this.lastOutput = null;
+ CommandSourceStack commandlistenerwrapper = this.createCommandSourceStack().withCallback((flag, i) -> {
+ if (flag) {
+ ++this.successCount;
+ }
+
+ });
+
+ minecraftserver.getCommands().dispatchServerCommand(commandlistenerwrapper, this.command); // CraftBukkit
+ } catch (Throwable throwable) {
+ CrashReport crashreport = CrashReport.forThrowable(throwable, "Executing command block");
+ CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Command to be executed");
+
+ crashreportsystemdetails.setDetail("Command", this::getCommand);
+ crashreportsystemdetails.setDetail("Name", () -> {
+ return this.getName().getString();
+ });
+ throw new ReportedException(crashreport);
+ }
}
- }
- if (this.updateLastExecution) {
- this.lastExecution = level.getGameTime();
- } else {
- this.lastExecution = -1L;
- }
+ if (this.updateLastExecution) {
+ this.lastExecution = level.getGameTime();
+ } else {
+ this.lastExecution = -1L;
+ }
- return true;
+ return true;
+ }
+ } else {
+ return false;
}
}
@@ -146,16 +164,21 @@
if (name != null) {
this.name = name;
} else {
- this.name = DEFAULT_NAME;
+ this.name = BaseCommandBlock.DEFAULT_NAME;
}
+
}
@Override
public void sendSystemMessage(Component component) {
if (this.trackOutput) {
- this.lastOutput = Component.literal("[" + TIME_FORMAT.format(new Date()) + "] ").append(component);
+ SimpleDateFormat simpledateformat = BaseCommandBlock.TIME_FORMAT;
+ Date date = new Date();
+
+ this.lastOutput = Component.literal("[" + simpledateformat.format(date) + "] ").append(component);
this.onUpdated();
}
+
}
public abstract ServerLevel getLevel();
|