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
|
--- a/net/minecraft/commands/arguments/EntityArgument.java
+++ b/net/minecraft/commands/arguments/EntityArgument.java
@@ -25,17 +25,14 @@
import net.minecraft.world.entity.Entity;
public class EntityArgument implements ArgumentType<EntitySelector> {
+
private static final Collection<String> EXAMPLES = Arrays.asList("Player", "0123", "@e", "@e[type=foo]", "dd12be42-52a9-4a91-a8a1-11c01849e498");
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_ENTITY = new SimpleCommandExceptionType(Component.translatable("argument.entity.toomany"));
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_PLAYER = new SimpleCommandExceptionType(Component.translatable("argument.player.toomany"));
- public static final SimpleCommandExceptionType ERROR_ONLY_PLAYERS_ALLOWED = new SimpleCommandExceptionType(
- Component.translatable("argument.player.entities")
- );
+ public static final SimpleCommandExceptionType ERROR_ONLY_PLAYERS_ALLOWED = new SimpleCommandExceptionType(Component.translatable("argument.player.entities"));
public static final SimpleCommandExceptionType NO_ENTITIES_FOUND = new SimpleCommandExceptionType(Component.translatable("argument.entity.notfound.entity"));
public static final SimpleCommandExceptionType NO_PLAYERS_FOUND = new SimpleCommandExceptionType(Component.translatable("argument.entity.notfound.player"));
- public static final SimpleCommandExceptionType ERROR_SELECTORS_NOT_ALLOWED = new SimpleCommandExceptionType(
- Component.translatable("argument.entity.selector.not_allowed")
- );
+ public static final SimpleCommandExceptionType ERROR_SELECTORS_NOT_ALLOWED = new SimpleCommandExceptionType(Component.translatable("argument.entity.selector.not_allowed"));
final boolean single;
final boolean playersOnly;
@@ -49,7 +46,7 @@
}
public static Entity getEntity(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- return context.getArgument(name, EntitySelector.class).findSingleEntity(context.getSource());
+ return ((EntitySelector) context.getArgument(name, EntitySelector.class)).findSingleEntity((CommandSourceStack) context.getSource());
}
public static EntityArgument entities() {
@@ -57,20 +54,21 @@
}
public static Collection<? extends Entity> getEntities(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- Collection<? extends Entity> optionalEntities = getOptionalEntities(context, name);
- if (optionalEntities.isEmpty()) {
- throw NO_ENTITIES_FOUND.create();
+ Collection<? extends Entity> collection = getOptionalEntities(context, name);
+
+ if (collection.isEmpty()) {
+ throw EntityArgument.NO_ENTITIES_FOUND.create();
} else {
- return optionalEntities;
+ return collection;
}
}
public static Collection<? extends Entity> getOptionalEntities(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- return context.getArgument(name, EntitySelector.class).findEntities(context.getSource());
+ return ((EntitySelector) context.getArgument(name, EntitySelector.class)).findEntities((CommandSourceStack) context.getSource());
}
public static Collection<ServerPlayer> getOptionalPlayers(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- return context.getArgument(name, EntitySelector.class).findPlayers(context.getSource());
+ return ((EntitySelector) context.getArgument(name, EntitySelector.class)).findPlayers((CommandSourceStack) context.getSource());
}
public static EntityArgument player() {
@@ -78,7 +76,7 @@
}
public static ServerPlayer getPlayer(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- return context.getArgument(name, EntitySelector.class).findSinglePlayer(context.getSource());
+ return ((EntitySelector) context.getArgument(name, EntitySelector.class)).findSinglePlayer((CommandSourceStack) context.getSource());
}
public static EntityArgument players() {
@@ -86,74 +84,83 @@
}
public static Collection<ServerPlayer> getPlayers(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
- List<ServerPlayer> list = context.getArgument(name, EntitySelector.class).findPlayers(context.getSource());
+ List<ServerPlayer> list = ((EntitySelector) context.getArgument(name, EntitySelector.class)).findPlayers((CommandSourceStack) context.getSource());
+
if (list.isEmpty()) {
- throw NO_PLAYERS_FOUND.create();
+ throw EntityArgument.NO_PLAYERS_FOUND.create();
} else {
return list;
}
}
- @Override
public EntitySelector parse(StringReader reader) throws CommandSyntaxException {
- int i = 0;
- EntitySelectorParser entitySelectorParser = new EntitySelectorParser(reader);
- EntitySelector entitySelector = entitySelectorParser.parse();
- if (entitySelector.getMaxResults() > 1 && this.single) {
+ // CraftBukkit start
+ return parse(reader, false);
+ }
+
+ public EntitySelector parse(StringReader stringreader, boolean overridePermissions) throws CommandSyntaxException {
+ // CraftBukkit end
+ boolean flag = false;
+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader);
+ EntitySelector entityselector = argumentparserselector.parse(overridePermissions); // CraftBukkit
+
+ if (entityselector.getMaxResults() > 1 && this.single) {
if (this.playersOnly) {
- reader.setCursor(0);
- throw ERROR_NOT_SINGLE_PLAYER.createWithContext(reader);
+ stringreader.setCursor(0);
+ throw EntityArgument.ERROR_NOT_SINGLE_PLAYER.createWithContext(stringreader);
} else {
- reader.setCursor(0);
- throw ERROR_NOT_SINGLE_ENTITY.createWithContext(reader);
+ stringreader.setCursor(0);
+ throw EntityArgument.ERROR_NOT_SINGLE_ENTITY.createWithContext(stringreader);
}
- } else if (entitySelector.includesEntities() && this.playersOnly && !entitySelector.isSelfSelector()) {
- reader.setCursor(0);
- throw ERROR_ONLY_PLAYERS_ALLOWED.createWithContext(reader);
+ } else if (entityselector.includesEntities() && this.playersOnly && !entityselector.isSelfSelector()) {
+ stringreader.setCursor(0);
+ throw EntityArgument.ERROR_ONLY_PLAYERS_ALLOWED.createWithContext(stringreader);
} else {
- return entitySelector;
+ return entityselector;
}
}
- @Override
- public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
- if (context.getSource() instanceof SharedSuggestionProvider sharedSuggestionProvider) {
- StringReader stringReader = new StringReader(builder.getInput());
- stringReader.setCursor(builder.getStart());
- EntitySelectorParser entitySelectorParser = new EntitySelectorParser(stringReader, sharedSuggestionProvider.hasPermission(2));
+ public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> commandcontext, SuggestionsBuilder suggestionsbuilder) {
+ Object object = commandcontext.getSource();
+ if (object instanceof SharedSuggestionProvider) {
+ SharedSuggestionProvider icompletionprovider = (SharedSuggestionProvider) object;
+ StringReader stringreader = new StringReader(suggestionsbuilder.getInput());
+
+ stringreader.setCursor(suggestionsbuilder.getStart());
+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, icompletionprovider.hasPermission(2));
+
try {
- entitySelectorParser.parse();
- } catch (CommandSyntaxException var7) {
+ argumentparserselector.parse();
+ } catch (CommandSyntaxException commandsyntaxexception) {
+ ;
}
- return entitySelectorParser.fillSuggestions(
- builder,
- offsetBuilder -> {
- Collection<String> onlinePlayerNames = sharedSuggestionProvider.getOnlinePlayerNames();
- Iterable<String> iterable = (Iterable<String>)(this.playersOnly
- ? onlinePlayerNames
- : Iterables.concat(onlinePlayerNames, sharedSuggestionProvider.getSelectedEntities()));
- SharedSuggestionProvider.suggest(iterable, offsetBuilder);
- }
- );
+ return argumentparserselector.fillSuggestions(suggestionsbuilder, (suggestionsbuilder1) -> {
+ Collection<String> collection = icompletionprovider.getOnlinePlayerNames();
+ Iterable<String> iterable = this.playersOnly ? collection : Iterables.concat(collection, icompletionprovider.getSelectedEntities());
+
+ SharedSuggestionProvider.suggest((Iterable) iterable, suggestionsbuilder1);
+ });
} else {
return Suggestions.empty();
}
}
- @Override
public Collection<String> getExamples() {
- return EXAMPLES;
+ return EntityArgument.EXAMPLES;
}
public static class Info implements ArgumentTypeInfo<EntityArgument, EntityArgument.Info.Template> {
+
private static final byte FLAG_SINGLE = 1;
private static final byte FLAG_PLAYERS_ONLY = 2;
- @Override
+ public Info() {}
+
public void serializeToNetwork(EntityArgument.Info.Template template, FriendlyByteBuf buffer) {
int i = 0;
+
if (template.single) {
i |= 1;
}
@@ -167,28 +174,28 @@
@Override
public EntityArgument.Info.Template deserializeFromNetwork(FriendlyByteBuf buffer) {
- byte _byte = buffer.readByte();
- return new EntityArgument.Info.Template((_byte & 1) != 0, (_byte & 2) != 0);
+ byte b0 = buffer.readByte();
+
+ return new EntityArgument.Info.Template((b0 & 1) != 0, (b0 & 2) != 0);
}
- @Override
public void serializeToJson(EntityArgument.Info.Template template, JsonObject json) {
json.addProperty("amount", template.single ? "single" : "multiple");
json.addProperty("type", template.playersOnly ? "players" : "entities");
}
- @Override
public EntityArgument.Info.Template unpack(EntityArgument argument) {
return new EntityArgument.Info.Template(argument.single, argument.playersOnly);
}
public final class Template implements ArgumentTypeInfo.Template<EntityArgument> {
+
final boolean single;
final boolean playersOnly;
- Template(boolean single, boolean playersOnly) {
- this.single = single;
- this.playersOnly = playersOnly;
+ Template(boolean flag, boolean flag1) {
+ this.single = flag;
+ this.playersOnly = flag1;
}
@Override
|