8000 Add `InitialParse` to the name of `ExceptionHandlingArgumentType` and… · CommandAPI/CommandAPI@7894328 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7894328

Browse files
committed
Add InitialParse to the name of ExceptionHandlingArgumentType and related classes
#476 (comment)
1 parent d7333ad commit 7894328

File tree

31 files changed

+183
-159
lines changed

31 files changed

+183
-159
lines changed

commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,9 @@ <T, EI> ArgumentType<T> wrapArgumentType(Argument argument, ArgumentType<T> rawT
826826
Optional<InitialParseExceptionHandler<T, EI>> handler = iPEA.getInitialParseExceptionHandler();
827827

828828
if (handler.isPresent()) {
829-
return new ExceptionHandlingArgumentType<>(rawType, handler.get(), iPEA::parseInitialParseException);
829+
return new InternalParseExceptionHandlingArgumentType<>(
830+
rawType, handler.get(), iPEA::parseInitialParseException
831+
);
830832
}
831833
}
832834

commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ExceptionHandlingArgumentType.java renamed to commandapi-core/src/main/java/dev/jorel/commandapi/arguments/InternalParseExceptionHandlingArgumentType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @param <T> The object returned when the wrapped {@link ArgumentType} is parsed.
2525
* @param <ExceptionInformation> The class that holds information about the exception.
2626
*/
27-
public record ExceptionHandlingArgumentType<T, ExceptionInformation>(
27+
public record InternalParseExceptionHandlingArgumentType<T, ExceptionInformation>(
2828
/**
2929
* @param baseType The {@link ArgumentType} this object is wrapping
3030
*/
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
import com.mojang.brigadier.CommandDispatcher;
55
import com.mojang.brigadier.arguments.ArgumentType;
66
import dev.jorel.commandapi.CommandAPIPlatform;
7-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
7+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
88
import io.netty.buffer.ByteBuf;
99

1010
import java.io.File;
1111
import java.nio.charset.StandardCharsets;
1212

1313
/**
14-
* An abstract class that handles common logic for serializing an {@link ExceptionHandlingArgumentType} in Minecraft
14+
* An abstract class that handles common logic for serializing an {@link InternalParseExceptionHandlingArgumentType} in Minecraft
1515
* versions 1.15 to 1.18. For context, see <a href="https://wiki.vg/index.php?title=Command_Data&oldid=17429#Node_Format">
1616
* Command Data: Node Format (pre 1.19)</a>.
1717
*
18-
* @param <T> The same type parameter T for {@link ExceptionHandlingArgumentType}. This fixes a silly generics issue.
19-
* @param <EI> The same type parameter as ExceptionInformation in {@link ExceptionHandlingArgumentType}. This fixes a silly generics issue.
18+
* @param <T> The same type parameter T for {@link InternalParseExceptionHandlingArgumentType}. This fixes a silly generics issue.
19+
* @param <EI> The same type parameter as ExceptionInformation in {@link InternalParseExceptionHandlingArgumentType}. This fixes a silly generics issue.
2020
* @param <WRITER> The netty {@link ByteBuf} subclass used to write packets in the version of Minecraft this is being used for.
2121
*/
22-
public abstract class ExceptionHandlingArgumentSerializer_Common<T, EI, WRITER extends ByteBuf> {
22+
public abstract class InitialParseExceptionHandlingArgumentSerializer_Common<T, EI, WRITER extends ByteBuf> {
2323
/**
2424
* This method is expected to write the properties section for an argument node that uses the
25-
* {@link ExceptionHandlingArgumentType}, so that the argument can be reconstructed when received by a client.
26-
* However, we can't add {@link ExceptionHandlingArgumentType} to the client, so if it actually received a node
25+
* {@link InternalParseExceptionHandlingArgumentType}, so that the argument can be reconstructed when received by a client.
26+
* However, we can't add {@link InternalParseExceptionHandlingArgumentType} to the client, so if it actually received a node
2727
* with that type it would freak out and disconnect. Instead, this method removes its own identifier and writes
28-
* the identifier and properties for the {@link ExceptionHandlingArgumentType#baseType()} instead.
28+
* the identifier and properties for the {@link InternalParseExceptionHandlingArgumentType#baseType()} instead.
2929
*
30-
* @param argument The {@link ExceptionHandlingArgumentType} to serialize
30+
* @param argument The {@link InternalParseExceptionHandlingArgumentType} to serialize
3131
* @param packetWriter The netty {@link ByteBuf} that contains the data
3232
*/
33-
protected void commonSerializeToNetwork(ExceptionHandlingArgumentType<T, EI> argument, WRITER packetWriter) {
33+
protected void commonSerializeToNetwork(InternalParseExceptionHandlingArgumentType<T, EI> argument, WRITER packetWriter) {
3434
// REMOVE MY KEY FROM THE PACKET
3535
Object myInfo = getArgumentTypeInformation(argument);
3636

@@ -53,14 +53,14 @@ protected void commonSerializeToNetwork(ExceptionHandlingArgumentType<T, EI> arg
5353
}
5454

5555
/**
56-
* Adds the properties of an {@link ExceptionHandlingArgumentType} node to a {@link JsonObject}. This is used when
56+
* Adds the properties of an {@link InternalParseExceptionHandlingArgumentType} node to a {@link JsonObject}. This is used when
5757
* generating a json representation for a Brigadier {@link CommandDispatcher}, like when
5858
* {@link CommandAPIPlatform#createDispatcherFile(File, CommandDispatcher)} is called.
5959
*
60-
* @param argument The {@link ExceptionHandlingArgumentType} to serialize
60+
* @param argument The {@link InternalParseExceptionHandlingArgumentType} to serialize
6161
* @param properties The {@link JsonObject} to put the properties in
6262
*/
63-
protected void commonSerializeToJson(ExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
63+
protected void commonSerializeToJson(InternalParseExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
6464
ArgumentType<T> baseType = argument.baseType();
6565

6666
Object baseInfo = getArgumentTypeInformation(baseType);
@@ -94,7 +94,7 @@ protected void commonSerializeToJson(ExceptionHandlingArgumentType<T, EI> argume
9494
protected abstract String getSerializationKey(Object info);
9595

9696
/**
97-
* Serializes the properties for the base type of {@link ExceptionHandlingArgumentType} into a packet.
97+
* Serializes the properties for the base type of {@link InternalParseExceptionHandlingArgumentType} into a packet.
9898
*
9999
* @param baseType The base {@link ArgumentType} that needs its properties serialized
100100
* @param baseInfo The serialization information object for the given {@link ArgumentType}
@@ -103,7 +103,7 @@ protected void commonSerializeToJson(ExceptionHandlingArgumentType<T, EI> argume
103103
protected abstract void serializeBaseTypeToNetwork(ArgumentType<T> baseType, Object baseInfo, WRITER packetWriter);
104104

105105
/**
106-
* Serializes the properties for the base type of {@link ExceptionHandlingArgumentType} into json format.
106+
* Serializes the properties for the base type of {@link InternalParseExceptionHandlingArgumentType} into json format.
107107
*
108108
* @param baseType The base {@link ArgumentType} that needs its properties serialized
109109
* @param baseInfo The serialization information object for the given {@link ArgumentType}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import com.mojang.brigadier.arguments.ArgumentType;
55
import dev.jorel.commandapi.SafeStaticOneParameterMethodHandle;
66
import dev.jorel.commandapi.SafeVarHandle;
7-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
7+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
88
import net.minecraft.server.v1_15_R1.ArgumentRegistry;
99
import net.minecraft.server.v1_15_R1.ArgumentSerializer;
1010
import net.minecraft.server.v1_15_R1.MinecraftKey;
1111
import net.minecraft.server.v1_15_R1.PacketDataSerializer;
1212

13-
public class ExceptionHandlingArgumentSerializer_1_15<T, EI>
14-
extends ExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
15-
implements ArgumentSerializer<ExceptionHandlingArgumentType<T, EI>> {
13+
public class InitialParseExceptionHandlingArgumentSerializer_1_15<T, EI>
14+
extends InitialParseExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
15+
implements ArgumentSerializer<InternalParseExceptionHandlingArgumentType<T, EI>> {
1616
// All the ? here should actually be ArgumentRegistry.a, but that is a private inner class. That makes everything really annoying.
1717
// TODO: We want to check this reflection, but we can't give ArgumentRegistry.a to the @RequireField annotation
1818
// Hopefully something works out, but the preprocessor needs to be expanded first
@@ -60,25 +60,26 @@ protected void serializeBaseTypeToJson(ArgumentType<T> baseType, Object baseInfo
6060
// ArgumentSerializer methods
6161
@Override
6262
// serializeToNetwork
63-
public void a(ExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
63+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
6464
commonSerializeToNetwork(argument, packetDataSerializer);
6565
}
6666

6767
@Override
6868
// serializeToJson
69-
public void a(ExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
69+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
7070
commonSerializeToJson(argument, properties);
7171
}
7272

7373
@Override
7474
// deserializeFromNetwork
75-
public ExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
75+
public InternalParseExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
7676
// Since this class overrides its ArgumentRegistry key with the baseType's,
7777
// this class's key should never show up in a packet and this method should never
7878
// be called to deserialize the ArgumentType info that wasn't put into the packet
7979
// anyway. Also, the server shouldn't ever deserialize a PacketPlay*Out*Commands
8080
// either. If this method ever gets called, either you or I are doing something very wrong!
81-
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms.ExceptionHandlingArgumentSerializer_1_15#b for more information");
81+
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms" +
82+
".InitialParseExceptionHandlingArgumentSerializer_1_15#b for more information");
8283
// Including a mini-stacktrace here in case this exception shows up
8384
// on a client-disconnected screen, which is not very helpful
8485
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.15/src/main/java/dev/jorel/commandapi/nms/NMS_1_15.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
import dev.jorel.commandapi.CommandAPIHandler;
7474
import dev.jorel.commandapi.SafeVarHandle;
7575
import dev.jorel.commandapi.arguments.ArgumentSubType;
76-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
76+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
7777
import dev.jorel.commandapi.arguments.SuggestionProviders;
7878
import dev.jorel.commandapi.commandsenders.AbstractCommandSender;
7979
import dev.jorel.commandapi.commandsenders.BukkitCommandSender;
@@ -963,7 +963,8 @@ public void reloadDataPacks() {
963963

964964
@Override
965965
public void registerCustomArgumentType() {
966-
ArgumentRegistry.a("commandapi:exception_handler", ExceptionHandlingArgumentType.class, new ExceptionHandlingArgumentSerializer_1_15());
966+
ArgumentRegistry.a("commandapi:exception_handler", InternalParseExceptionHandlingArgumentType.class,
967+
new InitialParseExceptionHandlingArgumentSerializer_1_15());
967968
}
968969

969970
@Override
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import com.mojang.brigadier.arguments.ArgumentType;
55
import dev.jorel.commandapi.SafeStaticOneParameterMethodHandle;
66
import dev.jorel.commandapi.SafeVarHandle;
7-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
7+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
88
import net.minecraft.server.v1_16_R1.ArgumentRegistry;
99
import net.minecraft.server.v1_16_R1.ArgumentSerializer;
1010
import net.minecraft.server.v1_16_R1.MinecraftKey;
1111
import net.minecraft.server.v1_16_R1.PacketDataSerializer;
1212

13-
public class ExceptionHandlingArgumentSerializer_1_16_R1<T, EI>
14-
extends ExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
15-
implements ArgumentSerializer<ExceptionHandlingArgumentType<T, EI>> {
13+
public class InitialParseExceptionHandlingArgumentSerializer_1_16_R1<T, EI>
14+
extends InitialParseExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
15+
implements ArgumentSerializer<InternalParseExceptionHandlingArgumentType<T, EI>> {
1616
// All the ? here should actually be ArgumentRegistry.a, but that is a private inner class. That makes everything really annoying.
1717
// TODO: We want to check this reflection, but we can't give ArgumentRegistry.a to the @RequireField annotation
1818
// Hopefully something works out, but the preprocessor needs to be expanded first
@@ -60,25 +60,26 @@ protected void serializeBaseTypeToJson(ArgumentType<T> baseType, Object baseInfo
6060
// ArgumentSerializer methods
6161
@Override
6262
// serializeToNetwork
63-
public void a(ExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
63+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
6464
commonSerializeToNetwork(argument, packetDataSerializer);
6565
}
6666

6767
@Override
6868
// serializeToJson
69-
public void a(ExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
69+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
7070
commonSerializeToJson(argument, properties);
7171
}
7272

7373
@Override
7474
// deserializeFromNetwork
75-
public ExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
75+
public InternalParseExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
7676
// Since this class overrides its ArgumentRegistry key with the baseType's,
7777
// this class's key should never show up in a packet and this method should never
7878
// be called to deserialize the ArgumentType info that wasn't put into the packet
7979
// anyway. Also, the server shouldn't ever deserialize a PacketPlay*Out*Commands
8080
// either. If this method ever gets called, either you or I are doing something very wrong!
81-
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms.ExceptionHandlingArgumentSerializer_1_16_R1#b for more information");
81+
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms" +
82+
".InitialParseExceptionHandlingArgumentSerializer_1_16_R1#b for more information");
8283
// Including a mini-stacktrace here in case this exception shows up
8384
// on a client-disconnected screen, which is not very helpful
8485
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R1.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
import dev.jorel.commandapi.CommandAPIHandler;
8080
import dev.jorel.commandapi.SafeVarHandle;
8181
import dev.jorel.commandapi.arguments.ArgumentSubType;
82-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
82+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
8383
import dev.jorel.commandapi.arguments.SuggestionProviders;
8484
import dev.jorel.commandapi.commandsenders.AbstractCommandSender;
8585
import dev.jorel.commandapi.commandsenders.BukkitCommandSender;
@@ -1040,7 +1040,8 @@ public void reloadDataPacks() {
10401040

10411041
@Override
10421042
public void registerCustomArgumentType() {
1043-
ArgumentRegistry.a("commandapi:exception_handler", ExceptionHandlingArgumentType.class, new ExceptionHandlingArgumentSerializer_1_16_R1());
1043+
ArgumentRegistry.a("commandapi:exception_handler", InternalParseExceptionHandlingArgumentType.class,
1044+
new InitialParseExceptionHandlingArgumentSerializer_1_16_R1());
10441045
}
10451046

10461047
@Override
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import com.mojang.brigadier.arguments.ArgumentType;
55
import dev.jorel.commandapi.SafeStaticOneParameterMethodHandle;
66
import dev.jorel.commandapi.SafeVarHandle;
7-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
7+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
88
import dev.jorel.commandapi.preprocessor.Differs;
99
import net.minecraft.server.v1_16_R2.ArgumentRegistry;
1010
import net.minecraft.server.v1_16_R2.ArgumentSerializer;
1111
import net.minecraft.server.v1_16_R2.MinecraftKey;
1212
import net.minecraft.server.v1_16_R2.PacketDataSerializer;
1313

1414
@Differs(from = {"1.15", "1.16.1"}, by = "Renamed ArgumentRegistry#a(ArgumentType) to ArgumentRegistry#b(ArgumentType)")
15-
public class ExceptionHandlingArgumentSerializer_1_16_R2<T, EI>
16-
extends ExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
17-
implements ArgumentSerializer<ExceptionHandlingArgumentType<T, EI>> {
15+
public class InitialParseExceptionHandlingArgumentSerializer_1_16_R2<T, EI>
16+
extends InitialParseExceptionHandlingArgumentSerializer_Common<T, EI, PacketDataSerializer>
17+
implements ArgumentSerializer<InternalParseExceptionHandlingArgumentType<T, EI>> {
1818
// All the ? here should actually be ArgumentRegistry.a, but that is a private inner class. That makes everything really annoying.
1919
// TODO: We want to check this reflection, but we can't give ArgumentRegistry.a to the @RequireField annotation
2020
// Hopefully something works out, but the preprocessor needs to be expanded first
@@ -62,25 +62,26 @@ protected void serializeBaseTypeToJson(ArgumentType<T> baseType, Object baseInfo
6262
// ArgumentSerializer methods
6363
@Override
6464
// serializeToNetwork
65-
public void a(ExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
65+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, PacketDataSerializer packetDataSerializer) {
6666
commonSerializeToNetwork(argument, packetDataSerializer);
6767
}
6868

6969
@Override
7070
// serializeToJson
71-
public void a(ExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
71+
public void a(InternalParseExceptionHandlingArgumentType<T, EI> argument, JsonObject properties) {
7272
commonSerializeToJson(argument, properties);
7373
}
7474

7575
@Override
7676
// deserializeFromNetwork
77-
public ExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
77+
public InternalParseExceptionHandlingArgumentType<T, EI> b(PacketDataSerializer packetDataSerializer) {
7878
// Since this class overrides its ArgumentRegistry key with the baseType's,
7979
// this class's key should never show up in a packet and this method should never
8080
// be called to deserialize the ArgumentType info that wasn't put into the packet
8181
// anyway. Also, the server shouldn't ever deserialize a PacketPlay*Out*Commands
8282
// either. If this method ever gets called, either you or I are doing something very wrong!
83-
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms.ExceptionHandlingArgumentSerializer_1_16_R2#b for more information");
83+
throw new IllegalStateException("This shouldn't happen! See dev.jorel.commandapi.nms" +
84+
".InitialParseExceptionHandlingArgumentSerializer_1_16_R2#b for more information");
8485
// Including a mini-stacktrace here in case this exception shows up
8586
// on a client-disconnected screen, which is not very helpful
8687
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R2.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
import dev.jorel.commandapi.CommandAPIHandler;
7979
import dev.jorel.commandapi.SafeVarHandle;
8080
import dev.jorel.commandapi.arguments.ArgumentSubType;
81-
import dev.jorel.commandapi.arguments.ExceptionHandlingArgumentType;
81+
import dev.jorel.commandapi.arguments.InternalParseExceptionHandlingArgumentType;
8282
import dev.jorel.commandapi.arguments.SuggestionProviders;
8383
import dev.jorel.commandapi.commandsenders.AbstractCommandSender;
8484
import dev.jorel.commandapi.commandsenders.BukkitCommandSender;
@@ -1025,7 +1025,8 @@ public void reloadDataPacks() {
10251025

10261026
@Override
10271027
public void registerCustomArgumentType() {
1028-
ArgumentRegistry.a("commandapi:exception_handler", ExceptionHandlingArgumentType.class, new ExceptionHandlingArgumentSerializer_1_16_R2());
1028+
ArgumentRegistry.a("commandapi:exception_handler", InternalParseExceptionHandlingArgumentType.class,
1029+
new InitialParseExceptionHandlingArgumentSerializer_1_16_R2());
10291030
}
10301031

10311032
@Override

0 commit comments

Comments
 (0)
0