Convert to an actual library
This commit is contained in:
parent
2e0745d505
commit
c36d001954
4 changed files with 15 additions and 55 deletions
|
|
@ -1,45 +0,0 @@
|
||||||
package org.adrianvictor.lib;
|
|
||||||
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
|
||||||
import org.adrianvictor.lib.reflection.VersionMatcher;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
|
||||||
VersionMatcher matcher;
|
|
||||||
String serverVersion;
|
|
||||||
ImplementationRegistry registry;
|
|
||||||
private static Main instance;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
getLogger().info("is being disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
getLogger().info("is loading.");
|
|
||||||
|
|
||||||
instance = this;
|
|
||||||
matcher = new VersionMatcher();
|
|
||||||
serverVersion = matcher.getServerVersion();
|
|
||||||
|
|
||||||
String classSuffix = matcher.getClassSuffix("release", serverVersion);
|
|
||||||
|
|
||||||
if (classSuffix == null) {
|
|
||||||
classSuffix = matcher.getClassSuffix("beta", serverVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classSuffix == null) {
|
|
||||||
throw new IllegalStateException("No suitable implementation found for version " + serverVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
registry = new ImplementationRegistry(classSuffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Main getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementationRegistry getRegistry() {
|
|
||||||
return registry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package org.adrianvictor.lib.configuration;
|
package org.adrianvictor.lib.configuration;
|
||||||
|
|
||||||
import org.adrianvictor.lib.Main;
|
|
||||||
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() {
|
public static ConfigurationProvider create(ImplementationRegistry registry) {
|
||||||
return Main.getInstance().getRegistry().getInstance(ConfigurationProvider.class, "org.adrianvictor.lib.configuraion");
|
return registry.getInstance(ConfigurationProvider.class, "org.adrianvictor.lib.configuraion");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package org.adrianvictor.lib.text;
|
package org.adrianvictor.lib.text;
|
||||||
|
|
||||||
import org.adrianvictor.lib.Main;
|
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
||||||
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
|
||||||
public class TextColor {
|
public class TextColor {
|
||||||
public static TextColorProvider create() {
|
public static TextColorProvider create(ImplementationRegistry registry) {
|
||||||
return Main.getInstance().getRegistry().getInstance(TextColorProvider.class, "org.adrianvictor.lib.text");
|
return registry.getInstance(TextColorProvider.class, "org.adrianvictor.lib.text");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,24 @@
|
||||||
package org.adrianvictor.lib.text;
|
package org.adrianvictor.lib.text;
|
||||||
|
|
||||||
|
import org.adrianvictor.lib.reflection.ImplementationRegistry;
|
||||||
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
import org.adrianvictor.lib.text.provider.TextColorProvider;
|
||||||
|
|
||||||
public class TextColorUtils {
|
public class TextColorUtils {
|
||||||
private static final TextColorProvider provider = TextColor.create();
|
private final TextColorProvider provider;
|
||||||
|
|
||||||
public static String formatColors(String message) {
|
public TextColorUtils(ImplementationRegistry registry) {
|
||||||
|
provider = TextColor.create(registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formatColors(String message) {
|
||||||
return message.replace("&", "§");
|
return message.replace("&", "§");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ignoreColors(String message) {
|
public String ignoreColors(String message) {
|
||||||
return message.replaceAll("&([0-9a-fk-or])", "");
|
return message.replaceAll("&([0-9a-fk-or])", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String rainbow(String message) {
|
public String rainbow(String message) {
|
||||||
String[] colorNames = {"RED", "GOLD", "YELLOW", "GREEN", "AQUA", "BLUE", "LIGHT_PURPLE"};
|
String[] colorNames = {"RED", "GOLD", "YELLOW", "GREEN", "AQUA", "BLUE", "LIGHT_PURPLE"};
|
||||||
int colorIndex = 0;
|
int colorIndex = 0;
|
||||||
String coloredMessage = "";
|
String coloredMessage = "";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue