Always generate classes with legal identifiers.
Certain types, such as ItemStack[], would cause the StructureCompiler to generate classes with the name CompiledStructure@ParentItemStack[], which are not legal names. Instead, we'll replace the brackets with the word Array. In addition, to accomodate classes with identical names, we'll use the following naming convention instead: CompiledStructure$[Canonical name of target]$Canonical name of type], where the canonical name (net.minecraft.server.ItemStack[]) is transformed to a legal name by replacing "." to "_" and "[]" to array. In our example, that would result in the following class name: net_minecraft_server_ItemStackArray
Dieser Commit ist enthalten in:
Ursprung
9170e48992
Commit
456764468a
@ -186,6 +186,15 @@ public final class StructureCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a variable identifier that can uniquely represent the given type.
|
||||
* @param type - a type.
|
||||
* @return A unique and legal identifier for the given type.
|
||||
*/
|
||||
private String getSafeTypeName(Class<?> type) {
|
||||
return type.getCanonicalName().replace("[]", "Array").replace(".", "_");
|
||||
}
|
||||
|
||||
private <TField> Class<?> generateClass(StructureModifier<TField> source) {
|
||||
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
@ -193,7 +202,9 @@ public final class StructureCompiler {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class targetType = source.getTargetType();
|
||||
|
||||
String className = "CompiledStructure$" + targetType.getSimpleName() + source.getFieldType().getSimpleName();
|
||||
String className = "CompiledStructure$" +
|
||||
getSafeTypeName(targetType) + "$" +
|
||||
getSafeTypeName(source.getFieldType());
|
||||
String targetSignature = Type.getDescriptor(targetType);
|
||||
String targetName = targetType.getName().replace('.', '/');
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren