3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 04:20:08 +01:00

SPIGOT-4193: API for selecting entities by strings

Dieser Commit ist enthalten in:
md_5 2019-01-31 15:08:25 +11:00
Ursprung ed274c517f
Commit ad6070dffd
5 geänderte Dateien mit 105 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,19 @@
--- a/net/minecraft/server/ArgumentEntity.java
+++ b/net/minecraft/server/ArgumentEntity.java
@@ -84,9 +84,15 @@
}
public EntitySelector parse(StringReader stringreader) throws CommandSyntaxException {
+ // CraftBukkit start
+ return parse(stringreader, false);
+ }
+
+ public EntitySelector parse(StringReader stringreader, boolean overridePermissions) throws CommandSyntaxException {
+ // CraftBukkit end
boolean flag = false;
ArgumentParserSelector argumentparserselector = new ArgumentParserSelector(stringreader);
- EntitySelector entityselector = argumentparserselector.s();
+ EntitySelector entityselector = argumentparserselector.s(overridePermissions); // CraftBukkit
if (entityselector.a() > 1 && this.h) {
if (this.i) {

Datei anzeigen

@ -0,0 +1,63 @@
--- a/net/minecraft/server/ArgumentParserSelector.java
+++ b/net/minecraft/server/ArgumentParserSelector.java
@@ -98,8 +98,14 @@
}
public ArgumentParserSelector(StringReader stringreader, boolean flag) {
- this.q = CriterionConditionValue.c.e;
- this.r = CriterionConditionValue.d.e;
+ // CraftBukkit start - decompile error
+ try {
+ this.q = (CriterionConditionValue.c) Class.forName("net.minecraft.server.CriterionConditionValue$c").getDeclaredField("e").get(null);
+ this.r = (CriterionConditionValue.d) Class.forName("net.minecraft.server.CriterionConditionValue$d").getDeclaredField("e").get(null);
+ } catch (Exception ex) {
+ throw new AssertionError(ex);
+ }
+ // CraftBukkit end
this.y = CriterionConditionRange.a;
this.z = CriterionConditionRange.a;
this.A = (entity) -> {
@@ -126,7 +132,7 @@
axisalignedbb = this.a(this.v == null ? 0.0D : this.v, this.w == null ? 0.0D : this.w, this.x == null ? 0.0D : this.x);
}
- Function function;
+ Function<Vec3D, Vec3D> function; // CraftBukkit - decompile error
if (this.s == null && this.t == null && this.u == null) {
function = (vec3d) -> {
@@ -187,8 +193,10 @@
};
}
- protected void b() throws CommandSyntaxException {
- this.T = true;
+ // CraftBukkit start
+ protected void b(boolean overridePermissions) throws CommandSyntaxException {
+ this.T = !overridePermissions;
+ // CraftBukkit end
this.G = this::d;
if (!this.l.canRead()) {
throw ArgumentParserSelector.d.createWithContext(this.l);
@@ -431,6 +439,12 @@
}
public EntitySelector s() throws CommandSyntaxException {
+ // CraftBukkit start
+ return s(false);
+ }
+
+ public EntitySelector s(boolean overridePermissions) throws CommandSyntaxException {
+ // CraftBukkit end
this.E = this.l.getCursor();
this.G = this::b;
if (this.l.canRead() && this.l.peek() == '@') {
@@ -439,7 +453,7 @@
}
this.l.skip();
- this.b();
+ this.b(overridePermissions); // CraftBukkit
} else {
this.c();
}

Datei anzeigen

@ -132,7 +132,9 @@ import com.google.common.collect.MapMaker;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
@ -1873,6 +1875,25 @@ public final class CraftServer implements Server {
return new CraftLootTable(key, registry.getLootTable(CraftNamespacedKey.toMinecraft(key))); return new CraftLootTable(key, registry.getLootTable(CraftNamespacedKey.toMinecraft(key)));
} }
@Override
public List<Entity> selectEntities(CommandSender sender, String selector) {
Preconditions.checkArgument(selector != null, "Selector cannot be null");
Preconditions.checkArgument(sender != null, "Sender cannot be null");
ArgumentEntity arg = ArgumentEntity.b();
List<? extends net.minecraft.server.Entity> nms;
try {
StringReader reader = new StringReader(selector);
nms = arg.parse(reader, true).b(VanillaCommandWrapper.getListener(sender));
Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data in selector: " + selector);
} catch (CommandSyntaxException ex) {
throw new IllegalArgumentException("Could not parse selector: " + selector, ex);
}
return new ArrayList<>(Lists.transform(nms, (entity) -> entity.getBukkitEntity()));
}
@Deprecated @Deprecated
@Override @Override
public UnsafeValues getUnsafe() { public UnsafeValues getUnsafe() {

Datei anzeigen

@ -505,7 +505,7 @@ public class CraftBlockData implements BlockData {
StringReader reader = new StringReader(data); StringReader reader = new StringReader(data);
ArgumentBlock arg = new ArgumentBlock(reader, false).a(false); ArgumentBlock arg = new ArgumentBlock(reader, false).a(false);
Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data"); Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data: " + data);
blockData = arg.getBlockData(); blockData = arg.getBlockData();
parsed = arg.getStateMap(); parsed = arg.getStateMap();

Datei anzeigen

@ -63,7 +63,7 @@ public final class VanillaCommandWrapper extends BukkitCommand {
return results; return results;
} }
private CommandListenerWrapper getListener(CommandSender sender) { public static CommandListenerWrapper getListener(CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
return ((CraftPlayer) sender).getHandle().getCommandListener(); return ((CraftPlayer) sender).getHandle().getCommandListener();
} }