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