mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
Compare commits
6 commits
fda211fe5b
...
162b171a89
| Author | SHA1 | Date | |
|---|---|---|---|
| 162b171a89 | |||
| ded892f2ec | |||
| 703bf40449 | |||
| 640bd1bfd8 | |||
| 1e0e8d5f6d | |||
| bef2dfdc2f |
36 changed files with 116 additions and 187 deletions
|
|
@ -5,23 +5,24 @@ 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.4.0"
|
||||
kotlin("jvm") version "2.3.0"
|
||||
java
|
||||
id("org.jetbrains.dokka").version("2.2.0")
|
||||
id("com.gradleup.shadow").version("9.6.1")
|
||||
id("org.jetbrains.dokka").version("1.9.20")
|
||||
id("com.gradleup.shadow").version("9.3.0")
|
||||
// Maven publish
|
||||
`maven-publish`
|
||||
signing
|
||||
id("cn.lalaki.central").version("2.0.8")
|
||||
id("cn.lalaki.central").version("1.2.8")
|
||||
// Paper
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" apply false
|
||||
id("io.papermc.hangar-publish-plugin") version "0.1.4"
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.17" apply false
|
||||
id("io.papermc.hangar-publish-plugin") version "0.1.2"
|
||||
}
|
||||
|
||||
group = "xyz.alexcrea"
|
||||
version = "2.0.2"
|
||||
version = "2.0.0"
|
||||
|
||||
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
|
||||
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
|
||||
|
|
@ -157,16 +158,16 @@ allprojects {
|
|||
// Set target version
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility =
|
||||
"21" // We aim for java 21 for minecraft 1.21.0
|
||||
targetCompatibility = "21"
|
||||
"16" // We aim for java 16 for minecraft 1.16.5. even if it not really supported by custom anvil.
|
||||
targetCompatibility = "16"
|
||||
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_16)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,10 +178,7 @@ tasks {
|
|||
|
||||
fun ShadowJar.configureBaseShadow(suffix: String, libraries: Array<String>) {
|
||||
val processedSuffix = if(suffix.isEmpty()) "" else "-$suffix"
|
||||
val version = effectiveVersion
|
||||
val name = "${rootProject.name}-${version}${processedSuffix}.jar"
|
||||
val librariesExpendTo = libraries.joinToString(transform = { "\"$it\"" })
|
||||
|
||||
val name = "${rootProject.name}-${effectiveVersion}${processedSuffix}.jar"
|
||||
archiveFileName.set(name)
|
||||
|
||||
// Shadow necessary dependency
|
||||
|
|
@ -189,8 +187,8 @@ tasks {
|
|||
|
||||
filesMatching("plugin.yml") {
|
||||
expand(
|
||||
"version" to version + processedSuffix,
|
||||
"libraries" to librariesExpendTo,
|
||||
"version" to effectiveVersion + processedSuffix,
|
||||
"libraries" to libraries.joinToString(transform = { "\"$it\"" }),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +200,7 @@ tasks {
|
|||
shadowJar {
|
||||
configureBaseShadow("",
|
||||
arrayOf(
|
||||
"org.jetbrains.kotlin:kotlin-stdlib:2.4.0",
|
||||
"org.jetbrains.kotlin:kotlin-stdlib:2.3.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",
|
||||
|
|
@ -214,7 +212,7 @@ tasks {
|
|||
exclude("net/kyori/**")
|
||||
}
|
||||
|
||||
val offlineJar = register<ShadowJar>("offlineJar") {
|
||||
val offlineJar by registering(ShadowJar::class) {
|
||||
configureBaseShadow("offline", emptyArray())
|
||||
|
||||
from(sourceSets.main.get().output)
|
||||
|
|
@ -228,12 +226,12 @@ tasks {
|
|||
|
||||
}
|
||||
|
||||
val sourcesJar = tasks.register<Jar>("sourcesJar") {
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
archiveClassifier.set("sources")
|
||||
from(kotlin.sourceSets.main.get().kotlin)
|
||||
}
|
||||
|
||||
val javadocJar = tasks.register<Jar>("javadocJar", fun Jar.() {
|
||||
val javadocJar by tasks.registering(Jar::class, fun Jar.() {
|
||||
group = JavaBasePlugin.DOCUMENTATION_GROUP
|
||||
description = "Assembles Javadoc JAR"
|
||||
archiveClassifier.set("javadoc")
|
||||
|
|
@ -357,25 +355,36 @@ publishing {
|
|||
}
|
||||
|
||||
// hangar publish
|
||||
fun latestCommitMessage(): Provider<String> {
|
||||
return providers.exec {
|
||||
commandLine("git", "log", "-1", "--pretty=%B")
|
||||
}.standardOutput.asText.map(String::trim)
|
||||
|
||||
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 changelog(isOnline: Boolean): Provider<String> {
|
||||
val changelog = if(isDevBuild) latestCommitMessage()
|
||||
else providers.environmentVariable("RELEASE_CHANGELOG")
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -386,12 +395,11 @@ hangarPublish {
|
|||
if(!isOnline) versionName+= "-offline"
|
||||
|
||||
version.set(versionName)
|
||||
var finalReleaseChannel = if (isDevBuild || isPreRelease) devChannel else releaseChannel
|
||||
if(finalReleaseChannel == null) return
|
||||
channel.set(finalReleaseChannel)
|
||||
var releaseChannel = if (isDevBuild || isPreRelease) devChannel else releaseChannel
|
||||
if(releaseChannel == null) return
|
||||
channel.set(releaseChannel)
|
||||
|
||||
changelog.set(changelog(isOnline))
|
||||
|
||||
id.set("CustomAnvil")
|
||||
apiKey.set(System.getenv("HANGAR_API_TOKEN"))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
kotlin.code.style=official
|
||||
org.gradle.configuration-cache=true
|
||||
|
||||
# Signing
|
||||
signing.secretKeyRingFile=~/.gnupg/secring.gpg
|
||||
|
|
|
|||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ group = rootProject.group
|
|||
version = rootProject.version
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.0"
|
||||
kotlin("jvm") version "2.3.0"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ group = rootProject.group
|
|||
version = rootProject.version
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.0"
|
||||
kotlin("jvm") version "2.3.0"
|
||||
}
|
||||
|
||||
// Imitate needed class and method to support legacy version of EcoEnchant
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,20 @@
|
|||
@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() {
|
||||
try {
|
||||
// will throw error if do not exist
|
||||
Bukkit::class.java.getDeclaredMethod("getDatapackManager")
|
||||
|
||||
return Bukkit.getDatapackManager().enabledPacks
|
||||
return try {
|
||||
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
|
||||
return Collections.emptyList()
|
||||
Collections.emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ 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
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_4)
|
||||
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
|
@ -34,7 +33,7 @@ public class ConfirmActionGui extends AbstractAskGui {
|
|||
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ public class ConfirmActionGui extends AbstractAskGui {
|
|||
}
|
||||
|
||||
if (!success) {
|
||||
MsgUI.INSTANCE.getCONFIRM_ACTION_FAILED().send(player);
|
||||
event.getWhoClicked().sendMessage("§cAction could not be completed. ");
|
||||
}
|
||||
backOnConfirm.show(player);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ 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;
|
||||
|
|
@ -37,7 +36,7 @@ public class SelectItemTypeGui extends AbstractAskGui {
|
|||
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
|
@ -53,12 +52,13 @@ public abstract class MappedElementListConfigGui<T, S> extends ElementListConfig
|
|||
// check permission
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
player.closeInventory();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
player.closeInventory();
|
||||
|
||||
MsgUI.INSTANCE.getELEMENT_LIST_INSTRUCTION_NEW().send(player, genericDisplayedName());
|
||||
player.sendMessage("§eWrite the " + genericDisplayedName() + " name you want to create in the chat.\n" +
|
||||
"§eOr write §ccancel §eto go back to " + genericDisplayedName() + " config menu");
|
||||
|
||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ 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;
|
||||
|
|
@ -70,13 +69,13 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
|
|||
|
||||
// check permission
|
||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
message = message.toLowerCase(Locale.ROOT);
|
||||
if ("cancel".equalsIgnoreCase(message)) {
|
||||
MsgUI.INSTANCE.getELEMENT_LIST_CANCELLED_NEW().send(player, genericDisplayedName());
|
||||
player.sendMessage(genericDisplayedName() + " creation cancelled...");
|
||||
show(player);
|
||||
return;
|
||||
}
|
||||
|
|
@ -87,7 +86,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)) {
|
||||
MsgUI.INSTANCE.getELEMENT_LIST_DUPLICATED_NEW().send(player, genericDisplayedName());
|
||||
player.sendMessage("§cPlease enter a " + genericDisplayedName() + " name that do not already exist...");
|
||||
// wait next message.
|
||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ 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;
|
||||
|
||||
|
|
@ -71,11 +70,11 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
|
|||
NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack);
|
||||
|
||||
if (!(meta instanceof Damageable)) {
|
||||
MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW().send(player);
|
||||
player.sendMessage("§cThis item can't be damaged, so it can't be repaired.");
|
||||
return;
|
||||
}
|
||||
if (type.equals(this.parentMaterial)) {
|
||||
MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_SAME_TYPE_NEW().send(player);
|
||||
player.sendMessage("§cItem can't repair something of the same type.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ 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.*;
|
||||
|
|
@ -114,7 +113,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
// test if group is used & cancel & warn user if so
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ 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;
|
||||
|
||||
|
|
@ -157,7 +156,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
if(testCantSave()) return;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ 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;
|
||||
|
|
@ -74,7 +73,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
new WorkPenaltyTypeSettingGui(parent).show(player);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ 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;
|
||||
|
|
@ -18,6 +17,8 @@ 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.
|
||||
*/
|
||||
|
|
@ -43,7 +44,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
@ -101,7 +102,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
goal.show(player);
|
||||
|
|
@ -126,7 +127,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();
|
||||
MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
|
||||
player.sendMessage(NO_EDIT_PERM);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ 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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
MsgUI.SHARED_CONFIG_NO_EDIT_PERM.send(sender)
|
||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||
return false
|
||||
}
|
||||
if(PlatformUtil.isFolia) {
|
||||
|
|
|
|||
|
|
@ -28,10 +28,9 @@ 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.IllegalStateException
|
||||
import java.lang.reflect.Constructor
|
||||
import java.util.logging.Level
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
|
|
@ -159,14 +158,18 @@ object DependencyManager {
|
|||
}
|
||||
|
||||
private fun logException(target: CommandSender, e: Exception) {
|
||||
CustomAnvil.logError(
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE,
|
||||
"Error while trying to handle custom anvil supported plugin: ",
|
||||
e
|
||||
)
|
||||
trackError(e)
|
||||
|
||||
// Finally, warn the player
|
||||
MsgWarning.DEPENDENCY_GENERIC_EXCEPTION.send(target)
|
||||
target.sendMessage(
|
||||
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
|
||||
ChatColor.RED.toString() + "Error while handling the anvil."
|
||||
)
|
||||
}
|
||||
|
||||
private fun logExceptionAndClear(view: AnvilView, e: Exception) {
|
||||
|
|
@ -334,14 +337,10 @@ object DependencyManager {
|
|||
|
||||
|
||||
private val prepareAnvilConstructor =
|
||||
PrepareAnvilEvent::class.java.constructors.first()
|
||||
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
||||
|
||||
fun createFakeEvent(view: AnvilView, result: ItemStack?): PrepareAnvilEvent {
|
||||
val result = prepareAnvilConstructor.newInstance(view, result)
|
||||
if(result !is PrepareAnvilEvent)
|
||||
throw IllegalStateException("Could not create a PrepareAnvilEvent ?")
|
||||
|
||||
return result
|
||||
return prepareAnvilConstructor.newInstance(view, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ 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
|
||||
|
|
@ -35,14 +34,12 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
|||
|
||||
}
|
||||
|
||||
fun getEcoLevelLimit(): Int {
|
||||
public 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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ 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() {
|
||||
|
|
|
|||
|
|
@ -10,20 +10,13 @@ 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) {
|
||||
// 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)
|
||||
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))
|
||||
}
|
||||
|
||||
ecoEnchantOldEnchantments = HashSet(enchantments)
|
||||
|
|
@ -38,13 +31,13 @@ class LegacyEcoEnchantDependency {
|
|||
// Add new enchantments
|
||||
for (ecoEnchant in newEnchantments)
|
||||
if (!this.ecoEnchantOldEnchantments!!.contains(ecoEnchant))
|
||||
registerEnchantment(ecoEnchant, ecoEnchant)
|
||||
EnchantmentApi.registerEnchantment(CALegacyEcoEnchant(ecoEnchant, ecoEnchant as Enchantment))
|
||||
|
||||
|
||||
// Remove old enchantments that not now currently used
|
||||
this.ecoEnchantOldEnchantments!!.removeAll(newEnchantments)
|
||||
for (oldEnchantment in this.ecoEnchantOldEnchantments!!) {
|
||||
unregisterEnchantment(oldEnchantment)
|
||||
EnchantmentApi.unregisterEnchantment(oldEnchantment as Enchantment)
|
||||
}
|
||||
|
||||
this.ecoEnchantOldEnchantments = HashSet(newEnchantments)
|
||||
|
|
|
|||
|
|
@ -18,13 +18,9 @@ class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
|||
getTokenMethod.trySetAccessible()
|
||||
}
|
||||
|
||||
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
|
||||
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<String> {
|
||||
if (item == null) return arrayOf()
|
||||
return getTokenMethod.invoke(this, item) as Array<String>
|
||||
}
|
||||
|
||||
override fun testAnvilResult(event: InventoryClickEvent): Boolean {
|
||||
|
|
|
|||
|
|
@ -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("config-ui.$key", *params)
|
||||
class UIMessage(key: String, vararg params: String) : Message("ui.$key", *params)
|
||||
|
|
@ -1,21 +1,6 @@
|
|||
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")
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -15,6 +15,4 @@ 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")
|
||||
|
||||
}
|
||||
|
|
@ -90,23 +90,3 @@ 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."
|
||||
Loading…
Add table
Add a link
Reference in a new issue