PluginBugs / Issues-ItemsAdder

Repository used to keep track of issues of my plugin ItemsAdder
https://itemsadder.devs.beer
53 stars 21 forks source link

HUD API doesn't work #2828

Closed Maxlego08 closed 1 year ago

Maxlego08 commented 1 year ago

Terms

Discord tag (optional)

maxlego08

What happened?

When using a quantity HUD with the API, nothing works - it's not displayed. However, using the API we can display a custom HUD (to display numbers). However, using the /iaplayerstat write Maxlego08 team 11 the image will be displayed correctly.

Desired result: image

Obtained result: image

Steps to reproduce the issue

We were in 1.18.2 and ItemAdder 3.4.1-R5 there was no problem, since we switched to 1.19.4 with ItemAdder 3.5.0c the API that will handle the quantity HUD type does not work. The code has not been changed, the custom huds work perfectly.

Server version

image

ItemsAdder Version

image

ProtocolLib Version

image

LoneLibs Version

image

FULL server log

latest.log

Error (optional)

No response

Problematic items yml configuration file (optional)

info:
  namespace: w_icons
huds:

  money:
    enabled: true
    show:
      auto: false
    type: CUSTOM

  money_gold:
    enabled: true
    show:
      auto: false
    type: CUSTOM

  team_hud:
    enabled: true
    show:
      auto: false
      creative: true
    type: FRAMES
    x_position_pixels: -42
    value:
      player_stat_name: team
      start: 0
      min: 0
      max: 22
    images:
      frames:
      - w_icons:transp
      - w_icons:bs_bleu #bleu float 1
      - w_icons:bs_rouge #rouge float 2
      - w_icons:blue_team #bw float 3
      - w_icons:lime_team #bw float 4 
      - w_icons:red_team #bw float 5
      - w_icons:team_cyan #bw float 6 
      - w_icons:team_jaune #bw float 7
      - w_icons:team_orange #bw float 8 
      - w_icons:team_rose #bw float 9 
      - w_icons:team_violet #bw float 10  
      - w_icons:passe #bw float 11 
      - w_icons:passe_anim_gold0 #bw float 12
      - w_icons:passe_anim_gold1 #bw float 13
      - w_icons:passe_anim_gold2 #bw float 14
      - w_icons:passe_anim_gold3 #bw float 15
      - w_icons:passe_anim_gold4 #bw float 16
      - w_icons:passe_anim_gold5 #bw float 17
      - w_icons:passe_anim_gold6 #bw float 18
      - w_icons:passe_anim_gold7 #bw float 19
      - w_icons:passe_anim_gold8 #bw float 20
      - w_icons:passe_anim_gold9 #bw float 21
      - w_icons:passe_anim_gold10 #bw float 22

Other files, you can drag and drop them here to upload. (optional)

Example of using custom HUD with code present in the document:

package fr.wyntale.wynhub.commands

import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper
import dev.lone.itemsadder.api.FontImages.PlayerQuantityHudWrapper
import fr.wyntale.api.core.player.rank.Permission
import fr.wyntale.core.WynCore
import fr.wyntale.core.command.PlayerCommand
import fr.wyntale.core.player.WynPlayer
import fr.wyntale.core.player.hud.PlayerHud
import org.bukkit.Bukkit
import org.bukkit.command.Command

object CommandTestAnimation : PlayerCommand(
    permission = Permission.ROOT
) {
    val values = listOf(11f, 12f, 13f, 14f, 15f, 16f, 17f, 18f, 19f, 20f, 21f, 22f, 11f)

    private lateinit var huds : PlayerHudsHolderWrapper

    override suspend fun onPlayerCommand(
        wynPlayer: WynPlayer, command: Command, label: String, args: Array<out String>
    ) {
        huds = PlayerHudsHolderWrapper(wynPlayer.getBukkitPlayer())
        val teamHud = PlayerQuantityHudWrapper(huds, "w_icons:team_hud")

        val hud = wynPlayer.getHud()
        animation(wynPlayer, 0, teamHud)
    }

    private fun animation(wynPlayer: WynPlayer, index: Int, hud: PlayerQuantityHudWrapper) {

        if (index >= values.size) return

        println("Index: $index - Value: ${values[index]}")

        hud.floatValue = values[index]

        Bukkit.getScheduler().runTaskLater(WynCore.instance, Runnable { animation(wynPlayer, index + 1, hud) }, 20)
    }

    override suspend fun onPlayerTabComplete(
        wynPlayer: WynPlayer, command: Command, alias: String, args: Array<out String>
    ): List<String> = emptyList()
}

Using the API with code based on HUD RPG sources:

package fr.wyntale.wynhub.commands

import fr.wyntale.api.core.player.rank.Permission
import fr.wyntale.core.WynCore
import fr.wyntale.core.command.PlayerCommand
import fr.wyntale.core.player.WynPlayer
import fr.wyntale.core.player.hud.PlayerHud
import org.bukkit.Bukkit
import org.bukkit.command.Command

object CommandTestAnimation : PlayerCommand(
    permission = Permission.ROOT
) {
    val values = listOf(11f, 12f, 13f, 14f, 15f, 16f, 17f, 18f, 19f, 20f, 21f, 22f, 11f)

    override suspend fun onPlayerCommand(
        wynPlayer: WynPlayer, command: Command, label: String, args: Array<out String>
    ) {
        val hud = wynPlayer.getHud()
        animation(wynPlayer, 0, hud)
    }

    private fun animation(wynPlayer: WynPlayer, index: Int, hud: PlayerHud) {

        if (index >= values.size) return

        println("Index: $index - Value: ${values[index]}")

        hud.setFloatValue("w_icons:team_hud", values[index])
        hud.sendPacket()

        Bukkit.getScheduler().runTaskLater(WynCore.instance, Runnable { animation(wynPlayer, index + 1, hud) }, 20)
    }

    override suspend fun onPlayerTabComplete(
        wynPlayer: WynPlayer, command: Command, alias: String, args: Array<out String>
    ): List<String> = emptyList()
}

Screenshots/Videos (you can drag and drop files or paste links)

No response

LoneDev6 commented 1 year ago

This was already reported: https://github.com/PluginBugs/Issues-ItemsAdder/issues/2454#issuecomment-1496391406 And this is the answer of your team member:

Okay my bad seems that i did something wrong, so I did reinstall the plugins and refreshing once again the pack its fixed for hud display


Please test if this plugin works: https://www.spigotmc.org/resources/plugin-servermonitor-for-itemsadder.78112/

Code: https://github.com/LoneDev6/API-ItemsAdder-Example-ServerMonitor/blob/a7d852a966ae1665ba61710ea6a75d54197473e5/src/main/java/dev/lone/ServerMonitor/PlayerDataHolder.java#L23

It loads just fine for me. image

Maxlego08 commented 1 year ago

I just tried again using your example code, something really simple. Still with the same HUD file configuration, you have an example video and the code used. However, with the command /iaplayerstats everything works perfectly. I don’t understand or maybe my mistake with the API.

Video: https://github.com/PluginBugs/Issues-ItemsAdder/assets/32517160/00c19672-fd22-4934-bce9-e337fa27ac37

Code:

package fr.wyntale.wynhub.hud

import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper
import dev.lone.itemsadder.api.FontImages.PlayerQuantityHudWrapper
import fr.wyntale.core.command.CommandModule
import fr.wyntale.core.command.PlayerCommand
import fr.wyntale.core.listener.WynPlayerJoinEvent
import fr.wyntale.core.listener.WynPlayerQuitEvent
import fr.wyntale.core.module.ModuleManager
import fr.wyntale.core.player.WynPlayer
import org.bukkit.command.Command
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import java.util.*

object HudManagerV2 : Listener {

    private var lastId = 1.0f
    private val users = mutableMapOf<UUID, PlayerDataHolder>()

    init {
        ModuleManager.getModule(CommandModule::class.java).registerCommand("testhud", CommandTestClass())
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    fun onJoin(event: WynPlayerJoinEvent) {
        val player = event.wynPlayer.getBukkitPlayer()
        users[player.uniqueId] = PlayerDataHolder(player)
    }

    class CommandTestClass : PlayerCommand() {

        override suspend fun onPlayerCommand(
            wynPlayer: WynPlayer,
            command: Command,
            label: String,
            args: Array<out String>
        ) {
            val holder = users[wynPlayer.getUniqueId()] ?: return
            holder.teamHud.isVisible = true
            println("Je vais mettre l'id: '$lastId'")
            holder.teamHud.floatValue = lastId
            lastId += 1f
        }

        override suspend fun onPlayerTabComplete(
            wynPlayer: WynPlayer,
            command: Command,
            alias: String,
            args: Array<out String>
        ): List<String> = emptyList()

    }

    class PlayerDataHolder(player: Player) {

        val holder: PlayerHudsHolderWrapper
        val teamHud: PlayerQuantityHudWrapper

        init {
            holder = PlayerHudsHolderWrapper(player)
            teamHud = PlayerQuantityHudWrapper(holder, "w_icons:team_hud")
            println("Start: $holder -> $teamHud")
        }
    }
}
LoneDev6 commented 1 year ago

Please first check if my plugin works on your server as I asked.

Maxlego08 commented 1 year ago

image The plugin does not work at all.

LoneDev6 commented 1 year ago

did you actually read the installation guide?

How to install?

  • extract the content of this .zip file inside plugins/ItemsAdder folder
  • use the command /iazip

You probably didn't download the assets.

LoneDev6 commented 1 year ago

News? Please check if my plugin works on your server as I asked.

Maxlego08 commented 1 year ago

Hey, yes your plugin works ok thé server

Maxlego08 commented 1 year ago

I went through a custom HUD and I will put the image directly. Everything works very well now. But there is clearly a problem with quantity HUDs. image

LoneDev6 commented 1 year ago

Sorry I don't understand what you want me to do and what is the issue, nor how you fixed the problem.

Maxlego08 commented 1 year ago

Sorry I don't understand what you want me to do and what is the issue, nor how you fixed the problem.

I just passed the HUD in custom and not in quantity and I have no more problems, its good

LoneDev6 commented 1 year ago

Okay but still I think the issue is related to your own code since I provided a working quantity hud here.