Fix ImplementationRegistry
This commit is contained in:
parent
c36d001954
commit
623e581623
7 changed files with 26 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package org.adrianvictor.lib.configuration;
|
||||
package org.adrianvictor.lib.impl.b1_7_3.configuration;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.adrianvictor.lib.text;
|
||||
package org.adrianvictor.lib.impl.b1_7_3.text;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
|
@ -5,6 +5,6 @@ import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
|||
|
||||
public class Configuration {
|
||||
public static ConfigurationProvider create(ImplementationRegistry registry) {
|
||||
return registry.getInstance(ConfigurationProvider.class, "org.adrianvictor.lib.configuraion");
|
||||
return registry.getInstance(ConfigurationProvider.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,17 +8,29 @@ public class ImplementationRegistry {
|
|||
this.classSuffix = classSuffix;
|
||||
}
|
||||
|
||||
public <T> T getInstance(Class<T> interfaceClass, String packagePath) {
|
||||
String implClassName = packagePath.replace(
|
||||
"org.adrianvictor.lib",
|
||||
"org.adrianvictor.lib.impl." + classSuffix
|
||||
);
|
||||
public <T> T getInstance(Class<T> apiClass, String target, String replacement) {
|
||||
String implName =
|
||||
apiClass.getName()
|
||||
.replace(
|
||||
target,
|
||||
replacement + classSuffix + "."
|
||||
);
|
||||
|
||||
try {
|
||||
Class<?> implClass = Class.forName(implClassName);
|
||||
return interfaceClass.cast(implClass.getDeclaredConstructor().newInstance());
|
||||
Class<?> implClass = Class.forName(implName);
|
||||
|
||||
return apiClass.cast(
|
||||
implClass.getDeclaredConstructor().newInstance()
|
||||
);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new IllegalStateException("Cannot load " + implClassName, e);
|
||||
throw new IllegalStateException(
|
||||
"Cannot load " + implName,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T getInstance(Class<T> apiClass) {
|
||||
return getInstance(apiClass, "org.adrianvictor.lib", "org.adrianvictor.lib.impl.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import org.adrianvictor.lib.text.provider.TextColorProvider;
|
|||
|
||||
public class TextColor {
|
||||
public static TextColorProvider create(ImplementationRegistry registry) {
|
||||
return registry.getInstance(TextColorProvider.class, "org.adrianvictor.lib.text");
|
||||
return registry.getInstance(TextColorProvider.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.adrianvictor.lib.configuration;
|
||||
package org.adrianvictor.lib.impl.r1_21.configuration;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.adrianvictor.lib.text;
|
||||
package org.adrianvictor.lib.impl.r1_21.text;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue