Skip to content

Commit

Permalink
Fix version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro committed Aug 27, 2024
1 parent 0f7d2df commit 537eb66
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions plugin/src/main/java/ru/boomearo/langhelper/LangHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Getter
public class LangHelper extends JavaPlugin {

@Getter
private static LangHelper instance = null;

private ConfigManager configManager;

private DefaultTranslateManager translateManager = null;
private static final Pattern VERSION_PATTERN = Pattern.compile("\\d+\\.\\d+(?:\\.\\d+)?");

private static final List<TranslationVersionWrapper> VERSIONS = Arrays.asList(
new TranslationVersionWrapper("1.12.2", Translate1_12_R1.class),
Expand All @@ -44,6 +41,13 @@ public class LangHelper extends JavaPlugin {
new TranslationVersionWrapper("1.21.1", Translate1_21_R1.class)
);

@Getter
private static LangHelper instance = null;

private ConfigManager configManager;

private DefaultTranslateManager translateManager = null;

@Override
public void onEnable() {
instance = this;
Expand Down Expand Up @@ -90,9 +94,17 @@ public void onDisable() {
private DefaultTranslateManager matchVersion(Plugin plugin, ConfigManager configManager) throws LangVersionException {
try {
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
this.getLogger().log(Level.INFO, "Detected bukkit version " + bukkitVersion);

return VERSIONS.stream()
.filter(translationVersionWrapper -> bukkitVersion.startsWith(translationVersionWrapper.version()))
.findFirst().orElseThrow(() -> new LangException("LangHelper does not support this minecraft version!"))
.filter(translationVersionWrapper -> {
Matcher matcher = VERSION_PATTERN.matcher(bukkitVersion);
if (matcher.find()) {
return matcher.group().equals(translationVersionWrapper.version());
}
return false;
})
.findFirst().orElseThrow(() -> new LangException("Version " + bukkitVersion + " is not supported!"))
.clazz()
.getConstructor(Plugin.class, ConfigManager.class).
newInstance(plugin, configManager);
Expand Down

0 comments on commit 537eb66

Please sign in to comment.