Remove reflection and add VersionedService to provide multiple versions support
This commit is contained in:
parent
811b54517a
commit
eec7b2fcbb
14 changed files with 310 additions and 111 deletions
|
|
@ -0,0 +1,126 @@
|
||||||
|
package org.adrianvictor.lib;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.reflection.VersionMatcher;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
// Define dummy interfaces for testing
|
||||||
|
interface TestService {}
|
||||||
|
class TestServiceB1_7_3 implements TestService {}
|
||||||
|
class TestServiceR1_21 implements TestService {}
|
||||||
|
|
||||||
|
// Dummy registrar for testing
|
||||||
|
class DummyRegistrarB1_7_3 implements VersionedServiceRegistrar {
|
||||||
|
@Override
|
||||||
|
public void register(VersionedServiceFactory factory) {
|
||||||
|
factory.register(TestService.class, "b1_7_3", TestServiceB1_7_3::new);
|
||||||
|
factory.register(TestService.class, "b1_8_compat", TestServiceB1_7_3::new); // Register for b1_8_compat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyRegistrarR1_21 implements VersionedServiceRegistrar {
|
||||||
|
@Override
|
||||||
|
public void register(VersionedServiceFactory factory) {
|
||||||
|
factory.register(TestService.class, "r1_21", TestServiceR1_21::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class DefaultVersionedServiceFactoryTest {
|
||||||
|
|
||||||
|
private VersionMatcher mockVersionMatcher;
|
||||||
|
private DefaultVersionedServiceFactory factory;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
mockVersionMatcher = mock(VersionMatcher.class);
|
||||||
|
factory = new DefaultVersionedServiceFactory(mockVersionMatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceRegistrationAndRetrievalForB1_7_3() {
|
||||||
|
// Mock VersionMatcher to return b1_7_3 suffix
|
||||||
|
when(mockVersionMatcher.getServerVersion()).thenReturn("1.7.3");
|
||||||
|
when(mockVersionMatcher.getClassSuffix(eq("1.7.3"))).thenReturn("b1_7_3");
|
||||||
|
|
||||||
|
// Register the dummy service for b1_7_3
|
||||||
|
new DummyRegistrarB1_7_3().register(factory);
|
||||||
|
|
||||||
|
// Retrieve the service
|
||||||
|
TestService service = factory.getService(TestService.class);
|
||||||
|
|
||||||
|
// Assert that the correct version is returned
|
||||||
|
assertNotNull(service);
|
||||||
|
assertTrue(service instanceof TestServiceB1_7_3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceRegistrationAndRetrievalForR1_21() {
|
||||||
|
// Mock VersionMatcher to return r1_21 suffix
|
||||||
|
when(mockVersionMatcher.getServerVersion()).thenReturn("1.21.0");
|
||||||
|
when(mockVersionMatcher.getClassSuffix(eq("1.21.0"))).thenReturn("r1_21");
|
||||||
|
|
||||||
|
// Register the dummy service for r1_21
|
||||||
|
new DummyRegistrarR1_21().register(factory);
|
||||||
|
|
||||||
|
// Retrieve the service
|
||||||
|
TestService service = factory.getService(TestService.class);
|
||||||
|
|
||||||
|
// Assert that the correct version is returned
|
||||||
|
assertNotNull(service);
|
||||||
|
assertTrue(service instanceof TestServiceR1_21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServiceRegistrationAndRetrievalForB1_8_Compat() {
|
||||||
|
// Mock VersionMatcher to return b1_8_compat suffix for a 1.16.5 server
|
||||||
|
when(mockVersionMatcher.getServerVersion()).thenReturn("1.16.5");
|
||||||
|
when(mockVersionMatcher.getClassSuffix(eq("1.16.5"))).thenReturn("b1_8_compat");
|
||||||
|
|
||||||
|
// Register the dummy service for b1_7_3 (which also covers b1_8_compat)
|
||||||
|
new DummyRegistrarB1_7_3().register(factory);
|
||||||
|
|
||||||
|
// Retrieve the service
|
||||||
|
TestService service = factory.getService(TestService.class);
|
||||||
|
|
||||||
|
// Assert that the correct compatible version is returned
|
||||||
|
assertNotNull(service);
|
||||||
|
assertTrue(service instanceof TestServiceB1_7_3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNoServiceRegisteredThrowsException() {
|
||||||
|
// Mock VersionMatcher to return an unknown suffix
|
||||||
|
when(mockVersionMatcher.getServerVersion()).thenReturn("unknown");
|
||||||
|
when(mockVersionMatcher.getClassSuffix(anyString())).thenReturn("unknown_version");
|
||||||
|
|
||||||
|
// Attempt to retrieve a service without any registration
|
||||||
|
IllegalStateException exception = assertThrows(IllegalStateException.class, () ->
|
||||||
|
factory.getService(TestService.class)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertTrue(exception.getMessage().contains("No service registered for type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSpecificServiceNotRegisteredForVersionThrowsException() {
|
||||||
|
// Mock VersionMatcher to return b1_7_3 suffix
|
||||||
|
when(mockVersionMatcher.getServerVersion()).thenReturn("1.7.3");
|
||||||
|
when(mockVersionMatcher.getClassSuffix(eq("1.7.3"))).thenReturn("b1_7_3");
|
||||||
|
|
||||||
|
// Register R1_21 service, but not B1_7_3
|
||||||
|
new DummyRegistrarR1_21().register(factory);
|
||||||
|
|
||||||
|
// Attempt to retrieve b1_7_3 service
|
||||||
|
IllegalStateException exception = assertThrows(IllegalStateException.class, () ->
|
||||||
|
factory.getService(TestService.class)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertTrue(exception.getMessage().contains("No service registered for type"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.adrianvictor.lib.impl.b1_7_3;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.VersionedServiceFactory;
|
||||||
|
import org.adrianvictor.lib.VersionedServiceRegistrar;
|
||||||
|
import org.adrianvictor.lib.configuration.provider.ConfigurationProvider;
|
||||||
|
import org.adrianvictor.lib.impl.b1_7_3.configuration.Configuration;
|
||||||
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
import org.adrianvictor.lib.impl.b1_7_3.text.TextColor;
|
||||||
|
|
||||||
|
public class B1_7_3Registrar implements VersionedServiceRegistrar {
|
||||||
|
@Override
|
||||||
|
public void register(VersionedServiceFactory factory) {
|
||||||
|
factory.register(ConfigurationProvider.class, "b1_7_3", Configuration::new);
|
||||||
|
factory.register(TextColorProvider.class, "b1_7_3", TextColor::new);
|
||||||
|
|
||||||
|
// Register for b1_8_compat as well, assuming compatibility
|
||||||
|
factory.register(ConfigurationProvider.class, "b1_8_compat", Configuration::new);
|
||||||
|
factory.register(TextColorProvider.class, "b1_8_compat", TextColor::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
org.adrianvictor.lib.impl.b1_7_3.B1_7_3Registrar
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.adrianvictor.lib;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.reflection.VersionMatcher;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class DefaultVersionedServiceFactory implements VersionedServiceFactory {
|
||||||
|
private final VersionMatcher versionMatcher;
|
||||||
|
private final Map<Class<?>, Map<String, Supplier<?>>> serviceRegistrations = new HashMap<>();
|
||||||
|
|
||||||
|
public DefaultVersionedServiceFactory(VersionMatcher versionMatcher) {
|
||||||
|
this.versionMatcher = versionMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> void register(Class<T> serviceType, String versionSuffix, Supplier<T> supplier) {
|
||||||
|
serviceRegistrations
|
||||||
|
.computeIfAbsent(serviceType, k -> new HashMap<>())
|
||||||
|
.put(versionSuffix, supplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getService(Class<T> serviceType) {
|
||||||
|
String serverVersion = versionMatcher.getServerVersion();
|
||||||
|
// Determine the correct suffix using VersionMatcher (adapted)
|
||||||
|
String versionSuffix = versionMatcher.getClassSuffix(serverVersion); // Removed "release" parameter
|
||||||
|
|
||||||
|
Map<String, Supplier<?>> versionSuppliers = serviceRegistrations.get(serviceType);
|
||||||
|
if (versionSuppliers == null || !versionSuppliers.containsKey(versionSuffix)) {
|
||||||
|
throw new IllegalStateException("No service registered for type " + serviceType.getName() + " and version " + versionSuffix + ". Current server version: " + serverVersion);
|
||||||
|
}
|
||||||
|
return (T) versionSuppliers.get(versionSuffix).get();
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/main/java/org/adrianvictor/lib/Main.java
Normal file
46
src/main/java/org/adrianvictor/lib/Main.java
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
package org.adrianvictor.lib;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.reflection.VersionMatcher;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
public class Main extends JavaPlugin {
|
||||||
|
|
||||||
|
private static VersionedServiceFactory versionedServiceFactory;
|
||||||
|
private static VersionMatcher versionMatcher;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Initialize VersionMatcher
|
||||||
|
versionMatcher = new VersionMatcher();
|
||||||
|
|
||||||
|
// Initialize DefaultVersionedServiceFactory
|
||||||
|
versionedServiceFactory = new DefaultVersionedServiceFactory(versionMatcher);
|
||||||
|
|
||||||
|
// Discover and register version-specific implementations using ServiceLoader
|
||||||
|
ServiceLoader<VersionedServiceRegistrar> registrars = ServiceLoader.load(VersionedServiceRegistrar.class);
|
||||||
|
for (VersionedServiceRegistrar registrar : registrars) {
|
||||||
|
registrar.register(versionedServiceFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage (for demonstration, can be removed later)
|
||||||
|
// ConfigurationProvider configProvider = Configuration.create(versionedServiceFactory);
|
||||||
|
// TextColorProvider textColorProvider = TextColor.create(versionedServiceFactory);
|
||||||
|
|
||||||
|
getLogger().info("tenkumaLib has been enabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
getLogger().info("tenkumaLib has been disabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VersionedServiceFactory getVersionedServiceFactory() {
|
||||||
|
return versionedServiceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VersionMatcher getVersionMatcher() {
|
||||||
|
return versionMatcher;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.adrianvictor.lib;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface VersionedServiceFactory {
|
||||||
|
<T> void register(Class<T> serviceType, String versionSuffix, Supplier<T> supplier);
|
||||||
|
<T> T getService(Class<T> serviceType);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.adrianvictor.lib;
|
||||||
|
|
||||||
|
public interface VersionedServiceRegistrar {
|
||||||
|
void register(VersionedServiceFactory factory);
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package org.adrianvictor.lib.configuration;
|
package org.adrianvictor.lib.configuration;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.VersionedServiceFactory;
|
||||||
import org.adrianvictor.lib.configuration.provider.ConfigurationProvider;
|
import org.adrianvictor.lib.configuration.provider.ConfigurationProvider;
|
||||||
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
public static ConfigurationProvider create(ImplementationRegistry registry) {
|
public static ConfigurationProvider create(VersionedServiceFactory factory) {
|
||||||
return registry.getInstance(ConfigurationProvider.class);
|
return factory.getService(ConfigurationProvider.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package org.adrianvictor.lib.reflection;
|
|
||||||
|
|
||||||
public class ImplementationRegistry {
|
|
||||||
|
|
||||||
private final String classSuffix;
|
|
||||||
|
|
||||||
public ImplementationRegistry(String classSuffix) {
|
|
||||||
this.classSuffix = classSuffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T getInstance(Class<T> apiClass, String target, String replacement) {
|
|
||||||
String base = apiClass.getName();
|
|
||||||
|
|
||||||
String implName =
|
|
||||||
base.replaceFirst(
|
|
||||||
"org\\.adrianvictor\\.lib",
|
|
||||||
"org.adrianvictor.lib.impl." + classSuffix
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class<?> implClass = Class.forName(implName);
|
|
||||||
|
|
||||||
return apiClass.cast(
|
|
||||||
implClass.getDeclaredConstructor().newInstance()
|
|
||||||
);
|
|
||||||
} catch (ReflectiveOperationException 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.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,54 +2,53 @@ package org.adrianvictor.lib.reflection;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Comparator;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class VersionMatcher {
|
public class VersionMatcher {
|
||||||
|
|
||||||
public VersionMatcher() {}
|
public VersionMatcher() {}
|
||||||
|
|
||||||
private record Entry(String pattern, String classSuffix) {}
|
private record Entry(String pattern, String classSuffix, int minMajor, int minMinor, int maxMajor, int maxMinor) {}
|
||||||
|
|
||||||
public String getClassSuffix(String type, String serverVersion) {
|
public String getClassSuffix(String serverVersion) {
|
||||||
if (type == null || serverVersion == null) {
|
if (serverVersion == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<Entry>> map = populateMap();
|
List<Entry> entries = populateEntries();
|
||||||
List<Entry> entries = map.get(type.toLowerCase());
|
List<Entry> applicableEntries = new ArrayList<>();
|
||||||
if (entries == null || entries.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exact match
|
int[] parsedServerVersion = parseVersion(serverVersion);
|
||||||
for (Entry e : entries) {
|
int serverMajor = parsedServerVersion[0];
|
||||||
if (safeMatches(e.pattern, serverVersion)) {
|
int serverMinor = parsedServerVersion[1];
|
||||||
return e.classSuffix;
|
|
||||||
|
for (Entry entry : entries) {
|
||||||
|
Pattern p = Pattern.compile(entry.pattern());
|
||||||
|
if (p.matcher(serverVersion).matches()) {
|
||||||
|
if (serverMajor >= entry.minMajor() && serverMinor >= entry.minMinor() &&
|
||||||
|
serverMajor <= entry.maxMajor() && serverMinor <= entry.maxMinor()) {
|
||||||
|
applicableEntries.add(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to closest version
|
// Sort by version (highest minor first for best match within range)
|
||||||
List<Entry> sorted = new ArrayList<>(entries);
|
applicableEntries.sort(Comparator
|
||||||
Collections.sort(sorted, (a, b) -> compareVersions(a.pattern, b.pattern));
|
.comparing(Entry::maxMajor).reversed()
|
||||||
|
.thenComparing(Entry::maxMinor).reversed()
|
||||||
|
.thenComparing(Entry::minMajor).reversed()
|
||||||
|
.thenComparing(Entry::minMinor).reversed());
|
||||||
|
|
||||||
Entry oldest = sorted.get(0);
|
Optional<Entry> bestMatch = applicableEntries.stream().findFirst();
|
||||||
Entry newest = sorted.get(sorted.size() - 1);
|
|
||||||
|
|
||||||
int cmpOldest = compareVersions(serverVersion, oldest.pattern);
|
return bestMatch.map(Entry::classSuffix).orElse(null);
|
||||||
int cmpNewest = compareVersions(serverVersion, newest.pattern);
|
|
||||||
|
|
||||||
if (cmpOldest < 0) {
|
|
||||||
return oldest.classSuffix;
|
|
||||||
} else if (cmpNewest > 0) {
|
|
||||||
return newest.classSuffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newest.classSuffix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerVersion() {
|
public String getServerVersion() {
|
||||||
|
|
@ -71,46 +70,21 @@ public class VersionMatcher {
|
||||||
return rawVersion;
|
return rawVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, List<Entry>> populateMap() {
|
private List<Entry> populateEntries() {
|
||||||
Map<String, List<Entry>> map = new HashMap<>();
|
return List.of(
|
||||||
map.put("release", List.of(
|
new Entry("^1\\.7\\.3$", "b1_7_3", 1, 7, 1, 7),
|
||||||
new Entry("^1\\.21\\..*$", "r1_21")
|
// Covers 1.8 up to 1.16 for compatibility (example for user request)
|
||||||
));
|
new Entry("^1\\.(8|9|10|11|12|13|14|15|16)\\..*$", "b1_8_compat", 1, 8, 1, 16),
|
||||||
map.put("beta", List.of(
|
new Entry("^1\\.21\\..*$", "r1_21", 1, 21, Integer.MAX_VALUE, Integer.MAX_VALUE) // Open-ended for future 1.21.x
|
||||||
new Entry("^1\\.7\\.3$", "b1_7_3")
|
);
|
||||||
));
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int compareVersions(String v1, String v2) {
|
// Helper to parse major and minor version from a string (e.g., "1.16.5" -> [1, 16])
|
||||||
String clean1 = v1.replaceAll("[^0-9.]", "");
|
private int[] parseVersion(String versionString) {
|
||||||
String clean2 = v2.replaceAll("[^0-9.]", "");
|
Matcher matcher = Pattern.compile("^(\\d+)\\.(\\d+).*").matcher(versionString);
|
||||||
|
if (matcher.find()) {
|
||||||
String[] a1 = clean1.split("\\.");
|
return new int[]{Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))};
|
||||||
String[] a2 = clean2.split("\\.");
|
|
||||||
|
|
||||||
int len = Math.max(a1.length, a2.length);
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
int n1 = i < a1.length ? parseInt(a1[i]) : 0;
|
|
||||||
int n2 = i < a2.length ? parseInt(a2[i]) : 0;
|
|
||||||
if (n1 != n2) {
|
|
||||||
return n1 - n2;
|
|
||||||
}
|
}
|
||||||
}
|
return new int[]{0, 0}; // Default for unknown format
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int parseInt(String s) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(s);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean safeMatches(String expression, String against) {
|
|
||||||
String cleanPattern = expression.trim();
|
|
||||||
Pattern pattern = Pattern.compile(cleanPattern, Pattern.CASE_INSENSITIVE);
|
|
||||||
return pattern.matcher(against).matches();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package org.adrianvictor.lib.text;
|
package org.adrianvictor.lib.text;
|
||||||
|
|
||||||
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
import org.adrianvictor.lib.VersionedServiceFactory;
|
||||||
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
|
||||||
public class TextColor {
|
public class TextColor {
|
||||||
public static TextColorProvider create(ImplementationRegistry registry) {
|
public static TextColorProvider create(VersionedServiceFactory factory) {
|
||||||
return registry.getInstance(TextColorProvider.class);
|
return factory.getService(TextColorProvider.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
package org.adrianvictor.lib.text;
|
package org.adrianvictor.lib.text;
|
||||||
|
|
||||||
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
import org.adrianvictor.lib.VersionedServiceFactory;
|
||||||
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
|
||||||
public class TextColorUtils {
|
public class TextColorUtils {
|
||||||
private final TextColorProvider provider;
|
private final TextColorProvider provider;
|
||||||
|
|
||||||
public TextColorUtils(ImplementationRegistry registry) {
|
public TextColorUtils(VersionedServiceFactory factory) {
|
||||||
provider = TextColor.create(registry);
|
provider = TextColor.create(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatColors(String message) {
|
public String formatColors(String message) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.adrianvictor.lib.impl.r1_21;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.VersionedServiceFactory;
|
||||||
|
import org.adrianvictor.lib.VersionedServiceRegistrar;
|
||||||
|
import org.adrianvictor.lib.configuration.provider.ConfigurationProvider;
|
||||||
|
import org.adrianvictor.lib.impl.r1_21.configuration.Configuration;
|
||||||
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
import org.adrianvictor.lib.impl.r1_21.text.TextColor;
|
||||||
|
|
||||||
|
public class R1_21Registrar implements VersionedServiceRegistrar {
|
||||||
|
@Override
|
||||||
|
public void register(VersionedServiceFactory factory) {
|
||||||
|
factory.register(ConfigurationProvider.class, "r1_21", Configuration::new);
|
||||||
|
factory.register(TextColorProvider.class, "r1_21", TextColor::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
org.adrianvictor.lib.impl.r1_21.R1_21Registrar
|
||||||
Loading…
Add table
Add a link
Reference in a new issue