diff --git a/eco-api/build.gradle b/eco-api/build.gradle index b7bba69c..a5ed23d8 100644 --- a/eco-api/build.gradle +++ b/eco-api/build.gradle @@ -13,6 +13,7 @@ dependencies { compileOnly 'net.kyori:adventure-text-serializer-gson:4.8.1' compileOnly 'net.kyori:adventure-text-serializer-legacy:4.8.1' compileOnly 'net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT' + compileOnly 'net.kyori:adventure-platform-bukkit:4.0.0' } java { diff --git a/eco-api/src/main/java/com/willfp/eco/core/Handler.java b/eco-api/src/main/java/com/willfp/eco/core/Handler.java index b8976df7..15581347 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/Handler.java +++ b/eco-api/src/main/java/com/willfp/eco/core/Handler.java @@ -15,6 +15,7 @@ import com.willfp.eco.core.proxy.Cleaner; import com.willfp.eco.core.proxy.ProxyFactory; import com.willfp.eco.core.requirement.RequirementFactory; import com.willfp.eco.core.scheduling.Scheduler; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -201,5 +202,14 @@ public interface Handler { * * @return The factory. */ + @NotNull RequirementFactory getRequirementFactory(); + + /** + * Get Adventure audiences. + * + * @return The audiences. + */ + @NotNull + BukkitAudiences getAdventure(); } diff --git a/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java new file mode 100644 index 00000000..bcdb8002 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java @@ -0,0 +1,36 @@ +package com.willfp.eco.util; + +import com.willfp.eco.core.Eco; +import lombok.experimental.UtilityClass; +import net.kyori.adventure.audience.Audience; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +/** + * Utilities / API methods for players. + */ +@UtilityClass +public class PlayerUtils { + /** + * Get the audience from a player. + * + * @param player The player. + * @return The audience. + */ + @NotNull + public Audience getAudience(@NotNull final Player player) { + return Eco.getHandler().getAdventure().player(player); + } + + /** + * Get the audience from a command sender. + * + * @param sender The command sender. + * @return The audience. + */ + @NotNull + public Audience getAudience(@NotNull final CommandSender sender) { + return Eco.getHandler().getAdventure().sender(sender); + } +} diff --git a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java index 58a43e92..1e07af36 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java @@ -27,7 +27,7 @@ import static net.md_5.bungee.api.ChatColor.COLOR_CHAR; * Utilities / API methods for strings. */ @UtilityClass -public class StringUtils { +public class StringUtils { /** * Regexes for gradients. */ @@ -370,6 +370,33 @@ public class StringUtils { ); } + /** + * Convert legacy (bukkit) text to Component. + * + * @param legacy The legacy text. + * @return The component. + */ + @NotNull + public Component toComponent(@Nullable final String legacy) { + String processed = legacy; + if (legacy == null) { + processed = ""; + } + + return LEGACY_COMPONENT_SERIALIZER.deserialize(processed); + } + + /** + * Convert Component to legacy (bukkit) text. + * + * @param component The component. + * @return The legacy text. + */ + @NotNull + public String toLegacy(@NotNull final Component component) { + return LEGACY_COMPONENT_SERIALIZER.serialize(component); + } + /** * Options for formatting. */ diff --git a/eco-core/core-backend/build.gradle b/eco-core/core-backend/build.gradle index 93d6594c..ed1d62a9 100644 --- a/eco-core/core-backend/build.gradle +++ b/eco-core/core-backend/build.gradle @@ -5,4 +5,6 @@ dependencies { compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT' compileOnly 'me.clip:placeholderapi:2.10.9' compileOnly 'org.reflections:reflections:0.9.12' + compileOnly 'net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT' + compileOnly 'net.kyori:adventure-platform-bukkit:4.0.0' } \ No newline at end of file diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/ExtendedInventory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/ExtendedInventory.kt index edaf15ac..b16e019a 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/ExtendedInventory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/ExtendedInventory.kt @@ -18,9 +18,7 @@ class ExtendedInventory( fun refresh(player: Player) { captiveItems.clear() for (i in 0 until inventory.size) { - val pair = MenuUtils.convertSlotToRowColumn(i) - val row = pair.first!! - val column = pair.second!! + val (row, column) = MenuUtils.convertSlotToRowColumn(i) val slot = menu.getSlot(row, column) if (slot is EcoCaptivatorSlot) { val defaultItem = slot.getItemStack(player) diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 7f416ed3..5a2dc068 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -23,6 +23,8 @@ dependencies { compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0' compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7' compileOnly 'me.arcaniax:HeadDatabase-API:1.2.0' + compileOnly 'net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT' + compileOnly 'net.kyori:adventure-platform-bukkit:4.0.0' // CombatLogX V10 + NewbieHelper Expansion compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT' diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoHandler.kt index a3ed6851..83126aea 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoHandler.kt @@ -35,6 +35,7 @@ import com.willfp.eco.internal.requirement.EcoRequirementFactory import com.willfp.eco.internal.scheduling.EcoScheduler import com.willfp.eco.proxy.FastItemStackFactoryProxy import com.willfp.eco.spigot.integrations.bstats.MetricHandler +import net.kyori.adventure.platform.bukkit.BukkitAudiences import org.bukkit.inventory.ItemStack import java.util.logging.Logger @@ -42,6 +43,7 @@ import java.util.logging.Logger class EcoHandler : EcoSpigotPlugin(), Handler { private val cleaner = EcoCleaner() private val requirementFactory = EcoRequirementFactory() + private val adventure = BukkitAudiences.create(this); override fun createScheduler(plugin: EcoPlugin): Scheduler { return EcoScheduler(plugin) @@ -126,4 +128,8 @@ class EcoHandler : EcoSpigotPlugin(), Handler { override fun getRequirementFactory(): RequirementFactory { return requirementFactory } + + override fun getAdventure(): BukkitAudiences { + return adventure + } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt index c17c5123..bd68d174 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt @@ -23,9 +23,7 @@ class GUIListener(private val plugin: EcoPlugin) : Listener { return } val menu = MenuHandler.getMenu(event.clickedInventory ?: return) ?: return - val rowColumn = MenuUtils.convertSlotToRowColumn(event.slot) - val row = rowColumn.first!! - val column = rowColumn.second!! + val (row, column) = MenuUtils.convertSlotToRowColumn(event.slot) val slot = menu.getSlot(row, column) Validate.isTrue(slot is EcoSlot, "Slot not instance of EcoSlot!") val ecoSlot = menu.getSlot(row, column) as EcoSlot diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index adf415cc..55735128 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -32,4 +32,5 @@ libraries: - net.kyori:adventure-text-serializer-gson:4.8.1 - net.kyori:adventure-text-serializer-legacy:4.8.1 - net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT - - org.jetbrains.kotlin:kotlin-stdlib:1.5.21 \ No newline at end of file + - org.jetbrains.kotlin:kotlin-stdlib:1.5.21 + - net.kyori:adventure-platform-bukkit:4.0.0 \ No newline at end of file