Skip to content

Commit

Permalink
Merge pull request #33 from OneLiteFeatherNET/develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
TheMeinerLP authored Dec 5, 2024
2 parents 217fd75 + 048f4e3 commit 4c60f85
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- master
- dev
- develop
jobs:
build:
# Run on all label events (won't be duplicated) or all push events or on PR syncs not from the same repo
Expand Down
82 changes: 56 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import io.papermc.hangarpublishplugin.model.Platforms
import kotlin.system.exitProcess
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import net.minecrell.pluginyml.paper.PaperPluginDescription
import xyz.jpenilla.runpaper.task.RunServer
import kotlin.system.exitProcess

plugins {
id("idea")
id("java")
id("java-library")
id("olf.build-logic")

alias(libs.plugins.shadowJar)
alias(libs.plugins.publishdata)
alias(libs.plugins.paper.run)
alias(libs.plugins.paper.yml)
alias(libs.plugins.hangar)
alias(libs.plugins.modrinth)
alias(libs.plugins.spotless)
alias(libs.plugins.minotaur)
alias(libs.plugins.shadow)
alias(libs.plugins.hangar.publish.plugin)
alias(libs.plugins.plugin.yml.paper)
alias(libs.plugins.run.paper)
id("olf.build-logic")
`maven-publish`
}

if (!File("$rootDir/.git").exists()) {
Expand All @@ -30,43 +29,45 @@ if (!File("$rootDir/.git").exists()) {

allprojects {
group = "net.onelitefeather.bettergopaint"
version = property("projectVersion") as String // from gradle.properties
version = "1.1.0"
}
group = "net.onelitefeather.bettergopaint"

val supportedMinecraftVersions = listOf(
"1.20",
"1.20.1",
"1.20.2",
"1.20.3",
"1.20.4",
"1.20.5",
"1.20.6"
"1.21"
)

repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://maven.enginehub.org/repo/")
}

dependencies {
// Paper / Spigot
compileOnly(libs.paper)
// Fawe / WorldEdit
implementation(platform(libs.fawe.bom))
compileOnlyApi(libs.fawe.bukkit)
compileOnly(libs.fawe.bukkit)
// Utils
implementation(libs.serverlib)
implementation(libs.paperlib)
implementation(libs.semver)
// Stats
implementation(libs.bstats)
// Commands
implementation(libs.cloud.annotations)
implementation(libs.cloud.minecraft.extras)
implementation(libs.cloud.paper)
annotationProcessor(libs.cloud.annotations)
implementation(libs.cloud.command.annotations)
implementation(libs.cloud.command.extras)
implementation(libs.cloud.command.paper)
annotationProcessor(libs.cloud.command.annotations)
}

publishData {
useEldoNexusRepos(false)
publishTask("shadowJar")
}


paper {
name = "BetterGoPaint"
main = "net.onelitefeather.bettergopaint.BetterGoPaint"
Expand All @@ -87,6 +88,12 @@ paper {
register("bettergopaint.command.admin.reload") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("bettergopaint.notify.admin.update") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("bettergopaint.notify.disable.donation") {
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("bettergopaint.use") {
default = BukkitPluginDescription.Permission.Default.OP
}
Expand Down Expand Up @@ -145,7 +152,7 @@ tasks {
}

val branch = rootProject.branchName()
val baseVersion = project.version as String
val baseVersion = publishData.getVersion(false)
val isRelease = !baseVersion.contains('-')
val isMainBranch = branch == "master"
if (!isRelease || isMainBranch) { // Only publish releases from the main branch
Expand All @@ -159,7 +166,7 @@ if (!isRelease || isMainBranch) { // Only publish releases from the main branch
hangarPublish {
publications.register("BetterGoPaint") {
version.set(suffixedVersion)
channel.set(if (isRelease) "Release" else if (isMainBranch) "Snapshot" else "Alpha")
channel.set(if (isRelease) "Release" else "Snapshot")
changelog.set(changelogContent)
apiKey.set(System.getenv("HANGAR_SECRET"))
id.set("BetterGoPaint")
Expand All @@ -175,7 +182,7 @@ if (!isRelease || isMainBranch) { // Only publish releases from the main branch
modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("qf7sNg9A")
versionType.set(if (isRelease) "release" else if (isMainBranch) "beta" else "alpha")
versionType.set(if (isRelease) "release" else "beta")
versionNumber.set(suffixedVersion)
versionName.set(suffixedVersion)
changelog.set(changelogContent)
Expand All @@ -186,3 +193,26 @@ if (!isRelease || isMainBranch) { // Only publish releases from the main branch
loaders.add("folia")
}
}

publishing {
publications.create<MavenPublication>("maven") {
// Configure our maven publication
publishData.configurePublication(this)
}

repositories {
// We add EldoNexus as our repository. The used url is defined by the publish data.
maven {
authentication {
credentials(PasswordCredentials::class) {
// Those credentials need to be set under "Settings -> Secrets -> Actions" in your repository
username = System.getenv("ELDO_USERNAME")
password = System.getenv("ELDO_PASSWORD")
}
}

name = "EldoNexus"
setUrl(publishData.getRepository())
}
}
}
3 changes: 3 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files:
- source: src/main/resources/bettergopaint.properties
translation: /src/main/resources/bettergopaint_%locale_with_underscore%.properties
25 changes: 0 additions & 25 deletions gradle/libs.versions.toml

This file was deleted.

52 changes: 52 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
rootProject.name = "BetterGoPaint"
includeBuild("build-logic")

pluginManagement {
repositories {
maven("https://eldonexus.de/repository/maven-public/")
gradlePluginPortal()
}
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("publishdata", "1.4.0")
version("modrinth", "2.+")
version("hangar", "0.1.2")
version("paper.yml", "0.6.0")
version("paper.run", "2.3.0")
version("shadowJar", "8.1.1")
version("intellectualsites", "1.51")

version("paper", "1.21.3-R0.1-SNAPSHOT")
version("bstats", "3.0.2")

version("cloudcommand", "2.0.0-SNAPSHOT")

version("adventure", "4.17.0")
version("semver", "0.10.2")

library("paper", "io.papermc.paper", "paper-api").versionRef("paper")
library("minimessage", "net.kyori", "adventure-text-minimessage").versionRef("adventure")
library("bstats", "org.bstats", "bstats-bukkit").versionRef("bstats")

library("fawe.bom", "com.intellectualsites.bom", "bom-newest").versionRef("intellectualsites")
library("fawe.bukkit", "com.fastasyncworldedit", "FastAsyncWorldEdit-Bukkit").withoutVersion()
library("serverlib", "dev.notmyfault.serverlib", "ServerLib").withoutVersion()
library("paperlib", "io.papermc", "paperlib").withoutVersion()

library("cloud.command.paper", "org.incendo", "cloud-paper").versionRef("cloudcommand")
library("cloud.command.annotations", "org.incendo", "cloud-annotations").versionRef("cloudcommand")
library("cloud.command.extras", "org.incendo", "cloud-minecraft-extras").versionRef("cloudcommand")

library("semver", "com.github.zafarkhaja", "java-semver").versionRef("semver")

plugin("publishdata","de.chojo.publishdata").versionRef("publishdata")
plugin("modrinth", "com.modrinth.minotaur").versionRef("modrinth")
plugin("hangar", "io.papermc.hangar-publish-plugin").versionRef("hangar")
plugin("paper.yml", "net.minecrell.plugin-yml.paper").versionRef("paper.yml")
plugin("paper.run", "xyz.jpenilla.run-paper").versionRef("paper.run")
plugin("shadowJar", "com.github.johnrengelman.shadow").versionRef("shadowJar")
plugin("spotless", "com.diffplug.spotless").version("6.18.0")
}
}
}
73 changes: 67 additions & 6 deletions src/main/java/net/onelitefeather/bettergopaint/BetterGoPaint.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@
package net.onelitefeather.bettergopaint;

import com.fastasyncworldedit.core.Fawe;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.translation.TranslationRegistry;
import net.kyori.adventure.util.UTF8ResourceBundleControl;
import net.onelitefeather.bettergopaint.brush.PlayerBrushManager;
import net.onelitefeather.bettergopaint.command.GoPaintCommand;
import net.onelitefeather.bettergopaint.command.ReloadCommand;
import net.onelitefeather.bettergopaint.listeners.ConnectListener;
import net.onelitefeather.bettergopaint.listeners.InteractListener;
import net.onelitefeather.bettergopaint.listeners.InventoryListener;
import net.onelitefeather.bettergopaint.objects.other.Settings;
import net.onelitefeather.bettergopaint.service.UpdateService;
import net.onelitefeather.bettergopaint.translations.PluginTranslationRegistry;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
Expand All @@ -44,19 +51,24 @@
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.logging.Level;

public class BetterGoPaint extends JavaPlugin implements Listener {

public static final String PAPER_DOCS = "https://jd.papermc.io/paper/1.20.6/org/bukkit/Material.html#enum-constant-summary";
public static final String USE_PERMISSION = "bettergopaint.use";
public static final String ADMIN_PERMISSION = "bettergopaint.admin";
public static final String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
public static final String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";

private final PlayerBrushManager brushManager = new PlayerBrushManager();
private final Metrics metrics = new Metrics(this, 18734);
private UpdateService updateService;

@Override
public void onLoad() {
Expand All @@ -81,6 +93,30 @@ public void onEnable() {

reloadConfig();

final TranslationRegistry translationRegistry = new PluginTranslationRegistry(TranslationRegistry.create(Key.key("bettergopaint", "translations")));
translationRegistry.defaultLocale(Locale.US);
Path langFolder = getDataFolder().toPath().resolve("lang");
var languages = new HashSet<>(Settings.settings().generic.LANGUAGES);
languages.add("en-US");
if (Files.exists(langFolder)) {
try (var urlClassLoader = new URLClassLoader(new URL[]{langFolder.toUri().toURL()})) {
languages.stream().map(Locale::forLanguageTag).forEach(r -> {
var bundle = ResourceBundle.getBundle("bettergopaint", r, urlClassLoader, UTF8ResourceBundleControl.get());
translationRegistry.registerAll(r, bundle, false);
});
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
languages.stream().map(Locale::forLanguageTag).forEach(r -> {
var bundle = ResourceBundle.getBundle("bettergopaint", r, UTF8ResourceBundleControl.get());
translationRegistry.registerAll(r, bundle, false);
});
}
GlobalTranslator.translator().addSource(translationRegistry);
donationInformation();


Material brush = Settings.settings().generic.DEFAULT_BRUSH;
if (!brush.isItem()) {
getComponentLogger().error("{} is not a valid default brush, it has to be an item", brush.name());
Expand All @@ -95,17 +131,34 @@ public void onEnable() {

registerListeners();
registerCommands();
updateService();
}

@Override
public void onDisable() {
metrics.shutdown();
this.updateService.shutdown();
}

public void reloadConfig() {
Settings.settings().reload(this, new File(getDataFolder(), "config.yml"));
try {
Files.createDirectories(getDataFolder().toPath());
final Path resolve = getDataFolder().toPath().resolve("config.yml");
Settings.settings().save(resolve.toFile());
Settings.settings().load(resolve.toFile());
} catch (IOException e) {
getLogger().log(Level.SEVERE, "Cannot init config", e);
}

}

private void updateService() {
this.updateService = new UpdateService(this);
this.updateService.run();
this.updateService.notifyConsole(getComponentLogger());
}


@SuppressWarnings("UnstableApiUsage")
private void registerCommands() {
Bukkit.getCommandMap().register("gopaint", getPluginMeta().getName(), new GoPaintCommand(this));
Expand All @@ -121,13 +174,17 @@ private void registerListeners() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new InventoryListener(getBrushManager()), this);
pm.registerEvents(new InteractListener(this), this);
pm.registerEvents(new ConnectListener(getBrushManager()), this);
pm.registerEvents(new ConnectListener(getBrushManager(), this), this);
}

private boolean hasOriginalGoPaint() {
return getServer().getPluginManager().getPlugin("goPaint") != this;
}

private void donationInformation() {
getComponentLogger().info(Component.translatable("bettergopaint.notify.donation.console"));
}

private @Nullable AnnotationParser<CommandSender> enableCommandSystem() {
try {
LegacyPaperCommandManager<CommandSender> commandManager = LegacyPaperCommandManager.createNative(
Expand All @@ -150,4 +207,8 @@ private boolean hasOriginalGoPaint() {
return brushManager;
}

public UpdateService getUpdateService() {
return updateService;
}

}
Loading

0 comments on commit 4c60f85

Please sign in to comment.