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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
--- a/net/minecraft/commands/CommandSourceStack.java
+++ b/net/minecraft/commands/CommandSourceStack.java
@@ -1,7 +1,6 @@
package net.minecraft.commands;
import com.google.common.collect.Lists;
-import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandExceptionType;
@@ -44,12 +43,13 @@
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
+import com.mojang.brigadier.tree.CommandNode; // CraftBukkit
public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider {
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player"));
public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity"));
- private final CommandSource source;
+ public final CommandSource source;
private final Vec3 worldPosition;
private final ServerLevel level;
private final int permissionLevel;
@@ -64,46 +64,46 @@
private final Vec2 rotation;
private final CommandSigningContext signingContext;
private final TaskChainer chatMessageChainer;
+ public volatile CommandNode currentCommand; // CraftBukkit
- public CommandSourceStack(CommandSource commandsource, Vec3 vec3, Vec2 vec2, ServerLevel serverlevel, int i, String s, Component component, MinecraftServer minecraftserver, @Nullable Entity entity) {
- this(commandsource, vec3, vec2, serverlevel, i, s, component, minecraftserver, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(minecraftserver));
+ public CommandSourceStack(CommandSource source, Vec3 worldPosition, Vec2 rotation, ServerLevel level, int permissionLevel, String textName, Component displayName, MinecraftServer server, @Nullable Entity entity) {
+ this(source, worldPosition, rotation, level, permissionLevel, textName, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
}
- protected CommandSourceStack(CommandSource commandsource, Vec3 vec3, Vec2 vec2, ServerLevel serverlevel, int i, String s, Component component, MinecraftServer minecraftserver, @Nullable Entity entity, boolean flag, CommandResultCallback commandresultcallback, EntityAnchorArgument.Anchor entityanchorargument_anchor, CommandSigningContext commandsigningcontext, TaskChainer taskchainer) {
- this.source = commandsource;
- this.worldPosition = vec3;
- this.level = serverlevel;
+ protected CommandSourceStack(CommandSource icommandlistener, Vec3 vec3d, Vec2 vec2f, ServerLevel worldserver, int i, String s, Component ichatbasecomponent, MinecraftServer minecraftserver, @Nullable Entity entity, boolean flag, CommandResultCallback commandresultcallback, EntityAnchorArgument.Anchor argumentanchor_anchor, CommandSigningContext commandsigningcontext, TaskChainer taskchainer) {
+ this.source = icommandlistener;
+ this.worldPosition = vec3d;
+ this.level = worldserver;
this.silent = flag;
this.entity = entity;
this.permissionLevel = i;
this.textName = s;
- this.displayName = component;
+ this.displayName = ichatbasecomponent;
this.server = minecraftserver;
this.resultCallback = commandresultcallback;
- this.anchor = entityanchorargument_anchor;
- this.rotation = vec2;
+ this.anchor = argumentanchor_anchor;
+ this.rotation = vec2f;
this.signingContext = commandsigningcontext;
this.chatMessageChainer = taskchainer;
}
- public CommandSourceStack withSource(CommandSource commandsource) {
- return this.source == commandsource ? this : new CommandSourceStack(commandsource, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withSource(CommandSource source) {
+ return this.source == source ? this : new CommandSourceStack(source, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
public CommandSourceStack withEntity(Entity entity) {
return this.entity == entity ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, this.permissionLevel, entity.getName().getString(), entity.getDisplayName(), this.server, entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
- public CommandSourceStack withPosition(Vec3 vec3) {
- return this.worldPosition.equals(vec3) ? this : new CommandSourceStack(this.source, vec3, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withPosition(Vec3 pos) {
+ return this.worldPosition.equals(pos) ? this : new CommandSourceStack(this.source, pos, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
- public CommandSourceStack withRotation(Vec2 vec2) {
- return this.rotation.equals(vec2) ? this : new CommandSourceStack(this.source, this.worldPosition, vec2, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withRotation(Vec2 rotation) {
+ return this.rotation.equals(rotation) ? this : new CommandSourceStack(this.source, this.worldPosition, rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
@Override
- @Override
public CommandSourceStack withCallback(CommandResultCallback commandresultcallback) {
return Objects.equals(this.resultCallback, commandresultcallback) ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, commandresultcallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
@@ -118,38 +118,38 @@
return !this.silent && !this.source.alwaysAccepts() ? new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, true, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer) : this;
}
- public CommandSourceStack withPermission(int i) {
- return i == this.permissionLevel ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, i, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withPermission(int permissionLevel) {
+ return permissionLevel == this.permissionLevel ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
- public CommandSourceStack withMaximumPermission(int i) {
- return i <= this.permissionLevel ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, i, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withMaximumPermission(int permissionLevel) {
+ return permissionLevel <= this.permissionLevel ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
- public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor entityanchorargument_anchor) {
- return entityanchorargument_anchor == this.anchor ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, entityanchorargument_anchor, this.signingContext, this.chatMessageChainer);
+ public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor anchor) {
+ return anchor == this.anchor ? this : new CommandSourceStack(this.source, this.worldPosition, this.rotation, this.level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, anchor, this.signingContext, this.chatMessageChainer);
}
- public CommandSourceStack withLevel(ServerLevel serverlevel) {
- if (serverlevel == this.level) {
+ public CommandSourceStack withLevel(ServerLevel level) {
+ if (level == this.level) {
return this;
} else {
- double d0 = DimensionType.getTeleportationScale(this.level.dimensionType(), serverlevel.dimensionType());
- Vec3 vec3 = new Vec3(this.worldPosition.x * d0, this.worldPosition.y, this.worldPosition.z * d0);
+ double d0 = DimensionType.getTeleportationScale(this.level.dimensionType(), level.dimensionType());
+ Vec3 vec3d = new Vec3(this.worldPosition.x * d0, this.worldPosition.y, this.worldPosition.z * d0);
- return new CommandSourceStack(this.source, vec3, this.rotation, serverlevel, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
+ return new CommandSourceStack(this.source, vec3d, this.rotation, level, this.permissionLevel, this.textName, this.displayName, this.server, this.entity, this.silent, this.resultCallback, this.anchor, this.signingContext, this.chatMessageChainer);
}
}
- public CommandSourceStack facing(Entity entity, EntityAnchorArgument.Anchor entityanchorargument_anchor) {
- return this.facing(entityanchorargument_anchor.apply(entity));
+ public CommandSourceStack facing(Entity entity, EntityAnchorArgument.Anchor anchor) {
+ return this.facing(anchor.apply(entity));
}
- public CommandSourceStack facing(Vec3 vec3) {
- Vec3 vec31 = this.anchor.apply(this);
- double d0 = vec3.x - vec31.x;
- double d1 = vec3.y - vec31.y;
- double d2 = vec3.z - vec31.z;
+ public CommandSourceStack facing(Vec3 lookPos) {
+ Vec3 vec3d1 = this.anchor.apply(this);
+ double d0 = lookPos.x - vec3d1.x;
+ double d1 = lookPos.y - vec3d1.y;
+ double d2 = lookPos.z - vec3d1.z;
double d3 = Math.sqrt(d0 * d0 + d2 * d2);
float f = Mth.wrapDegrees((float) (-(Mth.atan2(d1, d3) * 57.2957763671875D)));
float f1 = Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875D) - 90.0F);
@@ -170,11 +170,24 @@
}
@Override
- @Override
- public boolean hasPermission(int i) {
- return this.permissionLevel >= i;
+ public boolean hasPermission(int level) {
+ // CraftBukkit start
+ CommandNode currentCommand = this.currentCommand;
+ if (currentCommand != null) {
+ return hasPermission(level, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
+ }
+ // CraftBukkit end
+
+ return this.permissionLevel >= level;
}
+ // CraftBukkit start
+ public boolean hasPermission(int i, String bukkitPermission) {
+ // World is null when loading functions
+ return ((getLevel() == null || !getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || getBukkitSender().hasPermission(bukkitPermission);
+ }
+ // CraftBukkit end
+
public Vec3 getPosition() {
return this.worldPosition;
}
@@ -200,9 +213,9 @@
Entity entity = this.entity;
if (entity instanceof ServerPlayer) {
- ServerPlayer serverplayer = (ServerPlayer) entity;
+ ServerPlayer entityplayer = (ServerPlayer) entity;
- return serverplayer;
+ return entityplayer;
} else {
throw CommandSourceStack.ERROR_NOT_PLAYER.create();
}
@@ -211,17 +224,17 @@
@Nullable
public ServerPlayer getPlayer() {
Entity entity = this.entity;
- ServerPlayer serverplayer;
+ ServerPlayer entityplayer;
if (entity instanceof ServerPlayer) {
- ServerPlayer serverplayer1 = (ServerPlayer) entity;
+ ServerPlayer entityplayer1 = (ServerPlayer) entity;
- serverplayer = serverplayer1;
+ entityplayer = entityplayer1;
} else {
- serverplayer = null;
+ entityplayer = null;
}
- return serverplayer;
+ return entityplayer;
}
public boolean isPlayer() {
@@ -248,155 +261,143 @@
return this.chatMessageChainer;
}
- public boolean shouldFilterMessageTo(ServerPlayer serverplayer) {
- ServerPlayer serverplayer1 = this.getPlayer();
+ public boolean shouldFilterMessageTo(ServerPlayer receiver) {
+ ServerPlayer entityplayer1 = this.getPlayer();
- return serverplayer == serverplayer1 ? false : serverplayer1 != null && serverplayer1.isTextFilteringEnabled() || serverplayer.isTextFilteringEnabled();
+ return receiver == entityplayer1 ? false : entityplayer1 != null && entityplayer1.isTextFilteringEnabled() || receiver.isTextFilteringEnabled();
}
- public void sendChatMessage(OutgoingChatMessage outgoingchatmessage, boolean flag, ChatType.Bound chattype_bound) {
+ public void sendChatMessage(OutgoingChatMessage message, boolean shouldFilter, ChatType.Bound boundChatType) {
if (!this.silent) {
- ServerPlayer serverplayer = this.getPlayer();
+ ServerPlayer entityplayer = this.getPlayer();
- if (serverplayer != null) {
- serverplayer.sendChatMessage(outgoingchatmessage, flag, chattype_bound);
+ if (entityplayer != null) {
+ entityplayer.sendChatMessage(message, shouldFilter, boundChatType);
} else {
- this.source.sendSystemMessage(chattype_bound.decorate(outgoingchatmessage.content()));
+ this.source.sendSystemMessage(boundChatType.decorate(message.content()));
}
}
}
- public void sendSystemMessage(Component component) {
+ public void sendSystemMessage(Component message) {
if (!this.silent) {
- ServerPlayer serverplayer = this.getPlayer();
+ ServerPlayer entityplayer = this.getPlayer();
- if (serverplayer != null) {
- serverplayer.sendSystemMessage(component);
+ if (entityplayer != null) {
+ entityplayer.sendSystemMessage(message);
} else {
- this.source.sendSystemMessage(component);
+ this.source.sendSystemMessage(message);
}
}
}
- public void sendSuccess(Supplier<Component> supplier, boolean flag) {
+ public void sendSuccess(Supplier<Component> messageSupplier, boolean allowLogging) {
boolean flag1 = this.source.acceptsSuccess() && !this.silent;
- boolean flag2 = flag && this.source.shouldInformAdmins() && !this.silent;
+ boolean flag2 = allowLogging && this.source.shouldInformAdmins() && !this.silent;
if (flag1 || flag2) {
- Component component = (Component) supplier.get();
+ Component ichatbasecomponent = (Component) messageSupplier.get();
if (flag1) {
- this.source.sendSystemMessage(component);
+ this.source.sendSystemMessage(ichatbasecomponent);
}
if (flag2) {
- this.broadcastToAdmins(component);
+ this.broadcastToAdmins(ichatbasecomponent);
}
}
}
- private void broadcastToAdmins(Component component) {
- MutableComponent mutablecomponent = Component.translatable("chat.type.admin", this.getDisplayName(), component).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC);
+ private void broadcastToAdmins(Component message) {
+ MutableComponent ichatmutablecomponent = Component.translatable("chat.type.admin", this.getDisplayName(), message).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC);
if (this.server.getGameRules().getBoolean(GameRules.RULE_SENDCOMMANDFEEDBACK)) {
Iterator iterator = this.server.getPlayerList().getPlayers().iterator();
while (iterator.hasNext()) {
- ServerPlayer serverplayer = (ServerPlayer) iterator.next();
+ ServerPlayer entityplayer = (ServerPlayer) iterator.next();
- if (serverplayer != this.source && this.server.getPlayerList().isOp(serverplayer.getGameProfile())) {
- serverplayer.sendSystemMessage(mutablecomponent);
+ if (entityplayer != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit
+ entityplayer.sendSystemMessage(ichatmutablecomponent);
}
}
}
if (this.source != this.server && this.server.getGameRules().getBoolean(GameRules.RULE_LOGADMINCOMMANDS)) {
- this.server.sendSystemMessage(mutablecomponent);
+ this.server.sendSystemMessage(ichatmutablecomponent);
}
}
- public void sendFailure(Component component) {
+ public void sendFailure(Component message) {
if (this.source.acceptsFailure() && !this.silent) {
- this.source.sendSystemMessage(Component.empty().append(component).withStyle(ChatFormatting.RED));
+ this.source.sendSystemMessage(Component.empty().append(message).withStyle(ChatFormatting.RED));
}
}
@Override
- @Override
public CommandResultCallback callback() {
return this.resultCallback;
}
@Override
- @Override
public Collection<String> getOnlinePlayerNames() {
return Lists.newArrayList(this.server.getPlayerNames());
}
@Override
- @Override
public Collection<String> getAllTeams() {
return this.server.getScoreboard().getTeamNames();
}
@Override
- @Override
public Stream<ResourceLocation> getAvailableSounds() {
return BuiltInRegistries.SOUND_EVENT.stream().map(SoundEvent::getLocation);
}
@Override
- @Override
public Stream<ResourceLocation> getRecipeNames() {
return this.server.getRecipeManager().getRecipeIds();
}
@Override
- @Override
- public CompletableFuture<Suggestions> customSuggestion(CommandContext<?> commandcontext) {
+ public CompletableFuture<Suggestions> customSuggestion(CommandContext<?> context) {
return Suggestions.empty();
}
@Override
- @Override
- public CompletableFuture<Suggestions> suggestRegistryElements(ResourceKey<? extends Registry<?>> resourcekey, SharedSuggestionProvider.ElementSuggestionType sharedsuggestionprovider_elementsuggestiontype, SuggestionsBuilder suggestionsbuilder, CommandContext<?> commandcontext) {
- return (CompletableFuture) this.registryAccess().registry(resourcekey).map((registry) -> {
- this.suggestRegistryElements(registry, sharedsuggestionprovider_elementsuggestiontype, suggestionsbuilder);
- return suggestionsbuilder.buildFuture();
+ public CompletableFuture<Suggestions> suggestRegistryElements(ResourceKey<? extends Registry<?>> resourceKey, SharedSuggestionProvider.a registryKey, SuggestionsBuilder builder, CommandContext<?> context) {
+ return (CompletableFuture) this.registryAccess().registry(resourceKey).map((iregistry) -> {
+ this.suggestRegistryElements(iregistry, registryKey, builder);
+ return builder.buildFuture();
}).orElseGet(Suggestions::empty);
}
@Override
- @Override
public Set<ResourceKey<Level>> levels() {
return this.server.levelKeys();
}
@Override
- @Override
public RegistryAccess registryAccess() {
return this.server.registryAccess();
}
@Override
- @Override
public FeatureFlagSet enabledFeatures() {
return this.level.enabledFeatures();
}
@Override
- @Override
- public CommandDispatcher<CommandSourceStack> dispatcher() {
+ public com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher() {
return this.getServer().getFunctions().getDispatcher();
}
@Override
- @Override
public void handleError(CommandExceptionType commandexceptiontype, Message message, boolean flag, @Nullable TraceCallbacks tracecallbacks) {
if (tracecallbacks != null) {
tracecallbacks.onError(message.getString());
@@ -409,8 +410,13 @@
}
@Override
- @Override
public boolean isSilent() {
return this.silent;
}
+
+ // CraftBukkit start
+ public org.bukkit.command.CommandSender getBukkitSender() {
+ return source.getBukkitSender(this);
+ }
+ // CraftBukkit end
}
|