Skip to content

Commit

Permalink
feat: 1.19.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Dec 10, 2022
1 parent 2750c6b commit 16664c0
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 154 deletions.
7 changes: 3 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
max_line_length = 140
tab_width = 4
ij_continuation_indent_size = 8
ij_continuation_indent_size = 4
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_smart_tabs = false
ij_visual_guides = none
ij_visual_guides = 140
ij_wrap_on_typing = false

[*.bat]
end_of_line = crlf

[*.java]
max_line_length = 150
ij_java_align_consecutive_assignments = false
ij_java_align_consecutive_variable_declarations = false
ij_java_align_group_field_declarations = false
Expand Down
9 changes: 3 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ subprojects {

repositories {
mavenCentral()
sonatype.s01Snapshots().mavenContent {
includeGroup("net.kyori")
}
sonatype.ossSnapshots().mavenContent {
includeGroup("cloud.commandframework")
}
Expand All @@ -50,12 +47,12 @@ subprojects {
dependencies {
implementation("me.machinemaker.mirror:mirror-paper:0.1.1")
implementation("me.machinemaker.lectern:lectern-yaml:0.2.1")
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
implementation("net.kyori:adventure-platform-bukkit:4.2.0")
implementation("net.kyori:adventure-text-minimessage:4.12.0")
implementation(platform("cloud.commandframework:cloud-bom:1.8.0-SNAPSHOT")) // oss
implementation("cloud.commandframework:cloud-paper")
implementation("cloud.commandframework:cloud-minecraft-extras")
implementation("org.bstats:bstats-bukkit:2.2.1")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("io.papermc:paperlib:1.0.6")
implementation("net.kyori.moonshine:moonshine-standard:2.0.4")

Expand All @@ -75,7 +72,7 @@ subprojects {

// Native to minecraft
compileOnly("com.mojang:authlib:3.11.49")
compileOnly("org.slf4j:slf4j-api:1.8.0-beta4")
compileOnly("org.slf4j:slf4j-api:2.0.5")
compileOnly("com.mojang:brigadier:1.0.18")

// soft dependencies
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ repositories {
}

dependencies {
implementation("gradle.plugin.com.github.jengelman.gradle.plugins", "shadow", "7.0.0")
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
}

kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mcVersion=1.19.1-R0.1-SNAPSHOT
mcVersion=1.19.3-R0.1-SNAPSHOT

org.gradle.parallel=true
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class GlobalListener implements Listener {
private final PaperCommandManager<CommandDispatcher> commandManager;

@Inject
public GlobalListener(ModuleManager moduleManager, PaperCommandManager<CommandDispatcher> commandManager) {
public GlobalListener(final ModuleManager moduleManager, final PaperCommandManager<CommandDispatcher> commandManager) {
this.moduleManager = moduleManager;
this.commandManager = commandManager;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBukkitReload(ServerLoadEvent event) {
public void onBukkitReload(final ServerLoadEvent event) {
if (event.getType() == ServerLoadEvent.LoadType.RELOAD) {
moduleManager.reloadModules();
this.moduleManager.reloadModules();
} else if (event.getType() == ServerLoadEvent.LoadType.STARTUP && this.commandManager.hasCapability(CloudBukkitCapabilities.COMMODORE_BRIGADIER)) {
// This is very annoying
ModuleManager.reSyncCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,111 +19,106 @@
*/
package me.machinemaker.vanillatweaks;

import me.machinemaker.vanillatweaks.adventure.TranslationRegistry;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import me.machinemaker.vanillatweaks.adventure.TranslationRegistry;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

public final class I18n {

private static final Configurations CONFIGS = new Configurations();

private static final Logger LOGGER = LoggerFactory.getLogger("I18n");

private final Path i18nPath;
private final ClassLoader pluginClassLoader;
private I18n(Path i18nPath, ClassLoader pluginClassLoader) {

private I18n(final Path i18nPath, final ClassLoader pluginClassLoader) {
this.i18nPath = i18nPath;
this.pluginClassLoader = pluginClassLoader;
}

private static @MonotonicNonNull I18n instance;
static I18n create(final @NotNull Path i18nPath, final @NotNull ClassLoader pluginClassLoader) {
return new I18n(i18nPath, pluginClassLoader);
}

static I18n create(@NotNull Path i18nPath, @NotNull ClassLoader pluginClassLoader) {
if (instance == null) {
instance = new I18n(i18nPath, pluginClassLoader);
}
return instance;
private static String inJarResourceName(final Locale locale) {
return "i18n/lang_" + locale + ".properties";
}

private static String i18nFolderFileName(final Locale locale) {
return locale + ".properties";
}

public void setupI18n() {
ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.pluginClassLoader);
VanillaTweaks.SUPPORTED_LOCALES.forEach(locale -> {
this.updateI18nFile(locale);
TranslationRegistry.registerAll(locale, createBundle(locale));
TranslationRegistry.registerAll(locale, this.createBundle(locale));
});
TranslationRegistry.registerAll(Locale.US, createBundle(Locale.ENGLISH));
TranslationRegistry.registerAll(Locale.US, this.createBundle(Locale.ENGLISH));
} finally {
Thread.currentThread().setContextClassLoader(previousLoader);
}
}

private void updateI18nFile(Locale locale) {
Path localeFile = this.i18nPath.resolve(getI18nFolderFileName(locale));
private void updateI18nFile(final Locale locale) {
final Path localeFile = this.i18nPath.resolve(i18nFolderFileName(locale));
if (Files.notExists(localeFile)) {
InputStream inputStream = this.pluginClassLoader.getResourceAsStream(getInJarResourceName(locale));
final InputStream inputStream = this.pluginClassLoader.getResourceAsStream(inJarResourceName(locale));
if (inputStream == null) {
throw new IllegalArgumentException("Couldn't find a resource for " + locale);
}
try {
Files.createDirectories(localeFile.getParent());
Files.copy(inputStream, localeFile);
} catch (IOException exception) {
} catch (final IOException exception) {
LOGGER.error("Could not copy the locale file for {} to {}", locale, localeFile, exception);
}
} else {
try {
var localeFileBuilder = CONFIGS.propertiesBuilder(localeFile.toFile());
PropertiesConfiguration localeConfig = localeFileBuilder.getConfiguration();
PropertiesConfiguration inJarLocaleConfig = CONFIGS.properties(this.pluginClassLoader.getResource(getInJarResourceName(locale)));
final FileBasedConfigurationBuilder<PropertiesConfiguration> localeFileBuilder = CONFIGS.propertiesBuilder(localeFile.toFile());
final PropertiesConfiguration localeConfig = localeFileBuilder.getConfiguration();
final PropertiesConfiguration inJarLocaleConfig = CONFIGS.properties(this.pluginClassLoader.getResource(inJarResourceName(locale)));
if (!inJarLocaleConfig.getLayout().getKeys().containsAll(localeConfig.getLayout().getKeys())) {
for (String key : localeConfig.getLayout().getKeys()) {
for (final String key : localeConfig.getLayout().getKeys()) {
if (!inJarLocaleConfig.containsKey(key)) {
LOGGER.warn("{} is not a recognized key, it should be removed from {}", key, localeFile);
}
}
}
if (!localeConfig.getLayout().getKeys().containsAll(inJarLocaleConfig.getLayout().getKeys())) {
LOGGER.info("Found new additions to {}, updating that file with latest changes. This will not overwrite changes you have made", localeFile);
for (String key : inJarLocaleConfig.getLayout().getKeys()) {
for (final String key : inJarLocaleConfig.getLayout().getKeys()) {
if (!localeConfig.containsKey(key)) {
localeConfig.setProperty(key, inJarLocaleConfig.getProperty(key));
}
}
localeFileBuilder.save();
}
} catch (ConfigurationException exception) {
} catch (final ConfigurationException exception) {
LOGGER.error("Error reading/writing to {}", localeFile, exception);
}
}
}

private ResourceBundle createBundle(Locale locale) {
Path localeFile = this.i18nPath.resolve(getI18nFolderFileName(locale));
try (InputStream inputStream = Files.newInputStream(localeFile)) {
private ResourceBundle createBundle(final Locale locale) {
final Path localeFile = this.i18nPath.resolve(i18nFolderFileName(locale));
try (final InputStream inputStream = Files.newInputStream(localeFile)) {
return new PropertyResourceBundle(inputStream);
} catch (IOException e) {
throw new IllegalArgumentException("Could not load language from " + getInJarResourceName(locale), e);
} catch (final IOException e) {
throw new IllegalArgumentException("Could not load language from " + inJarResourceName(locale), e);
}
}

private static String getInJarResourceName(Locale locale) {
return "i18n/lang_" + locale + ".properties";
}

private static String getI18nFolderFileName(Locale locale) {
return locale + ".properties";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import me.machinemaker.vanillatweaks.annotations.ModuleInfo;
import me.machinemaker.vanillatweaks.modules.ModuleBase;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.slf4j.Logger;

@DefaultQualifier(NonNull.class)
public final class LoggerFactory {

static final String GLOBAL_PREFIX = "PaperTweaks";
Expand All @@ -35,15 +38,15 @@ public static Logger getLogger() {
return PLUGIN_LOGGER;
}

public static Logger getModuleLogger(Class<? extends ModuleBase> moduleClass) {
public static Logger getModuleLogger(final Class<? extends ModuleBase> moduleClass) {
return getLogger(moduleClass.getAnnotation(ModuleInfo.class).name());
}

public static Logger getLogger(Class<?> clazz) {
public static Logger getLogger(final Class<?> clazz) {
return getLogger(clazz.getSimpleName());
}

public static Logger getLogger(String name) {
public static Logger getLogger(final String name) {
return org.slf4j.LoggerFactory.getLogger(PLUGIN_LOGGER.getName() + ": " + name);
}
}
Loading

0 comments on commit 16664c0

Please sign in to comment.