mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
dialog rename working good enough
This commit is contained in:
parent
05951d0ace
commit
31f9e7e281
9 changed files with 276 additions and 27 deletions
|
|
@ -7,6 +7,7 @@ import org.bukkit.event.Listener
|
|||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.AnvilInventory
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
|
||||
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
|
||||
|
||||
class AnvilCloseListener(private val packetManager: PacketManager) : Listener {
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ class AnvilCloseListener(private val packetManager: PacketManager) : Listener {
|
|||
packetManager.setInstantBuild(player, false)
|
||||
}
|
||||
|
||||
AnvilRenameDialogUtil.anvilRenameDialog.closeInventory(player)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import org.bukkit.event.EventPriority
|
|||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.inventory.AnvilInventory
|
||||
import org.bukkit.inventory.InventoryView
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
|
@ -26,6 +27,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
|||
import xyz.alexcrea.cuanvil.util.*
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
|
|
@ -41,6 +43,8 @@ class PrepareAnvilListener : Listener {
|
|||
const val ANVIL_OUTPUT_SLOT = 2
|
||||
|
||||
var IS_EMPTY_TEST = false
|
||||
|
||||
const val RENAME_DIALOG_PERMISSION = "ca.rename.dialog"
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,6 +84,8 @@ class PrepareAnvilListener : Listener {
|
|||
return
|
||||
}
|
||||
|
||||
tryRenameDialog(player, event)
|
||||
|
||||
// Test if the event should bypass custom anvil.
|
||||
if (DependencyManager.tryEventPreAnvilBypass(event, player)) {
|
||||
// even if we got bypassed we still want to set price
|
||||
|
|
@ -117,6 +123,16 @@ class PrepareAnvilListener : Listener {
|
|||
|
||||
}
|
||||
|
||||
private fun tryRenameDialog(
|
||||
player: HumanEntity,
|
||||
event: PrepareAnvilEvent
|
||||
) {
|
||||
if(!ConfigOptions.doRenameDialog || !AnvilRenameDialogUtil.anvilRenameDialog.canSendDialog()) return
|
||||
if(ConfigOptions.doRenameDialogUsePermission && !player.hasPermission(RENAME_DIALOG_PERMISSION)) return
|
||||
|
||||
AnvilRenameDialogUtil.anvilRenameDialog.tryShowDialog(player, event)
|
||||
}
|
||||
|
||||
private fun isImmutable(item: ItemStack?): Boolean {
|
||||
if (item.isAir) return false
|
||||
|
||||
|
|
@ -208,11 +224,8 @@ class PrepareAnvilListener : Listener {
|
|||
var useColor = false
|
||||
if (ConfigOptions.renameColorPossible && renameText != null) {
|
||||
val component = AnvilColorUtil.handleColor(
|
||||
renameText, player,
|
||||
ConfigOptions.permissionNeededForColor,
|
||||
ConfigOptions.allowColorCode, ConfigOptions.allowHexadecimalColor, ConfigOptions.allowMinimessage,
|
||||
AnvilColorUtil.ColorUseType.RENAME
|
||||
)
|
||||
renameText,
|
||||
AnvilColorUtil.renamePermission(player))
|
||||
|
||||
if (component != null) {
|
||||
renameText = MiniMessageUtil.legacy_mm.serialize(component)
|
||||
|
|
|
|||
|
|
@ -60,25 +60,11 @@ object AnvilColorUtil {
|
|||
return ColorPermissions(canUseColorCode, canUseHexColor, canUseMinimessage, player)
|
||||
}
|
||||
|
||||
/**
|
||||
* Color a string depending on allowed color type, color use type and player permissions
|
||||
* @return colored component or null if nothing has been colored
|
||||
*/
|
||||
fun handleColor(
|
||||
textToColorText: String,
|
||||
player: Permissible,
|
||||
usePermission: Boolean,
|
||||
allowColorCode: Boolean,
|
||||
allowHexadecimalColor: Boolean,
|
||||
allowMinimessage: Boolean,
|
||||
useType: ColorUseType
|
||||
): Component? {
|
||||
val permission = calculatePermissions(
|
||||
player, usePermission,
|
||||
allowColorCode, allowHexadecimalColor, allowMinimessage,
|
||||
useType
|
||||
)
|
||||
return handleColor(textToColorText, permission)
|
||||
fun renamePermission(player: Permissible): ColorPermissions {
|
||||
return calculatePermissions(player,
|
||||
ConfigOptions.permissionNeededForColor,
|
||||
ConfigOptions.allowColorCode, ConfigOptions.allowHexadecimalColor, ConfigOptions.allowMinimessage,
|
||||
ColorUseType.RENAME)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package xyz.alexcrea.cuanvil.util.dialog
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import net.kyori.adventure.text.Component
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||
import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialog
|
||||
import xyz.alexcrea.cuanvil.dialog.AnvilRenameDialogImpl
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
import xyz.alexcrea.cuanvil.util.AnvilColorUtil
|
||||
|
||||
object AnvilRenameDialogUtil {
|
||||
|
||||
val anvilRenameDialog: AnvilRenameDialog;
|
||||
|
||||
init {
|
||||
val version = UpdateUtils.currentMinecraftVersion()
|
||||
anvilRenameDialog = (if(!PlatformUtil.isPaper ||
|
||||
(version.major <= 1 && version.minor <= 21 && version.patch <= 6)) {
|
||||
NoImplAnvilRenameDialog()
|
||||
} else {
|
||||
AnvilRenameDialogImpl({ player, component -> AnvilColorUtil.revertColorSmallest(
|
||||
component, AnvilColorUtil.renamePermission(player)
|
||||
) },
|
||||
{ ConfigOptions.renameDialogMaxSize },
|
||||
CustomAnvil.instance,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
class NoImplAnvilRenameDialog: AnvilRenameDialog {
|
||||
|
||||
override fun canSendDialog(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun tryShowDialog(
|
||||
player: HumanEntity,
|
||||
event: PrepareAnvilEvent
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
override fun closeInventory(player: HumanEntity) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,9 @@ permission_needed_for_color: true
|
|||
use_of_color_cost: 0
|
||||
|
||||
# Dialogue rename menu make use of dialog menu to allow bigger rename
|
||||
# You can change the maximum size
|
||||
# You can also change the maximum size up to 2147483647
|
||||
#
|
||||
# This feature only work on paper 1.21.7 or later
|
||||
#
|
||||
# At the moment only english is available for this menu... sorry !
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue