Skip to content

Commit

Permalink
Merge branch 'dev/bleeding' into feature/papi
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 committed Oct 7, 2024
2 parents 386487c + 4ceff1b commit f283f8b
Show file tree
Hide file tree
Showing 195 changed files with 10,854 additions and 6,264 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
os: ["ubuntu-latest", "windows-latest"]
runs-on: "${{ matrix.os }}"
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation[email protected]
- name: Set up JDK 17
uses: actions/setup-java@v2
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'zulu'
cache: 'gradle'
- name: Build with Gradle
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,6 @@ gradle-app.setting
### Gradle Patch ###
**/build/

# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,maven

**/run
130 changes: 80 additions & 50 deletions AreaShop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.github.goooler.shadow") version "8.1.7"
id("xyz.jpenilla.run-paper") version "2.3.0"
}

idea {
module {
isDownloadSources = true
}
}

description = "AreaShop"

dependencies {
// Platform
compileOnlyApi(libs.spigot)
compileOnlyApi(libs.worldeditCore) {
exclude("com.google.guava", "guava")
}
compileOnlyApi(libs.worldeditBukkit) {
exclude("com.google.guava", "guava")
}
compileOnlyApi(libs.worldguardCore) {
exclude("com.google.guava", "guava")
}
compileOnlyApi(libs.worldguardBukkit) {
exclude("com.google.guava", "guava")
}
compileOnlyApi("com.github.MilkBowl:VaultAPI:1.7") {
exclude("com.google.guava", "guava")
}
compileOnlyApi("me.clip:placeholderapi:2.11.2")
compileOnlyApi(libs.worldeditBukkit)
compileOnlyApi(libs.worldguardBukkit)
compileOnlyApi("com.github.MilkBowl:VaultAPI:1.7")
compileOnlyApi("me.clip:placeholderapi:2.11.6")

// 3rd party libraries
implementation(libs.findbugs)
implementation("io.papermc:paperlib:1.0.7")
implementation("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
implementation("com.github.NLthijs48:BukkitDo:819d51ec2b")
implementation("io.github.baked-libs:dough-data:1.2.0")
implementation("com.google.inject:guice:5.1.0") {
exclude("com.google.guava", "guava")
api("io.papermc:paperlib:1.0.8")
api("com.github.NLthijs48:InteractiveMessenger:e7749258ca")
api("com.github.NLthijs48:BukkitDo:819d51ec2b")
api("io.github.baked-libs:dough-data:1.2.0")
api("com.google.inject:guice:7.0.0") {
exclude("com.google.guava")
}
api("com.google.inject.extensions:guice-assistedinject:7.0.0") {
exclude("com.google.guava")
}
implementation("com.google.inject.extensions:guice-assistedinject:5.1.0") {
exclude("com.google.guava", "guava")
implementation("org.incendo:cloud-paper:2.0.0-beta.9") {
exclude("com.google.guava")
}
implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.3") {
exclude("com.google.guava")
}
implementation("net.kyori:adventure-text-minimessage:4.16.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.2")
implementation("org.spongepowered:configurate-yaml:4.1.2")

implementation("org.jetbrains:annotations:23.0.0")

// Project submodules
implementation(projects.areashopInterface)
implementation(projects.areashopNms)
// Adapters
runtimeOnly(projects.adapters.plugins.worldedit)
runtimeOnly(projects.adapters.plugins.worldguard)
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
runtimeOnly(project(":adapters:platform:bukkit-1-17", "reobf"))
runtimeOnly(project(":adapters:platform:bukkit-1-18", "reobf"))
runtimeOnly(project(":adapters:platform:bukkit-1-19", "reobf"))

testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("com.github.seeseemelk:MockBukkit-v1.19:2.119.3")
testImplementation("me.clip:placeholderapi:2.11.2")
testImplementation(libs.worldeditBukkit)
testImplementation(libs.worldguardBukkit)
}
api(projects.areashopInterface)
api(projects.adapters.platform.platformInterface)
api(projects.adapters.platform.paper)

repositories {
mavenCentral()
maven {
name = "extendedclip-repo"
url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
if (!providers.environmentVariable("JITPACK").isPresent) {
// We don't need these adapters if we are only publishing an api jar
runtimeOnly(projects.adapters.plugins.worldedit)
runtimeOnly(projects.adapters.plugins.worldguard)
runtimeOnly(projects.adapters.plugins.fastasyncworldedit)
runtimeOnly(projects.adapters.plugins.essentials)
}

testImplementation("com.github.MilkBowl:VaultAPI:1.7")
testImplementation("com.github.MilkBowl:VaultAPI:1.7")
testImplementation("me.clip:placeholderapi:2.11.6")
testImplementation(libs.worldeditBukkit)
testImplementation(libs.worldguardBukkit)
testImplementation("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
testImplementation("com.github.seeseemelk:MockBukkit-v1.21:3.131.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
}

tasks {
Expand All @@ -74,11 +74,24 @@ tasks {
}

assemble {
dependsOn(shadowJar)
if (!providers.environmentVariable("JITPACK").isPresent) {
dependsOn(shadowJar)
}
}

jar {
archiveClassifier.set("original")
archiveBaseName.set("AreaShop")
if (!providers.environmentVariable("JITPACK").isPresent) {
archiveClassifier.set("original")
} else {
archiveClassifier.set("")
}
}

if (providers.environmentVariable("JITPACK").isPresent) {
artifacts {
archives(jar)
}
}

java {
Expand All @@ -96,11 +109,13 @@ tasks {
archiveBaseName.set("AreaShop")
}
val base = "me.wiefferink.areashop.libraries"
relocate("org.incendo.cloud", "${base}.cloud")
relocate("me.wiefferink.interactivemessenger", "${base}.interactivemessenger")
relocate("me.wiefferink.bukkitdo", "${base}.bukkitdo")
relocate("io.papermc.lib", "${base}.paperlib")
relocate("io.github.bakedlibs.dough", "${base}.dough")
relocate("com.google.inject", "${base}.inject")
relocate("com.google.errorprone", "${base}.errorprone")
relocate("org.aopalliance", "${base}.aopalliance")
relocate("javax.annotation", "${base}.javax.annotation")
relocate("javax.inject", "${base}.javax.inject")
Expand All @@ -113,4 +128,19 @@ tasks {
events("passed", "skipped", "failed")
}
}
runServer {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.21")

downloadPlugins {
github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar")
github("MilkBowl", "Vault", "1.7.3", "Vault.jar")
// WorldEdit 7.3.3
url("https://mediafilez.forgecdn.net/files/5400/331/worldedit-bukkit-7.3.3.jar")
// WorldGuard 7.0.10
url("https://mediafilez.forgecdn.net/files/5344/377/worldguard-bukkit-7.0.10-dist.jar")
}
}
}
190 changes: 190 additions & 0 deletions AreaShop/src/main/java/me/wiefferink/areashop/ASLanguageManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package me.wiefferink.areashop;

import java.io.Reader;
import java.nio.charset.StandardCharsets;

import me.wiefferink.interactivemessenger.Log;
import me.wiefferink.interactivemessenger.processing.Message;
import me.wiefferink.interactivemessenger.source.LanguageManager;
import me.wiefferink.interactivemessenger.translation.Transifex;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.net.URISyntaxException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Collections;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;


public class ASLanguageManager extends LanguageManager {
private JavaPlugin plugin;
private String jarLanguagePath;
private File languageFolder;
private String wgPrefix;
private List<String> chatPrefix;
private Map<String, List<String>> currentLanguage, defaultLanguage;

public ASLanguageManager(JavaPlugin plugin,
String jarLanguagePath,
String currentLanguageName,
String defaultLanguageName,
List<String> chatPrefix,
String wgPrefix) {
super(plugin, jarLanguagePath, currentLanguageName, defaultLanguageName, chatPrefix);
this.plugin = plugin;
this.jarLanguagePath = jarLanguagePath;
this.chatPrefix = chatPrefix;
this.languageFolder = new File(plugin.getDataFolder() + File.separator + jarLanguagePath);

Message.init(this, plugin.getLogger());
saveDefaults();
currentLanguage = loadLanguage(currentLanguageName);
if (defaultLanguageName.equals(currentLanguageName)) {
defaultLanguage = currentLanguage;
} else {
defaultLanguage = loadLanguage(defaultLanguageName);
}
this.wgPrefix = wgPrefix;
}

@Override
public List<String> getMessage(String key) {
List<String> message;
if (key.equalsIgnoreCase(Message.CHATLANGUAGEVARIABLE)) {
message = chatPrefix;
} else if (key.equalsIgnoreCase("wgPrefix")) {
message = new ArrayList<>();
message.add(wgPrefix);
} else if (currentLanguage.containsKey(key)) {
message = currentLanguage.get(key);
} else {
message = defaultLanguage.get(key);
}
if (message == null) {
Log.warn("Did not find message '" + key + "' in the current or default language");
return new ArrayList<>();
}
return new ArrayList<>(message);
}

private void saveDefaults() {
// Create the language folder if it not exists
if (!languageFolder.exists()) {
if (!languageFolder.mkdirs()) {
Log.warn("Could not create language directory: " + languageFolder.getAbsolutePath());
return;
}
}
File jarPath;
try {
// Read jar as ZIP file
jarPath = new File(plugin.getClass()
.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI());
} catch (URISyntaxException e) {
Log.error("Failed to find location of jar file:", ExceptionUtils.getStackTrace(e));
return;
}
try (ZipFile jar = new ZipFile(jarPath)) {
Enumeration<? extends ZipEntry> entries = jar.entries();

// Each entry is a file or directory
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();

// Filter to YAML files in the language directory
if (!entry.isDirectory() && entry.getName()
.startsWith(jarLanguagePath + "/") && entry.getName()
.endsWith(".yml")) {
// Save the file to disk
File targetFile = new File(languageFolder.getAbsolutePath() + File.separator + entry.getName()
.substring(entry.getName().lastIndexOf("/")));
try (
InputStream input = jar.getInputStream(entry);
OutputStream output = new FileOutputStream(targetFile)
) {
byte[] bytes = input.readAllBytes();
output.write(bytes);
} catch (IOException e) {
Log.warn("Something went wrong saving a default language file: " + targetFile.getAbsolutePath());
}
}
}
} catch (
IOException e) {
Log.error("Failed to read zip file:", ExceptionUtils.getStackTrace(e));
}
}

private Map<String, List<String>> loadLanguage(String key) {
return loadLanguage(key, true);
}

/**
* Loads the specified language
*
* @param key The language to load
* @param convert try conversion or not (infinite recursion prevention)
* @return Map with the messages loaded from the file
*/
private Map<String, List<String>> loadLanguage(String key, boolean convert) {
Map<String, List<String>> result = new HashMap<>();

// Load the language file
boolean convertFromTransifex = false;
File file = new File(languageFolder.getAbsolutePath() + File.separator + key + ".yml");
try (
InputStream inputStream = new FileInputStream(file);
Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)
) {
// Detect empty language files, happens when the YAML parsers prints an exception (it does return an empty YamlConfiguration though)
YamlConfiguration ymlFile = YamlConfiguration.loadConfiguration(reader);
if (ymlFile.getKeys(false).isEmpty()) {
Log.warn("Language file " + key + ".yml has zero messages.");
return result;
}

// Retrieve the messages from the YAML file and create the result
if (convert && Transifex.needsConversion(ymlFile)) {
convertFromTransifex = true;
} else {
for (String messageKey : ymlFile.getKeys(false)) {
List<String> toPut;
if (ymlFile.isList(messageKey)) {
toPut = ymlFile.getStringList(messageKey);
} else {
toPut = Collections.singletonList(ymlFile.getString(messageKey));
}
result.put(messageKey, new ArrayList<>(toPut));
}
}
} catch (IOException e) {
Log.warn("Could not load language file: " + file.getAbsolutePath());
}

// Do conversion (after block above closed the reader)
if (convertFromTransifex) {
if (!Transifex.convertFrom(file)) {
Log.warn("Failed to convert " + file.getName() + " from the Transifex layout to the AreaShop layout, check the errors above");
}
return loadLanguage(key, false);
}

return result;
}
}
Loading

0 comments on commit f283f8b

Please sign in to comment.