mirror of
https://github.com/Auxilor/Reforges.git
synced 2025-12-24 01:19:31 +00:00
Added display-in-name
This commit is contained in:
@@ -47,6 +47,9 @@ allprojects {
|
||||
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.20'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
|
||||
@@ -29,7 +29,6 @@ public class ReforgesPlugin extends EcoPlugin {
|
||||
/**
|
||||
* Instance of Reforges.
|
||||
*/
|
||||
@Getter
|
||||
private static ReforgesPlugin instance;
|
||||
|
||||
/**
|
||||
@@ -103,4 +102,13 @@ public class ReforgesPlugin extends EcoPlugin {
|
||||
public String getMinimumEcoVersion() {
|
||||
return "6.8.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of Reforges.
|
||||
*
|
||||
* @return The instance.
|
||||
*/
|
||||
public static ReforgesPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ReforgeGUI {
|
||||
/**
|
||||
* The reforge GUI.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.reforges.vault;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
@@ -8,14 +7,12 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
@UtilityClass
|
||||
public class EconomyHandler {
|
||||
public final class EconomyHandler {
|
||||
/**
|
||||
* The instance.
|
||||
*/
|
||||
@Getter
|
||||
private static Economy instance = null;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private static boolean enabled = false;
|
||||
|
||||
@@ -24,7 +21,7 @@ public class EconomyHandler {
|
||||
*
|
||||
* @return If was successful.
|
||||
*/
|
||||
public boolean init() {
|
||||
public static boolean init() {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
@@ -32,4 +29,12 @@ public class EconomyHandler {
|
||||
instance = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Economy getInstance() {
|
||||
return EconomyHandler.instance;
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return EconomyHandler.enabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,21 @@ import com.willfp.eco.core.display.DisplayPriority
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.util.SkullUtils
|
||||
import com.willfp.reforges.ReforgesPlugin
|
||||
import com.willfp.reforges.paper.toBukkit
|
||||
import com.willfp.reforges.paper.toComponent
|
||||
import com.willfp.reforges.reforges.meta.ReforgeTarget
|
||||
import com.willfp.reforges.reforges.util.ReforgeUtils
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.TextReplacementConfig
|
||||
import net.kyori.adventure.text.format.TextDecoration
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.SkullMeta
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin, DisplayPriority.HIGHEST) {
|
||||
private val shadowKey = plugin.namespacedKeyFactory.create("shadowed_name")
|
||||
|
||||
override fun display(
|
||||
itemStack: ItemStack,
|
||||
vararg args: Any
|
||||
@@ -52,7 +56,7 @@ class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin
|
||||
meta.setDisplayName(plugin.configYml.getString("reforge.stone.name").replace("%reforge%", stone.name))
|
||||
SkullUtils.setSkullTexture(
|
||||
meta as SkullMeta,
|
||||
SkullUtils.getSkullTexture(stone.stone.itemMeta as SkullMeta) ?: return
|
||||
stone.config.getString("stone.texture")
|
||||
)
|
||||
itemStack.itemMeta = meta
|
||||
val stoneLore = plugin.configYml.getStrings("reforge.stone.lore").map {
|
||||
@@ -69,41 +73,20 @@ class ReforgesDisplay(private val plugin: ReforgesPlugin) : DisplayModule(plugin
|
||||
addLore.replaceAll { "${Display.PREFIX}$it" }
|
||||
lore.addAll(addLore)
|
||||
}
|
||||
if (plugin.configYml.getBool("reforge.display-in-name")) {
|
||||
if (Prerequisite.HAS_PAPER.isMet) {
|
||||
val displayName = itemStack.displayName().toBukkit()
|
||||
val newName = "${reforge.name} ${ChatColor.RESET}${displayName}"
|
||||
meta.setDisplayName(newName)
|
||||
meta.persistentDataContainer.set(
|
||||
plugin.namespacedKeyFactory.create("shadowed_name"),
|
||||
PersistentDataType.STRING,
|
||||
displayName
|
||||
)
|
||||
}
|
||||
if (plugin.configYml.getBool("reforge.display-in-name") && Prerequisite.HAS_PAPER.isMet) {
|
||||
var displayName = if (meta.hasDisplayName()) meta.displayName()!! else Component.translatable(itemStack)
|
||||
displayName = displayName.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.matchLiteral(ChatColor.stripColor(reforge.name + " "))
|
||||
.replacement("")
|
||||
.build()
|
||||
)
|
||||
val newName = reforge.name.toComponent().decoration(TextDecoration.ITALIC, false)
|
||||
.append(Component.text(" ").append(displayName))
|
||||
meta.displayName(newName)
|
||||
}
|
||||
}
|
||||
itemStack.itemMeta = meta
|
||||
fastItemStack.lore = lore
|
||||
}
|
||||
|
||||
override fun revert(itemStack: ItemStack) {
|
||||
if (!plugin.configYml.getBool("reforge.display-in-name")) {
|
||||
return
|
||||
}
|
||||
|
||||
val target = ReforgeTarget.getForItem(itemStack)
|
||||
|
||||
if (target == null && itemStack.type != Material.PLAYER_HEAD) {
|
||||
return
|
||||
}
|
||||
|
||||
val meta = itemStack.itemMeta ?: return
|
||||
val shadowed = meta.persistentDataContainer.get(
|
||||
plugin.namespacedKeyFactory.create("shadowed_name"),
|
||||
PersistentDataType.STRING
|
||||
) ?: return
|
||||
meta.setDisplayName(shadowed)
|
||||
|
||||
itemStack.itemMeta = meta
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ private val serializer = LegacyComponentSerializer.builder()
|
||||
.character('§')
|
||||
.build()
|
||||
|
||||
|
||||
fun String.toComponent(): Component {
|
||||
return serializer.deserialize(this)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.*
|
||||
|
||||
class Reforge(
|
||||
private val config: JSONConfig,
|
||||
internal val config: JSONConfig,
|
||||
private val plugin: ReforgesPlugin
|
||||
) {
|
||||
val id = config.getString("id")
|
||||
@@ -35,7 +35,7 @@ class Reforge(
|
||||
|
||||
val stone: ItemStack = SkullBuilder().apply {
|
||||
if (config.has("stone.texture")) {
|
||||
setSkullTexture(config.getString("texture"))
|
||||
setSkullTexture(config.getString("stone.texture"))
|
||||
}
|
||||
setDisplayName(plugin.configYml.getString("stone.name").replace("%reforge%", name))
|
||||
addLoreLines(
|
||||
|
||||
@@ -135,9 +135,6 @@ class WatcherTriggers(
|
||||
}
|
||||
val player = event.player
|
||||
for (itemStack in player.inventory.armorContents) {
|
||||
if (itemStack == null) {
|
||||
continue
|
||||
}
|
||||
val reforge = ReforgeUtils.getReforge(itemStack) ?: continue
|
||||
for ((effect, config) in reforge.effects) {
|
||||
if (NumberUtils.randFloat(0.0, 100.0) > config.getDoubleOrNull("chance") ?: 100.0) {
|
||||
|
||||
Reference in New Issue
Block a user