Compare commits

..

14 commits

Author SHA1 Message Date
fda211fe5b
progress on translation system 2026-08-16 20:43:39 +02:00
6e61ac815f
fix small translation issue 2026-08-16 19:16:08 +02:00
8a00cc1f92
rework multiline 2026-08-16 19:16:08 +02:00
35e0b34ecf
finished adding command text to trans file 2026-08-16 19:16:08 +02:00
743fd5d891
better translation system 2026-08-16 19:16:07 +02:00
de86fe16ba
translation key for load errors and warnings 2026-08-16 19:16:07 +02:00
948c49a719
language backend logic 2026-08-16 19:16:07 +02:00
64edb99ce0
use provider for hangar changelog
Some checks are pending
Java CI with Gradle / build (push) Waiting to run
2026-08-16 18:59:39 +02:00
4b3fd76dd0
make configuration cache work
Some checks are pending
Java CI with Gradle / build (push) Waiting to run
2026-08-16 18:19:26 +02:00
fc4df29033
suppress or remove most warnings 2026-08-16 10:51:14 +02:00
6ea8430247
update a bunch of stuff in gradle 2026-08-16 10:21:09 +02:00
ca89b0d095
go back to old datapack manager 2026-08-16 08:54:08 +02:00
6c4991f852
fix gradlew and up to 9.7.0, upgrade to java 21 [skip ci]
version bump to 2.0.2
2026-08-16 08:31:37 +02:00
643a5e9a8c
fix eco enchant again
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
2026-08-14 00:40:52 +02:00
36 changed files with 187 additions and 116 deletions

View file

@ -5,24 +5,23 @@ import groovy.util.NodeList
import io.papermc.hangarpublishplugin.model.HangarPublication
import io.papermc.hangarpublishplugin.model.Platforms
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.io.ByteArrayOutputStream
plugins {
kotlin("jvm") version "2.3.0"
kotlin("jvm") version "2.4.0"
java
id("org.jetbrains.dokka").version("1.9.20")
id("com.gradleup.shadow").version("9.3.0")
id("org.jetbrains.dokka").version("2.2.0")
id("com.gradleup.shadow").version("9.6.1")
// Maven publish
`maven-publish`
signing
id("cn.lalaki.central").version("1.2.8")
id("cn.lalaki.central").version("2.0.8")
// Paper
id("io.papermc.paperweight.userdev") version "2.0.0-beta.17" apply false
id("io.papermc.hangar-publish-plugin") version "0.1.2"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" apply false
id("io.papermc.hangar-publish-plugin") version "0.1.4"
}
group = "xyz.alexcrea"
version = "2.0.0"
version = "2.0.2"
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
@ -158,16 +157,16 @@ allprojects {
// Set target version
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility =
"16" // We aim for java 16 for minecraft 1.16.5. even if it not really supported by custom anvil.
targetCompatibility = "16"
"21" // We aim for java 21 for minecraft 1.21.0
targetCompatibility = "21"
options.encoding = "UTF-8"
}
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
jvmTarget.set(JvmTarget.JVM_16)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}
@ -178,7 +177,10 @@ tasks {
fun ShadowJar.configureBaseShadow(suffix: String, libraries: Array<String>) {
val processedSuffix = if(suffix.isEmpty()) "" else "-$suffix"
val name = "${rootProject.name}-${effectiveVersion}${processedSuffix}.jar"
val version = effectiveVersion
val name = "${rootProject.name}-${version}${processedSuffix}.jar"
val librariesExpendTo = libraries.joinToString(transform = { "\"$it\"" })
archiveFileName.set(name)
// Shadow necessary dependency
@ -187,8 +189,8 @@ tasks {
filesMatching("plugin.yml") {
expand(
"version" to effectiveVersion + processedSuffix,
"libraries" to libraries.joinToString(transform = { "\"$it\"" }),
"version" to version + processedSuffix,
"libraries" to librariesExpendTo,
)
}
@ -200,7 +202,7 @@ tasks {
shadowJar {
configureBaseShadow("",
arrayOf(
"org.jetbrains.kotlin:kotlin-stdlib:2.3.0",
"org.jetbrains.kotlin:kotlin-stdlib:2.4.0",
"net.kyori:adventure-text-minimessage:4.25.0",
"net.kyori:adventure-text-serializer-plain:4.25.0",
"net.kyori:adventure-text-serializer-legacy:4.25.0",
@ -212,7 +214,7 @@ tasks {
exclude("net/kyori/**")
}
val offlineJar by registering(ShadowJar::class) {
val offlineJar = register<ShadowJar>("offlineJar") {
configureBaseShadow("offline", emptyArray())
from(sourceSets.main.get().output)
@ -226,12 +228,12 @@ tasks {
}
val sourcesJar by tasks.registering(Jar::class) {
val sourcesJar = tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from(kotlin.sourceSets.main.get().kotlin)
}
val javadocJar by tasks.registering(Jar::class, fun Jar.() {
val javadocJar = tasks.register<Jar>("javadocJar", fun Jar.() {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Javadoc JAR"
archiveClassifier.set("javadoc")
@ -355,36 +357,25 @@ publishing {
}
// hangar publish
fun executeGitCommand(vararg command: String): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", *command)
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
fun latestCommitMessage(): Provider<String> {
return providers.exec {
commandLine("git", "log", "-1", "--pretty=%B")
}.standardOutput.asText.map(String::trim)
}
fun latestCommitMessage(): String {
return executeGitCommand("log", "-1", "--pretty=%B")
}
fun changelog(isOnline: Boolean): String {
var changelog = if(isDevBuild) latestCommitMessage()
else System.getenv("RELEASE_CHANGELOG")
if(!isOnline) {
changelog = "This is an offline version of the plugin. \\\n" +
"This mean that this plugin libraries are shaded into this plugin \\\n" +
"You likely want to use the normal version of this plugin\n\n" + changelog
}
if(changelog == null || changelog.isEmpty()) {
changelog = "empty changelog"
}
fun changelog(isOnline: Boolean): Provider<String> {
val changelog = if(isDevBuild) latestCommitMessage()
else providers.environmentVariable("RELEASE_CHANGELOG")
return changelog
.filter{!it.isEmpty()}
.map {
if(!isOnline)
return@map "This is an offline version of the plugin. \\\n" +
"This mean that this plugin libraries are shaded into this plugin \\\n" +
"You likely want to use the normal version of this plugin\n\n" + it
else return@map it
}.orElse("empty changelog")
}
hangarPublish {
@ -395,11 +386,12 @@ hangarPublish {
if(!isOnline) versionName+= "-offline"
version.set(versionName)
var releaseChannel = if (isDevBuild || isPreRelease) devChannel else releaseChannel
if(releaseChannel == null) return
channel.set(releaseChannel)
var finalReleaseChannel = if (isDevBuild || isPreRelease) devChannel else releaseChannel
if(finalReleaseChannel == null) return
channel.set(finalReleaseChannel)
changelog.set(changelog(isOnline))
id.set("CustomAnvil")
apiKey.set(System.getenv("HANGAR_API_TOKEN"))

View file

@ -1,4 +1,5 @@
kotlin.code.style=official
org.gradle.configuration-cache=true
# Signing
signing.secretKeyRingFile=~/.gnupg/secring.gpg

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -2,7 +2,7 @@ group = rootProject.group
version = rootProject.version
plugins {
kotlin("jvm") version "2.3.0"
kotlin("jvm") version "2.4.0"
}
repositories {

View file

@ -2,7 +2,7 @@ group = rootProject.group
version = rootProject.version
plugins {
kotlin("jvm") version "2.3.0"
kotlin("jvm") version "2.4.0"
}
// Imitate needed class and method to support legacy version of EcoEnchant

View file

@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -1,20 +1,39 @@
@file:Suppress("DEPRECATION", "removal")
package xyz.alexcrea.cuanvil.dependency.datapack
import io.papermc.paper.datapack.Datapack
import org.bukkit.Bukkit
import org.bukkit.packs.DataPack
import java.util.*
object DataPackTester {
val legacyNames: List<String>
get() = Bukkit.getDataPackManager().dataPacks
.stream().filter { obj -> obj.isEnabled }
.map { pack -> pack.key.key }
.toList()
val enabledPacks: List<String>
get() {
return try {
Bukkit.getDatapackManager().enabledPacks
try {
// will throw error if do not exist
Bukkit::class.java.getDeclaredMethod("getDatapackManager")
return Bukkit.getDatapackManager().enabledPacks
.stream().map { obj: Datapack -> obj.name }
.toList()
} catch(_: NoSuchMethodException) {
try {
DataPack::class.java.getDeclaredMethod("getKey")
} catch(_: NoSuchMethodException) {
System.err.println("Could not find compatible datapack manager")
System.err.println("If you are using a datapack that should be compatible with CustomAnvil. It will not get detected...")
return emptyList()
}
return legacyNames
} catch(_: Exception) {
// Assume cause UnimplementedOperationException on mock server
Collections.emptyList()
return Collections.emptyList()
}
}
}

View file

@ -13,6 +13,7 @@ object AnvilTitleUtil {
private val runTaskMap = HashMap<UUID, ScheduledTask>()
@Suppress("DEPRECATION")
private fun actualRename(view: AnvilView, name: String, player: HumanEntity, anvilDialog: AnvilRenameDialog) {
runTaskMap.remove(player.uniqueId)
if (view.title == name) return

View file

@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
kotlin {
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
jvmTarget.set(JvmTarget.JVM_21)
}
}

View file

@ -11,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.Arrays;
@ -33,7 +34,7 @@ public class ConfirmActionGui extends AbstractAskGui {
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
@ -47,7 +48,7 @@ public class ConfirmActionGui extends AbstractAskGui {
}
if (!success) {
event.getWhoClicked().sendMessage("§cAction could not be completed. ");
MsgUI.INSTANCE.getCONFIRM_ACTION_FAILED().send(player);
}
backOnConfirm.show(player);

View file

@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.MaterialUtil;
import java.util.Arrays;
@ -36,7 +37,7 @@ public class SelectItemTypeGui extends AbstractAskGui {
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}

View file

@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.util.Arrays;
import java.util.HashMap;
@ -52,13 +53,12 @@ public abstract class MappedElementListConfigGui<T, S> extends ElementListConfig
// check permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
player.closeInventory();
player.sendMessage("§eWrite the " + genericDisplayedName() + " name you want to create in the chat.\n" +
"§eOr write §ccancel §eto go back to " + genericDisplayedName() + " config menu");
MsgUI.INSTANCE.getELEMENT_LIST_INSTRUCTION_NEW().send(player, genericDisplayedName());
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));

View file

@ -8,6 +8,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.LazyValue;
import java.util.Locale;
@ -69,13 +70,13 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
// check permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
message = message.toLowerCase(Locale.ROOT);
if ("cancel".equalsIgnoreCase(message)) {
player.sendMessage(genericDisplayedName() + " creation cancelled...");
MsgUI.INSTANCE.getELEMENT_LIST_CANCELLED_NEW().send(player, genericDisplayedName());
show(player);
return;
}
@ -86,7 +87,7 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
// Not the most efficient on large number of conflict, but it should not run often.
for (T generic : getDisplayableInstanceOfGeneric()) {
if (generic.toString().equalsIgnoreCase(message)) {
player.sendMessage("§cPlease enter a " + genericDisplayedName() + " name that do not already exist...");
MsgUI.INSTANCE.getELEMENT_LIST_DUPLICATED_NEW().send(player, genericDisplayedName());
// wait next message.
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
return;

View file

@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MaterialUtil;
@ -70,11 +71,11 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack);
if (!(meta instanceof Damageable)) {
player.sendMessage("§cThis item can't be damaged, so it can't be repaired.");
MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW().send(player);
return;
}
if (type.equals(this.parentMaterial)) {
player.sendMessage("§cItem can't repair something of the same type.");
MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_SAME_TYPE_NEW().send(player);
return;
}

View file

@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.MaterialSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.*;
@ -113,7 +114,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
// test if group is used & cancel & warn user if so

View file

@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MaterialUtil;
@ -156,7 +157,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Namespa
// Do not allow to save configuration if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
if(testCantSave()) return;

View file

@ -16,6 +16,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.config.WorkPenaltyType;
import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.util.ArrayList;
import java.util.EnumMap;
@ -73,7 +74,7 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
new WorkPenaltyTypeSettingGui(parent).show(player);

View file

@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -17,8 +18,6 @@ import java.util.function.Consumer;
*/
public class GuiGlobalActions {
public static final String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
/**
* A Consumer that should be used if the item goal is to do nothing on click.
*/
@ -44,7 +43,7 @@ public class GuiGlobalActions {
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
try {
@ -102,7 +101,7 @@ public class GuiGlobalActions {
// Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}
goal.show(player);
@ -127,7 +126,7 @@ public class GuiGlobalActions {
// Do not allow to save configuration if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory();
player.sendMessage(NO_EDIT_PERM);
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return;
}

View file

@ -7,7 +7,6 @@ import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import xyz.alexcrea.cuanvil.lang.MsgCommand
import xyz.alexcrea.cuanvil.util.MetricsUtil
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {

View file

@ -10,9 +10,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
import xyz.alexcrea.cuanvil.lang.Message
import xyz.alexcrea.cuanvil.lang.MsgCommand
import xyz.alexcrea.cuanvil.lang.MsgUI
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
@ -35,7 +35,7 @@ class EditConfigExecutor : CASubCommand {
if(sender !is HumanEntity) return false
if(!allowed(sender)) {
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
MsgUI.SHARED_CONFIG_NO_EDIT_PERM.send(sender)
return false
}
if(PlatformUtil.isFolia) {

View file

@ -28,9 +28,10 @@ import xyz.alexcrea.cuanvil.dependency.scheduler.FoliaScheduler
import xyz.alexcrea.cuanvil.dependency.scheduler.TaskScheduler
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
import xyz.alexcrea.cuanvil.lang.MsgWarning
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
import java.lang.reflect.Constructor
import java.lang.IllegalStateException
import java.util.logging.Level
@Suppress("UnstableApiUsage")
@ -158,18 +159,14 @@ object DependencyManager {
}
private fun logException(target: CommandSender, e: Exception) {
CustomAnvil.instance.logger.log(
Level.SEVERE,
CustomAnvil.logError(
"Error while trying to handle custom anvil supported plugin: ",
e
)
trackError(e)
// Finally, warn the player
target.sendMessage(
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
)
MsgWarning.DEPENDENCY_GENERIC_EXCEPTION.send(target)
}
private fun logExceptionAndClear(view: AnvilView, e: Exception) {
@ -337,10 +334,14 @@ object DependencyManager {
private val prepareAnvilConstructor =
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
PrepareAnvilEvent::class.java.constructors.first()
fun createFakeEvent(view: AnvilView, result: ItemStack?): PrepareAnvilEvent {
return prepareAnvilConstructor.newInstance(view, result)
val result = prepareAnvilConstructor.newInstance(view, result)
if(result !is PrepareAnvilEvent)
throw IllegalStateException("Could not create a PrepareAnvilEvent ?")
return result
}
}

View file

@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchant.EcoEnchant
import com.willfp.ecoenchants.enchant.EcoEnchants
import com.willfp.ecoenchants.enchant.UtilKt
import io.delilaheve.CustomAnvil
import org.bukkit.Bukkit
import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.plugin.Plugin
import xyz.alexcrea.cuanvil.api.EnchantmentApi
@ -34,12 +35,14 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
}
public fun getEcoLevelLimit(): Int {
fun getEcoLevelLimit(): Int {
return UtilKt.infiniteIfNegative((ecoEnchantPlugin as EcoPlugin).configYml.getInt("anvil.enchant-limit"))
}
fun disableAnvilListener() {
PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin)
// I don't like that but modern ee use eco prepare anvil event
PrepareAnvilEvent.getHandlerList().unregister(Bukkit.getPluginManager().getPlugin("eco")!!)
}
private var ecoEnchantOldEnchantments: MutableSet<EcoEnchant>? = null

View file

@ -6,6 +6,7 @@ import org.bukkit.NamespacedKey
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.Plugin
@Suppress("DEPRECATION")
class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
var isLoaded: Boolean = false
get() {

View file

@ -10,13 +10,20 @@ class LegacyEcoEnchantDependency {
private var ecoEnchantOldEnchantments: MutableSet<EcoEnchant>? = null
private fun unregisterEnchantment(enchant: Any) {
EnchantmentApi.unregisterEnchantment((enchant as Enchantment).key)
}
private fun registerEnchantment(ecoEnchant: EcoEnchant, enchant: Any) {
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, enchant as Enchantment))
}
fun registerEnchantments() {
val enchantments = EcoEnchants.values()
for (ecoEnchant in enchantments) {
ecoEnchant as Enchantment
EnchantmentApi.unregisterEnchantment(ecoEnchant) // As eco enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, ecoEnchant))
// As eco enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant.
unregisterEnchantment(ecoEnchant)
registerEnchantment(ecoEnchant, ecoEnchant)
}
ecoEnchantOldEnchantments = HashSet(enchantments)
@ -31,13 +38,13 @@ class LegacyEcoEnchantDependency {
// Add new enchantments
for (ecoEnchant in newEnchantments)
if (!this.ecoEnchantOldEnchantments!!.contains(ecoEnchant))
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, ecoEnchant as Enchantment))
registerEnchantment(ecoEnchant, ecoEnchant)
// Remove old enchantments that not now currently used
this.ecoEnchantOldEnchantments!!.removeAll(newEnchantments)
for (oldEnchantment in this.ecoEnchantOldEnchantments!!) {
EnchantmentApi.unregisterEnchantment(oldEnchantment as Enchantment)
unregisterEnchantment(oldEnchantment)
}
this.ecoEnchantOldEnchantments = HashSet(newEnchantments)

View file

@ -18,9 +18,13 @@ class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
getTokenMethod.trySetAccessible()
}
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<String> {
if (item == null) return arrayOf()
return getTokenMethod.invoke(this, item) as Array<String>
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<*> {
if (item == null) return arrayOf<Any>()
val result = getTokenMethod.invoke(this, item)
if(result !is Array<*>)
throw IllegalStateException("Could not get token from ToolStats")
return result
}
override fun testAnvilResult(event: InventoryClickEvent): Boolean {

View file

@ -144,4 +144,4 @@ class ErrorMessage(key: String, vararg params: String) : Message("error.$key", *
}
class CommandMessage(key: String, vararg params: String) : Message("command.$key", *params)
class UIMessage(key: String, vararg params: String) : Message("ui.$key", *params)
class UIMessage(key: String, vararg params: String) : Message("config-ui.$key", *params)

View file

@ -1,6 +1,21 @@
package xyz.alexcrea.cuanvil.lang
import xyz.alexcrea.cuanvil.lang.UIMessage as Message
object MsgUI {
val SHARED_CONFIG_NO_EDIT_PERM = Message("shared.no-permission")
val CONFIRM_ACTION_FAILED = Message("confirm-action.fail")
val ELEMENT_LIST_INSTRUCTION_NEW = Message("element-list.instruction-new", "type")
val ELEMENT_LIST_CANCELLED_NEW = Message("element-list.cancelled-new", "type")
val ELEMENT_LIST_DUPLICATED_NEW = Message("element-list.duplicated-new", "type")
val UNIT_REPAIR_ELEMENT_TITLE = Message("unit-repair.element.title")
val UNIT_REPAIR_ELEMENT_DESCRIPTION = Message("unit-repair.element.description")
val UNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW = Message("unit-repair.element.cannot-damage-new")
val UNIT_REPAIR_ELEMENT_SAME_TYPE_NEW = Message("unit-repair.element.same-type-new")
}

View file

@ -15,4 +15,6 @@ object MsgWarning {
val LOAD_LEGACY_SPIGOT = Message("load.legacy.spigot")
val LOAD_LEGACY_SPIGOT_OLD = Message("load.legacy.spigot-old")
val DEPENDENCY_GENERIC_EXCEPTION = Message("config-ui.shared.no-permission")
}

View file

@ -90,3 +90,23 @@ command:
success: "<green>Config reloaded !"
fail: "<red>Config was not able to be reloaded..."
hard-fail: "<red>Hard fail, plugin disabled"
config-ui:
shared:
no-permission: "<red>You do not have permission to edit the config"
confirm-action:
fail: "<red>Action could not be completed."
element-list:
instruction-new:
1: "<yellow>Write the %type name you want to create in the chat."
2: "<yellow>Or write <red>cancel <yellow>to go back to %type config menu"
cancelled-new: "%type creation cancelled..."
duplicated-new: "<red>Please enter a %type name that do not already exist..."
unit-repair:
element:
title: "Select item to be repaired."
description:
1: "<gray>Click here with an item to set the item"
2: "<gray>You like to be repaired by %name"
cannot-damage-new: "<red>This item can't be damaged, so it can't be repaired."
same-type-new: "<red>Item can't repair something of the same type."