Featherboard custom placeholder not updating

Discussion in 'Plugin Development' started by OTF Catastrophe, Jan 2, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    OTF Catastrophe

    So I have two separate custom placeholders inside an Addons plugin for my server. One grabs the amount of GalacticCrate keys a player has from CrazyCrates and one grabs your KD Ratio from a plugin called ProSkyWars. The crate key placeholder works fine and updates immediately but the KD Ratio from ProSkyWars only updates if you reload ProSkyWars or restart the server. Unfortunately ProSkyWars doesn't have an automatic KD Ration calculation I had to make it myself. The number displays fine after the reload of the plugin and or restart of the server. I was just wondering why the CrazyCrates placeholder updates automatically but the ProSkyWars placeholder doesn't. Here's my code:


    Code:
    public static api skywarsAPI;
       
        @Override
        public void onEnable()
        {
           
            getServer().getPluginManager().registerEvents(new BlockPlace(), this);
           
            super.onEnable();
                   
            PlaceholderAPI.registerOfflinePlaceholder("galacticcrate", true, new PlaceholderRequestEventHandler()
            {
    
                public String onPlaceholderRequest(PlaceholderRequestEvent e)
                {
                           
                    return getKeys(e.getPlayer().getUniqueId());
                           
                }
                   
            });
           
            PlaceholderAPI.registerOfflinePlaceholder("proskywars_kd", true, new PlaceholderRequestEventHandler()
            {
    
                public String onPlaceholderRequest(PlaceholderRequestEvent e)
                {
                           
                    return getKD(e.getPlayer().getUniqueId());
                           
                }
                   
            });
       
        }
       
        public String getKeys(UUID uuid)
        {
           
            File folder = new File("plugins/CrazyCrates/data.yml");
            final FileConfiguration customConfig = YamlConfiguration.loadConfiguration(folder);
               
            String keys = customConfig.getString("Players." + uuid + ".Galactic");
            return keys;
           
        }
    
        public String getKD(UUID uuid)
        {
           
            File pswFolder = new File("plugins/ProSkyWars/playerdata/" + uuid + ".yml");
            final FileConfiguration pswConfig = YamlConfiguration.loadConfiguration(pswFolder);
               
            double kills = pswConfig.getInt("statistics.kills");
            double deaths = pswConfig.getInt("statistics.deaths");
           
            double kd = (kills / deaths);
           
            if (kills < deaths)
            {
               
                DecimalFormat negativeKD = new DecimalFormat("0.##");
                negativeKD.format(kd);
               
                double number = kd;
    
                number = Math.round(number * 100);
                number = number/100;
    
                return String.valueOf(number);
               
            }
           
            else
            {
               
                DecimalFormat positiveKD = new DecimalFormat("1.##");
                positiveKD.format(kd);
               
                double number = kd;
    
                number = Math.round(number * 100);
                number = number/100;
    
                return String.valueOf(number);
               
            }
    
        }
     
  2. Offline

    I Al Istannen

    @OTF Catastrophe
    My guess would be that ProSkyWars does only save its data in onDisable, which means your plugin will read outdated data.

    Hook into their API to get the kills and deaths and work with that.

    And maybe make your two decimal formats a constant. And shouldn't [new DecimalFormat("0.##")] cover both, negative and positive KDRs?
     
  3. Offline

    OTF Catastrophe

    See, I was thinking that too but PlaceholderAPI supports ProSkyWars placeholders so I can put things like kills and deaths on the scoreboard and it updates automatically. So I'm starting to believe it might just be trying to get data before the data updates. I believe this could be it because player data might not actually update until the end of the match. Therefore making it try to calculate it before data is finalized.

    I tried hooking into their api and I'm having some issues if you don't mind helping me out with em' aha :) The issue is, I have to grab the KD Ratio from a method that uses UUID because Featherboard requires it. But the api with ProSkyWars needs a player instance. I'm not entirely sure how I'd go about writing this out. I have the method for getting the KD but could you point me in the right direction of how to make a method that grabs a player?
     
  4. Offline

    I Al Istannen

    @OTF Catastrophe
    So, you want to grab it by UUID but ProSkyWars only allows Players? Could you link me to the ProSkyWars plugin and any documentation/source code for it?

    And the scoreboard placeholder is probably supplied by ProSkyWars itself, and they know what the up-to-date data is. They can access the one in the RAM, not the one saved to file.
     
  5. Offline

    OTF Catastrophe

    [quote uid=91064682 name="I Al Istannen" post=3464793]@OTF Catastrophe
    So, you want to grab it by UUID but ProSkyWars only allows Players? Could you link me to the ProSkyWars plugin and any documentation/source code for it?

    And the scoreboard placeholder is probably supplied by ProSkyWars itself, and they know what the up-to-date data is. They can access the one in the RAM, not the one saved to file.[/QUOTE]
    <Edit by Moderator: Redacted not allowed paid resource url>

    The API is under Setup if you scroll down a bit. It's a very simple api, he recently added some new stuff in the update logs.

    EDIT: Also just wanted to say thank you for taking your time to try and help me! :)
    EDIT: And sorry it was a quick reply, yes it only allows players.
     
    Last edited by a moderator: Jan 2, 2017
  6. Offline

    I Al Istannen

    @OTF Catastrophe
    Ugh, it is a premium plugin, so no looking at the source for me.
    This limits my ability to help to basically zero.

    I am quite sure you have no way of getting the data from the file, as the saving is not done the moment the change coccurs. That would be way to inefficient.

    This means you will need to grab the data from the API/"hack" the plugin to return it.

    He may have had some great reason to make it only accept a player, but I heavily doubt it. Ask him to add an API using UUIDs!

    With "hacking" it, I mean getting to know its internal structure and using i.e. reflection to extract what you need. I wouldn't reccommend it, as that may change.

    TL;DR: Ask the developer why he chose to make the method accept a Player and not an UUID. I doubt there is any reason for not accepting a UUID.
     
  7. Offline

    OTF Catastrophe

    @I Al Istannen I don't know if it's against the rules or not but if I provide what's posted under the API section could that help? :')

    Honestly the whole plugin revoles around uuid's even the player files so I have no idea why in the world he would use player instances as opposed to uuids lmao. I'll definitely ask him to make uuid support for his API. Thank you for your help anyhow man, I appreciate it aha! :)
     
  8. Offline

    I Al Istannen

    @OTF Catastrophe
    From a quick glance that section revealed absolutely nothing about why he chose that way.

    Your only chance is asking him. If it was an open source plugin, I probably could have hacked together a solution in under 5 minutes for the time before he updates :D

    Have a nice day and sorry I couldn't help that much :/
     
  9. Offline

    OTF Catastrophe

    I tagged him in the discussion thread and I'll wait for a response. But don't worry about it, thank you for trying ^-^ Have a good day.

    EDIT: I don't think I should set this to solved just in case someone else eventually see's this post looking for an answer. Could a moderator lock it?
     
  10. Offline

    I Al Istannen

    @OTF Catastrophe
    Look at the link in the Bold text above. The plugin page stated to contact him using freshdesk for issues. You may want to follow that ;)

    Thanks though :)
     
Thread Status:
Not open for further replies.

Share This Page